Annotation of loncom/interface/domainprefs.pm, revision 1.330
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.330 ! raeburn 4: # $Id: domainprefs.pm,v 1.329 2018/07/06 04:23:58 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 107: (official, unofficial, community, textbook, placement, and lti).
1.271 raeburn 108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.1 raeburn 179:
1.155 raeburn 180: my $registered_cleanup;
181: my $modified_urls;
182:
1.1 raeburn 183: sub handler {
184: my $r=shift;
185: if ($r->header_only) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: return OK;
189: }
190:
1.91 raeburn 191: my $context = 'domain';
1.1 raeburn 192: my $dom = $env{'request.role.domain'};
1.5 albertel 193: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 194: if (&Apache::lonnet::allowed('mau',$dom)) {
195: &Apache::loncommon::content_type($r,'text/html');
196: $r->send_http_header;
197: } else {
198: $env{'user.error.msg'}=
199: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
200: return HTTP_NOT_ACCEPTABLE;
201: }
1.155 raeburn 202:
203: $registered_cleanup=0;
204: @{$modified_urls}=();
205:
1.1 raeburn 206: &Apache::lonhtmlcommon::clear_breadcrumbs();
207: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 208: ['phase','actions']);
1.30 raeburn 209: my $phase = 'pickactions';
1.3 raeburn 210: if ( exists($env{'form.phase'}) ) {
211: $phase = $env{'form.phase'};
212: }
1.150 raeburn 213: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 214: my %domconfig =
1.6 raeburn 215: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 216: 'quotas','autoenroll','autoupdate','autocreate',
217: 'directorysrch','usercreation','usermodification',
218: 'contacts','defaults','scantron','coursecategories',
219: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 220: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 221: 'requestauthor','selfenrollment','inststatus',
1.320 raeburn 222: 'ltitools','ssl','trust','lti'],$dom);
223: my %encconfig =
224: &Apache::lonnet::get_dom('encconfig',['ltitools','lti'],$dom);
1.297 raeburn 225: if (ref($domconfig{'ltitools'}) eq 'HASH') {
226: if (ref($encconfig{'ltitools'}) eq 'HASH') {
227: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 228: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
229: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297 raeburn 230: foreach my $item ('key','secret') {
231: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
232: }
233: }
234: }
235: }
236: }
1.320 raeburn 237: if (ref($domconfig{'lti'}) eq 'HASH') {
238: if (ref($encconfig{'lti'}) eq 'HASH') {
239: foreach my $id (keys(%{$domconfig{'lti'}})) {
240: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
241: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
242: foreach my $item ('key','secret') {
243: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
244: }
245: }
246: }
247: }
248: }
1.43 raeburn 249: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 250: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 251: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 252: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 253: 'serverstatuses','helpsettings','coursedefaults',
1.320 raeburn 254: 'ltitools','selfenrollment','usersessions','ssl','trust','lti');
1.171 raeburn 255: my %existing;
256: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
257: %existing = %{$domconfig{'loadbalancing'}};
258: }
259: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 260: push(@prefs_order,'loadbalancing');
261: }
1.30 raeburn 262: my %prefs = (
263: 'rolecolors' =>
264: { text => 'Default color schemes',
1.67 raeburn 265: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 266: header => [{col1 => 'Student Settings',
267: col2 => '',},
268: {col1 => 'Coordinator Settings',
269: col2 => '',},
270: {col1 => 'Author Settings',
271: col2 => '',},
272: {col1 => 'Administrator Settings',
273: col2 => '',}],
1.230 raeburn 274: print => \&print_rolecolors,
275: modify => \&modify_rolecolors,
1.30 raeburn 276: },
1.110 raeburn 277: 'login' =>
1.30 raeburn 278: { text => 'Log-in page options',
1.67 raeburn 279: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 280: header => [{col1 => 'Log-in Page Items',
281: col2 => '',},
282: {col1 => 'Log-in Help',
1.256 raeburn 283: col2 => 'Value'},
284: {col1 => 'Custom HTML in document head',
1.168 raeburn 285: col2 => 'Value'}],
1.230 raeburn 286: print => \&print_login,
287: modify => \&modify_login,
1.30 raeburn 288: },
1.43 raeburn 289: 'defaults' =>
1.236 raeburn 290: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 291: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 292: header => [{col1 => 'Setting',
1.236 raeburn 293: col2 => 'Value'},
1.294 raeburn 294: {col1 => 'Internal Authentication',
295: col2 => 'Value'},
1.236 raeburn 296: {col1 => 'Institutional user types',
1.305 raeburn 297: col2 => 'Name displayed'}],
1.230 raeburn 298: print => \&print_defaults,
299: modify => \&modify_defaults,
1.43 raeburn 300: },
1.30 raeburn 301: 'quotas' =>
1.197 raeburn 302: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 303: help => 'Domain_Configuration_Quotas',
1.77 raeburn 304: header => [{col1 => 'User affiliation',
1.72 raeburn 305: col2 => 'Available tools',
1.213 raeburn 306: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 307: print => \&print_quotas,
308: modify => \&modify_quotas,
1.30 raeburn 309: },
310: 'autoenroll' =>
311: { text => 'Auto-enrollment settings',
1.67 raeburn 312: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 313: header => [{col1 => 'Configuration setting',
314: col2 => 'Value(s)'}],
1.230 raeburn 315: print => \&print_autoenroll,
316: modify => \&modify_autoenroll,
1.30 raeburn 317: },
318: 'autoupdate' =>
319: { text => 'Auto-update settings',
1.67 raeburn 320: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 321: header => [{col1 => 'Setting',
322: col2 => 'Value',},
1.131 raeburn 323: {col1 => 'Setting',
324: col2 => 'Affiliation'},
1.43 raeburn 325: {col1 => 'User population',
1.227 bisitz 326: col2 => 'Updatable user data'}],
1.230 raeburn 327: print => \&print_autoupdate,
328: modify => \&modify_autoupdate,
1.30 raeburn 329: },
1.125 raeburn 330: 'autocreate' =>
331: { text => 'Auto-course creation settings',
332: help => 'Domain_Configuration_Auto_Creation',
333: header => [{col1 => 'Configuration Setting',
334: col2 => 'Value',}],
1.230 raeburn 335: print => \&print_autocreate,
336: modify => \&modify_autocreate,
1.125 raeburn 337: },
1.30 raeburn 338: 'directorysrch' =>
1.277 raeburn 339: { text => 'Directory searches',
1.67 raeburn 340: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 341: header => [{col1 => 'Institutional Directory Setting',
342: col2 => 'Value',},
343: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 344: col2 => 'Value',}],
1.230 raeburn 345: print => \&print_directorysrch,
346: modify => \&modify_directorysrch,
1.30 raeburn 347: },
348: 'contacts' =>
1.286 raeburn 349: { text => 'E-mail addresses and helpform',
1.67 raeburn 350: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 351: header => [{col1 => 'Default e-mail addresses',
352: col2 => 'Value',},
353: {col1 => 'Recipient(s) for notifications',
354: col2 => 'Value',},
355: {col1 => 'Ask helpdesk form settings',
356: col2 => 'Value',},],
1.230 raeburn 357: print => \&print_contacts,
358: modify => \&modify_contacts,
1.30 raeburn 359: },
360: 'usercreation' =>
361: { text => 'User creation',
1.67 raeburn 362: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 363: header => [{col1 => 'Format rule type',
364: col2 => 'Format rules in force'},
1.34 raeburn 365: {col1 => 'User account creation',
366: col2 => 'Usernames which may be created',},
1.30 raeburn 367: {col1 => 'Context',
1.43 raeburn 368: col2 => 'Assignable authentication types'}],
1.230 raeburn 369: print => \&print_usercreation,
370: modify => \&modify_usercreation,
1.30 raeburn 371: },
1.224 raeburn 372: 'selfcreation' =>
373: { text => 'Users self-creating accounts',
374: help => 'Domain_Configuration_Self_Creation',
375: header => [{col1 => 'Self-creation with institutional username',
376: col2 => 'Enabled?'},
377: {col1 => 'Institutional user type (login/SSO self-creation)',
378: col2 => 'Information user can enter'},
1.303 raeburn 379: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 380: col2 => 'Settings'}],
1.230 raeburn 381: print => \&print_selfcreation,
382: modify => \&modify_selfcreation,
1.224 raeburn 383: },
1.69 raeburn 384: 'usermodification' =>
1.33 raeburn 385: { text => 'User modification',
1.67 raeburn 386: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 387: header => [{col1 => 'Target user has role',
1.227 bisitz 388: col2 => 'User information updatable in author context'},
1.33 raeburn 389: {col1 => 'Target user has role',
1.227 bisitz 390: col2 => 'User information updatable in course context'}],
1.230 raeburn 391: print => \&print_usermodification,
392: modify => \&modify_usermodification,
1.33 raeburn 393: },
1.69 raeburn 394: 'scantron' =>
1.95 www 395: { text => 'Bubblesheet format file',
1.67 raeburn 396: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 397: header => [ {col1 => 'Item',
398: col2 => '',
399: }],
1.230 raeburn 400: print => \&print_scantron,
401: modify => \&modify_scantron,
1.46 raeburn 402: },
1.86 raeburn 403: 'requestcourses' =>
404: {text => 'Request creation of courses',
405: help => 'Domain_Configuration_Request_Courses',
406: header => [{col1 => 'User affiliation',
1.102 raeburn 407: col2 => 'Availability/Processing of requests',},
408: {col1 => 'Setting',
1.216 raeburn 409: col2 => 'Value'},
410: {col1 => 'Available textbooks',
1.235 raeburn 411: col2 => ''},
1.242 raeburn 412: {col1 => 'Available templates',
413: col2 => ''},
1.235 raeburn 414: {col1 => 'Validation (not official courses)',
415: col2 => 'Value'},],
1.230 raeburn 416: print => \&print_quotas,
417: modify => \&modify_quotas,
1.86 raeburn 418: },
1.163 raeburn 419: 'requestauthor' =>
1.223 bisitz 420: {text => 'Request Authoring Space',
1.163 raeburn 421: help => 'Domain_Configuration_Request_Author',
422: header => [{col1 => 'User affiliation',
423: col2 => 'Availability/Processing of requests',},
424: {col1 => 'Setting',
425: col2 => 'Value'}],
1.230 raeburn 426: print => \&print_quotas,
427: modify => \&modify_quotas,
1.163 raeburn 428: },
1.69 raeburn 429: 'coursecategories' =>
1.120 raeburn 430: { text => 'Cataloging of courses/communities',
1.67 raeburn 431: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 432: header => [{col1 => 'Catalog type/availability',
433: col2 => '',},
434: {col1 => 'Category settings for standard catalog',
1.57 raeburn 435: col2 => '',},
436: {col1 => 'Categories',
437: col2 => '',
438: }],
1.230 raeburn 439: print => \&print_coursecategories,
440: modify => \&modify_coursecategories,
1.69 raeburn 441: },
442: 'serverstatuses' =>
1.77 raeburn 443: {text => 'Access to server status pages',
1.69 raeburn 444: help => 'Domain_Configuration_Server_Status',
445: header => [{col1 => 'Status Page',
446: col2 => 'Other named users',
447: col3 => 'Specific IPs',
448: }],
1.230 raeburn 449: print => \&print_serverstatuses,
450: modify => \&modify_serverstatuses,
1.69 raeburn 451: },
1.118 jms 452: 'helpsettings' =>
1.282 raeburn 453: {text => 'Support settings',
1.118 jms 454: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 455: header => [{col1 => 'Help Page Settings (logged-in users)',
456: col2 => 'Value'},
457: {col1 => 'Helpdesk Roles',
458: col2 => 'Settings'},],
1.230 raeburn 459: print => \&print_helpsettings,
460: modify => \&modify_helpsettings,
1.118 jms 461: },
1.121 raeburn 462: 'coursedefaults' =>
463: {text => 'Course/Community defaults',
464: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 465: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
466: col2 => 'Value',},
467: {col1 => 'Defaults which can be overridden for each course by a DC',
468: col2 => 'Value',},],
1.230 raeburn 469: print => \&print_coursedefaults,
470: modify => \&modify_coursedefaults,
1.121 raeburn 471: },
1.231 raeburn 472: 'selfenrollment' =>
473: {text => 'Self-enrollment in Course/Community',
474: help => 'Domain_Configuration_Selfenrollment',
475: header => [{col1 => 'Configuration Rights',
476: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
477: {col1 => 'Defaults',
478: col2 => 'Value'},
479: {col1 => 'Self-enrollment validation (optional)',
480: col2 => 'Value'},],
481: print => \&print_selfenrollment,
482: modify => \&modify_selfenrollment,
483: },
1.120 raeburn 484: 'privacy' =>
485: {text => 'User Privacy',
486: help => 'Domain_Configuration_User_Privacy',
487: header => [{col1 => 'Setting',
488: col2 => 'Value',}],
1.230 raeburn 489: print => \&print_privacy,
490: modify => \&modify_privacy,
1.120 raeburn 491: },
1.141 raeburn 492: 'usersessions' =>
1.145 raeburn 493: {text => 'User session hosting/offloading',
1.137 raeburn 494: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 495: header => [{col1 => 'Domain server',
496: col2 => 'Servers to offload sessions to when busy'},
497: {col1 => 'Hosting of users from other domains',
1.137 raeburn 498: col2 => 'Rules'},
499: {col1 => "Hosting domain's own users elsewhere",
500: col2 => 'Rules'}],
1.230 raeburn 501: print => \&print_usersessions,
502: modify => \&modify_usersessions,
1.137 raeburn 503: },
1.279 raeburn 504: 'loadbalancing' =>
1.185 raeburn 505: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 506: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 507: header => [{col1 => 'Balancers',
1.150 raeburn 508: col2 => 'Default destinations',
1.183 bisitz 509: col3 => 'User affiliation',
1.150 raeburn 510: col4 => 'Overrides'},
511: ],
1.230 raeburn 512: print => \&print_loadbalancing,
513: modify => \&modify_loadbalancing,
1.150 raeburn 514: },
1.279 raeburn 515: 'ltitools' =>
1.267 raeburn 516: {text => 'External Tools (LTI)',
1.296 raeburn 517: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 518: header => [{col1 => 'Setting',
519: col2 => 'Value',}],
520: print => \&print_ltitools,
521: modify => \&modify_ltitools,
522: },
1.279 raeburn 523: 'ssl' =>
1.275 raeburn 524: {text => 'LON-CAPA Network (SSL)',
525: help => 'Domain_Configuration_Network_SSL',
526: header => [{col1 => 'Server',
527: col2 => 'Certificate Status'},
528: {col1 => 'Connections to other servers',
529: col2 => 'Rules'},
1.293 raeburn 530: {col1 => 'Connections from other servers',
531: col2 => 'Rules'},
1.275 raeburn 532: {col1 => "Replicating domain's published content",
533: col2 => 'Rules'}],
534: print => \&print_ssl,
535: modify => \&modify_ssl,
536: },
1.279 raeburn 537: 'trust' =>
538: {text => 'Trust Settings',
539: help => 'Domain_Configuration_Trust',
540: header => [{col1 => "Access to this domain's content by others",
541: col2 => 'Rules'},
542: {col1 => "Access to other domain's content by this domain",
543: col2 => 'Rules'},
544: {col1 => "Enrollment in this domain's courses by others",
545: col2 => 'Rules',},
546: {col1 => "Co-author roles in this domain for others",
547: col2 => 'Rules',},
548: {col1 => "Co-author roles for this domain's users elsewhere",
549: col2 => 'Rules',},
550: {col1 => "Domain roles in this domain assignable to others",
551: col2 => 'Rules'},
552: {col1 => "Course catalog for this domain displayed elsewhere",
553: col2 => 'Rules'},
554: {col1 => "Requests for creation of courses in this domain by others",
555: col2 => 'Rules'},
556: {col1 => "Users in other domains can send messages to this domain",
557: col2 => 'Rules'},],
558: print => \&print_trust,
559: modify => \&modify_trust,
560: },
1.320 raeburn 561: 'lti' =>
562: {text => 'LTI Provider',
563: help => 'Domain_Configuration_LTI_Provider',
564: header => [{col1 => 'Setting',
565: col2 => 'Value',}],
566: print => \&print_lti,
567: modify => \&modify_lti,
568: },
1.3 raeburn 569: );
1.110 raeburn 570: if (keys(%servers) > 1) {
571: $prefs{'login'} = { text => 'Log-in page options',
572: help => 'Domain_Configuration_Login_Page',
573: header => [{col1 => 'Log-in Service',
574: col2 => 'Server Setting',},
575: {col1 => 'Log-in Page Items',
1.168 raeburn 576: col2 => ''},
577: {col1 => 'Log-in Help',
1.256 raeburn 578: col2 => 'Value'},
579: {col1 => 'Custom HTML in document head',
1.168 raeburn 580: col2 => 'Value'}],
1.230 raeburn 581: print => \&print_login,
582: modify => \&modify_login,
1.110 raeburn 583: };
584: }
1.174 foxr 585:
1.6 raeburn 586: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 587: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 588: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 589: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 590: text=>"Settings to display/modify"});
1.9 raeburn 591: my $confname = $dom.'-domainconfig';
1.174 foxr 592:
1.3 raeburn 593: if ($phase eq 'process') {
1.212 raeburn 594: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
595: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 596: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 597: $r->rflush();
1.212 raeburn 598: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 599: }
1.30 raeburn 600: } elsif ($phase eq 'display') {
1.192 raeburn 601: my $js = &recaptcha_js().
1.236 raeburn 602: &toggle_display_js();
1.171 raeburn 603: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 604: my ($othertitle,$usertypes,$types) =
605: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 606: $js .= &lonbalance_targets_js($dom,$types,\%servers,
607: $domconfig{'loadbalancing'}).
1.170 raeburn 608: &new_spares_js().
609: &common_domprefs_js().
610: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 611: }
1.216 raeburn 612: if (grep(/^requestcourses$/,@actions)) {
613: my $javascript_validations;
614: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
615: $js .= <<END;
616: <script type="text/javascript">
617: $javascript_validations
618: </script>
619: $coursebrowserjs
620: END
621: }
1.305 raeburn 622: if (grep(/^selfcreation$/,@actions)) {
623: $js .= &selfcreate_javascript();
624: }
1.286 raeburn 625: if (grep(/^contacts$/,@actions)) {
626: $js .= &contacts_javascript();
627: }
1.150 raeburn 628: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 629: } else {
1.180 raeburn 630: # check if domconfig user exists for the domain.
631: my $servadm = $r->dir_config('lonAdmEMail');
632: my ($configuserok,$author_ok,$switchserver) =
633: &config_check($dom,$confname,$servadm);
634: unless ($configuserok eq 'ok') {
1.181 raeburn 635: &Apache::lonconfigsettings::print_header($r,$phase,$context);
636: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 637: $confname).
1.181 raeburn 638: '<br />'
639: );
1.180 raeburn 640: if ($switchserver) {
1.181 raeburn 641: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
642: '<br />'.
643: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
644: '<br />'.
645: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
646: '<br />'.
647: &mt('To do that now, use the following link: [_1]',$switchserver)
648: );
649: } else {
650: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
651: '<br />'.
652: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
653: );
1.180 raeburn 654: }
655: $r->print(&Apache::loncommon::end_page());
656: return OK;
657: }
1.21 raeburn 658: if (keys(%domconfig) == 0) {
659: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 660: my @ids=&Apache::lonnet::current_machine_ids();
661: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 662: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 663: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 664: my $custom_img_count = 0;
665: foreach my $img (@loginimages) {
666: if ($designhash{$dom.'.login.'.$img} ne '') {
667: $custom_img_count ++;
668: }
669: }
670: foreach my $role (@roles) {
671: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
672: $custom_img_count ++;
673: }
674: }
675: if ($custom_img_count > 0) {
1.94 raeburn 676: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 677: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 678: $r->print(
679: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
680: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
681: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
682: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
683: if ($switch_server) {
1.30 raeburn 684: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 685: }
1.91 raeburn 686: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 687: return OK;
688: }
689: }
690: }
1.91 raeburn 691: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 692: }
693: return OK;
694: }
695:
696: sub process_changes {
1.205 raeburn 697: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 698: my %domconfig;
699: if (ref($values) eq 'HASH') {
700: %domconfig = %{$values};
701: }
1.3 raeburn 702: my $output;
703: if ($action eq 'login') {
1.205 raeburn 704: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 705: } elsif ($action eq 'rolecolors') {
1.9 raeburn 706: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 707: $lastactref,%domconfig);
1.3 raeburn 708: } elsif ($action eq 'quotas') {
1.216 raeburn 709: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 710: } elsif ($action eq 'autoenroll') {
1.205 raeburn 711: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 712: } elsif ($action eq 'autoupdate') {
713: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 714: } elsif ($action eq 'autocreate') {
715: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 716: } elsif ($action eq 'directorysrch') {
1.295 raeburn 717: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 718: } elsif ($action eq 'usercreation') {
1.28 raeburn 719: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 720: } elsif ($action eq 'selfcreation') {
1.305 raeburn 721: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 722: } elsif ($action eq 'usermodification') {
723: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 724: } elsif ($action eq 'contacts') {
1.205 raeburn 725: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 726: } elsif ($action eq 'defaults') {
1.212 raeburn 727: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 728: } elsif ($action eq 'scantron') {
1.205 raeburn 729: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 730: } elsif ($action eq 'coursecategories') {
1.239 raeburn 731: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 732: } elsif ($action eq 'serverstatuses') {
733: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 734: } elsif ($action eq 'requestcourses') {
1.216 raeburn 735: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 736: } elsif ($action eq 'requestauthor') {
1.216 raeburn 737: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 738: } elsif ($action eq 'helpsettings') {
1.285 raeburn 739: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 740: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 741: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 742: } elsif ($action eq 'selfenrollment') {
743: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 744: } elsif ($action eq 'usersessions') {
1.212 raeburn 745: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 746: } elsif ($action eq 'loadbalancing') {
747: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 748: } elsif ($action eq 'ltitools') {
749: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 750: } elsif ($action eq 'ssl') {
751: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 752: } elsif ($action eq 'trust') {
753: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 754: } elsif ($action eq 'lti') {
755: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 756: }
757: return $output;
758: }
759:
760: sub print_config_box {
1.9 raeburn 761: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 762: my $rowtotal = 0;
1.49 raeburn 763: my $output;
764: if ($action eq 'coursecategories') {
765: $output = &coursecategories_javascript($settings);
1.236 raeburn 766: } elsif ($action eq 'defaults') {
767: $output = &defaults_javascript($settings);
1.282 raeburn 768: } elsif ($action eq 'helpsettings') {
769: my (%privs,%levelscurrent);
770: my %full=();
771: my %levels=(
772: course => {},
773: domain => {},
774: system => {},
775: );
776: my $context = 'domain';
777: my $crstype = 'Course';
778: my $formname = 'display';
779: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
780: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
781: $output =
782: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
783: \@templateroles);
1.91 raeburn 784: }
1.236 raeburn 785: $output .=
1.30 raeburn 786: '<table class="LC_nested_outer">
1.3 raeburn 787: <tr>
1.306 raeburn 788: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 789: &mt($item->{text}).' '.
790: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
791: '</tr>';
1.30 raeburn 792: $rowtotal ++;
1.110 raeburn 793: my $numheaders = 1;
794: if (ref($item->{'header'}) eq 'ARRAY') {
795: $numheaders = scalar(@{$item->{'header'}});
796: }
797: if ($numheaders > 1) {
1.64 raeburn 798: my $colspan = '';
1.145 raeburn 799: my $rightcolspan = '';
1.238 raeburn 800: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 801: ($action eq 'directorysrch') ||
1.256 raeburn 802: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 803: $colspan = ' colspan="2"';
804: }
1.145 raeburn 805: if ($action eq 'usersessions') {
806: $rightcolspan = ' colspan="3"';
807: }
1.30 raeburn 808: $output .= '
1.3 raeburn 809: <tr>
810: <td>
811: <table class="LC_nested">
812: <tr class="LC_info_row">
1.59 bisitz 813: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 814: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 815: </tr>';
1.69 raeburn 816: $rowtotal ++;
1.230 raeburn 817: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 818: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 819: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 820: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
821: ($action eq 'contacts')) {
1.230 raeburn 822: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 823: } elsif ($action eq 'coursecategories') {
1.230 raeburn 824: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 825: } elsif ($action eq 'login') {
1.256 raeburn 826: if ($numheaders == 4) {
1.168 raeburn 827: $colspan = ' colspan="2"';
828: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
829: } else {
830: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
831: }
1.230 raeburn 832: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 833: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 834: } elsif ($action eq 'rolecolors') {
1.30 raeburn 835: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 836: }
1.30 raeburn 837: $output .= '
1.6 raeburn 838: </table>
839: </td>
840: </tr>
841: <tr>
842: <td>
843: <table class="LC_nested">
844: <tr class="LC_info_row">
1.230 raeburn 845: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 846: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 847: </tr>';
848: $rowtotal ++;
1.230 raeburn 849: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
850: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 851: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.294 raeburn 852: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {
1.238 raeburn 853: if ($action eq 'coursecategories') {
854: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
855: $colspan = ' colspan="2"';
1.279 raeburn 856: } elsif ($action eq 'trust') {
857: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 858: } else {
859: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
860: }
1.279 raeburn 861: if ($action eq 'trust') {
862: $output .= '
863: </table>
864: </td>
865: </tr>';
866: my @trusthdrs = qw(2 3 4 5 6 7);
867: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
868: for (my $i=0; $i<@trusthdrs; $i++) {
869: $output .= '
870: <tr>
871: <td>
872: <table class="LC_nested">
873: <tr class="LC_info_row">
874: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
875: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
876: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
877: </table>
878: </td>
879: </tr>';
880: }
881: $output .= '
882: <tr>
883: <td>
884: <table class="LC_nested">
885: <tr class="LC_info_row">
886: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
887: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
888: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
889: } else {
890: $output .= '
1.63 raeburn 891: </table>
892: </td>
893: </tr>
894: <tr>
895: <td>
896: <table class="LC_nested">
897: <tr class="LC_info_row">
898: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 899: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 900: </tr>'."\n";
1.279 raeburn 901: if ($action eq 'coursecategories') {
902: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
903: } else {
904: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
905: }
1.238 raeburn 906: }
1.63 raeburn 907: $rowtotal ++;
1.236 raeburn 908: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 909: ($action eq 'defaults') || ($action eq 'directorysrch') ||
910: ($action eq 'helpsettings')) {
1.230 raeburn 911: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.293 raeburn 912: } elsif ($action eq 'ssl') {
913: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
914: </table>
915: </td>
916: </tr>
917: <tr>
918: <td>
919: <table class="LC_nested">
920: <tr class="LC_info_row">
921: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
922: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
923: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
924: </table>
925: </td>
926: </tr>
927: <tr>
928: <td>
929: <table class="LC_nested">
930: <tr class="LC_info_row">
931: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
932: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
933: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 934: } elsif ($action eq 'login') {
1.256 raeburn 935: if ($numheaders == 4) {
1.168 raeburn 936: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
937: </table>
938: </td>
939: </tr>
940: <tr>
941: <td>
942: <table class="LC_nested">
943: <tr class="LC_info_row">
944: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 945: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 946: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
947: $rowtotal ++;
948: } else {
949: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
950: }
1.256 raeburn 951: $output .= '
952: </table>
953: </td>
954: </tr>
955: <tr>
956: <td>
957: <table class="LC_nested">
958: <tr class="LC_info_row">';
959: if ($numheaders == 4) {
960: $output .= '
961: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
962: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
963: </tr>';
964: } else {
965: $output .= '
966: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
967: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
968: </tr>';
969: }
970: $rowtotal ++;
971: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 972: } elsif ($action eq 'requestcourses') {
1.247 raeburn 973: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
974: $rowtotal ++;
975: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 976: </table>
977: </td>
978: </tr>
979: <tr>
980: <td>
981: <table class="LC_nested">
982: <tr class="LC_info_row">
983: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
984: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 985: &textbookcourses_javascript($settings).
986: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
987: </table>
988: </td>
989: </tr>
990: <tr>
991: <td>
992: <table class="LC_nested">
993: <tr class="LC_info_row">
994: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
995: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
996: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 997: </table>
998: </td>
999: </tr>
1000: <tr>
1001: <td>
1002: <table class="LC_nested">
1003: <tr class="LC_info_row">
1.306 raeburn 1004: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1005: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1006: </tr>'.
1007: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1008: } elsif ($action eq 'requestauthor') {
1009: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1010: $rowtotal ++;
1.122 jms 1011: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1012: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1013: </table>
1014: </td>
1015: </tr>
1016: <tr>
1017: <td>
1018: <table class="LC_nested">
1019: <tr class="LC_info_row">
1.306 raeburn 1020: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1021: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1022: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1023: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1024: </tr>'.
1.30 raeburn 1025: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1026: </table>
1027: </td>
1028: </tr>
1029: <tr>
1030: <td>
1031: <table class="LC_nested">
1032: <tr class="LC_info_row">
1.59 bisitz 1033: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1034: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1035: </tr>'.
1.30 raeburn 1036: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1037: $rowtotal += 2;
1.6 raeburn 1038: }
1.3 raeburn 1039: } else {
1.30 raeburn 1040: $output .= '
1.3 raeburn 1041: <tr>
1042: <td>
1043: <table class="LC_nested">
1.30 raeburn 1044: <tr class="LC_info_row">';
1.277 raeburn 1045: if ($action eq 'login') {
1.30 raeburn 1046: $output .= '
1.59 bisitz 1047: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1048: } elsif ($action eq 'serverstatuses') {
1049: $output .= '
1.306 raeburn 1050: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1051: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1052:
1.6 raeburn 1053: } else {
1.30 raeburn 1054: $output .= '
1.306 raeburn 1055: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1056: }
1.72 raeburn 1057: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1058: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1059: &mt($item->{'header'}->[0]->{'col2'});
1060: if ($action eq 'serverstatuses') {
1061: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1062: }
1.69 raeburn 1063: } else {
1.306 raeburn 1064: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1065: &mt($item->{'header'}->[0]->{'col2'});
1066: }
1067: $output .= '</td>';
1068: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1069: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1070: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1071: &mt($item->{'header'}->[0]->{'col3'});
1072: } else {
1.306 raeburn 1073: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1074: &mt($item->{'header'}->[0]->{'col3'});
1075: }
1.69 raeburn 1076: if ($action eq 'serverstatuses') {
1077: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1078: }
1079: $output .= '</td>';
1.6 raeburn 1080: }
1.150 raeburn 1081: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1082: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1083: &mt($item->{'header'}->[0]->{'col4'});
1084: }
1.69 raeburn 1085: $output .= '</tr>';
1.48 raeburn 1086: $rowtotal ++;
1.168 raeburn 1087: if ($action eq 'quotas') {
1.86 raeburn 1088: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1089: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1090: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.320 raeburn 1091: ($action eq 'ltitools') || ($action eq 'lti')) {
1.230 raeburn 1092: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1093: } elsif ($action eq 'scantron') {
1094: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1095: }
1.3 raeburn 1096: }
1.30 raeburn 1097: $output .= '
1.3 raeburn 1098: </table>
1099: </td>
1100: </tr>
1.30 raeburn 1101: </table><br />';
1102: return ($output,$rowtotal);
1.1 raeburn 1103: }
1104:
1.3 raeburn 1105: sub print_login {
1.168 raeburn 1106: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1107: my ($css_class,$datatable);
1.6 raeburn 1108: my %choices = &login_choices();
1.110 raeburn 1109:
1.168 raeburn 1110: if ($caller eq 'service') {
1.149 raeburn 1111: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1112: my $choice = $choices{'disallowlogin'};
1113: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1114: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1115: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1116: '<th>'.$choices{'server'}.'</th>'.
1117: '<th>'.$choices{'serverpath'}.'</th>'.
1118: '<th>'.$choices{'custompath'}.'</th>'.
1119: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1120: my %disallowed;
1121: if (ref($settings) eq 'HASH') {
1122: if (ref($settings->{'loginvia'}) eq 'HASH') {
1123: %disallowed = %{$settings->{'loginvia'}};
1124: }
1125: }
1126: foreach my $lonhost (sort(keys(%servers))) {
1127: my $direct = 'selected="selected"';
1.128 raeburn 1128: if (ref($disallowed{$lonhost}) eq 'HASH') {
1129: if ($disallowed{$lonhost}{'server'} ne '') {
1130: $direct = '';
1131: }
1.110 raeburn 1132: }
1.115 raeburn 1133: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1134: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1135: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1136: '</option>';
1.184 raeburn 1137: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1138: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1139: my $selected = '';
1.128 raeburn 1140: if (ref($disallowed{$lonhost}) eq 'HASH') {
1141: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1142: $selected = 'selected="selected"';
1143: }
1.110 raeburn 1144: }
1145: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1146: $servers{$hostid}.'</option>';
1147: }
1.128 raeburn 1148: $datatable .= '</select></td>'.
1149: '<td><select name="'.$lonhost.'_serverpath">';
1150: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1151: my $pathname = $path;
1152: if ($path eq 'custom') {
1153: $pathname = &mt('Custom Path').' ->';
1154: }
1155: my $selected = '';
1156: if (ref($disallowed{$lonhost}) eq 'HASH') {
1157: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1158: $selected = 'selected="selected"';
1159: }
1160: } elsif ($path eq '') {
1161: $selected = 'selected="selected"';
1162: }
1163: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1164: }
1165: $datatable .= '</select></td>';
1166: my ($custom,$exempt);
1167: if (ref($disallowed{$lonhost}) eq 'HASH') {
1168: $custom = $disallowed{$lonhost}{'custompath'};
1169: $exempt = $disallowed{$lonhost}{'exempt'};
1170: }
1171: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1172: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1173: '</tr>';
1.110 raeburn 1174: }
1175: $datatable .= '</table></td></tr>';
1176: return $datatable;
1.168 raeburn 1177: } elsif ($caller eq 'page') {
1178: my %defaultchecked = (
1179: 'coursecatalog' => 'on',
1.188 raeburn 1180: 'helpdesk' => 'on',
1.168 raeburn 1181: 'adminmail' => 'off',
1182: 'newuser' => 'off',
1183: );
1.188 raeburn 1184: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1185: my (%checkedon,%checkedoff);
1.42 raeburn 1186: foreach my $item (@toggles) {
1.168 raeburn 1187: if ($defaultchecked{$item} eq 'on') {
1188: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1189: $checkedoff{$item} = ' ';
1.168 raeburn 1190: } elsif ($defaultchecked{$item} eq 'off') {
1191: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1192: $checkedon{$item} = ' ';
1193: }
1.1 raeburn 1194: }
1.168 raeburn 1195: my @images = ('img','logo','domlogo','login');
1196: my @logintext = ('textcol','bgcol');
1197: my @bgs = ('pgbg','mainbg','sidebg');
1198: my @links = ('link','alink','vlink');
1199: my %designhash = &Apache::loncommon::get_domainconf($dom);
1200: my %defaultdesign = %Apache::loncommon::defaultdesign;
1201: my (%is_custom,%designs);
1202: my %defaults = (
1203: font => $defaultdesign{'login.font'},
1204: );
1.6 raeburn 1205: foreach my $item (@images) {
1.168 raeburn 1206: $defaults{$item} = $defaultdesign{'login.'.$item};
1207: $defaults{'showlogo'}{$item} = 1;
1208: }
1209: foreach my $item (@bgs) {
1210: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1211: }
1.41 raeburn 1212: foreach my $item (@logintext) {
1.168 raeburn 1213: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1214: }
1.168 raeburn 1215: foreach my $item (@links) {
1216: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1217: }
1.168 raeburn 1218: if (ref($settings) eq 'HASH') {
1219: foreach my $item (@toggles) {
1220: if ($settings->{$item} eq '1') {
1221: $checkedon{$item} = ' checked="checked" ';
1222: $checkedoff{$item} = ' ';
1223: } elsif ($settings->{$item} eq '0') {
1224: $checkedoff{$item} = ' checked="checked" ';
1225: $checkedon{$item} = ' ';
1226: }
1227: }
1228: foreach my $item (@images) {
1229: if (defined($settings->{$item})) {
1230: $designs{$item} = $settings->{$item};
1231: $is_custom{$item} = 1;
1232: }
1233: if (defined($settings->{'showlogo'}{$item})) {
1234: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1235: }
1236: }
1237: foreach my $item (@logintext) {
1238: if ($settings->{$item} ne '') {
1239: $designs{'logintext'}{$item} = $settings->{$item};
1240: $is_custom{$item} = 1;
1241: }
1242: }
1243: if ($settings->{'font'} ne '') {
1244: $designs{'font'} = $settings->{'font'};
1245: $is_custom{'font'} = 1;
1246: }
1247: foreach my $item (@bgs) {
1248: if ($settings->{$item} ne '') {
1249: $designs{'bgs'}{$item} = $settings->{$item};
1250: $is_custom{$item} = 1;
1251: }
1252: }
1253: foreach my $item (@links) {
1254: if ($settings->{$item} ne '') {
1255: $designs{'links'}{$item} = $settings->{$item};
1256: $is_custom{$item} = 1;
1257: }
1258: }
1259: } else {
1260: if ($designhash{$dom.'.login.font'} ne '') {
1261: $designs{'font'} = $designhash{$dom.'.login.font'};
1262: $is_custom{'font'} = 1;
1263: }
1264: foreach my $item (@images) {
1265: if ($designhash{$dom.'.login.'.$item} ne '') {
1266: $designs{$item} = $designhash{$dom.'.login.'.$item};
1267: $is_custom{$item} = 1;
1268: }
1269: }
1270: foreach my $item (@bgs) {
1271: if ($designhash{$dom.'.login.'.$item} ne '') {
1272: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1273: $is_custom{$item} = 1;
1274: }
1.6 raeburn 1275: }
1.168 raeburn 1276: foreach my $item (@links) {
1277: if ($designhash{$dom.'.login.'.$item} ne '') {
1278: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1279: $is_custom{$item} = 1;
1280: }
1.6 raeburn 1281: }
1282: }
1.168 raeburn 1283: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1284: logo => 'Institution Logo',
1285: domlogo => 'Domain Logo',
1286: login => 'Login box');
1287: my $itemcount = 1;
1288: foreach my $item (@toggles) {
1289: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1290: $datatable .=
1291: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1292: '</td><td>'.
1293: '<span class="LC_nobreak"><label><input type="radio" name="'.
1294: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1295: '</label> <label><input type="radio" name="'.$item.'"'.
1296: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1297: '</tr>';
1298: $itemcount ++;
1.6 raeburn 1299: }
1.168 raeburn 1300: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1301: $datatable .= '</tr></table></td></tr>';
1302: } elsif ($caller eq 'help') {
1303: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1304: my $switchserver = &check_switchserver($dom,$confname);
1305: my $itemcount = 1;
1306: $defaulturl = '/adm/loginproblems.html';
1307: $defaulttype = 'default';
1308: %lt = &Apache::lonlocal::texthash (
1309: del => 'Delete?',
1310: rep => 'Replace:',
1311: upl => 'Upload:',
1312: default => 'Default',
1313: custom => 'Custom',
1314: );
1315: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1316: my @currlangs;
1317: if (ref($settings) eq 'HASH') {
1318: if (ref($settings->{'helpurl'}) eq 'HASH') {
1319: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1320: next if ($settings->{'helpurl'}{$key} eq '');
1321: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1322: $type{$key} = 'custom';
1323: unless ($key eq 'nolang') {
1324: push(@currlangs,$key);
1325: }
1326: }
1327: } elsif ($settings->{'helpurl'} ne '') {
1328: $type{'nolang'} = 'custom';
1329: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1330: }
1331: }
1.168 raeburn 1332: foreach my $lang ('nolang',sort(@currlangs)) {
1333: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1334: $datatable .= '<tr'.$css_class.'>';
1335: if ($url{$lang} eq '') {
1336: $url{$lang} = $defaulturl;
1337: }
1338: if ($type{$lang} eq '') {
1339: $type{$lang} = $defaulttype;
1340: }
1341: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1342: if ($lang eq 'nolang') {
1343: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1344: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1345: } else {
1346: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1347: $langchoices{$lang},
1348: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1349: }
1350: $datatable .= '</span></td>'."\n".
1351: '<td class="LC_left_item">';
1352: if ($type{$lang} eq 'custom') {
1353: $datatable .= '<span class="LC_nobreak"><label>'.
1354: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1355: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1356: } else {
1357: $datatable .= $lt{'upl'};
1358: }
1359: $datatable .='<br />';
1360: if ($switchserver) {
1361: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1362: } else {
1363: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1364: }
1.168 raeburn 1365: $datatable .= '</td></tr>';
1366: $itemcount ++;
1.6 raeburn 1367: }
1.168 raeburn 1368: my @addlangs;
1369: foreach my $lang (sort(keys(%langchoices))) {
1370: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1371: push(@addlangs,$lang);
1372: }
1373: if (@addlangs > 0) {
1374: my %toadd;
1375: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1376: $toadd{''} = &mt('Select');
1377: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1378: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1379: &mt('Add log-in help page for a specific language:').' '.
1380: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1381: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1382: if ($switchserver) {
1383: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1384: } else {
1385: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1386: }
1.168 raeburn 1387: $datatable .= '</td></tr>';
1.169 raeburn 1388: $itemcount ++;
1.6 raeburn 1389: }
1.169 raeburn 1390: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1391: } elsif ($caller eq 'headtag') {
1392: my %domservers = &Apache::lonnet::get_servers($dom);
1393: my $choice = $choices{'headtag'};
1394: $css_class = ' class="LC_odd_row"';
1395: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1396: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1397: '<th>'.$choices{'current'}.'</th>'.
1398: '<th>'.$choices{'action'}.'</th>'.
1399: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1400: my (%currurls,%currexempt);
1401: if (ref($settings) eq 'HASH') {
1402: if (ref($settings->{'headtag'}) eq 'HASH') {
1403: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1404: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1405: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1406: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1407: }
1408: }
1409: }
1410: }
1411: my %lt = &Apache::lonlocal::texthash(
1412: del => 'Delete?',
1413: rep => 'Replace:',
1414: upl => 'Upload:',
1415: curr => 'View contents',
1416: none => 'None',
1417: );
1418: my $switchserver = &check_switchserver($dom,$confname);
1419: foreach my $lonhost (sort(keys(%domservers))) {
1420: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1421: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1422: if ($currurls{$lonhost}) {
1423: $datatable .= '<td class="LC_right_item"><a href="'.
1424: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1425: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1426: '">'.$lt{'curr'}.'</a></td>'.
1427: '<td><span class="LC_nobreak"><label>'.
1428: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1429: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1430: } else {
1431: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1432: }
1433: $datatable .='<br />';
1434: if ($switchserver) {
1435: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1436: } else {
1437: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1438: }
1.330 ! raeburn 1439: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1440: }
1441: $datatable .= '</table></td></tr>';
1.1 raeburn 1442: }
1.6 raeburn 1443: return $datatable;
1444: }
1445:
1446: sub login_choices {
1447: my %choices =
1448: &Apache::lonlocal::texthash (
1.116 bisitz 1449: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1450: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1451: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1452: disallowlogin => "Login page requests redirected",
1453: hostid => "Server",
1.128 raeburn 1454: server => "Redirect to:",
1455: serverpath => "Path",
1456: custompath => "Custom",
1457: exempt => "Exempt IP(s)",
1.110 raeburn 1458: directlogin => "No redirect",
1459: newuser => "Link to create a user account",
1460: img => "Header",
1461: logo => "Main Logo",
1462: domlogo => "Domain Logo",
1463: login => "Log-in Header",
1464: textcol => "Text color",
1465: bgcol => "Box color",
1466: bgs => "Background colors",
1467: links => "Link colors",
1468: font => "Font color",
1469: pgbg => "Header",
1470: mainbg => "Page",
1471: sidebg => "Login box",
1472: link => "Link",
1473: alink => "Active link",
1474: vlink => "Visited link",
1.256 raeburn 1475: headtag => "Custom markup",
1476: action => "Action",
1477: current => "Current",
1.6 raeburn 1478: );
1479: return %choices;
1480: }
1481:
1482: sub print_rolecolors {
1.30 raeburn 1483: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1484: my %choices = &color_font_choices();
1485: my @bgs = ('pgbg','tabbg','sidebg');
1486: my @links = ('link','alink','vlink');
1487: my @images = ('img');
1488: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1489: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1490: my %defaultdesign = %Apache::loncommon::defaultdesign;
1491: my (%is_custom,%designs);
1.200 raeburn 1492: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1493: if (ref($settings) eq 'HASH') {
1494: if (ref($settings->{$role}) eq 'HASH') {
1495: if ($settings->{$role}->{'img'} ne '') {
1496: $designs{'img'} = $settings->{$role}->{'img'};
1497: $is_custom{'img'} = 1;
1498: }
1499: if ($settings->{$role}->{'font'} ne '') {
1500: $designs{'font'} = $settings->{$role}->{'font'};
1501: $is_custom{'font'} = 1;
1502: }
1.97 tempelho 1503: if ($settings->{$role}->{'fontmenu'} ne '') {
1504: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1505: $is_custom{'fontmenu'} = 1;
1506: }
1.6 raeburn 1507: foreach my $item (@bgs) {
1508: if ($settings->{$role}->{$item} ne '') {
1509: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1510: $is_custom{$item} = 1;
1511: }
1512: }
1513: foreach my $item (@links) {
1514: if ($settings->{$role}->{$item} ne '') {
1515: $designs{'links'}{$item} = $settings->{$role}->{$item};
1516: $is_custom{$item} = 1;
1517: }
1518: }
1519: }
1520: } else {
1521: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1522: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1523: $is_custom{'img'} = 1;
1524: }
1.97 tempelho 1525: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1526: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1527: $is_custom{'fontmenu'} = 1;
1528: }
1.6 raeburn 1529: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1530: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1531: $is_custom{'font'} = 1;
1532: }
1533: foreach my $item (@bgs) {
1534: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1535: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1536: $is_custom{$item} = 1;
1537:
1538: }
1539: }
1540: foreach my $item (@links) {
1541: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1542: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1543: $is_custom{$item} = 1;
1544: }
1545: }
1546: }
1547: my $itemcount = 1;
1.30 raeburn 1548: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1549: $datatable .= '</tr></table></td></tr>';
1550: return $datatable;
1551: }
1552:
1.200 raeburn 1553: sub role_defaults {
1554: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1555: my %defaults;
1556: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1557: return %defaults;
1558: }
1559: my %defaultdesign = %Apache::loncommon::defaultdesign;
1560: if ($role eq 'login') {
1561: %defaults = (
1562: font => $defaultdesign{$role.'.font'},
1563: );
1564: if (ref($logintext) eq 'ARRAY') {
1565: foreach my $item (@{$logintext}) {
1566: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1567: }
1568: }
1569: foreach my $item (@{$images}) {
1570: $defaults{'showlogo'}{$item} = 1;
1571: }
1572: } else {
1573: %defaults = (
1574: img => $defaultdesign{$role.'.img'},
1575: font => $defaultdesign{$role.'.font'},
1576: fontmenu => $defaultdesign{$role.'.fontmenu'},
1577: );
1578: }
1579: foreach my $item (@{$bgs}) {
1580: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1581: }
1582: foreach my $item (@{$links}) {
1583: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1584: }
1585: foreach my $item (@{$images}) {
1586: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1587: }
1588: return %defaults;
1589: }
1590:
1.6 raeburn 1591: sub display_color_options {
1.9 raeburn 1592: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1593: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1594: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1595: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1596: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1597: '<td>'.$choices->{'font'}.'</td>';
1598: if (!$is_custom->{'font'}) {
1.329 raeburn 1599: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1600: } else {
1601: $datatable .= '<td> </td>';
1602: }
1.174 foxr 1603: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1604:
1.8 raeburn 1605: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1606: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1607: ' value="'.$current_color.'" /> '.
1.329 raeburn 1608: ' </span></td></tr>';
1.107 raeburn 1609: unless ($role eq 'login') {
1610: $datatable .= '<tr'.$css_class.'>'.
1611: '<td>'.$choices->{'fontmenu'}.'</td>';
1612: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 1613: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1614: } else {
1615: $datatable .= '<td> </td>';
1616: }
1.202 raeburn 1617: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1618: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1619: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1620: '<input class="colorchooser" type="text" size="10" name="'
1621: .$role.'_fontmenu"'.
1622: ' value="'.$current_color.'" /> '.
1.329 raeburn 1623: ' </span></td></tr>';
1.97 tempelho 1624: }
1.9 raeburn 1625: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1626: foreach my $img (@{$images}) {
1.18 albertel 1627: $itemcount ++;
1.6 raeburn 1628: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1629: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1630: '<td>'.$choices->{$img};
1.41 raeburn 1631: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1632: if ($role eq 'login') {
1633: if ($img eq 'login') {
1634: $login_hdr_pick =
1.135 bisitz 1635: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1636: $logincolors =
1637: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1638: $designs,$defaults);
1.70 raeburn 1639: } elsif ($img ne 'domlogo') {
1640: $datatable.= &logo_display_options($img,$defaults,$designs);
1641: }
1642: }
1643: $datatable .= '</td>';
1.6 raeburn 1644: if ($designs->{$img} ne '') {
1645: $imgfile = $designs->{$img};
1.18 albertel 1646: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1647: } else {
1648: $imgfile = $defaults->{$img};
1649: }
1650: if ($imgfile) {
1.9 raeburn 1651: my ($showfile,$fullsize);
1652: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1653: my $urldir = $1;
1654: my $filename = $2;
1655: my @info = &Apache::lonnet::stat_file($designs->{$img});
1656: if (@info) {
1657: my $thumbfile = 'tn-'.$filename;
1658: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1659: if (@thumb) {
1660: $showfile = $urldir.'/'.$thumbfile;
1661: } else {
1662: $showfile = $imgfile;
1663: }
1664: } else {
1665: $showfile = '';
1666: }
1667: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1668: $showfile = $imgfile;
1.6 raeburn 1669: my $imgdir = $1;
1670: my $filename = $2;
1.159 raeburn 1671: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1672: $showfile = "/$imgdir/tn-".$filename;
1673: } else {
1.159 raeburn 1674: my $input = $londocroot.$imgfile;
1675: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1676: if (!-e $output) {
1.9 raeburn 1677: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1678: my ($fullwidth,$fullheight) = &check_dimensions($input);
1679: if ($fullwidth ne '' && $fullheight ne '') {
1680: if ($fullwidth > $width && $fullheight > $height) {
1681: my $size = $width.'x'.$height;
1.316 raeburn 1682: my @args = ('convert','-sample',$size,$input,$output);
1683: system({$args[0]} @args);
1.159 raeburn 1684: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1685: }
1686: }
1.6 raeburn 1687: }
1688: }
1.16 raeburn 1689: }
1.6 raeburn 1690: if ($showfile) {
1.40 raeburn 1691: if ($showfile =~ m{^/(adm|res)/}) {
1692: if ($showfile =~ m{^/res/}) {
1693: my $local_showfile =
1694: &Apache::lonnet::filelocation('',$showfile);
1695: &Apache::lonnet::repcopy($local_showfile);
1696: }
1697: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1698: }
1699: if ($imgfile) {
1700: if ($imgfile =~ m{^/(adm|res)/}) {
1701: if ($imgfile =~ m{^/res/}) {
1702: my $local_imgfile =
1703: &Apache::lonnet::filelocation('',$imgfile);
1704: &Apache::lonnet::repcopy($local_imgfile);
1705: }
1706: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1707: } else {
1708: $fullsize = $imgfile;
1709: }
1710: }
1.41 raeburn 1711: $datatable .= '<td>';
1712: if ($img eq 'login') {
1.135 bisitz 1713: $datatable .= $login_hdr_pick;
1714: }
1.41 raeburn 1715: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1716: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1717: } else {
1.201 raeburn 1718: $datatable .= '<td> </td><td class="LC_left_item">'.
1719: &mt('Upload:').'<br />';
1.6 raeburn 1720: }
1721: } else {
1.201 raeburn 1722: $datatable .= '<td> </td><td class="LC_left_item">'.
1723: &mt('Upload:').'<br />';
1.6 raeburn 1724: }
1.9 raeburn 1725: if ($switchserver) {
1726: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1727: } else {
1.135 bisitz 1728: if ($img ne 'login') { # suppress file selection for Log-in header
1729: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1730: }
1.9 raeburn 1731: }
1732: $datatable .= '</td></tr>';
1.6 raeburn 1733: }
1734: $itemcount ++;
1735: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1736: $datatable .= '<tr'.$css_class.'>'.
1737: '<td>'.$choices->{'bgs'}.'</td>';
1738: my $bgs_def;
1739: foreach my $item (@{$bgs}) {
1740: if (!$is_custom->{$item}) {
1.329 raeburn 1741: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1742: }
1743: }
1744: if ($bgs_def) {
1.8 raeburn 1745: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1746: } else {
1747: $datatable .= '<td> </td>';
1748: }
1749: $datatable .= '<td class="LC_right_item">'.
1750: '<table border="0"><tr>';
1.174 foxr 1751:
1.6 raeburn 1752: foreach my $item (@{$bgs}) {
1.306 raeburn 1753: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1754: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1755: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1756: $datatable .= ' ';
1.6 raeburn 1757: }
1.174 foxr 1758: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1759: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1760: }
1761: $datatable .= '</tr></table></td></tr>';
1762: $itemcount ++;
1763: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1764: $datatable .= '<tr'.$css_class.'>'.
1765: '<td>'.$choices->{'links'}.'</td>';
1766: my $links_def;
1767: foreach my $item (@{$links}) {
1768: if (!$is_custom->{$item}) {
1.329 raeburn 1769: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1770: }
1771: }
1772: if ($links_def) {
1.8 raeburn 1773: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1774: } else {
1775: $datatable .= '<td> </td>';
1776: }
1777: $datatable .= '<td class="LC_right_item">'.
1778: '<table border="0"><tr>';
1779: foreach my $item (@{$links}) {
1.234 raeburn 1780: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1781: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1782: if ($designs->{'links'}{$item}) {
1.174 foxr 1783: $datatable.=' ';
1.6 raeburn 1784: }
1.174 foxr 1785: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1786: '" /></td>';
1787: }
1.30 raeburn 1788: $$rowtotal += $itemcount;
1.3 raeburn 1789: return $datatable;
1790: }
1791:
1.70 raeburn 1792: sub logo_display_options {
1793: my ($img,$defaults,$designs) = @_;
1794: my $checkedon;
1795: if (ref($defaults) eq 'HASH') {
1796: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1797: if ($defaults->{'showlogo'}{$img}) {
1798: $checkedon = 'checked="checked" ';
1799: }
1800: }
1801: }
1802: if (ref($designs) eq 'HASH') {
1803: if (ref($designs->{'showlogo'}) eq 'HASH') {
1804: if (defined($designs->{'showlogo'}{$img})) {
1805: if ($designs->{'showlogo'}{$img} == 0) {
1806: $checkedon = '';
1807: } elsif ($designs->{'showlogo'}{$img} == 1) {
1808: $checkedon = 'checked="checked" ';
1809: }
1810: }
1811: }
1812: }
1813: return '<br /><label> <input type="checkbox" name="'.
1814: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1815: &mt('show').'</label>'."\n";
1816: }
1817:
1.41 raeburn 1818: sub login_header_options {
1.135 bisitz 1819: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1820: my $output = '';
1.41 raeburn 1821: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1822: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1823: if (!$is_custom->{'textcol'}) {
1824: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1825: ' ';
1826: }
1827: if (!$is_custom->{'bgcol'}) {
1828: $output .= $choices->{'bgcol'}.': '.
1829: '<span id="css_'.$role.'_font" style="background-color: '.
1830: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1831: }
1832: $output .= '<br />';
1833: }
1834: $output .='<br />';
1835: return $output;
1836: }
1837:
1838: sub login_text_colors {
1.201 raeburn 1839: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1840: my $color_menu = '<table border="0"><tr>';
1841: foreach my $item (@{$logintext}) {
1.306 raeburn 1842: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1843: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1844: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1845: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1846: }
1847: $color_menu .= '</tr></table><br />';
1848: return $color_menu;
1849: }
1850:
1851: sub image_changes {
1852: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1853: my $output;
1.135 bisitz 1854: if ($img eq 'login') {
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: );
1.328 raeburn 8484: my %selnum = (
8485: instcode => '0',
8486: communities => '1',
8487: placement => '2',
8488: );
8489: my %selected;
1.272 raeburn 8490: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8491: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 8492: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 8493: map { $selected{$selnum{$_}} = '' } keys(%selnum);
8494: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 8495: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 8496: .'<select name="'.$default.'_pos"'.$chgstr.'>'
8497: .'<option value="0"'.$selected{'0'}.'>1</option>'
8498: .'<option value="1"'.$selected{'1'}.'>2</option>'
8499: .'<option value="2"'.$selected{'2'}.'>3</option>'
8500: .'<option value="3">4</option></select> '
1.120 raeburn 8501: .$default_names{$default}
8502: .'</span></td><td><span class="LC_nobreak">'
8503: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8504: .&mt('Display').'</label> <label>'
8505: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8506: .'</label></span></td></tr>';
1.120 raeburn 8507: $itemcount ++;
8508: }
1.48 raeburn 8509: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8510: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8511: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8512: .'<select name="addcategory_pos"'.$chgstr.'>'
8513: .'<option value="0">1</option>'
8514: .'<option value="1">2</option>'
1.328 raeburn 8515: .'<option value="2">3</option>'
8516: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 8517: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
8518: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8519: .'</td></tr>';
1.48 raeburn 8520: return $datatable;
8521: }
8522:
8523: sub build_category_rows {
1.49 raeburn 8524: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8525: my ($text,$name,$item,$chgstr);
1.48 raeburn 8526: if (ref($cats) eq 'ARRAY') {
8527: my $maxdepth = scalar(@{$cats});
8528: if (ref($cats->[$depth]) eq 'HASH') {
8529: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8530: my $numchildren = @{$cats->[$depth]{$parent}};
8531: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 8532: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8533: my ($idxnum,$parent_name,$parent_item);
8534: my $higher = $depth - 1;
8535: if ($higher == 0) {
8536: $parent_name = &escape($parent).'::'.$higher;
8537: } else {
8538: if (ref($path) eq 'ARRAY') {
8539: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8540: }
8541: }
8542: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8543: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8544: if ($j < $numchildren) {
1.48 raeburn 8545: $name = $cats->[$depth]{$parent}[$j];
8546: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8547: $idxnum = $idx->{$item};
8548: } else {
8549: $name = $parent_name;
8550: $item = $parent_item;
1.48 raeburn 8551: }
1.49 raeburn 8552: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8553: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8554: for (my $i=0; $i<=$numchildren; $i++) {
8555: my $vpos = $i+1;
8556: my $selstr;
8557: if ($j == $i) {
8558: $selstr = ' selected="selected" ';
8559: }
8560: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8561: }
8562: $text .= '</select> ';
8563: if ($j < $numchildren) {
8564: my $deeper = $depth+1;
8565: $text .= $name.' '
8566: .'<label><input type="checkbox" name="deletecategory" value="'
8567: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8568: if(ref($path) eq 'ARRAY') {
8569: push(@{$path},$name);
1.49 raeburn 8570: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8571: pop(@{$path});
8572: }
8573: } else {
1.330 ! raeburn 8574: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 8575: if ($j == $numchildren) {
8576: $text .= $name;
8577: } else {
8578: $text .= $item;
8579: }
8580: $text .= '" value="" />';
8581: }
8582: $text .= '</td></tr>';
8583: }
8584: $text .= '</table></td>';
8585: } else {
8586: my $higher = $depth-1;
8587: if ($higher == 0) {
8588: $name = &escape($parent).'::'.$higher;
8589: } else {
8590: if (ref($path) eq 'ARRAY') {
8591: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8592: }
8593: }
8594: my $colspan;
8595: if ($parent ne 'instcode') {
8596: $colspan = $maxdepth - $depth - 1;
1.330 ! raeburn 8597: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 8598: }
8599: }
8600: }
8601: }
8602: return $text;
8603: }
8604:
1.33 raeburn 8605: sub modifiable_userdata_row {
1.305 raeburn 8606: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8607: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 8608: my ($role,$rolename,$statustype);
8609: $role = $item;
1.224 raeburn 8610: if ($context eq 'cancreate') {
1.305 raeburn 8611: if ($item =~ /^(emailusername)_(.+)$/) {
8612: $role = $1;
8613: $statustype = $2;
1.228 raeburn 8614: if (ref($usertypes) eq 'HASH') {
8615: if ($usertypes->{$statustype}) {
8616: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8617: } else {
8618: $rolename = &mt('Data provided by user');
8619: }
8620: }
1.224 raeburn 8621: }
8622: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8623: if (ref($usertypes) eq 'HASH') {
8624: $rolename = $usertypes->{$role};
8625: } else {
8626: $rolename = $role;
8627: }
1.325 raeburn 8628: } elsif ($context eq 'lti') {
8629: $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 8630: } else {
1.63 raeburn 8631: if ($role eq 'cr') {
8632: $rolename = &mt('Custom role');
8633: } else {
8634: $rolename = &Apache::lonnet::plaintext($role);
8635: }
1.33 raeburn 8636: }
1.224 raeburn 8637: my (@fields,%fieldtitles);
8638: if (ref($fieldsref) eq 'ARRAY') {
8639: @fields = @{$fieldsref};
8640: } else {
8641: @fields = ('lastname','firstname','middlename','generation',
8642: 'permanentemail','id');
8643: }
8644: if ((ref($titlesref) eq 'HASH')) {
8645: %fieldtitles = %{$titlesref};
8646: } else {
8647: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8648: }
1.33 raeburn 8649: my $output;
1.305 raeburn 8650: my $css_class;
8651: if ($rowcount%2) {
8652: $css_class = 'LC_odd_row';
8653: }
8654: if ($customcss) {
8655: $css_class .= " $customcss";
8656: }
8657: $css_class =~ s/^\s+//;
8658: if ($css_class) {
8659: $css_class = ' class="'.$css_class.'"';
8660: }
8661: if ($rowstyle) {
8662: $css_class .= ' style="'.$rowstyle.'"';
8663: }
8664: if ($rowid) {
8665: $rowid = ' id="'.$rowid.'"';
8666: }
8667: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8668: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8669: '<td class="LC_left_item" colspan="2"><table>';
8670: my $rem;
8671: my %checks;
1.325 raeburn 8672: my %current;
1.33 raeburn 8673: if (ref($settings) eq 'HASH') {
1.325 raeburn 8674: my $hashref;
8675: if ($context eq 'lti') {
8676: if (ref($settings) eq 'HASH') {
8677: $hashref = $settings->{'instdata'};
8678: }
8679: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 8680: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 8681: $hashref = $settings->{'lti_instdata'};
8682: }
8683: if ($role eq 'emailusername') {
8684: if ($statustype) {
8685: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8686: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 8687: }
1.325 raeburn 8688: }
8689: }
8690: }
8691: if (ref($hashref) eq 'HASH') {
8692: foreach my $field (@fields) {
8693: if ($hashref->{$field}) {
8694: if ($role eq 'emailusername') {
8695: $checks{$field} = $hashref->{$field};
8696: } else {
8697: $checks{$field} = ' checked="checked" ';
1.33 raeburn 8698: }
8699: }
8700: }
8701: }
8702: }
1.305 raeburn 8703:
8704: my $total = scalar(@fields);
8705: for (my $i=0; $i<$total; $i++) {
8706: $rem = $i%($numinrow);
1.33 raeburn 8707: if ($rem == 0) {
8708: if ($i > 0) {
8709: $output .= '</tr>';
8710: }
8711: $output .= '<tr>';
8712: }
8713: my $check = ' ';
1.228 raeburn 8714: unless ($role eq 'emailusername') {
8715: if (exists($checks{$fields[$i]})) {
8716: $check = $checks{$fields[$i]}
1.325 raeburn 8717: } elsif ($context ne 'lti') {
1.228 raeburn 8718: if ($role eq 'st') {
8719: if (ref($settings) ne 'HASH') {
8720: $check = ' checked="checked" ';
8721: }
1.33 raeburn 8722: }
8723: }
8724: }
8725: $output .= '<td class="LC_left_item">'.
1.228 raeburn 8726: '<span class="LC_nobreak">';
1.325 raeburn 8727: my $prefix = 'canmodify';
1.228 raeburn 8728: if ($role eq 'emailusername') {
8729: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8730: $checks{$fields[$i]} = 'omit';
8731: }
8732: foreach my $option ('required','optional','omit') {
8733: my $checked='';
8734: if ($checks{$fields[$i]} eq $option) {
8735: $checked='checked="checked" ';
8736: }
8737: $output .= '<label>'.
1.325 raeburn 8738: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 8739: &mt($option).'</label>'.(' ' x2);
8740: }
8741: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8742: } else {
1.325 raeburn 8743: if ($context eq 'lti') {
8744: $prefix = 'lti';
8745: }
1.228 raeburn 8746: $output .= '<label>'.
1.325 raeburn 8747: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 8748: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8749: '</label>';
8750: }
8751: $output .= '</span></td>';
1.33 raeburn 8752: }
1.305 raeburn 8753: $rem = $total%$numinrow;
8754: my $colsleft;
8755: if ($rem) {
8756: $colsleft = $numinrow - $rem;
8757: }
8758: if ($colsleft > 1) {
1.33 raeburn 8759: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8760: ' </td>';
8761: } elsif ($colsleft == 1) {
8762: $output .= '<td class="LC_left_item"> </td>';
8763: }
8764: $output .= '</tr></table></td></tr>';
8765: return $output;
8766: }
1.28 raeburn 8767:
1.93 raeburn 8768: sub insttypes_row {
1.305 raeburn 8769: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8770: $customcss,$rowstyle) = @_;
1.93 raeburn 8771: my %lt = &Apache::lonlocal::texthash (
8772: cansearch => 'Users allowed to search',
8773: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8774: lockablenames => 'User preference to lock name',
1.305 raeburn 8775: selfassign => 'Self-reportable affiliations',
1.315 raeburn 8776: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8777: );
8778: my $showdom;
8779: if ($context eq 'cansearch') {
8780: $showdom = ' ('.$dom.')';
8781: }
1.165 raeburn 8782: my $class = 'LC_left_item';
8783: if ($context eq 'statustocreate') {
8784: $class = 'LC_right_item';
8785: }
1.305 raeburn 8786: my $css_class;
8787: if ($$rowtotal%2) {
8788: $css_class = 'LC_odd_row';
8789: }
8790: if ($customcss) {
8791: $css_class .= ' '.$customcss;
8792: }
8793: $css_class =~ s/^\s+//;
8794: if ($css_class) {
8795: $css_class = ' class="'.$css_class.'"';
8796: }
8797: if ($rowstyle) {
8798: $css_class .= ' style="'.$rowstyle.'"';
8799: }
8800: if ($onclick) {
8801: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 8802: }
8803: my $output = '<tr'.$css_class.'>'.
8804: '<td>'.$lt{$context}.$showdom.
8805: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8806: my $rem;
8807: if (ref($types) eq 'ARRAY') {
8808: for (my $i=0; $i<@{$types}; $i++) {
8809: if (defined($usertypes->{$types->[$i]})) {
8810: my $rem = $i%($numinrow);
8811: if ($rem == 0) {
8812: if ($i > 0) {
8813: $output .= '</tr>';
8814: }
8815: $output .= '<tr>';
1.23 raeburn 8816: }
1.26 raeburn 8817: my $check = ' ';
1.99 raeburn 8818: if (ref($settings) eq 'HASH') {
8819: if (ref($settings->{$context}) eq 'ARRAY') {
8820: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8821: $check = ' checked="checked" ';
8822: }
1.315 raeburn 8823: } elsif (ref($settings->{$context}) eq 'HASH') {
8824: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8825: $check = ' checked="checked" ';
8826: }
1.99 raeburn 8827: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8828: $check = ' checked="checked" ';
8829: }
1.23 raeburn 8830: }
1.26 raeburn 8831: $output .= '<td class="LC_left_item">'.
8832: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8833: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 8834: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 8835: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8836: }
8837: }
1.26 raeburn 8838: $rem = @{$types}%($numinrow);
1.23 raeburn 8839: }
8840: my $colsleft = $numinrow - $rem;
1.315 raeburn 8841: if ($context eq 'overrides') {
8842: if ($colsleft > 1) {
8843: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8844: } else {
8845: $output .= '<td class="LC_left_item">';
8846: }
8847: $output .= ' ';
1.23 raeburn 8848: } else {
1.315 raeburn 8849: if (($rem == 0) && (@{$types} > 0)) {
8850: $output .= '<tr>';
8851: }
8852: if ($colsleft > 1) {
8853: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8854: } else {
8855: $output .= '<td class="LC_left_item">';
8856: }
8857: my $defcheck = ' ';
8858: if (ref($settings) eq 'HASH') {
8859: if (ref($settings->{$context}) eq 'ARRAY') {
8860: if (grep(/^default$/,@{$settings->{$context}})) {
8861: $defcheck = ' checked="checked" ';
8862: }
8863: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8864: $defcheck = ' checked="checked" ';
8865: }
1.26 raeburn 8866: }
1.315 raeburn 8867: $output .= '<span class="LC_nobreak"><label>'.
8868: '<input type="checkbox" name="'.$context.'" '.
8869: 'value="default"'.$defcheck.$onclick.' />'.
8870: $othertitle.'</label></span>';
1.23 raeburn 8871: }
1.315 raeburn 8872: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8873: return $output;
1.23 raeburn 8874: }
8875:
8876: sub sorted_searchtitles {
8877: my %searchtitles = &Apache::lonlocal::texthash(
8878: 'uname' => 'username',
8879: 'lastname' => 'last name',
8880: 'lastfirst' => 'last name, first name',
8881: );
8882: my @titleorder = ('uname','lastname','lastfirst');
8883: return (\%searchtitles,\@titleorder);
8884: }
8885:
1.25 raeburn 8886: sub sorted_searchtypes {
8887: my %srchtypes_desc = (
8888: exact => 'is exact match',
8889: contains => 'contains ..',
8890: begins => 'begins with ..',
8891: );
8892: my @srchtypeorder = ('exact','begins','contains');
8893: return (\%srchtypes_desc,\@srchtypeorder);
8894: }
8895:
1.3 raeburn 8896: sub usertype_update_row {
8897: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8898: my $datatable;
8899: my $numinrow = 4;
8900: foreach my $type (@{$types}) {
8901: if (defined($usertypes->{$type})) {
8902: $$rownums ++;
8903: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8904: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8905: '</td><td class="LC_left_item"><table>';
8906: for (my $i=0; $i<@{$fields}; $i++) {
8907: my $rem = $i%($numinrow);
8908: if ($rem == 0) {
8909: if ($i > 0) {
8910: $datatable .= '</tr>';
8911: }
8912: $datatable .= '<tr>';
8913: }
8914: my $check = ' ';
1.39 raeburn 8915: if (ref($settings) eq 'HASH') {
8916: if (ref($settings->{'fields'}) eq 'HASH') {
8917: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8918: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8919: $check = ' checked="checked" ';
8920: }
1.3 raeburn 8921: }
8922: }
8923: }
8924:
8925: if ($i == @{$fields}-1) {
8926: my $colsleft = $numinrow - $rem;
8927: if ($colsleft > 1) {
8928: $datatable .= '<td colspan="'.$colsleft.'">';
8929: } else {
8930: $datatable .= '<td>';
8931: }
8932: } else {
8933: $datatable .= '<td>';
8934: }
1.8 raeburn 8935: $datatable .= '<span class="LC_nobreak"><label>'.
8936: '<input type="checkbox" name="updateable_'.$type.
8937: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8938: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8939: }
8940: $datatable .= '</tr></table></td></tr>';
8941: }
8942: }
8943: return $datatable;
1.1 raeburn 8944: }
8945:
8946: sub modify_login {
1.205 raeburn 8947: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 8948: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8949: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8950: %title = ( coursecatalog => 'Display course catalog',
8951: adminmail => 'Display administrator E-mail address',
1.188 raeburn 8952: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 8953: newuser => 'Link for visitors to create a user account',
8954: loginheader => 'Log-in box header');
8955: @offon = ('off','on');
1.112 raeburn 8956: if (ref($domconfig{login}) eq 'HASH') {
8957: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8958: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8959: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8960: }
8961: }
8962: }
1.9 raeburn 8963: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8964: \%domconfig,\%loginhash);
1.188 raeburn 8965: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8966: foreach my $item (@toggles) {
8967: $loginhash{login}{$item} = $env{'form.'.$item};
8968: }
1.41 raeburn 8969: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 8970: if (ref($colchanges{'login'}) eq 'HASH') {
8971: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8972: \%loginhash);
8973: }
1.110 raeburn 8974:
1.149 raeburn 8975: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 8976: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 8977: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 8978: if (keys(%servers) > 1) {
8979: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 8980: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8981: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8982: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8983: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8984: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8985: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8986: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8987: $changes{'loginvia'}{$lonhost} = 1;
8988: } else {
8989: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8990: $changes{'loginvia'}{$lonhost} = 1;
8991: }
8992: } else {
8993: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8994: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8995: $changes{'loginvia'}{$lonhost} = 1;
8996: }
8997: }
8998: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8999: foreach my $item (@loginvia_attribs) {
9000: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9001: }
9002: } else {
9003: foreach my $item (@loginvia_attribs) {
9004: my $new = $env{'form.'.$lonhost.'_'.$item};
9005: if (($item eq 'serverpath') && ($new eq 'custom')) {
9006: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9007: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9008: $new = '/';
9009: }
9010: }
9011: if (($item eq 'custompath') &&
9012: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9013: $new = '';
9014: }
9015: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9016: $changes{'loginvia'}{$lonhost} = 1;
9017: }
9018: if ($item eq 'exempt') {
1.256 raeburn 9019: $new = &check_exempt_addresses($new);
1.128 raeburn 9020: }
9021: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9022: }
9023: }
1.112 raeburn 9024: } else {
1.128 raeburn 9025: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9026: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9027: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9028: foreach my $item (@loginvia_attribs) {
9029: my $new = $env{'form.'.$lonhost.'_'.$item};
9030: if (($item eq 'serverpath') && ($new eq 'custom')) {
9031: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9032: $new = '/';
9033: }
9034: }
9035: if (($item eq 'custompath') &&
9036: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9037: $new = '';
9038: }
9039: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9040: }
1.110 raeburn 9041: }
9042: }
9043: }
9044: }
1.119 raeburn 9045:
1.168 raeburn 9046: my $servadm = $r->dir_config('lonAdmEMail');
9047: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9048: if (ref($domconfig{'login'}) eq 'HASH') {
9049: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9050: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9051: if ($lang eq 'nolang') {
9052: push(@currlangs,$lang);
9053: } elsif (defined($langchoices{$lang})) {
9054: push(@currlangs,$lang);
9055: } else {
9056: next;
9057: }
9058: }
9059: }
9060: }
9061: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9062: if (@currlangs > 0) {
9063: foreach my $lang (@currlangs) {
9064: if (grep(/^\Q$lang\E$/,@delurls)) {
9065: $changes{'helpurl'}{$lang} = 1;
9066: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9067: $changes{'helpurl'}{$lang} = 1;
9068: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9069: push(@newlangs,$lang);
9070: } else {
9071: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9072: }
9073: }
9074: }
9075: unless (grep(/^nolang$/,@currlangs)) {
9076: if ($env{'form.loginhelpurl_nolang.filename'}) {
9077: $changes{'helpurl'}{'nolang'} = 1;
9078: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9079: push(@newlangs,'nolang');
9080: }
9081: }
9082: if ($env{'form.loginhelpurl_add_lang'}) {
9083: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9084: ($env{'form.loginhelpurl_add_file.filename'})) {
9085: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9086: $addedfile = $env{'form.loginhelpurl_add_lang'};
9087: }
9088: }
9089: if ((@newlangs > 0) || ($addedfile)) {
9090: my $error;
9091: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9092: if ($configuserok eq 'ok') {
9093: if ($switchserver) {
9094: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9095: } elsif ($author_ok eq 'ok') {
9096: my @allnew = @newlangs;
9097: if ($addedfile ne '') {
9098: push(@allnew,$addedfile);
9099: }
9100: foreach my $lang (@allnew) {
9101: my $formelem = 'loginhelpurl_'.$lang;
9102: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9103: $formelem = 'loginhelpurl_add_file';
9104: }
9105: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9106: "help/$lang",'','',$newfile{$lang});
9107: if ($result eq 'ok') {
9108: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9109: $changes{'helpurl'}{$lang} = 1;
9110: } else {
9111: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9112: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 9113: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 9114: (!grep(/^\Q$lang\E$/,@delurls))) {
9115: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9116: }
9117: }
9118: }
9119: } else {
9120: $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);
9121: }
9122: } else {
9123: $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);
9124: }
9125: if ($error) {
9126: &Apache::lonnet::logthis($error);
9127: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9128: }
9129: }
1.256 raeburn 9130:
9131: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9132: if (ref($domconfig{'login'}) eq 'HASH') {
9133: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9134: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9135: if ($domservers{$lonhost}) {
9136: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9137: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 9138: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 9139: }
9140: }
9141: }
9142: }
9143: }
9144: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9145: foreach my $lonhost (sort(keys(%domservers))) {
9146: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9147: $changes{'headtag'}{$lonhost} = 1;
9148: } else {
9149: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9150: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9151: }
9152: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9153: push(@newhosts,$lonhost);
9154: } elsif ($currheadtagurls{$lonhost}) {
9155: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9156: if ($currexempt{$lonhost}) {
1.289 raeburn 9157: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 9158: $changes{'headtag'}{$lonhost} = 1;
9159: }
9160: } elsif ($possexempt{$lonhost}) {
9161: $changes{'headtag'}{$lonhost} = 1;
9162: }
9163: if ($possexempt{$lonhost}) {
9164: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9165: }
9166: }
9167: }
9168: }
9169: if (@newhosts) {
9170: my $error;
9171: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9172: if ($configuserok eq 'ok') {
9173: if ($switchserver) {
9174: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9175: } elsif ($author_ok eq 'ok') {
9176: foreach my $lonhost (@newhosts) {
9177: my $formelem = 'loginheadtag_'.$lonhost;
9178: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9179: "login/headtag/$lonhost",'','',
9180: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9181: if ($result eq 'ok') {
9182: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9183: $changes{'headtag'}{$lonhost} = 1;
9184: if ($possexempt{$lonhost}) {
9185: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9186: }
9187: } else {
9188: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9189: $newheadtagurls{$lonhost},$result);
9190: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9191: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9192: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9193: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9194: }
9195: }
9196: }
9197: } else {
9198: $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);
9199: }
9200: } else {
9201: $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);
9202: }
9203: if ($error) {
9204: &Apache::lonnet::logthis($error);
9205: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9206: }
9207: }
1.169 raeburn 9208: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 9209:
9210: my $defaulthelpfile = '/adm/loginproblems.html';
9211: my $defaulttext = &mt('Default in use');
9212:
1.1 raeburn 9213: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9214: $dom);
9215: if ($putresult eq 'ok') {
1.188 raeburn 9216: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9217: my %defaultchecked = (
9218: 'coursecatalog' => 'on',
1.188 raeburn 9219: 'helpdesk' => 'on',
1.42 raeburn 9220: 'adminmail' => 'off',
1.43 raeburn 9221: 'newuser' => 'off',
1.42 raeburn 9222: );
1.55 raeburn 9223: if (ref($domconfig{'login'}) eq 'HASH') {
9224: foreach my $item (@toggles) {
9225: if ($defaultchecked{$item} eq 'on') {
9226: if (($domconfig{'login'}{$item} eq '0') &&
9227: ($env{'form.'.$item} eq '1')) {
9228: $changes{$item} = 1;
9229: } elsif (($domconfig{'login'}{$item} eq '' ||
9230: $domconfig{'login'}{$item} eq '1') &&
9231: ($env{'form.'.$item} eq '0')) {
9232: $changes{$item} = 1;
9233: }
9234: } elsif ($defaultchecked{$item} eq 'off') {
9235: if (($domconfig{'login'}{$item} eq '1') &&
9236: ($env{'form.'.$item} eq '0')) {
9237: $changes{$item} = 1;
9238: } elsif (($domconfig{'login'}{$item} eq '' ||
9239: $domconfig{'login'}{$item} eq '0') &&
9240: ($env{'form.'.$item} eq '1')) {
9241: $changes{$item} = 1;
9242: }
1.42 raeburn 9243: }
9244: }
1.41 raeburn 9245: }
1.6 raeburn 9246: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9247: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9248: if (ref($lastactref) eq 'HASH') {
9249: $lastactref->{'domainconfig'} = 1;
9250: }
1.1 raeburn 9251: $resulttext = &mt('Changes made:').'<ul>';
9252: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9253: if ($item eq 'loginvia') {
1.112 raeburn 9254: if (ref($changes{$item}) eq 'HASH') {
9255: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9256: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9257: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9258: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9259: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9260: $protocol = 'http' if ($protocol ne 'https');
9261: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9262:
9263: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9264: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9265: } else {
9266: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9267: }
9268: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9269: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9270: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9271: }
9272: $resulttext .= '</li>';
9273: } else {
9274: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9275: }
1.112 raeburn 9276: } else {
1.128 raeburn 9277: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9278: }
9279: }
1.128 raeburn 9280: $resulttext .= '</ul></li>';
1.112 raeburn 9281: }
1.168 raeburn 9282: } elsif ($item eq 'helpurl') {
9283: if (ref($changes{$item}) eq 'HASH') {
9284: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9285: if (grep(/^\Q$lang\E$/,@delurls)) {
9286: my ($chg,$link);
9287: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9288: if ($lang eq 'nolang') {
9289: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9290: } else {
9291: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9292: }
9293: $resulttext .= '<li>'.$chg.'</li>';
9294: } else {
9295: my $chg;
9296: if ($lang eq 'nolang') {
9297: $chg = &mt('custom log-in help file for no preferred language');
9298: } else {
9299: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9300: }
9301: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9302: $loginhash{'login'}{'helpurl'}{$lang}.
9303: '?inhibitmenu=yes',$chg,600,500).
9304: '</li>';
9305: }
9306: }
9307: }
1.256 raeburn 9308: } elsif ($item eq 'headtag') {
9309: if (ref($changes{$item}) eq 'HASH') {
9310: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9311: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9312: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9313: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9314: $resulttext .= '<li><a href="'.
9315: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9316: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9317: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9318: if ($possexempt{$lonhost}) {
9319: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9320: } else {
9321: $resulttext .= &mt('included for any client IP');
9322: }
9323: $resulttext .= '</li>';
9324: }
9325: }
9326: }
1.169 raeburn 9327: } elsif ($item eq 'captcha') {
9328: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 9329: my $chgtxt;
1.169 raeburn 9330: if ($loginhash{'login'}{$item} eq 'notused') {
9331: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9332: } else {
9333: my %captchas = &captcha_phrases();
9334: if ($captchas{$loginhash{'login'}{$item}}) {
9335: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9336: } else {
9337: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9338: }
9339: }
9340: $resulttext .= '<li>'.$chgtxt.'</li>';
9341: }
9342: } elsif ($item eq 'recaptchakeys') {
9343: if (ref($loginhash{'login'}) eq 'HASH') {
9344: my ($privkey,$pubkey);
9345: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9346: $pubkey = $loginhash{'login'}{$item}{'public'};
9347: $privkey = $loginhash{'login'}{$item}{'private'};
9348: }
9349: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9350: if (!$pubkey) {
9351: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9352: } else {
9353: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9354: }
9355: if (!$privkey) {
9356: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9357: } else {
1.251 raeburn 9358: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 9359: }
9360: $chgtxt .= '</ul>';
9361: $resulttext .= '<li>'.$chgtxt.'</li>';
9362: }
1.269 raeburn 9363: } elsif ($item eq 'recaptchaversion') {
9364: if (ref($loginhash{'login'}) eq 'HASH') {
9365: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 9366: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 9367: '</li>';
9368: }
9369: }
1.41 raeburn 9370: } else {
9371: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9372: }
1.1 raeburn 9373: }
1.6 raeburn 9374: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9375: } else {
9376: $resulttext = &mt('No changes made to log-in page settings');
9377: }
9378: } else {
1.11 albertel 9379: $resulttext = '<span class="LC_error">'.
9380: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9381: }
1.6 raeburn 9382: if ($errors) {
1.9 raeburn 9383: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9384: $errors.'</ul>';
9385: }
9386: return $resulttext;
9387: }
9388:
1.256 raeburn 9389: sub check_exempt_addresses {
9390: my ($iplist) = @_;
9391: $iplist =~ s/^\s+//;
9392: $iplist =~ s/\s+$//;
9393: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9394: my (@okips,$new);
9395: foreach my $ip (@poss_ips) {
9396: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9397: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9398: push(@okips,$ip);
9399: }
9400: }
9401: }
9402: if (@okips > 0) {
9403: $new = join(',',@okips);
9404: } else {
9405: $new = '';
9406: }
9407: return $new;
9408: }
9409:
1.6 raeburn 9410: sub color_font_choices {
9411: my %choices =
9412: &Apache::lonlocal::texthash (
9413: img => "Header",
9414: bgs => "Background colors",
9415: links => "Link colors",
1.55 raeburn 9416: images => "Images",
1.6 raeburn 9417: font => "Font color",
1.201 raeburn 9418: fontmenu => "Font menu",
1.76 raeburn 9419: pgbg => "Page",
1.6 raeburn 9420: tabbg => "Header",
9421: sidebg => "Border",
9422: link => "Link",
9423: alink => "Active link",
9424: vlink => "Visited link",
9425: );
9426: return %choices;
9427: }
9428:
9429: sub modify_rolecolors {
1.205 raeburn 9430: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9431: my ($resulttext,%rolehash);
9432: $rolehash{'rolecolors'} = {};
1.55 raeburn 9433: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9434: if ($domconfig{'rolecolors'} eq '') {
9435: $domconfig{'rolecolors'} = {};
9436: }
9437: }
1.9 raeburn 9438: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9439: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9440: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9441: $dom);
9442: if ($putresult eq 'ok') {
9443: if (keys(%changes) > 0) {
1.41 raeburn 9444: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9445: if (ref($lastactref) eq 'HASH') {
9446: $lastactref->{'domainconfig'} = 1;
9447: }
1.6 raeburn 9448: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9449: $rolehash{'rolecolors'});
9450: } else {
9451: $resulttext = &mt('No changes made to default color schemes');
9452: }
9453: } else {
1.11 albertel 9454: $resulttext = '<span class="LC_error">'.
9455: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9456: }
9457: if ($errors) {
9458: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9459: $errors.'</ul>';
9460: }
9461: return $resulttext;
9462: }
9463:
9464: sub modify_colors {
1.9 raeburn 9465: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9466: my (%changes,%choices);
1.51 raeburn 9467: my @bgs;
1.6 raeburn 9468: my @links = ('link','alink','vlink');
1.41 raeburn 9469: my @logintext;
1.6 raeburn 9470: my @images;
9471: my $servadm = $r->dir_config('lonAdmEMail');
9472: my $errors;
1.200 raeburn 9473: my %defaults;
1.6 raeburn 9474: foreach my $role (@{$roles}) {
9475: if ($role eq 'login') {
1.12 raeburn 9476: %choices = &login_choices();
1.41 raeburn 9477: @logintext = ('textcol','bgcol');
1.12 raeburn 9478: } else {
9479: %choices = &color_font_choices();
9480: }
9481: if ($role eq 'login') {
1.41 raeburn 9482: @images = ('img','logo','domlogo','login');
1.51 raeburn 9483: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9484: } else {
9485: @images = ('img');
1.200 raeburn 9486: @bgs = ('pgbg','tabbg','sidebg');
9487: }
9488: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9489: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9490: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9491: }
9492: if ($role eq 'login') {
9493: foreach my $item (@logintext) {
1.234 raeburn 9494: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9495: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9496: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9497: }
9498: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 9499: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9500: }
9501: }
9502: } else {
1.234 raeburn 9503: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9504: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9505: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9506: }
9507: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 9508: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9509: }
1.6 raeburn 9510: }
1.200 raeburn 9511: foreach my $item (@bgs) {
1.234 raeburn 9512: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9513: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9514: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9515: }
9516: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 9517: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9518: }
9519: }
9520: foreach my $item (@links) {
1.234 raeburn 9521: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9522: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9523: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9524: }
9525: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 9526: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9527: }
1.6 raeburn 9528: }
1.46 raeburn 9529: my ($configuserok,$author_ok,$switchserver) =
9530: &config_check($dom,$confname,$servadm);
1.9 raeburn 9531: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 9532: if (ref($domconfig->{$role}) ne 'HASH') {
9533: $domconfig->{$role} = {};
9534: }
1.8 raeburn 9535: foreach my $img (@images) {
1.70 raeburn 9536: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9537: if (defined($env{'form.login_showlogo_'.$img})) {
9538: $confhash->{$role}{'showlogo'}{$img} = 1;
9539: } else {
9540: $confhash->{$role}{'showlogo'}{$img} = 0;
9541: }
9542: }
1.18 albertel 9543: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9544: && !defined($domconfig->{$role}{$img})
9545: && !$env{'form.'.$role.'_del_'.$img}
9546: && $env{'form.'.$role.'_import_'.$img}) {
9547: # import the old configured image from the .tab setting
9548: # if they haven't provided a new one
9549: $domconfig->{$role}{$img} =
9550: $env{'form.'.$role.'_import_'.$img};
9551: }
1.6 raeburn 9552: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9553: my $error;
1.6 raeburn 9554: if ($configuserok eq 'ok') {
1.9 raeburn 9555: if ($switchserver) {
1.12 raeburn 9556: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9557: } else {
9558: if ($author_ok eq 'ok') {
9559: my ($result,$logourl) =
9560: &publishlogo($r,'upload',$role.'_'.$img,
9561: $dom,$confname,$img,$width,$height);
9562: if ($result eq 'ok') {
9563: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9564: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9565: } else {
1.12 raeburn 9566: $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 9567: }
9568: } else {
1.46 raeburn 9569: $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 9570: }
9571: }
9572: } else {
1.46 raeburn 9573: $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 9574: }
9575: if ($error) {
1.8 raeburn 9576: &Apache::lonnet::logthis($error);
1.11 albertel 9577: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9578: }
9579: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9580: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9581: my $error;
9582: if ($configuserok eq 'ok') {
9583: # is confname an author?
9584: if ($switchserver eq '') {
9585: if ($author_ok eq 'ok') {
9586: my ($result,$logourl) =
9587: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9588: $dom,$confname,$img,$width,$height);
9589: if ($result eq 'ok') {
9590: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9591: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9592: }
9593: }
9594: }
9595: }
1.6 raeburn 9596: }
9597: }
9598: }
9599: if (ref($domconfig) eq 'HASH') {
9600: if (ref($domconfig->{$role}) eq 'HASH') {
9601: foreach my $img (@images) {
9602: if ($domconfig->{$role}{$img} ne '') {
9603: if ($env{'form.'.$role.'_del_'.$img}) {
9604: $confhash->{$role}{$img} = '';
1.12 raeburn 9605: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9606: } else {
1.9 raeburn 9607: if ($confhash->{$role}{$img} eq '') {
9608: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
9609: }
1.6 raeburn 9610: }
9611: } else {
9612: if ($env{'form.'.$role.'_del_'.$img}) {
9613: $confhash->{$role}{$img} = '';
1.12 raeburn 9614: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9615: }
9616: }
1.70 raeburn 9617: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
9618: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
9619: if ($confhash->{$role}{'showlogo'}{$img} ne
9620: $domconfig->{$role}{'showlogo'}{$img}) {
9621: $changes{$role}{'showlogo'}{$img} = 1;
9622: }
9623: } else {
9624: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9625: $changes{$role}{'showlogo'}{$img} = 1;
9626: }
9627: }
9628: }
9629: }
1.6 raeburn 9630: if ($domconfig->{$role}{'font'} ne '') {
9631: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
9632: $changes{$role}{'font'} = 1;
9633: }
9634: } else {
9635: if ($confhash->{$role}{'font'}) {
9636: $changes{$role}{'font'} = 1;
9637: }
9638: }
1.107 raeburn 9639: if ($role ne 'login') {
9640: if ($domconfig->{$role}{'fontmenu'} ne '') {
9641: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
9642: $changes{$role}{'fontmenu'} = 1;
9643: }
9644: } else {
9645: if ($confhash->{$role}{'fontmenu'}) {
9646: $changes{$role}{'fontmenu'} = 1;
9647: }
1.97 tempelho 9648: }
9649: }
1.6 raeburn 9650: foreach my $item (@bgs) {
9651: if ($domconfig->{$role}{$item} ne '') {
9652: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9653: $changes{$role}{'bgs'}{$item} = 1;
9654: }
9655: } else {
9656: if ($confhash->{$role}{$item}) {
9657: $changes{$role}{'bgs'}{$item} = 1;
9658: }
9659: }
9660: }
9661: foreach my $item (@links) {
9662: if ($domconfig->{$role}{$item} ne '') {
9663: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9664: $changes{$role}{'links'}{$item} = 1;
9665: }
9666: } else {
9667: if ($confhash->{$role}{$item}) {
9668: $changes{$role}{'links'}{$item} = 1;
9669: }
9670: }
9671: }
1.41 raeburn 9672: foreach my $item (@logintext) {
9673: if ($domconfig->{$role}{$item} ne '') {
9674: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9675: $changes{$role}{'logintext'}{$item} = 1;
9676: }
9677: } else {
9678: if ($confhash->{$role}{$item}) {
9679: $changes{$role}{'logintext'}{$item} = 1;
9680: }
9681: }
9682: }
1.6 raeburn 9683: } else {
9684: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9685: \@logintext,$confhash,\%changes);
1.6 raeburn 9686: }
9687: } else {
9688: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9689: \@logintext,$confhash,\%changes);
1.6 raeburn 9690: }
9691: }
9692: return ($errors,%changes);
9693: }
9694:
1.46 raeburn 9695: sub config_check {
9696: my ($dom,$confname,$servadm) = @_;
9697: my ($configuserok,$author_ok,$switchserver,%currroles);
9698: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
9699: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
9700: $confname,$servadm);
9701: if ($configuserok eq 'ok') {
9702: $switchserver = &check_switchserver($dom,$confname);
9703: if ($switchserver eq '') {
9704: $author_ok = &check_authorstatus($dom,$confname,%currroles);
9705: }
9706: }
9707: return ($configuserok,$author_ok,$switchserver);
9708: }
9709:
1.6 raeburn 9710: sub default_change_checker {
1.41 raeburn 9711: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 9712: foreach my $item (@{$links}) {
9713: if ($confhash->{$role}{$item}) {
9714: $changes->{$role}{'links'}{$item} = 1;
9715: }
9716: }
9717: foreach my $item (@{$bgs}) {
9718: if ($confhash->{$role}{$item}) {
9719: $changes->{$role}{'bgs'}{$item} = 1;
9720: }
9721: }
1.41 raeburn 9722: foreach my $item (@{$logintext}) {
9723: if ($confhash->{$role}{$item}) {
9724: $changes->{$role}{'logintext'}{$item} = 1;
9725: }
9726: }
1.6 raeburn 9727: foreach my $img (@{$images}) {
9728: if ($env{'form.'.$role.'_del_'.$img}) {
9729: $confhash->{$role}{$img} = '';
1.12 raeburn 9730: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 9731: }
1.70 raeburn 9732: if ($role eq 'login') {
9733: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9734: $changes->{$role}{'showlogo'}{$img} = 1;
9735: }
9736: }
1.6 raeburn 9737: }
9738: if ($confhash->{$role}{'font'}) {
9739: $changes->{$role}{'font'} = 1;
9740: }
1.48 raeburn 9741: }
1.6 raeburn 9742:
9743: sub display_colorchgs {
9744: my ($dom,$changes,$roles,$confhash) = @_;
9745: my (%choices,$resulttext);
9746: if (!grep(/^login$/,@{$roles})) {
9747: $resulttext = &mt('Changes made:').'<br />';
9748: }
9749: foreach my $role (@{$roles}) {
9750: if ($role eq 'login') {
9751: %choices = &login_choices();
9752: } else {
9753: %choices = &color_font_choices();
9754: }
9755: if (ref($changes->{$role}) eq 'HASH') {
9756: if ($role ne 'login') {
9757: $resulttext .= '<h4>'.&mt($role).'</h4>';
9758: }
9759: foreach my $key (sort(keys(%{$changes->{$role}}))) {
9760: if ($role ne 'login') {
9761: $resulttext .= '<ul>';
9762: }
9763: if (ref($changes->{$role}{$key}) eq 'HASH') {
9764: if ($role ne 'login') {
9765: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9766: }
9767: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 9768: if (($role eq 'login') && ($key eq 'showlogo')) {
9769: if ($confhash->{$role}{$key}{$item}) {
9770: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9771: } else {
9772: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9773: }
9774: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 9775: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9776: } else {
1.12 raeburn 9777: my $newitem = $confhash->{$role}{$item};
9778: if ($key eq 'images') {
1.306 raeburn 9779: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 9780: }
9781: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 9782: }
9783: }
9784: if ($role ne 'login') {
9785: $resulttext .= '</ul></li>';
9786: }
9787: } else {
9788: if ($confhash->{$role}{$key} eq '') {
9789: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9790: } else {
9791: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9792: }
9793: }
9794: if ($role ne 'login') {
9795: $resulttext .= '</ul>';
9796: }
9797: }
9798: }
9799: }
1.3 raeburn 9800: return $resulttext;
1.1 raeburn 9801: }
9802:
1.9 raeburn 9803: sub thumb_dimensions {
9804: return ('200','50');
9805: }
9806:
1.16 raeburn 9807: sub check_dimensions {
9808: my ($inputfile) = @_;
9809: my ($fullwidth,$fullheight);
9810: if ($inputfile =~ m|^[/\w.\-]+$|) {
9811: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9812: my $imageinfo = <PIPE>;
9813: if (!close(PIPE)) {
9814: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9815: }
9816: chomp($imageinfo);
9817: my ($fullsize) =
1.21 raeburn 9818: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 9819: if ($fullsize) {
9820: ($fullwidth,$fullheight) = split(/x/,$fullsize);
9821: }
9822: }
9823: }
9824: return ($fullwidth,$fullheight);
9825: }
9826:
1.9 raeburn 9827: sub check_configuser {
9828: my ($uhome,$dom,$confname,$servadm) = @_;
9829: my ($configuserok,%currroles);
9830: if ($uhome eq 'no_host') {
9831: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
9832: my $configpass = &LONCAPA::Enrollment::create_password();
9833: $configuserok =
9834: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
9835: $configpass,'','','','','',undef,$servadm);
9836: } else {
9837: $configuserok = 'ok';
9838: %currroles =
9839: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9840: }
9841: return ($configuserok,%currroles);
9842: }
9843:
9844: sub check_authorstatus {
9845: my ($dom,$confname,%currroles) = @_;
9846: my $author_ok;
1.40 raeburn 9847: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 9848: my $start = time;
9849: my $end = 0;
9850: $author_ok =
9851: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 9852: 'au',$end,$start,'','','domconfig');
1.9 raeburn 9853: } else {
9854: $author_ok = 'ok';
9855: }
9856: return $author_ok;
9857: }
9858:
9859: sub publishlogo {
1.46 raeburn 9860: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 9861: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 9862: if ($action eq 'upload') {
9863: $fname=$env{'form.'.$formname.'.filename'};
9864: chop($env{'form.'.$formname});
9865: } else {
9866: ($fname) = ($formname =~ /([^\/]+)$/);
9867: }
1.46 raeburn 9868: if ($savefileas ne '') {
9869: $fname = $savefileas;
9870: }
1.9 raeburn 9871: $fname=&Apache::lonnet::clean_filename($fname);
9872: # See if there is anything left
9873: unless ($fname) { return ('error: no uploaded file'); }
9874: $fname="$subdir/$fname";
1.210 raeburn 9875: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 9876: my $filepath="$docroot/priv";
9877: my $relpath = "$dom/$confname";
1.9 raeburn 9878: my ($fnamepath,$file,$fetchthumb);
9879: $file=$fname;
9880: if ($fname=~m|/|) {
9881: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9882: }
1.164 raeburn 9883: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9884: my $count;
1.164 raeburn 9885: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9886: $filepath.="/$parts[$count]";
9887: if ((-e $filepath)!=1) {
9888: mkdir($filepath,02770);
9889: }
9890: }
9891: # Check for bad extension and disallow upload
9892: if ($file=~/\.(\w+)$/ &&
9893: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9894: $output =
1.207 bisitz 9895: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9896: } elsif ($file=~/\.(\w+)$/ &&
9897: !defined(&Apache::loncommon::fileembstyle($1))) {
9898: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9899: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 9900: $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 9901: } elsif (-d "$filepath/$file") {
1.195 bisitz 9902: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9903: } else {
9904: my $source = $filepath.'/'.$file;
9905: my $logfile;
1.316 raeburn 9906: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 9907: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9908: }
9909: print $logfile
9910: "\n================= Publish ".localtime()." ================\n".
9911: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9912: # Save the file
1.316 raeburn 9913: if (!open(FH,">",$source)) {
1.9 raeburn 9914: &Apache::lonnet::logthis('Failed to create '.$source);
9915: return (&mt('Failed to create file'));
9916: }
9917: if ($action eq 'upload') {
9918: if (!print FH ($env{'form.'.$formname})) {
9919: &Apache::lonnet::logthis('Failed to write to '.$source);
9920: return (&mt('Failed to write file'));
9921: }
9922: } else {
9923: my $original = &Apache::lonnet::filelocation('',$formname);
9924: if(!copy($original,$source)) {
9925: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9926: return (&mt('Failed to write file'));
9927: }
9928: }
9929: close(FH);
9930: chmod(0660, $source); # Permissions to rw-rw---.
9931:
9932: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9933: my $copyfile=$targetdir.'/'.$file;
9934:
9935: my @parts=split(/\//,$targetdir);
9936: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9937: for (my $count=5;$count<=$#parts;$count++) {
9938: $path.="/$parts[$count]";
9939: if (!-e $path) {
9940: print $logfile "\nCreating directory ".$path;
9941: mkdir($path,02770);
9942: }
9943: }
9944: my $versionresult;
9945: if (-e $copyfile) {
9946: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9947: } else {
9948: $versionresult = 'ok';
9949: }
9950: if ($versionresult eq 'ok') {
9951: if (copy($source,$copyfile)) {
9952: print $logfile "\nCopied original source to ".$copyfile."\n";
9953: $output = 'ok';
9954: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9955: push(@{$modified_urls},[$copyfile,$source]);
9956: my $metaoutput =
9957: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9958: unless ($registered_cleanup) {
9959: my $handlers = $r->get_handlers('PerlCleanupHandler');
9960: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9961: $registered_cleanup=1;
9962: }
1.9 raeburn 9963: } else {
9964: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9965: $output = &mt('Failed to copy file to RES space').", $!";
9966: }
9967: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9968: my $inputfile = $filepath.'/'.$file;
9969: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 9970: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9971: if ($fullwidth ne '' && $fullheight ne '') {
9972: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9973: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 9974: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
9975: system({$args[0]} @args);
1.16 raeburn 9976: chmod(0660, $filepath.'/tn-'.$file);
9977: if (-e $outfile) {
9978: my $copyfile=$targetdir.'/tn-'.$file;
9979: if (copy($outfile,$copyfile)) {
9980: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 9981: my $thumb_metaoutput =
9982: &write_metadata($dom,$confname,$formname,
9983: $targetdir,'tn-'.$file,$logfile);
9984: push(@{$modified_urls},[$copyfile,$outfile]);
9985: unless ($registered_cleanup) {
9986: my $handlers = $r->get_handlers('PerlCleanupHandler');
9987: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9988: $registered_cleanup=1;
9989: }
1.267 raeburn 9990: $madethumb = 1;
1.16 raeburn 9991: } else {
9992: print $logfile "\nUnable to write ".$copyfile.
9993: ':'.$!."\n";
9994: }
9995: }
1.9 raeburn 9996: }
9997: }
9998: }
9999: } else {
10000: $output = $versionresult;
10001: }
10002: }
1.267 raeburn 10003: return ($output,$logourl,$madethumb);
1.9 raeburn 10004: }
10005:
10006: sub logo_versioning {
10007: my ($targetdir,$file,$logfile) = @_;
10008: my $target = $targetdir.'/'.$file;
10009: my ($maxversion,$fn,$extn,$output);
10010: $maxversion = 0;
10011: if ($file =~ /^(.+)\.(\w+)$/) {
10012: $fn=$1;
10013: $extn=$2;
10014: }
10015: opendir(DIR,$targetdir);
10016: while (my $filename=readdir(DIR)) {
10017: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10018: $maxversion=($1>$maxversion)?$1:$maxversion;
10019: }
10020: }
10021: $maxversion++;
10022: print $logfile "\nCreating old version ".$maxversion."\n";
10023: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10024: if (copy($target,$copyfile)) {
10025: print $logfile "Copied old target to ".$copyfile."\n";
10026: $copyfile=$copyfile.'.meta';
10027: if (copy($target.'.meta',$copyfile)) {
10028: print $logfile "Copied old target metadata to ".$copyfile."\n";
10029: $output = 'ok';
10030: } else {
10031: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10032: $output = &mt('Failed to copy old meta').", $!, ";
10033: }
10034: } else {
10035: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10036: $output = &mt('Failed to copy old target').", $!, ";
10037: }
10038: return $output;
10039: }
10040:
10041: sub write_metadata {
10042: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10043: my (%metadatafields,%metadatakeys,$output);
10044: $metadatafields{'title'}=$formname;
10045: $metadatafields{'creationdate'}=time;
10046: $metadatafields{'lastrevisiondate'}=time;
10047: $metadatafields{'copyright'}='public';
10048: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10049: $env{'user.domain'};
10050: $metadatafields{'authorspace'}=$confname.':'.$dom;
10051: $metadatafields{'domain'}=$dom;
10052: {
10053: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10054: my $mfh;
1.316 raeburn 10055: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 10056: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10057: unless ($_=~/\./) {
10058: my $unikey=$_;
10059: $unikey=~/^([A-Za-z]+)/;
10060: my $tag=$1;
10061: $tag=~tr/A-Z/a-z/;
10062: print $mfh "\n\<$tag";
10063: foreach (split(/\,/,$metadatakeys{$unikey})) {
10064: my $value=$metadatafields{$unikey.'.'.$_};
10065: $value=~s/\"/\'\'/g;
10066: print $mfh ' '.$_.'="'.$value.'"';
10067: }
10068: print $mfh '>'.
10069: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10070: .'</'.$tag.'>';
10071: }
10072: }
10073: $output = 'ok';
10074: print $logfile "\nWrote metadata";
10075: close($mfh);
10076: } else {
10077: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10078: $output = &mt('Could not write metadata');
10079: }
10080: }
1.155 raeburn 10081: return $output;
10082: }
10083:
10084: sub notifysubscribed {
10085: foreach my $targetsource (@{$modified_urls}){
10086: next unless (ref($targetsource) eq 'ARRAY');
10087: my ($target,$source)=@{$targetsource};
10088: if ($source ne '') {
1.316 raeburn 10089: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10090: print $logfh "\nCleanup phase: Notifications\n";
10091: my @subscribed=&subscribed_hosts($target);
10092: foreach my $subhost (@subscribed) {
10093: print $logfh "\nNotifying host ".$subhost.':';
10094: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10095: print $logfh $reply;
10096: }
10097: my @subscribedmeta=&subscribed_hosts("$target.meta");
10098: foreach my $subhost (@subscribedmeta) {
10099: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10100: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10101: $subhost);
10102: print $logfh $reply;
10103: }
10104: print $logfh "\n============ Done ============\n";
1.160 raeburn 10105: close($logfh);
1.155 raeburn 10106: }
10107: }
10108: }
10109: return OK;
10110: }
10111:
10112: sub subscribed_hosts {
10113: my ($target) = @_;
10114: my @subscribed;
1.316 raeburn 10115: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10116: while (my $subline=<$fh>) {
10117: if ($subline =~ /^($match_lonid):/) {
10118: my $host = $1;
10119: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10120: unless (grep(/^\Q$host\E$/,@subscribed)) {
10121: push(@subscribed,$host);
10122: }
10123: }
10124: }
10125: }
10126: }
10127: return @subscribed;
1.9 raeburn 10128: }
10129:
10130: sub check_switchserver {
10131: my ($dom,$confname) = @_;
10132: my ($allowed,$switchserver);
10133: my $home = &Apache::lonnet::homeserver($confname,$dom);
10134: if ($home eq 'no_host') {
10135: $home = &Apache::lonnet::domain($dom,'primary');
10136: }
10137: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10138: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10139: if (!$allowed) {
1.180 raeburn 10140: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10141: }
10142: return $switchserver;
10143: }
10144:
1.1 raeburn 10145: sub modify_quotas {
1.216 raeburn 10146: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10147: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 10148: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 10149: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10150: $validationfieldsref);
1.86 raeburn 10151: if ($action eq 'quotas') {
10152: $context = 'tools';
1.163 raeburn 10153: } else {
1.86 raeburn 10154: $context = $action;
10155: }
10156: if ($context eq 'requestcourses') {
1.325 raeburn 10157: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 10158: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10159: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10160: %titles = &courserequest_titles();
10161: $toolregexp = join('|',@usertools);
10162: %conditions = &courserequest_conditions();
1.216 raeburn 10163: $confname = $dom.'-domainconfig';
10164: my $servadm = $r->dir_config('lonAdmEMail');
10165: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 10166: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10167: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 10168: } elsif ($context eq 'requestauthor') {
10169: @usertools = ('author');
10170: %titles = &authorrequest_titles();
1.86 raeburn 10171: } else {
1.162 raeburn 10172: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10173: %titles = &tool_titles();
1.86 raeburn 10174: }
1.212 raeburn 10175: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10176: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10177: foreach my $key (keys(%env)) {
1.101 raeburn 10178: if ($context eq 'requestcourses') {
10179: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10180: my $item = $1;
10181: my $type = $2;
10182: if ($type =~ /^limit_(.+)/) {
10183: $limithash{$item}{$1} = $env{$key};
10184: } else {
10185: $confhash{$item}{$type} = $env{$key};
10186: }
10187: }
1.163 raeburn 10188: } elsif ($context eq 'requestauthor') {
10189: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10190: $confhash{$1} = $env{$key};
10191: }
1.101 raeburn 10192: } else {
1.86 raeburn 10193: if ($key =~ /^form\.quota_(.+)$/) {
10194: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 10195: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10196: $confhash{'authorquota'}{$1} = $env{$key};
10197: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10198: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10199: }
1.72 raeburn 10200: }
10201: }
1.163 raeburn 10202: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 10203: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10204: @approvalnotify = sort(@approvalnotify);
10205: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 10206: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 10207: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10208: foreach my $type (@hasuniquecode) {
10209: if (grep(/^\Q$type\E$/,@crstypes)) {
10210: $confhash{'uniquecode'}{$type} = 1;
10211: }
1.216 raeburn 10212: }
1.242 raeburn 10213: my (%newbook,%allpos);
1.216 raeburn 10214: if ($context eq 'requestcourses') {
1.242 raeburn 10215: foreach my $type ('textbooks','templates') {
10216: @{$allpos{$type}} = ();
10217: my $invalid;
10218: if ($type eq 'textbooks') {
10219: $invalid = &mt('Invalid LON-CAPA course for textbook');
10220: } else {
10221: $invalid = &mt('Invalid LON-CAPA course for template');
10222: }
10223: if ($env{'form.'.$type.'_addbook'}) {
10224: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10225: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10226: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10227: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10228: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10229: } else {
10230: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10231: my $position = $env{'form.'.$type.'_addbook_pos'};
10232: $position =~ s/\D+//g;
10233: if ($position ne '') {
10234: $allpos{$type}[$position] = $newbook{$type};
10235: }
1.216 raeburn 10236: }
1.242 raeburn 10237: } else {
10238: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 10239: }
10240: }
1.242 raeburn 10241: }
1.216 raeburn 10242: }
1.102 raeburn 10243: if (ref($domconfig{$action}) eq 'HASH') {
10244: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10245: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10246: $changes{'notify'}{'approval'} = 1;
10247: }
10248: } else {
1.144 raeburn 10249: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10250: $changes{'notify'}{'approval'} = 1;
10251: }
10252: }
1.218 raeburn 10253: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10254: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10255: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10256: unless ($confhash{'uniquecode'}{$crstype}) {
10257: $changes{'uniquecode'} = 1;
10258: }
10259: }
10260: unless ($changes{'uniquecode'}) {
10261: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10262: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10263: $changes{'uniquecode'} = 1;
10264: }
10265: }
10266: }
10267: } else {
10268: $changes{'uniquecode'} = 1;
10269: }
10270: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10271: $changes{'uniquecode'} = 1;
1.216 raeburn 10272: }
10273: if ($context eq 'requestcourses') {
1.242 raeburn 10274: foreach my $type ('textbooks','templates') {
10275: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10276: my %deletions;
10277: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10278: if (@todelete) {
10279: map { $deletions{$_} = 1; } @todelete;
10280: }
10281: my %imgdeletions;
10282: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10283: if (@todeleteimages) {
10284: map { $imgdeletions{$_} = 1; } @todeleteimages;
10285: }
10286: my $maxnum = $env{'form.'.$type.'_maxnum'};
10287: for (my $i=0; $i<=$maxnum; $i++) {
10288: my $itemid = $env{'form.'.$type.'_id_'.$i};
10289: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10290: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10291: if ($deletions{$key}) {
10292: if ($domconfig{$action}{$type}{$key}{'image'}) {
10293: #FIXME need to obsolete item in RES space
10294: }
10295: next;
10296: } else {
10297: my $newpos = $env{'form.'.$itemid};
10298: $newpos =~ s/\D+//g;
1.243 raeburn 10299: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 10300: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 10301: ($type eq 'templates'));
1.242 raeburn 10302: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10303: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10304: $changes{$type}{$key} = 1;
10305: }
10306: }
10307: $allpos{$type}[$newpos] = $key;
10308: }
10309: if ($imgdeletions{$key}) {
10310: $changes{$type}{$key} = 1;
1.216 raeburn 10311: #FIXME need to obsolete item in RES space
1.242 raeburn 10312: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10313: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 10314: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10315: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10316: } else {
10317: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10318: $cdom,$cnum,$type,$configuserok,
10319: $switchserver,$author_ok);
10320: if ($imgurl) {
10321: $confhash{$type}{$key}{'image'} = $imgurl;
10322: $changes{$type}{$key} = 1;
10323: }
10324: if ($error) {
10325: &Apache::lonnet::logthis($error);
10326: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10327: }
10328: }
1.242 raeburn 10329: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10330: $confhash{$type}{$key}{'image'} =
10331: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 10332: }
10333: }
10334: }
10335: }
10336: }
10337: }
1.102 raeburn 10338: } else {
1.144 raeburn 10339: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10340: $changes{'notify'}{'approval'} = 1;
10341: }
1.218 raeburn 10342: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 10343: $changes{'uniquecode'} = 1;
10344: }
10345: }
10346: if ($context eq 'requestcourses') {
1.242 raeburn 10347: foreach my $type ('textbooks','templates') {
10348: if ($newbook{$type}) {
10349: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 10350: foreach my $item ('subject','title','publisher','author') {
10351: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10352: ($type eq 'template'));
1.242 raeburn 10353: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10354: if ($env{'form.'.$type.'_addbook_'.$item}) {
10355: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10356: }
10357: }
10358: if ($type eq 'textbooks') {
10359: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10360: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 10361: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10362: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10363: } else {
10364: my ($imageurl,$error) =
10365: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10366: $configuserok,$switchserver,$author_ok);
10367: if ($imageurl) {
10368: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10369: }
10370: if ($error) {
10371: &Apache::lonnet::logthis($error);
10372: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10373: }
1.242 raeburn 10374: }
10375: }
1.216 raeburn 10376: }
10377: }
1.242 raeburn 10378: if (@{$allpos{$type}} > 0) {
10379: my $idx = 0;
10380: foreach my $item (@{$allpos{$type}}) {
10381: if ($item ne '') {
10382: $confhash{$type}{$item}{'order'} = $idx;
10383: if (ref($domconfig{$action}) eq 'HASH') {
10384: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10385: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10386: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10387: $changes{$type}{$item} = 1;
10388: }
1.216 raeburn 10389: }
10390: }
10391: }
1.242 raeburn 10392: $idx ++;
1.216 raeburn 10393: }
10394: }
10395: }
10396: }
1.235 raeburn 10397: if (ref($validationitemsref) eq 'ARRAY') {
10398: foreach my $item (@{$validationitemsref}) {
10399: if ($item eq 'fields') {
10400: my @changed;
10401: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10402: if (@{$confhash{'validation'}{$item}} > 0) {
10403: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10404: }
1.266 raeburn 10405: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10406: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10407: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10408: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10409: $domconfig{'requestcourses'}{'validation'}{$item});
10410: } else {
10411: @changed = @{$confhash{'validation'}{$item}};
10412: }
1.235 raeburn 10413: } else {
10414: @changed = @{$confhash{'validation'}{$item}};
10415: }
10416: } else {
10417: @changed = @{$confhash{'validation'}{$item}};
10418: }
10419: if (@changed) {
10420: if ($confhash{'validation'}{$item}) {
10421: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10422: } else {
10423: $changes{'validation'}{$item} = &mt('None');
10424: }
10425: }
10426: } else {
10427: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10428: if ($item eq 'markup') {
10429: if ($env{'form.requestcourses_validation_'.$item}) {
10430: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10431: }
10432: }
1.266 raeburn 10433: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10434: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10435: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10436: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10437: }
10438: } else {
10439: if ($confhash{'validation'}{$item} ne '') {
10440: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10441: }
1.235 raeburn 10442: }
10443: } else {
10444: if ($confhash{'validation'}{$item} ne '') {
10445: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10446: }
10447: }
10448: }
10449: }
10450: }
10451: if ($env{'form.validationdc'}) {
10452: my $newval = $env{'form.validationdc'};
1.285 raeburn 10453: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 10454: if (exists($domcoords{$newval})) {
10455: $confhash{'validation'}{'dc'} = $newval;
10456: }
10457: }
10458: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 10459: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10460: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10461: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10462: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10463: if ($confhash{'validation'}{'dc'} eq '') {
10464: $changes{'validation'}{'dc'} = &mt('None');
10465: } else {
10466: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10467: }
1.235 raeburn 10468: }
1.266 raeburn 10469: } elsif ($confhash{'validation'}{'dc'} ne '') {
10470: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 10471: }
10472: } elsif ($confhash{'validation'}{'dc'} ne '') {
10473: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10474: }
10475: } elsif ($confhash{'validation'}{'dc'} ne '') {
10476: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 10477: }
1.266 raeburn 10478: } else {
10479: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10480: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10481: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10482: $changes{'validation'}{'dc'} = &mt('None');
10483: }
10484: }
1.235 raeburn 10485: }
10486: }
1.102 raeburn 10487: }
10488: } else {
1.86 raeburn 10489: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 10490: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10491: }
1.72 raeburn 10492: foreach my $item (@usertools) {
10493: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10494: my $unset;
1.101 raeburn 10495: if ($context eq 'requestcourses') {
1.104 raeburn 10496: $unset = '0';
10497: if ($type eq '_LC_adv') {
10498: $unset = '';
10499: }
1.101 raeburn 10500: if ($confhash{$item}{$type} eq 'autolimit') {
10501: $confhash{$item}{$type} .= '=';
10502: unless ($limithash{$item}{$type} =~ /\D/) {
10503: $confhash{$item}{$type} .= $limithash{$item}{$type};
10504: }
10505: }
1.163 raeburn 10506: } elsif ($context eq 'requestauthor') {
10507: $unset = '0';
10508: if ($type eq '_LC_adv') {
10509: $unset = '';
10510: }
1.72 raeburn 10511: } else {
1.101 raeburn 10512: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10513: $confhash{$item}{$type} = 1;
10514: } else {
10515: $confhash{$item}{$type} = 0;
10516: }
1.72 raeburn 10517: }
1.86 raeburn 10518: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 10519: if ($action eq 'requestauthor') {
10520: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10521: $changes{$type} = 1;
10522: }
10523: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10524: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10525: $changes{$item}{$type} = 1;
10526: }
10527: } else {
10528: if ($context eq 'requestcourses') {
1.104 raeburn 10529: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 10530: $changes{$item}{$type} = 1;
10531: }
10532: } else {
10533: if (!$confhash{$item}{$type}) {
10534: $changes{$item}{$type} = 1;
10535: }
10536: }
10537: }
10538: } else {
10539: if ($context eq 'requestcourses') {
1.104 raeburn 10540: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10541: $changes{$item}{$type} = 1;
10542: }
1.163 raeburn 10543: } elsif ($context eq 'requestauthor') {
10544: if ($confhash{$type} ne $unset) {
10545: $changes{$type} = 1;
10546: }
1.72 raeburn 10547: } else {
10548: if (!$confhash{$item}{$type}) {
10549: $changes{$item}{$type} = 1;
10550: }
10551: }
10552: }
1.1 raeburn 10553: }
10554: }
1.163 raeburn 10555: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10556: if (ref($domconfig{'quotas'}) eq 'HASH') {
10557: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10558: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10559: if (exists($confhash{'defaultquota'}{$key})) {
10560: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10561: $changes{'defaultquota'}{$key} = 1;
10562: }
10563: } else {
10564: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10565: }
10566: }
1.86 raeburn 10567: } else {
10568: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10569: if (exists($confhash{'defaultquota'}{$key})) {
10570: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10571: $changes{'defaultquota'}{$key} = 1;
10572: }
10573: } else {
10574: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10575: }
1.1 raeburn 10576: }
10577: }
1.197 raeburn 10578: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10579: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10580: if (exists($confhash{'authorquota'}{$key})) {
10581: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10582: $changes{'authorquota'}{$key} = 1;
10583: }
10584: } else {
10585: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10586: }
10587: }
10588: }
1.1 raeburn 10589: }
1.86 raeburn 10590: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10591: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10592: if (ref($domconfig{'quotas'}) eq 'HASH') {
10593: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10594: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
10595: $changes{'defaultquota'}{$key} = 1;
10596: }
10597: } else {
10598: if (!exists($domconfig{'quotas'}{$key})) {
10599: $changes{'defaultquota'}{$key} = 1;
10600: }
1.72 raeburn 10601: }
10602: } else {
1.86 raeburn 10603: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 10604: }
1.1 raeburn 10605: }
10606: }
1.197 raeburn 10607: if (ref($confhash{'authorquota'}) eq 'HASH') {
10608: foreach my $key (keys(%{$confhash{'authorquota'}})) {
10609: if (ref($domconfig{'quotas'}) eq 'HASH') {
10610: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10611: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
10612: $changes{'authorquota'}{$key} = 1;
10613: }
10614: } else {
10615: $changes{'authorquota'}{$key} = 1;
10616: }
10617: } else {
10618: $changes{'authorquota'}{$key} = 1;
10619: }
10620: }
10621: }
1.1 raeburn 10622: }
1.72 raeburn 10623:
1.163 raeburn 10624: if ($context eq 'requestauthor') {
10625: $domdefaults{'requestauthor'} = \%confhash;
10626: } else {
10627: foreach my $key (keys(%confhash)) {
1.242 raeburn 10628: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 10629: $domdefaults{$key} = $confhash{$key};
10630: }
1.163 raeburn 10631: }
1.72 raeburn 10632: }
1.163 raeburn 10633:
1.1 raeburn 10634: my %quotahash = (
1.86 raeburn 10635: $action => { %confhash }
1.1 raeburn 10636: );
10637: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
10638: $dom);
10639: if ($putresult eq 'ok') {
10640: if (keys(%changes) > 0) {
1.72 raeburn 10641: my $cachetime = 24*60*60;
10642: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10643: if (ref($lastactref) eq 'HASH') {
10644: $lastactref->{'domdefaults'} = 1;
10645: }
1.1 raeburn 10646: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 10647: unless (($context eq 'requestcourses') ||
1.163 raeburn 10648: ($context eq 'requestauthor')) {
1.86 raeburn 10649: if (ref($changes{'defaultquota'}) eq 'HASH') {
10650: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
10651: foreach my $type (@{$types},'default') {
10652: if (defined($changes{'defaultquota'}{$type})) {
10653: my $typetitle = $usertypes->{$type};
10654: if ($type eq 'default') {
10655: $typetitle = $othertitle;
10656: }
1.213 raeburn 10657: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 10658: }
10659: }
1.86 raeburn 10660: $resulttext .= '</ul></li>';
1.72 raeburn 10661: }
1.197 raeburn 10662: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 10663: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 10664: foreach my $type (@{$types},'default') {
10665: if (defined($changes{'authorquota'}{$type})) {
10666: my $typetitle = $usertypes->{$type};
10667: if ($type eq 'default') {
10668: $typetitle = $othertitle;
10669: }
1.213 raeburn 10670: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 10671: }
10672: }
10673: $resulttext .= '</ul></li>';
10674: }
1.72 raeburn 10675: }
1.80 raeburn 10676: my %newenv;
1.72 raeburn 10677: foreach my $item (@usertools) {
1.163 raeburn 10678: my (%haschgs,%inconf);
10679: if ($context eq 'requestauthor') {
10680: %haschgs = %changes;
1.210 raeburn 10681: %inconf = %confhash;
1.163 raeburn 10682: } else {
10683: if (ref($changes{$item}) eq 'HASH') {
10684: %haschgs = %{$changes{$item}};
10685: }
10686: if (ref($confhash{$item}) eq 'HASH') {
10687: %inconf = %{$confhash{$item}};
10688: }
10689: }
10690: if (keys(%haschgs) > 0) {
1.80 raeburn 10691: my $newacc =
10692: &Apache::lonnet::usertools_access($env{'user.name'},
10693: $env{'user.domain'},
1.86 raeburn 10694: $item,'reload',$context);
1.210 raeburn 10695: if (($context eq 'requestcourses') ||
1.163 raeburn 10696: ($context eq 'requestauthor')) {
1.108 raeburn 10697: if ($env{'environment.canrequest.'.$item} ne $newacc) {
10698: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 10699: }
10700: } else {
10701: if ($env{'environment.availabletools.'.$item} ne $newacc) {
10702: $newenv{'environment.availabletools.'.$item} = $newacc;
10703: }
1.80 raeburn 10704: }
1.163 raeburn 10705: unless ($context eq 'requestauthor') {
10706: $resulttext .= '<li>'.$titles{$item}.'<ul>';
10707: }
1.72 raeburn 10708: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 10709: if ($haschgs{$type}) {
1.72 raeburn 10710: my $typetitle = $usertypes->{$type};
10711: if ($type eq 'default') {
10712: $typetitle = $othertitle;
10713: } elsif ($type eq '_LC_adv') {
10714: $typetitle = 'LON-CAPA Advanced Users';
10715: }
1.163 raeburn 10716: if ($inconf{$type}) {
1.101 raeburn 10717: if ($context eq 'requestcourses') {
10718: my $cond;
1.163 raeburn 10719: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 10720: if ($1 eq '') {
10721: $cond = &mt('(Automatic processing of any request).');
10722: } else {
10723: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
10724: }
10725: } else {
1.163 raeburn 10726: $cond = $conditions{$inconf{$type}};
1.101 raeburn 10727: }
10728: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 10729: } elsif ($context eq 'requestauthor') {
10730: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
10731: $titles{$inconf{$type}},$typetitle);
10732:
1.101 raeburn 10733: } else {
10734: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
10735: }
1.72 raeburn 10736: } else {
1.104 raeburn 10737: if ($type eq '_LC_adv') {
1.163 raeburn 10738: if ($inconf{$type} eq '0') {
1.104 raeburn 10739: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10740: } else {
10741: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
10742: }
10743: } else {
10744: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10745: }
1.72 raeburn 10746: }
10747: }
1.26 raeburn 10748: }
1.163 raeburn 10749: unless ($context eq 'requestauthor') {
10750: $resulttext .= '</ul></li>';
10751: }
1.26 raeburn 10752: }
1.1 raeburn 10753: }
1.163 raeburn 10754: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 10755: if (ref($changes{'notify'}) eq 'HASH') {
10756: if ($changes{'notify'}{'approval'}) {
10757: if (ref($confhash{'notify'}) eq 'HASH') {
10758: if ($confhash{'notify'}{'approval'}) {
10759: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
10760: } else {
1.163 raeburn 10761: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 10762: }
10763: }
10764: }
10765: }
10766: }
1.216 raeburn 10767: if ($action eq 'requestcourses') {
10768: my @offon = ('off','on');
10769: if ($changes{'uniquecode'}) {
1.218 raeburn 10770: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10771: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10772: $resulttext .= '<li>'.
10773: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10774: '</li>';
10775: } else {
10776: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10777: '</li>';
10778: }
1.216 raeburn 10779: }
1.242 raeburn 10780: foreach my $type ('textbooks','templates') {
10781: if (ref($changes{$type}) eq 'HASH') {
10782: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10783: foreach my $key (sort(keys(%{$changes{$type}}))) {
10784: my %coursehash = &Apache::lonnet::coursedescription($key);
10785: my $coursetitle = $coursehash{'description'};
10786: my $position = $confhash{$type}{$key}{'order'} + 1;
10787: $resulttext .= '<li>';
1.243 raeburn 10788: foreach my $item ('subject','title','publisher','author') {
10789: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10790: ($type eq 'templates'));
1.242 raeburn 10791: my $name = $item.':';
10792: $name =~ s/^(\w)/\U$1/;
10793: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10794: }
10795: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10796: if ($type eq 'textbooks') {
10797: if ($confhash{$type}{$key}{'image'}) {
10798: $resulttext .= ' '.&mt('Image: [_1]',
10799: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10800: ' alt="Textbook cover" />').'<br />';
10801: }
10802: }
10803: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 10804: }
1.242 raeburn 10805: $resulttext .= '</ul></li>';
1.216 raeburn 10806: }
10807: }
1.235 raeburn 10808: if (ref($changes{'validation'}) eq 'HASH') {
10809: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10810: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10811: foreach my $item (@{$validationitemsref}) {
10812: if (exists($changes{'validation'}{$item})) {
10813: if ($item eq 'markup') {
10814: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10815: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10816: } else {
10817: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10818: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10819: }
10820: }
10821: }
10822: if (exists($changes{'validation'}{'dc'})) {
10823: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
10824: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
10825: }
10826: }
10827: }
1.216 raeburn 10828: }
1.1 raeburn 10829: $resulttext .= '</ul>';
1.80 raeburn 10830: if (keys(%newenv)) {
10831: &Apache::lonnet::appenv(\%newenv);
10832: }
1.1 raeburn 10833: } else {
1.86 raeburn 10834: if ($context eq 'requestcourses') {
10835: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 10836: } elsif ($context eq 'requestauthor') {
10837: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 10838: } else {
1.90 weissno 10839: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 10840: }
1.1 raeburn 10841: }
10842: } else {
1.11 albertel 10843: $resulttext = '<span class="LC_error">'.
10844: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10845: }
1.216 raeburn 10846: if ($errors) {
10847: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10848: '<ul>'.$errors.'</ul></p>';
10849: }
1.3 raeburn 10850: return $resulttext;
1.1 raeburn 10851: }
10852:
1.216 raeburn 10853: sub process_textbook_image {
1.242 raeburn 10854: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 10855: my $filename = $env{'form.'.$caller.'.filename'};
10856: my ($error,$url);
10857: my ($width,$height) = (50,50);
10858: if ($configuserok eq 'ok') {
10859: if ($switchserver) {
10860: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10861: $switchserver);
10862: } elsif ($author_ok eq 'ok') {
10863: my ($result,$imageurl) =
10864: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 10865: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 10866: if ($result eq 'ok') {
10867: $url = $imageurl;
10868: } else {
10869: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10870: }
10871: } else {
10872: $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);
10873: }
10874: } else {
10875: $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);
10876: }
10877: return ($url,$error);
10878: }
10879:
1.267 raeburn 10880: sub modify_ltitools {
10881: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10882: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 10883: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 10884: my $confname = $dom.'-domainconfig';
10885: my $servadm = $r->dir_config('lonAdmEMail');
10886: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10887: my (%posslti,%possfield);
10888: my @courseroles = ('cc','in','ta','ep','st');
10889: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10890: map { $posslti{$_} = 1; } @ltiroles;
10891: my @allfields = ('fullname','firstname','lastname','email','user','roles');
10892: map { $possfield{$_} = 1; } @allfields;
10893: my %lt = <itools_names();
10894: if ($env{'form.ltitools_add'}) {
10895: my $title = $env{'form.ltitools_add_title'};
10896: $title =~ s/(`)/'/g;
10897: ($newid,my $error) = &get_ltitools_id($dom,$title);
10898: if ($newid) {
10899: my $position = $env{'form.ltitools_add_pos'};
10900: $position =~ s/\D+//g;
10901: if ($position ne '') {
10902: $allpos[$position] = $newid;
10903: }
10904: $changes{$newid} = 1;
1.322 raeburn 10905: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 10906: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 10907: if ($item eq 'lifetime') {
10908: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
10909: }
1.267 raeburn 10910: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 10911: if (($item eq 'key') || ($item eq 'secret')) {
10912: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10913: } else {
10914: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10915: }
1.267 raeburn 10916: }
10917: }
10918: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10919: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10920: }
10921: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10922: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10923: }
1.323 raeburn 10924: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
10925: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
10926: } else {
10927: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
10928: }
1.296 raeburn 10929: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 10930: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10931: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 10932: if (($item eq 'width') || ($item eq 'height')) {
10933: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10934: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10935: }
10936: } else {
10937: if ($env{'form.ltitools_add_'.$item} ne '') {
10938: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10939: }
1.267 raeburn 10940: }
10941: }
10942: if ($env{'form.ltitools_add_target'} eq 'window') {
10943: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 10944: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10945: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 10946: } else {
10947: $confhash{$newid}{'display'}{'target'} = 'iframe';
10948: }
10949: foreach my $item ('passback','roster') {
1.319 raeburn 10950: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 10951: $confhash{$newid}{$item} = 1;
1.319 raeburn 10952: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
10953: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
10954: $lifetime =~ s/^\s+|\s+$//g;
10955: if ($lifetime =~ /^\d+\.?\d*$/) {
10956: $confhash{$newid}{$item.'valid'} = $lifetime;
10957: }
10958: }
1.267 raeburn 10959: }
10960: }
10961: if ($env{'form.ltitools_add_image.filename'} ne '') {
10962: my ($imageurl,$error) =
1.307 raeburn 10963: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 10964: $configuserok,$switchserver,$author_ok);
10965: if ($imageurl) {
10966: $confhash{$newid}{'image'} = $imageurl;
10967: }
10968: if ($error) {
10969: &Apache::lonnet::logthis($error);
10970: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10971: }
10972: }
10973: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
10974: foreach my $field (@fields) {
10975: if ($possfield{$field}) {
10976: if ($field eq 'roles') {
10977: foreach my $role (@courseroles) {
10978: my $choice = $env{'form.ltitools_add_roles_'.$role};
10979: if (($choice ne '') && ($posslti{$choice})) {
10980: $confhash{$newid}{'roles'}{$role} = $choice;
10981: if ($role eq 'cc') {
10982: $confhash{$newid}{'roles'}{'co'} = $choice;
10983: }
10984: }
10985: }
10986: } else {
10987: $confhash{$newid}{'fields'}{$field} = 1;
10988: }
10989: }
10990: }
1.324 raeburn 10991: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
10992: if ($confhash{$newid}{'fields'}{'user'}) {
10993: if ($env{'form.ltitools_userincdom_add'}) {
10994: $confhash{$newid}{'incdom'} = 1;
10995: }
10996: }
10997: }
1.273 raeburn 10998: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
10999: foreach my $item (@courseconfig) {
11000: $confhash{$newid}{'crsconf'}{$item} = 1;
11001: }
1.267 raeburn 11002: if ($env{'form.ltitools_add_custom'}) {
11003: my $name = $env{'form.ltitools_add_custom_name'};
11004: my $value = $env{'form.ltitools_add_custom_value'};
11005: $value =~ s/(`)/'/g;
11006: $name =~ s/(`)/'/g;
11007: $confhash{$newid}{'custom'}{$name} = $value;
11008: }
11009: } else {
11010: my $error = &mt('Failed to acquire unique ID for new external tool');
11011: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11012: }
11013: }
11014: if (ref($domconfig{$action}) eq 'HASH') {
11015: my %deletions;
11016: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
11017: if (@todelete) {
11018: map { $deletions{$_} = 1; } @todelete;
11019: }
11020: my %customadds;
11021: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
11022: if (@newcustom) {
11023: map { $customadds{$_} = 1; } @newcustom;
11024: }
11025: my %imgdeletions;
11026: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
11027: if (@todeleteimages) {
11028: map { $imgdeletions{$_} = 1; } @todeleteimages;
11029: }
11030: my $maxnum = $env{'form.ltitools_maxnum'};
11031: for (my $i=0; $i<=$maxnum; $i++) {
11032: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 11033: $itemid =~ s/\D+//g;
1.267 raeburn 11034: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11035: if ($deletions{$itemid}) {
11036: if ($domconfig{$action}{$itemid}{'image'}) {
11037: #FIXME need to obsolete item in RES space
11038: }
11039: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
11040: next;
11041: } else {
11042: my $newpos = $env{'form.ltitools_'.$itemid};
11043: $newpos =~ s/\D+//g;
1.322 raeburn 11044: foreach my $item ('title','url','lifetime') {
1.267 raeburn 11045: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11046: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11047: $changes{$itemid} = 1;
11048: }
11049: }
1.297 raeburn 11050: foreach my $item ('key','secret') {
11051: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11052: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
11053: $changes{$itemid} = 1;
11054: }
11055: }
1.267 raeburn 11056: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
11057: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
11058: }
11059: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
11060: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
11061: }
1.323 raeburn 11062: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
11063: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
11064: } else {
11065: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
11066: }
11067: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
11068: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
11069: $changes{$itemid} = 1;
11070: }
11071: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
11072: $changes{$itemid} = 1;
11073: }
1.267 raeburn 11074: foreach my $size ('width','height') {
11075: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
11076: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
11077: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
11078: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
11079: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11080: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
11081: $changes{$itemid} = 1;
11082: }
11083: } else {
11084: $changes{$itemid} = 1;
11085: }
1.296 raeburn 11086: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11087: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
11088: $changes{$itemid} = 1;
11089: }
11090: }
11091: }
11092: foreach my $item ('linktext','explanation') {
11093: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
11094: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
11095: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
11096: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11097: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11098: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
11099: $changes{$itemid} = 1;
11100: }
11101: } else {
11102: $changes{$itemid} = 1;
11103: }
11104: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11105: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
11106: $changes{$itemid} = 1;
11107: }
1.267 raeburn 11108: }
11109: }
11110: if ($env{'form.ltitools_target_'.$i} eq 'window') {
11111: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 11112: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
11113: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 11114: } else {
11115: $confhash{$itemid}{'display'}{'target'} = 'iframe';
11116: }
11117: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11118: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
11119: $changes{$itemid} = 1;
11120: }
11121: } else {
11122: $changes{$itemid} = 1;
11123: }
11124: foreach my $extra ('passback','roster') {
11125: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
11126: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 11127: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
11128: my $lifetime = $env{'form.ltitools_'.$extra.'valid_add'};
11129: $lifetime =~ s/^\s+|\s+$//g;
11130: if ($lifetime =~ /^\d+\.?\d*$/) {
11131: $confhash{$itemid}{$extra.'valid'} = $lifetime;
11132: }
11133: }
1.267 raeburn 11134: }
11135: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
11136: $changes{$itemid} = 1;
11137: }
1.319 raeburn 11138: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
11139: $changes{$itemid} = 1;
11140: }
1.267 raeburn 11141: }
1.273 raeburn 11142: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 11143: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 11144: if (grep(/^\Q$item\E$/,@courseconfig)) {
11145: $confhash{$itemid}{'crsconf'}{$item} = 1;
11146: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
11147: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
11148: $changes{$itemid} = 1;
11149: }
11150: } else {
11151: $changes{$itemid} = 1;
11152: }
11153: }
11154: }
1.267 raeburn 11155: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
11156: foreach my $field (@fields) {
11157: if ($possfield{$field}) {
11158: if ($field eq 'roles') {
11159: foreach my $role (@courseroles) {
11160: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
11161: if (($choice ne '') && ($posslti{$choice})) {
11162: $confhash{$itemid}{'roles'}{$role} = $choice;
11163: if ($role eq 'cc') {
11164: $confhash{$itemid}{'roles'}{'co'} = $choice;
11165: }
11166: }
11167: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
11168: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
11169: $changes{$itemid} = 1;
11170: }
11171: } elsif ($confhash{$itemid}{'roles'}{$role}) {
11172: $changes{$itemid} = 1;
11173: }
11174: }
11175: } else {
11176: $confhash{$itemid}{'fields'}{$field} = 1;
11177: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
11178: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
11179: $changes{$itemid} = 1;
11180: }
11181: } else {
11182: $changes{$itemid} = 1;
11183: }
11184: }
11185: }
11186: }
1.324 raeburn 11187: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11188: if ($confhash{$itemid}{'fields'}{'user'}) {
11189: if ($env{'form.ltitools_userincdom_'.$i}) {
11190: $confhash{$itemid}{'incdom'} = 1;
11191: }
11192: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
11193: $changes{$itemid} = 1;
11194: }
11195: }
11196: }
1.267 raeburn 11197: $allpos[$newpos] = $itemid;
11198: }
11199: if ($imgdeletions{$itemid}) {
11200: $changes{$itemid} = 1;
11201: #FIXME need to obsolete item in RES space
11202: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
11203: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
11204: $itemid,$configuserok,$switchserver,
11205: $author_ok);
11206: if ($imgurl) {
11207: $confhash{$itemid}{'image'} = $imgurl;
11208: $changes{$itemid} = 1;
11209: }
11210: if ($error) {
11211: &Apache::lonnet::logthis($error);
11212: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11213: }
11214: } elsif ($domconfig{$action}{$itemid}{'image'}) {
11215: $confhash{$itemid}{'image'} =
11216: $domconfig{$action}{$itemid}{'image'};
11217: }
11218: if ($customadds{$i}) {
11219: my $name = $env{'form.ltitools_custom_name_'.$i};
11220: $name =~ s/(`)/'/g;
11221: $name =~ s/^\s+//;
11222: $name =~ s/\s+$//;
11223: my $value = $env{'form.ltitools_custom_value_'.$i};
11224: $value =~ s/(`)/'/g;
11225: $value =~ s/^\s+//;
11226: $value =~ s/\s+$//;
11227: if ($name ne '') {
11228: $confhash{$itemid}{'custom'}{$name} = $value;
11229: $changes{$itemid} = 1;
11230: }
11231: }
11232: my %customdels;
11233: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
11234: if (@customdeletions) {
11235: $changes{$itemid} = 1;
11236: }
11237: map { $customdels{$_} = 1; } @customdeletions;
11238: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
11239: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
11240: unless ($customdels{$key}) {
11241: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
11242: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
11243: }
11244: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
11245: $changes{$itemid} = 1;
11246: }
11247: }
11248: }
11249: }
11250: unless ($changes{$itemid}) {
11251: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
11252: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
11253: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
11254: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
11255: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
11256: $changes{$itemid} = 1;
11257: last;
11258: }
11259: }
11260: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
11261: $changes{$itemid} = 1;
11262: }
11263: }
11264: last if ($changes{$itemid});
11265: }
11266: }
11267: }
11268: }
11269: }
11270: if (@allpos > 0) {
11271: my $idx = 0;
11272: foreach my $itemid (@allpos) {
11273: if ($itemid ne '') {
11274: $confhash{$itemid}{'order'} = $idx;
11275: if (ref($domconfig{$action}) eq 'HASH') {
11276: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11277: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11278: $changes{$itemid} = 1;
11279: }
11280: }
11281: }
11282: $idx ++;
11283: }
11284: }
11285: }
11286: my %ltitoolshash = (
11287: $action => { %confhash }
11288: );
11289: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
11290: $dom);
11291: if ($putresult eq 'ok') {
1.297 raeburn 11292: my %ltienchash = (
11293: $action => { %encconfig }
11294: );
11295: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 11296: if (keys(%changes) > 0) {
11297: my $cachetime = 24*60*60;
1.297 raeburn 11298: my %ltiall = %confhash;
11299: foreach my $id (keys(%ltiall)) {
11300: if (ref($encconfig{$id}) eq 'HASH') {
11301: foreach my $item ('key','secret') {
11302: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11303: }
11304: }
11305: }
11306: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 11307: if (ref($lastactref) eq 'HASH') {
11308: $lastactref->{'ltitools'} = 1;
11309: }
11310: $resulttext = &mt('Changes made:').'<ul>';
11311: my %bynum;
11312: foreach my $itemid (sort(keys(%changes))) {
11313: my $position = $confhash{$itemid}{'order'};
11314: $bynum{$position} = $itemid;
11315: }
11316: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11317: my $itemid = $bynum{$pos};
11318: if (ref($confhash{$itemid}) ne 'HASH') {
11319: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11320: } else {
11321: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
11322: if ($confhash{$itemid}{'image'}) {
11323: $resulttext .= ' '.
11324: '<img src="'.$confhash{$itemid}{'image'}.'"'.
11325: ' alt="'.&mt('Tool Provider icon').'" />';
11326: }
11327: $resulttext .= '</li><ul>';
11328: my $position = $pos + 1;
11329: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 11330: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 11331: if ($confhash{$itemid}{$item} ne '') {
11332: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11333: }
11334: }
1.297 raeburn 11335: if ($encconfig{$itemid}{'key'} ne '') {
11336: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11337: }
11338: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 11339: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 11340: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 11341: $resulttext .= ('*'x$num).'</li>';
11342: }
1.273 raeburn 11343: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 11344: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 11345: my $numconfig = 0;
11346: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
11347: foreach my $item (@possconfig) {
11348: if ($confhash{$itemid}{'crsconf'}{$item}) {
11349: $numconfig ++;
1.296 raeburn 11350: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 11351: }
11352: }
11353: }
11354: if (!$numconfig) {
11355: $resulttext .= &mt('None');
11356: }
11357: $resulttext .= '</li>';
1.267 raeburn 11358: foreach my $item ('passback','roster') {
11359: $resulttext .= '<li>'.$lt{$item}.' ';
11360: if ($confhash{$itemid}{$item}) {
11361: $resulttext .= &mt('Yes');
1.319 raeburn 11362: if ($confhash{$itemid}{$item.'valid'}) {
11363: if ($item eq 'passback') {
11364: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
11365: $confhash{$itemid}{$item.'valid'});
11366: } else {
11367: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
11368: $confhash{$itemid}{$item.'valid'});
11369: }
11370: }
1.267 raeburn 11371: } else {
11372: $resulttext .= &mt('No');
11373: }
11374: $resulttext .= '</li>';
11375: }
11376: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11377: my $displaylist;
11378: if ($confhash{$itemid}{'display'}{'target'}) {
11379: $displaylist = &mt('Display target').': '.
11380: $confhash{$itemid}{'display'}{'target'}.',';
11381: }
11382: foreach my $size ('width','height') {
11383: if ($confhash{$itemid}{'display'}{$size}) {
11384: $displaylist .= (' 'x2).$lt{$size}.': '.
11385: $confhash{$itemid}{'display'}{$size}.',';
11386: }
11387: }
11388: if ($displaylist) {
11389: $displaylist =~ s/,$//;
11390: $resulttext .= '<li>'.$displaylist.'</li>';
11391: }
1.296 raeburn 11392: foreach my $item ('linktext','explanation') {
11393: if ($confhash{$itemid}{'display'}{$item}) {
11394: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11395: }
11396: }
11397: }
1.267 raeburn 11398: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11399: my $fieldlist;
11400: foreach my $field (@allfields) {
11401: if ($confhash{$itemid}{'fields'}{$field}) {
11402: $fieldlist .= (' 'x2).$lt{$field}.',';
11403: }
11404: }
11405: if ($fieldlist) {
11406: $fieldlist =~ s/,$//;
1.324 raeburn 11407: if ($confhash{$itemid}{'fields'}{'user'}) {
11408: if ($confhash{$itemid}{'incdom'}) {
11409: $fieldlist .= ' ('.&mt('username:domain').')';
11410: } else {
11411: $fieldlist .= ' ('.&mt('username').')';
11412: }
11413: }
1.267 raeburn 11414: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11415: }
11416: }
11417: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11418: my $rolemaps;
11419: foreach my $role (@courseroles) {
11420: if ($confhash{$itemid}{'roles'}{$role}) {
11421: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11422: $confhash{$itemid}{'roles'}{$role}.',';
11423: }
11424: }
11425: if ($rolemaps) {
11426: $rolemaps =~ s/,$//;
11427: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11428: }
11429: }
11430: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11431: my $customlist;
11432: if (keys(%{$confhash{$itemid}{'custom'}})) {
11433: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11434: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11435: }
11436: }
11437: if ($customlist) {
1.317 raeburn 11438: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 11439: }
11440: }
11441: $resulttext .= '</ul></li>';
11442: }
11443: }
11444: $resulttext .= '</ul>';
11445: } else {
11446: $resulttext = &mt('No changes made.');
11447: }
11448: } else {
11449: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11450: }
11451: if ($errors) {
11452: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11453: $errors.'</ul>';
11454: }
11455: return $resulttext;
11456: }
11457:
11458: sub process_ltitools_image {
11459: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11460: my $filename = $env{'form.'.$caller.'.filename'};
11461: my ($error,$url);
11462: my ($width,$height) = (21,21);
11463: if ($configuserok eq 'ok') {
11464: if ($switchserver) {
11465: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11466: $switchserver);
11467: } elsif ($author_ok eq 'ok') {
11468: my ($result,$imageurl,$madethumb) =
11469: &publishlogo($r,'upload',$caller,$dom,$confname,
11470: "ltitools/$itemid/icon",$width,$height);
11471: if ($result eq 'ok') {
11472: if ($madethumb) {
11473: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11474: my $imagethumb = "$path/tn-".$imagefile;
11475: $url = $imagethumb;
11476: } else {
11477: $url = $imageurl;
11478: }
11479: } else {
11480: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11481: }
11482: } else {
11483: $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);
11484: }
11485: } else {
11486: $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);
11487: }
11488: return ($url,$error);
11489: }
11490:
11491: sub get_ltitools_id {
11492: my ($cdom,$title) = @_;
11493: # get lock on ltitools db
11494: my $lockhash = {
11495: lock => $env{'user.name'}.
11496: ':'.$env{'user.domain'},
11497: };
11498: my $tries = 0;
11499: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11500: my ($id,$error);
11501:
11502: while (($gotlock ne 'ok') && ($tries<10)) {
11503: $tries ++;
11504: sleep (0.1);
11505: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11506: }
11507: if ($gotlock eq 'ok') {
11508: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11509: if ($currids{'lock'}) {
11510: delete($currids{'lock'});
11511: if (keys(%currids)) {
11512: my @curr = sort { $a <=> $b } keys(%currids);
11513: if ($curr[-1] =~ /^\d+$/) {
11514: $id = 1 + $curr[-1];
11515: }
11516: } else {
11517: $id = 1;
11518: }
11519: if ($id) {
11520: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11521: $error = 'nostore';
11522: }
11523: } else {
11524: $error = 'nonumber';
11525: }
11526: }
11527: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11528: } else {
11529: $error = 'nolock';
11530: }
11531: return ($id,$error);
11532: }
11533:
1.320 raeburn 11534: sub modify_lti {
11535: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11536: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11537: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
11538: my (%posslti,%posslticrs,%posscrstype);
11539: my @courseroles = ('cc','in','ta','ep','st');
11540: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
11541: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
11542: my @coursetypes = ('official','unofficial','community','textbook','placement');
11543: my %coursetypetitles = &Apache::lonlocal::texthash (
11544: official => 'Official',
11545: unofficial => 'Unofficial',
11546: community => 'Community',
11547: textbook => 'Textbook',
11548: placement => 'Placement Test',
11549: );
1.325 raeburn 11550: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 11551: my %lt = <i_names();
11552: map { $posslti{$_} = 1; } @ltiroles;
11553: map { $posslticrs{$_} = 1; } @lticourseroles;
11554: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 11555:
1.326 raeburn 11556: my %menutitles = <imenu_titles();
11557:
1.320 raeburn 11558: my (@items,%deletions,%itemids);
11559: if ($env{'form.lti_add'}) {
11560: my $consumer = $env{'form.lti_consumer_add'};
11561: $consumer =~ s/(`)/'/g;
11562: ($newid,my $error) = &get_lti_id($dom,$consumer);
11563: if ($newid) {
11564: $itemids{'add'} = $newid;
11565: push(@items,'add');
11566: $changes{$newid} = 1;
11567: } else {
11568: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
11569: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11570: }
11571: }
11572: if (ref($domconfig{$action}) eq 'HASH') {
11573: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
11574: if (@todelete) {
11575: map { $deletions{$_} = 1; } @todelete;
11576: }
11577: my $maxnum = $env{'form.lti_maxnum'};
11578: for (my $i=0; $i<=$maxnum; $i++) {
11579: my $itemid = $env{'form.lti_id_'.$i};
11580: $itemid =~ s/\D+//g;
11581: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11582: if ($deletions{$itemid}) {
11583: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
11584: } else {
11585: push(@items,$i);
11586: $itemids{$i} = $itemid;
11587: }
11588: }
11589: }
11590: }
11591: foreach my $idx (@items) {
11592: my $itemid = $itemids{$idx};
11593: next unless ($itemid);
11594: my $position = $env{'form.lti_pos_'.$idx};
11595: $position =~ s/\D+//g;
11596: if ($position ne '') {
11597: $allpos[$position] = $itemid;
11598: }
11599: foreach my $item ('consumer','key','secret','lifetime') {
11600: my $formitem = 'form.lti_'.$item.'_'.$idx;
11601: $env{$formitem} =~ s/(`)/'/g;
11602: if ($item eq 'lifetime') {
11603: $env{$formitem} =~ s/[^\d.]//g;
11604: }
11605: if ($env{$formitem} ne '') {
11606: if (($item eq 'key') || ($item eq 'secret')) {
11607: $encconfig{$itemid}{$item} = $env{$formitem};
11608: } else {
11609: $confhash{$itemid}{$item} = $env{$formitem};
11610: unless (($idx eq 'add') || ($changes{$itemid})) {
11611: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11612: $changes{$itemid} = 1;
11613: }
11614: }
11615: }
11616: }
11617: }
11618: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
11619: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
11620: }
11621: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
11622: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
11623: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
11624: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
11625: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
11626: my $mapuser = $env{'form.lti_customuser_'.$idx};
11627: $mapuser =~ s/(`)/'/g;
11628: $mapuser =~ s/^\s+|\s+$//g;
11629: $confhash{$itemid}{'mapuser'} = $mapuser;
11630: }
11631: foreach my $ltirole (@lticourseroles) {
11632: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
11633: if (grep(/^\Q$possrole\E$/,@courseroles)) {
11634: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
11635: }
11636: }
11637: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
11638: my @makeuser;
11639: foreach my $ltirole (sort(@possmakeuser)) {
11640: if ($posslti{$ltirole}) {
11641: push(@makeuser,$ltirole);
11642: }
11643: }
11644: $confhash{$itemid}{'makeuser'} = \@makeuser;
1.325 raeburn 11645: if (@makeuser) {
11646: my $lcauth = $env{'form.lti_lcauth_'.$idx};
11647: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
11648: $confhash{$itemid}{'lcauth'} = $lcauth;
11649: if ($lcauth ne 'internal') {
11650: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
11651: $lcauthparm =~ s/^(\s+|\s+)$//g;
11652: $lcauthparm =~ s/`//g;
11653: if ($lcauthparm ne '') {
11654: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
11655: }
11656: }
11657: } else {
11658: $confhash{$itemid}{'lcauth'} = 'lti';
11659: }
11660: }
11661: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
11662: if (@possinstdata) {
11663: foreach my $field (@possinstdata) {
11664: if (exists($fieldtitles{$field})) {
11665: push(@{$confhash{$itemid}{'instdata'}});
11666: }
11667: }
11668: }
1.320 raeburn 11669: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
11670: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
11671: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
11672: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
11673: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
11674: $mapcrs =~ s/(`)/'/g;
11675: $mapcrs =~ s/^\s+|\s+$//g;
11676: $confhash{$itemid}{'mapcrs'} = $mapcrs;
11677: }
11678: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
11679: my @crstypes;
11680: foreach my $type (sort(@posstypes)) {
11681: if ($posscrstype{$type}) {
11682: push(@crstypes,$type);
11683: }
11684: }
11685: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
11686: if ($env{'form.lti_makecrs_'.$idx}) {
11687: $confhash{$itemid}{'makecrs'} = 1;
11688: }
11689: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
11690: my @selfenroll;
11691: foreach my $type (sort(@possenroll)) {
11692: if ($posslticrs{$type}) {
11693: push(@selfenroll,$type);
11694: }
11695: }
11696: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
11697: if ($env{'form.lti_crssec_'.$idx}) {
11698: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
11699: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
11700: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
11701: my $section = $env{'form.lti_customsection_'.$idx};
11702: $section =~ s/(`)/'/g;
11703: $section =~ s/^\s+|\s+$//g;
11704: if ($section ne '') {
11705: $confhash{$itemid}{'section'} = $section;
11706: }
11707: }
11708: }
1.326 raeburn 11709: foreach my $field ('passback','roster','topmenu','inlinemenu') {
1.321 raeburn 11710: if ($env{'form.lti_'.$field.'_'.$idx}) {
1.320 raeburn 11711: $confhash{$itemid}{$field} = 1;
11712: }
11713: }
1.326 raeburn 11714:
11715: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
11716: $confhash{$itemid}{lcmenu} = [];
11717: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
11718: foreach my $field (@possmenu) {
11719: if (exists($menutitles{$field})) {
11720: if ($field eq 'grades') {
11721: next unless ($env{'form.lti_inlinemenu_'.$idx});
11722: }
11723: push(@{$confhash{$itemid}{lcmenu}},$field);
11724: }
11725: }
11726: }
1.320 raeburn 11727: unless (($idx eq 'add') || ($changes{$itemid})) {
1.326 raeburn 11728: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu') {
1.320 raeburn 11729: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
11730: $changes{$itemid} = 1;
11731: }
11732: }
1.326 raeburn 11733: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
1.320 raeburn 11734: unless ($changes{$itemid}) {
11735: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
11736: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11737: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
11738: $confhash{$itemid}{$field});
11739: if (@diffs) {
11740: $changes{$itemid} = 1;
11741: }
11742: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
11743: $changes{$itemid} = 1;
11744: }
11745: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11746: if (@{$confhash{$itemid}{$field}} > 0) {
11747: $changes{$itemid} = 1;
11748: }
11749: }
11750: }
11751: }
11752: unless ($changes{$itemid}) {
11753: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
11754: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11755: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
11756: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
11757: $confhash{$itemid}{'maproles'}{$ltirole}) {
11758: $changes{$itemid} = 1;
11759: last;
11760: }
11761: }
11762: unless ($changes{$itemid}) {
11763: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
11764: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
11765: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
11766: $changes{$itemid} = 1;
11767: last;
11768: }
11769: }
11770: }
11771: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
11772: $changes{$itemid} = 1;
11773: }
11774: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11775: unless ($changes{$itemid}) {
11776: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
11777: $changes{$itemid} = 1;
11778: }
11779: }
11780: }
11781: }
11782: }
11783: }
11784: if (@allpos > 0) {
11785: my $idx = 0;
11786: foreach my $itemid (@allpos) {
11787: if ($itemid ne '') {
11788: $confhash{$itemid}{'order'} = $idx;
11789: if (ref($domconfig{$action}) eq 'HASH') {
11790: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11791: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11792: $changes{$itemid} = 1;
11793: }
11794: }
11795: }
11796: $idx ++;
11797: }
11798: }
11799: }
11800: my %ltihash = (
11801: $action => { %confhash }
11802: );
11803: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
11804: $dom);
11805: if ($putresult eq 'ok') {
11806: my %ltienchash = (
11807: $action => { %encconfig }
11808: );
11809: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
11810: if (keys(%changes) > 0) {
11811: my $cachetime = 24*60*60;
11812: my %ltiall = %confhash;
11813: foreach my $id (keys(%ltiall)) {
11814: if (ref($encconfig{$id}) eq 'HASH') {
11815: foreach my $item ('key','secret') {
11816: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11817: }
11818: }
11819: }
11820: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
11821: if (ref($lastactref) eq 'HASH') {
11822: $lastactref->{'lti'} = 1;
11823: }
11824: $resulttext = &mt('Changes made:').'<ul>';
11825: my %bynum;
11826: foreach my $itemid (sort(keys(%changes))) {
11827: my $position = $confhash{$itemid}{'order'};
11828: $bynum{$position} = $itemid;
11829: }
11830: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11831: my $itemid = $bynum{$pos};
11832: if (ref($confhash{$itemid}) ne 'HASH') {
11833: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11834: } else {
11835: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
11836: my $position = $pos + 1;
11837: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11838: foreach my $item ('version','lifetime') {
11839: if ($confhash{$itemid}{$item} ne '') {
11840: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11841: }
11842: }
11843: if ($encconfig{$itemid}{'key'} ne '') {
11844: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11845: }
11846: if ($encconfig{$itemid}{'secret'} ne '') {
11847: $resulttext .= '<li>'.$lt{'secret'}.': ';
11848: my $num = length($encconfig{$itemid}{'secret'});
11849: $resulttext .= ('*'x$num).'</li>';
11850: }
11851: if ($confhash{$itemid}{'mapuser'}) {
11852: my $shownmapuser;
11853: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
11854: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
11855: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
11856: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
11857: } else {
11858: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
11859: }
11860: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
11861: }
11862: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11863: my $rolemaps;
11864: foreach my $role (@ltiroles) {
11865: if ($confhash{$itemid}{'maproles'}{$role}) {
11866: $rolemaps .= (' 'x2).$role.'='.
11867: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
11868: 'Course').',';
11869: }
11870: }
11871: if ($rolemaps) {
11872: $rolemaps =~ s/,$//;
11873: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11874: }
11875: }
11876: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
11877: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
11878: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
1.325 raeburn 11879: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
11880: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
11881: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
11882: } else {
11883: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
11884: $confhash{$itemid}{'lcauth'});
11885: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
11886: $resulttext .= '; '.&mt('a randomly generated password will be created');
11887: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
11888: if ($confhash{$itemid}{'lcauthparm'} ne '') {
11889: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
11890: }
11891: } else {
11892: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
11893: }
11894: }
11895: $resulttext .= '</li>';
1.320 raeburn 11896: } else {
11897: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
11898: }
11899: }
1.325 raeburn 11900: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
11901: if (@{$confhash{$itemid}{'instdata'}} > 0) {
11902: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
11903: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
11904: } else {
11905: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
11906: }
11907: }
1.320 raeburn 11908: if ($confhash{$itemid}{'mapcrs'}) {
11909: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
11910: }
11911: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
11912: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
11913: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
11914: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
11915: '</li>';
11916: } else {
11917: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
11918: }
11919: }
11920: if ($confhash{$itemid}{'makecrs'}) {
11921: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
11922: } else {
11923: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
11924: }
11925: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
11926: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
11927: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
11928: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
11929: '</li>';
11930: } else {
11931: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
11932: }
11933: }
11934: if ($confhash{$itemid}{'section'}) {
11935: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
11936: $resulttext .= '<li>'.&mt('User section from standard field:').
11937: ' (course_section_sourcedid)'.'</li>';
11938: } else {
11939: $resulttext .= '<li>'.&mt('User section from:').' '.
11940: $confhash{$itemid}{'section'}.'</li>';
11941: }
11942: } else {
11943: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
11944: }
1.326 raeburn 11945: foreach my $item ('passback','roster','topmenu','inlinemenu') {
11946: $resulttext .= '<li>'.$lt{$item}.': ';
1.320 raeburn 11947: if ($confhash{$itemid}{$item}) {
11948: $resulttext .= &mt('Yes');
11949: } else {
11950: $resulttext .= &mt('No');
11951: }
11952: $resulttext .= '</li>';
11953: }
1.326 raeburn 11954: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
11955: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
11956: $resulttext .= '<li>'.&mt('Menu items:').' '.
11957: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
11958: } else {
11959: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
11960: }
11961: }
1.320 raeburn 11962: $resulttext .= '</ul></li>';
11963: }
11964: }
11965: $resulttext .= '</ul>';
11966: } else {
11967: $resulttext = &mt('No changes made.');
11968: }
11969: } else {
11970: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11971: }
11972: if ($errors) {
11973: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11974: $errors.'</ul>';
11975: }
11976: return $resulttext;
11977: }
11978:
11979: sub get_lti_id {
11980: my ($domain,$consumer) = @_;
11981: # get lock on lti db
11982: my $lockhash = {
11983: lock => $env{'user.name'}.
11984: ':'.$env{'user.domain'},
11985: };
11986: my $tries = 0;
11987: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11988: my ($id,$error);
11989:
11990: while (($gotlock ne 'ok') && ($tries<10)) {
11991: $tries ++;
11992: sleep (0.1);
11993: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11994: }
11995: if ($gotlock eq 'ok') {
11996: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
11997: if ($currids{'lock'}) {
11998: delete($currids{'lock'});
11999: if (keys(%currids)) {
12000: my @curr = sort { $a <=> $b } keys(%currids);
12001: if ($curr[-1] =~ /^\d+$/) {
12002: $id = 1 + $curr[-1];
12003: }
12004: } else {
12005: $id = 1;
12006: }
12007: if ($id) {
12008: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
12009: $error = 'nostore';
12010: }
12011: } else {
12012: $error = 'nonumber';
12013: }
12014: }
12015: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
12016: } else {
12017: $error = 'nolock';
12018: }
12019: return ($id,$error);
12020: }
12021:
1.3 raeburn 12022: sub modify_autoenroll {
1.205 raeburn 12023: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 12024: my ($resulttext,%changes);
12025: my %currautoenroll;
12026: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
12027: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
12028: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
12029: }
12030: }
12031: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
12032: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 12033: sender => 'Sender for notification messages',
1.274 raeburn 12034: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
12035: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 12036: my @offon = ('off','on');
1.17 raeburn 12037: my $sender_uname = $env{'form.sender_uname'};
12038: my $sender_domain = $env{'form.sender_domain'};
12039: if ($sender_domain eq '') {
12040: $sender_uname = '';
12041: } elsif ($sender_uname eq '') {
12042: $sender_domain = '';
12043: }
1.129 raeburn 12044: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 12045: my $failsafe = $env{'form.autoenroll_failsafe'};
12046: $failsafe =~ s{^\s+|\s+$}{}g;
12047: if ($failsafe =~ /\D/) {
12048: undef($failsafe);
12049: }
1.1 raeburn 12050: my %autoenrollhash = (
1.129 raeburn 12051: autoenroll => { 'run' => $env{'form.autoenroll_run'},
12052: 'sender_uname' => $sender_uname,
12053: 'sender_domain' => $sender_domain,
12054: 'co-owners' => $coowners,
1.274 raeburn 12055: 'autofailsafe' => $failsafe,
1.1 raeburn 12056: }
12057: );
1.4 raeburn 12058: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
12059: $dom);
1.1 raeburn 12060: if ($putresult eq 'ok') {
12061: if (exists($currautoenroll{'run'})) {
12062: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
12063: $changes{'run'} = 1;
12064: }
12065: } elsif ($autorun) {
12066: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 12067: $changes{'run'} = 1;
1.1 raeburn 12068: }
12069: }
1.17 raeburn 12070: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 12071: $changes{'sender'} = 1;
12072: }
1.17 raeburn 12073: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 12074: $changes{'sender'} = 1;
12075: }
1.129 raeburn 12076: if ($currautoenroll{'co-owners'} ne '') {
12077: if ($currautoenroll{'co-owners'} ne $coowners) {
12078: $changes{'coowners'} = 1;
12079: }
12080: } elsif ($coowners) {
12081: $changes{'coowners'} = 1;
1.274 raeburn 12082: }
12083: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
12084: $changes{'autofailsafe'} = 1;
12085: }
1.1 raeburn 12086: if (keys(%changes) > 0) {
12087: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 12088: if ($changes{'run'}) {
1.1 raeburn 12089: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
12090: }
12091: if ($changes{'sender'}) {
1.17 raeburn 12092: if ($sender_uname eq '' || $sender_domain eq '') {
12093: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
12094: } else {
12095: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
12096: }
1.1 raeburn 12097: }
1.129 raeburn 12098: if ($changes{'coowners'}) {
12099: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
12100: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12101: if (ref($lastactref) eq 'HASH') {
12102: $lastactref->{'domainconfig'} = 1;
12103: }
1.129 raeburn 12104: }
1.274 raeburn 12105: if ($changes{'autofailsafe'}) {
12106: if ($failsafe ne '') {
1.299 raeburn 12107: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 12108: } else {
1.299 raeburn 12109: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 12110: }
12111: &Apache::lonnet::get_domain_defaults($dom,1);
12112: if (ref($lastactref) eq 'HASH') {
12113: $lastactref->{'domdefaults'} = 1;
12114: }
12115: }
1.1 raeburn 12116: $resulttext .= '</ul>';
12117: } else {
12118: $resulttext = &mt('No changes made to auto-enrollment settings');
12119: }
12120: } else {
1.11 albertel 12121: $resulttext = '<span class="LC_error">'.
12122: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12123: }
1.3 raeburn 12124: return $resulttext;
1.1 raeburn 12125: }
12126:
12127: sub modify_autoupdate {
1.3 raeburn 12128: my ($dom,%domconfig) = @_;
1.1 raeburn 12129: my ($resulttext,%currautoupdate,%fields,%changes);
12130: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
12131: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
12132: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
12133: }
12134: }
12135: my @offon = ('off','on');
12136: my %title = &Apache::lonlocal::texthash (
12137: run => 'Auto-update:',
12138: classlists => 'Updates to user information in classlists?'
12139: );
1.44 raeburn 12140: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12141: my %fieldtitles = &Apache::lonlocal::texthash (
12142: id => 'Student/Employee ID',
1.20 raeburn 12143: permanentemail => 'E-mail address',
1.1 raeburn 12144: lastname => 'Last Name',
12145: firstname => 'First Name',
12146: middlename => 'Middle Name',
1.132 raeburn 12147: generation => 'Generation',
1.1 raeburn 12148: );
1.142 raeburn 12149: $othertitle = &mt('All users');
1.1 raeburn 12150: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 12151: $othertitle = &mt('Other users');
1.1 raeburn 12152: }
12153: foreach my $key (keys(%env)) {
12154: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 12155: my ($usertype,$item) = ($1,$2);
12156: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
12157: if ($usertype eq 'default') {
12158: push(@{$fields{$1}},$2);
12159: } elsif (ref($types) eq 'ARRAY') {
12160: if (grep(/^\Q$usertype\E$/,@{$types})) {
12161: push(@{$fields{$1}},$2);
12162: }
12163: }
12164: }
1.1 raeburn 12165: }
12166: }
1.131 raeburn 12167: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
12168: @lockablenames = sort(@lockablenames);
12169: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
12170: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12171: if (@changed) {
12172: $changes{'lockablenames'} = 1;
12173: }
12174: } else {
12175: if (@lockablenames) {
12176: $changes{'lockablenames'} = 1;
12177: }
12178: }
1.1 raeburn 12179: my %updatehash = (
12180: autoupdate => { run => $env{'form.autoupdate_run'},
12181: classlists => $env{'form.classlists'},
12182: fields => {%fields},
1.131 raeburn 12183: lockablenames => \@lockablenames,
1.1 raeburn 12184: }
12185: );
12186: foreach my $key (keys(%currautoupdate)) {
12187: if (($key eq 'run') || ($key eq 'classlists')) {
12188: if (exists($updatehash{autoupdate}{$key})) {
12189: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
12190: $changes{$key} = 1;
12191: }
12192: }
12193: } elsif ($key eq 'fields') {
12194: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 12195: foreach my $item (@{$types},'default') {
1.1 raeburn 12196: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
12197: my $change = 0;
12198: foreach my $type (@{$currautoupdate{$key}{$item}}) {
12199: if (!exists($fields{$item})) {
12200: $change = 1;
1.132 raeburn 12201: last;
1.1 raeburn 12202: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 12203: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 12204: $change = 1;
1.132 raeburn 12205: last;
1.1 raeburn 12206: }
12207: }
12208: }
12209: if ($change) {
12210: push(@{$changes{$key}},$item);
12211: }
1.26 raeburn 12212: }
1.1 raeburn 12213: }
12214: }
1.131 raeburn 12215: } elsif ($key eq 'lockablenames') {
12216: if (ref($currautoupdate{$key}) eq 'ARRAY') {
12217: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12218: if (@changed) {
12219: $changes{'lockablenames'} = 1;
12220: }
12221: } else {
12222: if (@lockablenames) {
12223: $changes{'lockablenames'} = 1;
12224: }
12225: }
12226: }
12227: }
12228: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
12229: if (@lockablenames) {
12230: $changes{'lockablenames'} = 1;
1.1 raeburn 12231: }
12232: }
1.26 raeburn 12233: foreach my $item (@{$types},'default') {
12234: if (defined($fields{$item})) {
12235: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 12236: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
12237: my $change = 0;
12238: if (ref($fields{$item}) eq 'ARRAY') {
12239: foreach my $type (@{$fields{$item}}) {
12240: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
12241: $change = 1;
12242: last;
12243: }
12244: }
12245: }
12246: if ($change) {
12247: push(@{$changes{'fields'}},$item);
12248: }
12249: } else {
1.26 raeburn 12250: push(@{$changes{'fields'}},$item);
12251: }
12252: } else {
12253: push(@{$changes{'fields'}},$item);
1.1 raeburn 12254: }
12255: }
12256: }
12257: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
12258: $dom);
12259: if ($putresult eq 'ok') {
12260: if (keys(%changes) > 0) {
12261: $resulttext = &mt('Changes made:').'<ul>';
12262: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 12263: if ($key eq 'lockablenames') {
12264: $resulttext .= '<li>';
12265: if (@lockablenames) {
12266: $usertypes->{'default'} = $othertitle;
12267: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
12268: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
12269: } else {
12270: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
12271: }
12272: $resulttext .= '</li>';
12273: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 12274: foreach my $item (@{$changes{$key}}) {
12275: my @newvalues;
12276: foreach my $type (@{$fields{$item}}) {
12277: push(@newvalues,$fieldtitles{$type});
12278: }
1.3 raeburn 12279: my $newvaluestr;
12280: if (@newvalues > 0) {
12281: $newvaluestr = join(', ',@newvalues);
12282: } else {
12283: $newvaluestr = &mt('none');
1.6 raeburn 12284: }
1.1 raeburn 12285: if ($item eq 'default') {
1.26 raeburn 12286: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 12287: } else {
1.26 raeburn 12288: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 12289: }
12290: }
12291: } else {
12292: my $newvalue;
12293: if ($key eq 'run') {
12294: $newvalue = $offon[$env{'form.autoupdate_run'}];
12295: } else {
12296: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 12297: }
1.1 raeburn 12298: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
12299: }
12300: }
12301: $resulttext .= '</ul>';
12302: } else {
1.3 raeburn 12303: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 12304: }
12305: } else {
1.11 albertel 12306: $resulttext = '<span class="LC_error">'.
12307: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12308: }
1.3 raeburn 12309: return $resulttext;
1.1 raeburn 12310: }
12311:
1.125 raeburn 12312: sub modify_autocreate {
12313: my ($dom,%domconfig) = @_;
12314: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
12315: if (ref($domconfig{'autocreate'}) eq 'HASH') {
12316: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
12317: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
12318: }
12319: }
12320: my %title= ( xml => 'Auto-creation of courses in XML course description files',
12321: req => 'Auto-creation of validated requests for official courses',
12322: xmldc => 'Identity of course creator of courses from XML files',
12323: );
12324: my @types = ('xml','req');
12325: foreach my $item (@types) {
12326: $newvals{$item} = $env{'form.autocreate_'.$item};
12327: $newvals{$item} =~ s/\D//g;
12328: $newvals{$item} = 0 if ($newvals{$item} eq '');
12329: }
12330: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 12331: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 12332: unless (exists($domcoords{$newvals{'xmldc'}})) {
12333: $newvals{'xmldc'} = '';
12334: }
12335: %autocreatehash = (
12336: autocreate => { xml => $newvals{'xml'},
12337: req => $newvals{'req'},
12338: }
12339: );
12340: if ($newvals{'xmldc'} ne '') {
12341: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
12342: }
12343: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
12344: $dom);
12345: if ($putresult eq 'ok') {
12346: my @items = @types;
12347: if ($newvals{'xml'}) {
12348: push(@items,'xmldc');
12349: }
12350: foreach my $item (@items) {
12351: if (exists($currautocreate{$item})) {
12352: if ($currautocreate{$item} ne $newvals{$item}) {
12353: $changes{$item} = 1;
12354: }
12355: } elsif ($newvals{$item}) {
12356: $changes{$item} = 1;
12357: }
12358: }
12359: if (keys(%changes) > 0) {
12360: my @offon = ('off','on');
12361: $resulttext = &mt('Changes made:').'<ul>';
12362: foreach my $item (@types) {
12363: if ($changes{$item}) {
12364: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 12365: $resulttext .= '<li>'.
12366: &mt("$title{$item} set to [_1]$newtxt [_2]",
12367: '<b>','</b>').
12368: '</li>';
1.125 raeburn 12369: }
12370: }
12371: if ($changes{'xmldc'}) {
12372: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
12373: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 12374: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 12375: }
12376: $resulttext .= '</ul>';
12377: } else {
12378: $resulttext = &mt('No changes made to auto-creation settings');
12379: }
12380: } else {
12381: $resulttext = '<span class="LC_error">'.
12382: &mt('An error occurred: [_1]',$putresult).'</span>';
12383: }
12384: return $resulttext;
12385: }
12386:
1.23 raeburn 12387: sub modify_directorysrch {
1.295 raeburn 12388: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 12389: my ($resulttext,%changes);
12390: my %currdirsrch;
12391: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
12392: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
12393: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
12394: }
12395: }
1.277 raeburn 12396: my %title = ( available => 'Institutional directory search available',
12397: localonly => 'Other domains can search institution',
12398: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 12399: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 12400: searchby => 'Search types',
12401: searchtypes => 'Search latitude');
12402: my @offon = ('off','on');
1.24 raeburn 12403: my @otherdoms = ('Yes','No');
1.23 raeburn 12404:
1.25 raeburn 12405: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 12406: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
12407: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
12408:
1.44 raeburn 12409: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 12410: if (keys(%{$usertypes}) == 0) {
12411: @cansearch = ('default');
12412: } else {
12413: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
12414: foreach my $type (@{$currdirsrch{'cansearch'}}) {
12415: if (!grep(/^\Q$type\E$/,@cansearch)) {
12416: push(@{$changes{'cansearch'}},$type);
12417: }
1.23 raeburn 12418: }
1.26 raeburn 12419: foreach my $type (@cansearch) {
12420: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
12421: push(@{$changes{'cansearch'}},$type);
12422: }
1.23 raeburn 12423: }
1.26 raeburn 12424: } else {
12425: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 12426: }
12427: }
12428:
12429: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
12430: foreach my $by (@{$currdirsrch{'searchby'}}) {
12431: if (!grep(/^\Q$by\E$/,@searchby)) {
12432: push(@{$changes{'searchby'}},$by);
12433: }
12434: }
12435: foreach my $by (@searchby) {
12436: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
12437: push(@{$changes{'searchby'}},$by);
12438: }
12439: }
12440: } else {
12441: push(@{$changes{'searchby'}},@searchby);
12442: }
1.25 raeburn 12443:
12444: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
12445: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
12446: if (!grep(/^\Q$type\E$/,@searchtypes)) {
12447: push(@{$changes{'searchtypes'}},$type);
12448: }
12449: }
12450: foreach my $type (@searchtypes) {
12451: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
12452: push(@{$changes{'searchtypes'}},$type);
12453: }
12454: }
12455: } else {
12456: if (exists($currdirsrch{'searchtypes'})) {
12457: foreach my $type (@searchtypes) {
12458: if ($type ne $currdirsrch{'searchtypes'}) {
12459: push(@{$changes{'searchtypes'}},$type);
12460: }
12461: }
12462: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
12463: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12464: }
12465: } else {
12466: push(@{$changes{'searchtypes'}},@searchtypes);
12467: }
12468: }
12469:
1.23 raeburn 12470: my %dirsrch_hash = (
12471: directorysrch => { available => $env{'form.dirsrch_available'},
12472: cansearch => \@cansearch,
1.277 raeburn 12473: localonly => $env{'form.dirsrch_instlocalonly'},
12474: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12475: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 12476: searchby => \@searchby,
1.25 raeburn 12477: searchtypes => \@searchtypes,
1.23 raeburn 12478: }
12479: );
12480: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12481: $dom);
12482: if ($putresult eq 'ok') {
12483: if (exists($currdirsrch{'available'})) {
12484: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12485: $changes{'available'} = 1;
12486: }
12487: } else {
12488: if ($env{'form.dirsrch_available'} eq '1') {
12489: $changes{'available'} = 1;
12490: }
12491: }
1.277 raeburn 12492: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 12493: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12494: $changes{'lcavailable'} = 1;
12495: }
1.277 raeburn 12496: } else {
12497: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12498: $changes{'lcavailable'} = 1;
12499: }
12500: }
1.24 raeburn 12501: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 12502: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
12503: $changes{'localonly'} = 1;
12504: }
1.24 raeburn 12505: } else {
1.277 raeburn 12506: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 12507: $changes{'localonly'} = 1;
12508: }
12509: }
1.277 raeburn 12510: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 12511: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12512: $changes{'lclocalonly'} = 1;
12513: }
1.277 raeburn 12514: } else {
12515: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12516: $changes{'lclocalonly'} = 1;
12517: }
12518: }
1.23 raeburn 12519: if (keys(%changes) > 0) {
12520: $resulttext = &mt('Changes made:').'<ul>';
12521: if ($changes{'available'}) {
12522: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12523: }
1.277 raeburn 12524: if ($changes{'lcavailable'}) {
12525: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12526: }
1.24 raeburn 12527: if ($changes{'localonly'}) {
1.277 raeburn 12528: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 12529: }
1.277 raeburn 12530: if ($changes{'lclocalonly'}) {
12531: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 12532: }
1.23 raeburn 12533: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12534: my $chgtext;
1.26 raeburn 12535: if (ref($usertypes) eq 'HASH') {
12536: if (keys(%{$usertypes}) > 0) {
12537: foreach my $type (@{$types}) {
12538: if (grep(/^\Q$type\E$/,@cansearch)) {
12539: $chgtext .= $usertypes->{$type}.'; ';
12540: }
12541: }
12542: if (grep(/^default$/,@cansearch)) {
12543: $chgtext .= $othertitle;
12544: } else {
12545: $chgtext =~ s/\; $//;
12546: }
1.210 raeburn 12547: $resulttext .=
1.178 raeburn 12548: '<li>'.
12549: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12550: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12551: '</li>';
1.23 raeburn 12552: }
12553: }
12554: }
12555: if (ref($changes{'searchby'}) eq 'ARRAY') {
12556: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12557: my $chgtext;
12558: foreach my $type (@{$titleorder}) {
12559: if (grep(/^\Q$type\E$/,@searchby)) {
12560: if (defined($searchtitles->{$type})) {
12561: $chgtext .= $searchtitles->{$type}.'; ';
12562: }
12563: }
12564: }
12565: $chgtext =~ s/\; $//;
12566: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12567: }
1.25 raeburn 12568: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
12569: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
12570: my $chgtext;
12571: foreach my $type (@{$srchtypeorder}) {
12572: if (grep(/^\Q$type\E$/,@searchtypes)) {
12573: if (defined($srchtypes_desc->{$type})) {
12574: $chgtext .= $srchtypes_desc->{$type}.'; ';
12575: }
12576: }
12577: }
12578: $chgtext =~ s/\; $//;
1.178 raeburn 12579: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 12580: }
12581: $resulttext .= '</ul>';
1.295 raeburn 12582: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
12583: if (ref($lastactref) eq 'HASH') {
12584: $lastactref->{'directorysrch'} = 1;
12585: }
1.23 raeburn 12586: } else {
1.277 raeburn 12587: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 12588: }
12589: } else {
12590: $resulttext = '<span class="LC_error">'.
1.27 raeburn 12591: &mt('An error occurred: [_1]',$putresult).'</span>';
12592: }
12593: return $resulttext;
12594: }
12595:
1.28 raeburn 12596: sub modify_contacts {
1.205 raeburn 12597: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 12598: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
12599: if (ref($domconfig{'contacts'}) eq 'HASH') {
12600: foreach my $key (keys(%{$domconfig{'contacts'}})) {
12601: $currsetting{$key} = $domconfig{'contacts'}{$key};
12602: }
12603: }
1.286 raeburn 12604: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 12605: my @contacts = ('supportemail','adminemail');
1.286 raeburn 12606: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
12607: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 12608: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 12609: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 12610: foreach my $type (@mailings) {
12611: @{$newsetting{$type}} =
12612: &Apache::loncommon::get_env_multiple('form.'.$type);
12613: foreach my $item (@contacts) {
12614: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
12615: $contacts_hash{contacts}{$type}{$item} = 1;
12616: } else {
12617: $contacts_hash{contacts}{$type}{$item} = 0;
12618: }
1.289 raeburn 12619: }
1.28 raeburn 12620: $others{$type} = $env{'form.'.$type.'_others'};
12621: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 12622: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12623: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12624: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 12625: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12626: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12627: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12628: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12629: }
1.134 raeburn 12630: }
1.28 raeburn 12631: }
12632: foreach my $item (@contacts) {
12633: $to{$item} = $env{'form.'.$item};
12634: $contacts_hash{'contacts'}{$item} = $to{$item};
12635: }
1.203 raeburn 12636: foreach my $item (@toggles) {
12637: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12638: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12639: }
12640: }
1.286 raeburn 12641: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12642: foreach my $field (@{$fields}) {
12643: if (ref($possoptions->{$field}) eq 'ARRAY') {
12644: my $value = $env{'form.helpform_'.$field};
12645: $value =~ s/^\s+|\s+$//g;
12646: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 12647: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 12648: if ($field eq 'screenshot') {
12649: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12650: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 12651: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 12652: }
12653: }
12654: }
12655: }
12656: }
12657: }
1.315 raeburn 12658: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12659: my (@statuses,%usertypeshash,@overrides);
12660: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12661: @statuses = @{$types};
12662: if (ref($usertypes) eq 'HASH') {
12663: %usertypeshash = %{$usertypes};
12664: }
12665: }
12666: if (@statuses) {
12667: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12668: foreach my $type (@possoverrides) {
12669: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12670: push(@overrides,$type);
12671: }
12672: }
12673: if (@overrides) {
12674: foreach my $type (@overrides) {
12675: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12676: foreach my $item (@contacts) {
12677: if (grep(/^\Q$item\E$/,@standard)) {
12678: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12679: $newsetting{'override_'.$type}{$item} = 1;
12680: } else {
12681: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12682: $newsetting{'override_'.$type}{$item} = 0;
12683: }
12684: }
12685: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12686: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12687: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12688: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12689: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12690: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12691: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12692: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12693: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12694: }
12695: }
12696: }
12697: }
1.28 raeburn 12698: if (keys(%currsetting) > 0) {
12699: foreach my $item (@contacts) {
12700: if ($to{$item} ne $currsetting{$item}) {
12701: $changes{$item} = 1;
12702: }
12703: }
12704: foreach my $type (@mailings) {
12705: foreach my $item (@contacts) {
12706: if (ref($currsetting{$type}) eq 'HASH') {
12707: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12708: push(@{$changes{$type}},$item);
12709: }
12710: } else {
12711: push(@{$changes{$type}},@{$newsetting{$type}});
12712: }
12713: }
12714: if ($others{$type} ne $currsetting{$type}{'others'}) {
12715: push(@{$changes{$type}},'others');
12716: }
1.289 raeburn 12717: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12718: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12719: push(@{$changes{$type}},'bcc');
12720: }
1.286 raeburn 12721: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12722: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12723: push(@{$changes{$type}},'include');
12724: }
12725: }
12726: }
12727: if (ref($fields) eq 'ARRAY') {
12728: if (ref($currsetting{'helpform'}) eq 'HASH') {
12729: foreach my $field (@{$fields}) {
12730: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12731: push(@{$changes{'helpform'}},$field);
12732: }
12733: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12734: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12735: push(@{$changes{'helpform'}},'maxsize');
12736: }
12737: }
12738: }
12739: } else {
12740: foreach my $field (@{$fields}) {
12741: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12742: push(@{$changes{'helpform'}},$field);
12743: }
12744: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12745: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12746: push(@{$changes{'helpform'}},'maxsize');
12747: }
12748: }
12749: }
1.134 raeburn 12750: }
1.28 raeburn 12751: }
1.315 raeburn 12752: if (@statuses) {
12753: if (ref($currsetting{'overrides'}) eq 'HASH') {
12754: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12755: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12756: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12757: foreach my $item (@contacts,'bcc','others','include') {
12758: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12759: push(@{$changes{'overrides'}},$key);
12760: last;
12761: }
12762: }
12763: } else {
12764: push(@{$changes{'overrides'}},$key);
12765: }
12766: }
12767: }
12768: foreach my $key (@overrides) {
12769: unless (exists($currsetting{'overrides'}{$key})) {
12770: push(@{$changes{'overrides'}},$key);
12771: }
12772: }
12773: } else {
12774: foreach my $key (@overrides) {
12775: push(@{$changes{'overrides'}},$key);
12776: }
12777: }
12778: }
1.28 raeburn 12779: } else {
12780: my %default;
12781: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12782: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12783: $default{'errormail'} = 'adminemail';
12784: $default{'packagesmail'} = 'adminemail';
12785: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 12786: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12787: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12788: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 12789: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 12790: foreach my $item (@contacts) {
12791: if ($to{$item} ne $default{$item}) {
1.286 raeburn 12792: $changes{$item} = 1;
1.203 raeburn 12793: }
1.28 raeburn 12794: }
12795: foreach my $type (@mailings) {
12796: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12797: push(@{$changes{$type}},@{$newsetting{$type}});
12798: }
12799: if ($others{$type} ne '') {
12800: push(@{$changes{$type}},'others');
1.134 raeburn 12801: }
1.286 raeburn 12802: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12803: if ($bcc{$type} ne '') {
12804: push(@{$changes{$type}},'bcc');
12805: }
1.286 raeburn 12806: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12807: push(@{$changes{$type}},'include');
12808: }
1.134 raeburn 12809: }
1.28 raeburn 12810: }
1.286 raeburn 12811: if (ref($fields) eq 'ARRAY') {
12812: foreach my $field (@{$fields}) {
12813: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12814: push(@{$changes{'helpform'}},$field);
12815: }
12816: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12817: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12818: push(@{$changes{'helpform'}},'maxsize');
12819: }
12820: }
12821: }
1.289 raeburn 12822: }
1.28 raeburn 12823: }
1.203 raeburn 12824: foreach my $item (@toggles) {
12825: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12826: $changes{$item} = 1;
12827: } elsif ((!$env{'form.'.$item}) &&
12828: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12829: $changes{$item} = 1;
12830: }
12831: }
1.28 raeburn 12832: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12833: $dom);
12834: if ($putresult eq 'ok') {
12835: if (keys(%changes) > 0) {
1.205 raeburn 12836: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12837: if (ref($lastactref) eq 'HASH') {
12838: $lastactref->{'domainconfig'} = 1;
12839: }
1.28 raeburn 12840: my ($titles,$short_titles) = &contact_titles();
12841: $resulttext = &mt('Changes made:').'<ul>';
12842: foreach my $item (@contacts) {
12843: if ($changes{$item}) {
12844: $resulttext .= '<li>'.$titles->{$item}.
12845: &mt(' set to: ').
12846: '<span class="LC_cusr_emph">'.
12847: $to{$item}.'</span></li>';
12848: }
12849: }
12850: foreach my $type (@mailings) {
12851: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 12852: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 12853: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 12854: } else {
12855: $resulttext .= '<li>'.$titles->{$type}.': ';
12856: }
1.28 raeburn 12857: my @text;
12858: foreach my $item (@{$newsetting{$type}}) {
12859: push(@text,$short_titles->{$item});
12860: }
12861: if ($others{$type} ne '') {
12862: push(@text,$others{$type});
12863: }
1.286 raeburn 12864: if (@text) {
12865: $resulttext .= '<span class="LC_cusr_emph">'.
12866: join(', ',@text).'</span>';
12867: }
12868: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12869: if ($bcc{$type} ne '') {
1.286 raeburn 12870: my $bcctext;
12871: if (@text) {
1.289 raeburn 12872: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 12873: } else {
12874: $bcctext = '(Bcc)';
12875: }
12876: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12877: } elsif (!@text) {
12878: $resulttext .= &mt('No one');
12879: }
1.289 raeburn 12880: if ($includestr{$type} ne '') {
1.286 raeburn 12881: if ($includeloc{$type} eq 'b') {
12882: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12883: } elsif ($includeloc{$type} eq 's') {
12884: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12885: }
1.134 raeburn 12886: }
1.286 raeburn 12887: } elsif (!@text) {
12888: $resulttext .= &mt('No recipients');
1.134 raeburn 12889: }
12890: $resulttext .= '</li>';
1.28 raeburn 12891: }
12892: }
1.315 raeburn 12893: if (ref($changes{'overrides'}) eq 'ARRAY') {
12894: my @deletions;
12895: foreach my $type (@{$changes{'overrides'}}) {
12896: if ($usertypeshash{$type}) {
12897: if (grep(/^\Q$type\E/,@overrides)) {
12898: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12899: $usertypeshash{$type}).'<ul><li>';
12900: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12901: my @text;
12902: foreach my $item (@contacts) {
12903: if ($newsetting{'override_'.$type}{$item}) {
12904: push(@text,$short_titles->{$item});
12905: }
12906: }
12907: if ($newsetting{'override_'.$type}{'others'} ne '') {
12908: push(@text,$newsetting{'override_'.$type}{'others'});
12909: }
12910:
12911: if (@text) {
12912: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12913: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12914: }
12915: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12916: my $bcctext;
12917: if (@text) {
12918: $bcctext = ' '.&mt('with Bcc to');
12919: } else {
12920: $bcctext = '(Bcc)';
12921: }
12922: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12923: } elsif (!@text) {
12924: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12925: }
12926: $resulttext .= '</li>';
12927: if ($newsetting{'override_'.$type}{'include'} ne '') {
12928: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12929: if ($loc eq 'b') {
12930: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12931: } elsif ($loc eq 's') {
12932: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12933: }
12934: }
12935: }
12936: $resulttext .= '</li></ul></li>';
12937: } else {
12938: push(@deletions,$usertypeshash{$type});
12939: }
12940: }
12941: }
12942: if (@deletions) {
12943: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12944: join(', ',@deletions)).'</li>';
12945: }
12946: }
1.203 raeburn 12947: my @offon = ('off','on');
12948: if ($changes{'reporterrors'}) {
12949: $resulttext .= '<li>'.
12950: &mt('E-mail error reports to [_1] set to "'.
12951: $offon[$env{'form.reporterrors'}].'".',
12952: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12953: &mt('LON-CAPA core group - MSU'),600,500)).
12954: '</li>';
12955: }
12956: if ($changes{'reportupdates'}) {
12957: $resulttext .= '<li>'.
12958: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12959: $offon[$env{'form.reportupdates'}].'".',
12960: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12961: &mt('LON-CAPA core group - MSU'),600,500)).
12962: '</li>';
12963: }
1.286 raeburn 12964: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12965: my (@optional,@required,@unused,$maxsizechg);
12966: foreach my $field (@{$changes{'helpform'}}) {
12967: if ($field eq 'maxsize') {
12968: $maxsizechg = 1;
12969: next;
12970: }
12971: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 12972: push(@optional,$field);
1.286 raeburn 12973: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12974: push(@unused,$field);
12975: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 12976: push(@required,$field);
1.286 raeburn 12977: }
12978: }
12979: if (@optional) {
12980: $resulttext .= '<li>'.
12981: &mt('Help form fields changed to "Optional": [_1].',
12982: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12983: '</li>';
12984: }
12985: if (@required) {
12986: $resulttext .= '<li>'.
12987: &mt('Help form fields changed to "Required": [_1].',
12988: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12989: '</li>';
12990: }
12991: if (@unused) {
12992: $resulttext .= '<li>'.
12993: &mt('Help form fields changed to "Not shown": [_1].',
12994: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12995: '</li>';
12996: }
12997: if ($maxsizechg) {
12998: $resulttext .= '<li>'.
12999: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
13000: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
13001: '</li>';
13002: }
13003: }
1.28 raeburn 13004: $resulttext .= '</ul>';
13005: } else {
1.288 raeburn 13006: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 13007: }
13008: } else {
13009: $resulttext = '<span class="LC_error">'.
13010: &mt('An error occurred: [_1].',$putresult).'</span>';
13011: }
13012: return $resulttext;
13013: }
13014:
13015: sub modify_usercreation {
1.27 raeburn 13016: my ($dom,%domconfig) = @_;
1.224 raeburn 13017: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 13018: my $warningmsg;
1.27 raeburn 13019: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13020: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 13021: if ($key eq 'cancreate') {
13022: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13023: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 13024: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
13025: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13026: } else {
1.224 raeburn 13027: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13028: }
13029: }
13030: }
13031: } elsif ($key eq 'email_rule') {
13032: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13033: } else {
13034: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13035: }
1.27 raeburn 13036: }
13037: }
13038: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 13039: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 13040: my @contexts = ('author','course','requestcrs');
1.34 raeburn 13041: foreach my $item(@contexts) {
1.224 raeburn 13042: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 13043: }
1.34 raeburn 13044: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13045: foreach my $item (@contexts) {
1.224 raeburn 13046: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
13047: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 13048: }
1.27 raeburn 13049: }
1.34 raeburn 13050: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
13051: foreach my $item (@contexts) {
1.43 raeburn 13052: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 13053: if ($cancreate{$item} ne 'any') {
13054: push(@{$changes{'cancreate'}},$item);
13055: }
13056: } else {
13057: if ($cancreate{$item} ne 'none') {
13058: push(@{$changes{'cancreate'}},$item);
13059: }
1.27 raeburn 13060: }
13061: }
13062: } else {
1.43 raeburn 13063: foreach my $item (@contexts) {
1.34 raeburn 13064: push(@{$changes{'cancreate'}},$item);
13065: }
1.27 raeburn 13066: }
1.34 raeburn 13067:
1.27 raeburn 13068: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
13069: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
13070: if (!grep(/^\Q$type\E$/,@username_rule)) {
13071: push(@{$changes{'username_rule'}},$type);
13072: }
13073: }
13074: foreach my $type (@username_rule) {
13075: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
13076: push(@{$changes{'username_rule'}},$type);
13077: }
13078: }
13079: } else {
13080: push(@{$changes{'username_rule'}},@username_rule);
13081: }
13082:
1.32 raeburn 13083: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
13084: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
13085: if (!grep(/^\Q$type\E$/,@id_rule)) {
13086: push(@{$changes{'id_rule'}},$type);
13087: }
13088: }
13089: foreach my $type (@id_rule) {
13090: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
13091: push(@{$changes{'id_rule'}},$type);
13092: }
13093: }
13094: } else {
13095: push(@{$changes{'id_rule'}},@id_rule);
13096: }
13097:
1.43 raeburn 13098: my @authen_contexts = ('author','course','domain');
1.325 raeburn 13099: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 13100: my %authhash;
1.43 raeburn 13101: foreach my $item (@authen_contexts) {
1.28 raeburn 13102: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
13103: foreach my $auth (@authtypes) {
13104: if (grep(/^\Q$auth\E$/,@authallowed)) {
13105: $authhash{$item}{$auth} = 1;
13106: } else {
13107: $authhash{$item}{$auth} = 0;
13108: }
13109: }
13110: }
13111: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 13112: foreach my $item (@authen_contexts) {
1.28 raeburn 13113: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
13114: foreach my $auth (@authtypes) {
13115: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
13116: push(@{$changes{'authtypes'}},$item);
13117: last;
13118: }
13119: }
13120: }
13121: }
13122: } else {
1.43 raeburn 13123: foreach my $item (@authen_contexts) {
1.28 raeburn 13124: push(@{$changes{'authtypes'}},$item);
13125: }
13126: }
13127:
1.224 raeburn 13128: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13129: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13130: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13131: $save_usercreate{'id_rule'} = \@id_rule;
13132: $save_usercreate{'username_rule'} = \@username_rule,
13133: $save_usercreate{'authtypes'} = \%authhash;
13134:
1.27 raeburn 13135: my %usercreation_hash = (
1.224 raeburn 13136: usercreation => \%save_usercreate,
13137: );
1.27 raeburn 13138:
13139: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13140: $dom);
1.50 raeburn 13141:
1.224 raeburn 13142: if ($putresult eq 'ok') {
13143: if (keys(%changes) > 0) {
13144: $resulttext = &mt('Changes made:').'<ul>';
13145: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13146: my %lt = &usercreation_types();
13147: foreach my $type (@{$changes{'cancreate'}}) {
13148: my $chgtext = $lt{$type}.', ';
13149: if ($cancreate{$type} eq 'none') {
13150: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13151: } elsif ($cancreate{$type} eq 'any') {
13152: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13153: } elsif ($cancreate{$type} eq 'official') {
13154: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13155: } elsif ($cancreate{$type} eq 'unofficial') {
13156: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13157: }
13158: $resulttext .= '<li>'.$chgtext.'</li>';
13159: }
13160: }
13161: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13162: my ($rules,$ruleorder) =
13163: &Apache::lonnet::inst_userrules($dom,'username');
13164: my $chgtext = '<ul>';
13165: foreach my $type (@username_rule) {
13166: if (ref($rules->{$type}) eq 'HASH') {
13167: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13168: }
13169: }
13170: $chgtext .= '</ul>';
13171: if (@username_rule > 0) {
13172: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13173: } else {
13174: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13175: }
13176: }
13177: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13178: my ($idrules,$idruleorder) =
13179: &Apache::lonnet::inst_userrules($dom,'id');
13180: my $chgtext = '<ul>';
13181: foreach my $type (@id_rule) {
13182: if (ref($idrules->{$type}) eq 'HASH') {
13183: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13184: }
13185: }
13186: $chgtext .= '</ul>';
13187: if (@id_rule > 0) {
13188: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13189: } else {
13190: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13191: }
13192: }
13193: my %authname = &authtype_names();
13194: my %context_title = &context_names();
13195: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13196: my $chgtext = '<ul>';
13197: foreach my $type (@{$changes{'authtypes'}}) {
13198: my @allowed;
13199: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13200: foreach my $auth (@authtypes) {
13201: if ($authhash{$type}{$auth}) {
13202: push(@allowed,$authname{$auth});
13203: }
13204: }
13205: if (@allowed > 0) {
13206: $chgtext .= join(', ',@allowed).'</li>';
13207: } else {
13208: $chgtext .= &mt('none').'</li>';
13209: }
13210: }
13211: $chgtext .= '</ul>';
13212: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13213: $resulttext .= '</li>';
13214: }
13215: $resulttext .= '</ul>';
13216: } else {
13217: $resulttext = &mt('No changes made to user creation settings');
13218: }
13219: } else {
13220: $resulttext = '<span class="LC_error">'.
13221: &mt('An error occurred: [_1]',$putresult).'</span>';
13222: }
13223: if ($warningmsg ne '') {
13224: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13225: }
13226: return $resulttext;
13227: }
13228:
13229: sub modify_selfcreation {
1.305 raeburn 13230: my ($dom,$lastactref,%domconfig) = @_;
13231: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13232: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13233: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 13234: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13235: if (ref($typesref) eq 'ARRAY') {
13236: @types = @{$typesref};
13237: }
13238: if (ref($usertypesref) eq 'HASH') {
13239: %usertypes = %{$usertypesref};
1.228 raeburn 13240: }
1.303 raeburn 13241: $usertypes{'default'} = $othertitle;
1.224 raeburn 13242: #
13243: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13244: #
13245: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13246: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13247: if ($key eq 'cancreate') {
13248: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13249: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13250: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 13251: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13252: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13253: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13254: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 13255: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 13256: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13257: } else {
13258: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13259: }
13260: }
13261: }
13262: } elsif ($key eq 'email_rule') {
13263: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13264: } else {
13265: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13266: }
13267: }
13268: }
13269: #
13270: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13271: #
13272: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13273: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13274: if ($key eq 'selfcreate') {
13275: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13276: } else {
13277: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13278: }
13279: }
13280: }
1.305 raeburn 13281: #
13282: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13283: #
13284: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13285: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13286: if ($key eq 'inststatusguest') {
13287: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13288: } else {
13289: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13290: }
13291: }
13292: }
1.224 raeburn 13293:
13294: my @contexts = ('selfcreate');
13295: @{$cancreate{'selfcreate'}} = ();
13296: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 13297: if (@types) {
13298: @{$cancreate{'statustocreate'}} = ();
13299: }
1.236 raeburn 13300: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 13301: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 13302: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 13303: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 13304: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13305: my %selfcreatetypes = (
13306: sso => 'users authenticated by institutional single sign on',
13307: login => 'users authenticated by institutional log-in',
1.303 raeburn 13308: email => 'users verified by e-mail',
1.50 raeburn 13309: );
1.224 raeburn 13310: #
13311: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13312: # is permitted.
13313: #
1.305 raeburn 13314: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 13315:
1.305 raeburn 13316: my (@statuses,%email_rule);
1.228 raeburn 13317: foreach my $item ('login','sso','email') {
1.224 raeburn 13318: if ($item eq 'email') {
1.236 raeburn 13319: if ($env{'form.cancreate_email'}) {
1.305 raeburn 13320: if (@types) {
13321: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13322: foreach my $status (@poss_statuses) {
13323: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13324: push(@statuses,$status);
13325: }
13326: }
13327: $save_inststatus{'inststatusguest'} = \@statuses;
13328: } else {
13329: push(@statuses,'default');
13330: }
13331: if (@statuses) {
13332: my %curr_rule;
13333: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13334: foreach my $type (@statuses) {
13335: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 13336: }
1.305 raeburn 13337: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13338: foreach my $type (@statuses) {
13339: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13340: }
13341: }
13342: push(@{$cancreate{'selfcreate'}},'email');
13343: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13344: my %curremaildom;
13345: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13346: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13347: }
13348: foreach my $type (@statuses) {
13349: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13350: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13351: }
13352: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13353: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13354: }
13355: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13356: #
13357: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13358: #
13359: my $chosen = $1;
13360: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13361: my $emaildom;
13362: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13363: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13364: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13365: if (ref($curremaildom{$type}) eq 'HASH') {
13366: if (exists($curremaildom{$type}{$chosen})) {
13367: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13368: push(@{$changes{'cancreate'}},'emaildomain');
13369: }
13370: } elsif ($emaildom ne '') {
13371: push(@{$changes{'cancreate'}},'emaildomain');
13372: }
13373: } elsif ($emaildom ne '') {
13374: push(@{$changes{'cancreate'}},'emaildomain');
13375: }
13376: }
13377: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13378: } elsif ($chosen eq 'custom') {
13379: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13380: $email_rule{$type} = [];
13381: if (ref($emailrules) eq 'HASH') {
13382: foreach my $rule (@possemail_rules) {
13383: if (exists($emailrules->{$rule})) {
13384: push(@{$email_rule{$type}},$rule);
13385: }
13386: }
13387: }
13388: if (@{$email_rule{$type}}) {
13389: $cancreate{'emailoptions'}{$type} = 'custom';
13390: if (ref($curr_rule{$type}) eq 'ARRAY') {
13391: if (@{$curr_rule{$type}} > 0) {
13392: foreach my $rule (@{$curr_rule{$type}}) {
13393: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13394: push(@{$changes{'email_rule'}},$type);
13395: }
13396: }
13397: }
13398: foreach my $type (@{$email_rule{$type}}) {
13399: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13400: push(@{$changes{'email_rule'}},$type);
13401: }
13402: }
13403: } else {
13404: push(@{$changes{'email_rule'}},$type);
13405: }
13406: }
13407: } else {
13408: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13409: }
13410: }
13411: }
13412: if (@types) {
13413: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13414: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13415: if (@changed) {
13416: push(@{$changes{'inststatus'}},'inststatusguest');
13417: }
13418: } else {
13419: push(@{$changes{'inststatus'}},'inststatusguest');
13420: }
13421: }
13422: } else {
13423: delete($env{'form.cancreate_email'});
13424: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13425: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13426: push(@{$changes{'inststatus'}},'inststatusguest');
13427: }
13428: }
13429: }
13430: } else {
13431: $save_inststatus{'inststatusguest'} = [];
13432: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13433: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13434: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 13435: }
13436: }
1.224 raeburn 13437: }
13438: } else {
13439: if ($env{'form.cancreate_'.$item}) {
13440: push(@{$cancreate{'selfcreate'}},$item);
13441: }
13442: }
13443: }
1.305 raeburn 13444: my (%userinfo,%savecaptcha);
1.224 raeburn 13445: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13446: #
1.228 raeburn 13447: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13448: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 13449: #
1.236 raeburn 13450:
1.244 raeburn 13451: if ($env{'form.cancreate_email'}) {
1.228 raeburn 13452: push(@contexts,'emailusername');
1.305 raeburn 13453: if (@statuses) {
13454: foreach my $type (@statuses) {
1.228 raeburn 13455: if (ref($infofields) eq 'ARRAY') {
13456: foreach my $field (@{$infofields}) {
13457: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13458: $cancreate{'emailusername'}{$type}{$field} = $1;
13459: }
13460: }
1.224 raeburn 13461: }
13462: }
13463: }
13464: #
13465: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 13466: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 13467: #
13468:
13469: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13470: @approvalnotify = sort(@approvalnotify);
13471: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13472: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13473: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13474: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13475: push(@{$changes{'cancreate'}},'notify');
13476: }
13477: } else {
13478: if ($cancreate{'notify'}{'approval'}) {
13479: push(@{$changes{'cancreate'}},'notify');
13480: }
13481: }
13482: } elsif ($cancreate{'notify'}{'approval'}) {
13483: push(@{$changes{'cancreate'}},'notify');
13484: }
13485:
13486: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13487: }
13488: #
1.236 raeburn 13489: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 13490: # institutional log-in.
13491: #
13492: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13493: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13494: ($domdefaults{'auth_def'} eq 'localauth'))) {
13495: $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.').' '.
13496: &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.');
13497: }
13498: }
13499: my @fields = ('lastname','firstname','middlename','generation',
13500: 'permanentemail','id');
1.240 raeburn 13501: my @shibfields = (@fields,'inststatus');
1.224 raeburn 13502: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13503: #
13504: # Where usernames may created for institutional log-in and/or institutional single sign on:
13505: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13506: # may self-create accounts
13507: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13508: # which the user may supply, if institutional data is unavailable.
13509: #
13510: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 13511: if (@types) {
1.305 raeburn 13512: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13513: push(@contexts,'statustocreate');
1.303 raeburn 13514: foreach my $type (@types) {
1.224 raeburn 13515: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13516: foreach my $field (@fields) {
13517: if (grep(/^\Q$field\E$/,@modifiable)) {
13518: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13519: } else {
13520: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13521: }
13522: }
13523: }
13524: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 13525: foreach my $type (@types) {
1.224 raeburn 13526: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13527: foreach my $field (@fields) {
13528: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13529: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13530: push(@{$changes{'selfcreate'}},$type);
13531: last;
13532: }
13533: }
13534: }
13535: }
13536: } else {
1.303 raeburn 13537: foreach my $type (@types) {
1.224 raeburn 13538: push(@{$changes{'selfcreate'}},$type);
13539: }
13540: }
13541: }
1.240 raeburn 13542: foreach my $field (@shibfields) {
13543: if ($env{'form.shibenv_'.$field} ne '') {
13544: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13545: }
13546: }
13547: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13548: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13549: foreach my $field (@shibfields) {
13550: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13551: push(@{$changes{'cancreate'}},'shibenv');
13552: }
13553: }
13554: } else {
13555: foreach my $field (@shibfields) {
13556: if ($env{'form.shibenv_'.$field}) {
13557: push(@{$changes{'cancreate'}},'shibenv');
13558: last;
13559: }
13560: }
13561: }
13562: }
1.224 raeburn 13563: }
13564: foreach my $item (@contexts) {
13565: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13566: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13567: if (ref($cancreate{$item}) eq 'ARRAY') {
13568: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13569: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13570: push(@{$changes{'cancreate'}},$item);
13571: }
13572: }
13573: }
13574: }
13575: if (ref($cancreate{$item}) eq 'ARRAY') {
13576: foreach my $type (@{$cancreate{$item}}) {
13577: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13578: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13579: push(@{$changes{'cancreate'}},$item);
13580: }
13581: }
13582: }
13583: }
13584: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13585: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 13586: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13587: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13588: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13589: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13590: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13591: push(@{$changes{'cancreate'}},$item);
13592: }
13593: }
13594: }
1.305 raeburn 13595: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13596: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13597: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13598: push(@{$changes{'cancreate'}},$item);
13599: }
1.224 raeburn 13600: }
13601: }
13602: }
1.305 raeburn 13603: foreach my $type (keys(%{$cancreate{$item}})) {
13604: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13605: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13606: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13607: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13608: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13609: push(@{$changes{'cancreate'}},$item);
13610: }
13611: }
13612: } else {
13613: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13614: push(@{$changes{'cancreate'}},$item);
13615: }
13616: }
13617: }
1.305 raeburn 13618: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13619: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13620: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13621: push(@{$changes{'cancreate'}},$item);
13622: }
1.224 raeburn 13623: }
13624: }
13625: }
13626: }
13627: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13628: if (ref($cancreate{$item}) eq 'ARRAY') {
13629: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13630: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13631: push(@{$changes{'cancreate'}},$item);
13632: }
13633: }
1.305 raeburn 13634: }
13635: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13636: if (ref($cancreate{$item}) eq 'HASH') {
13637: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13638: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 13639: }
13640: }
13641: } elsif ($item eq 'emailusername') {
1.228 raeburn 13642: if (ref($cancreate{$item}) eq 'HASH') {
13643: foreach my $type (keys(%{$cancreate{$item}})) {
13644: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13645: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13646: if ($cancreate{$item}{$type}{$field}) {
13647: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13648: push(@{$changes{'cancreate'}},$item);
13649: }
13650: last;
13651: }
13652: }
13653: }
13654: }
1.224 raeburn 13655: }
13656: }
13657: }
13658: #
13659: # Populate %save_usercreate hash with updates to self-creation configuration.
13660: #
13661: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13662: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 13663: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 13664: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13665: if (ref($cancreate{'notify'}) eq 'HASH') {
13666: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13667: }
1.236 raeburn 13668: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13669: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13670: }
1.303 raeburn 13671: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13672: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13673: }
1.305 raeburn 13674: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13675: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13676: }
1.303 raeburn 13677: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13678: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13679: }
1.224 raeburn 13680: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13681: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13682: }
1.240 raeburn 13683: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13684: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13685: }
1.224 raeburn 13686: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 13687: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 13688:
13689: my %userconfig_hash = (
13690: usercreation => \%save_usercreate,
13691: usermodification => \%save_usermodify,
1.305 raeburn 13692: inststatus => \%save_inststatus,
1.224 raeburn 13693: );
1.305 raeburn 13694:
1.224 raeburn 13695: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13696: $dom);
13697: #
1.305 raeburn 13698: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 13699: #
1.27 raeburn 13700: if ($putresult eq 'ok') {
13701: if (keys(%changes) > 0) {
13702: $resulttext = &mt('Changes made:').'<ul>';
13703: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 13704: my %lt = &selfcreation_types();
1.34 raeburn 13705: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 13706: my $chgtext = '';
1.45 raeburn 13707: if ($type eq 'selfcreate') {
1.50 raeburn 13708: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 13709: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13710: } else {
1.224 raeburn 13711: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13712: '<ul>';
1.50 raeburn 13713: foreach my $case (@{$cancreate{$type}}) {
13714: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13715: }
13716: $chgtext .= '</ul>';
1.100 raeburn 13717: if (ref($cancreate{$type}) eq 'ARRAY') {
13718: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13719: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13720: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 13721: $chgtext .= '<span class="LC_warning">'.
13722: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13723: '</span><br />';
13724: }
13725: }
13726: }
13727: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 13728: if (!@statuses) {
13729: $chgtext .= '<span class="LC_warning">'.
13730: &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.").
13731: '</span><br />';
1.303 raeburn 13732:
1.100 raeburn 13733: }
13734: }
13735: }
1.43 raeburn 13736: }
1.240 raeburn 13737: } elsif ($type eq 'shibenv') {
13738: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 13739: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 13740: } else {
13741: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13742: '<ul>';
13743: foreach my $field (@shibfields) {
13744: next if ($cancreate{$type}{$field} eq '');
13745: if ($field eq 'inststatus') {
13746: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13747: } else {
13748: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13749: }
13750: }
13751: $chgtext .= '</ul>';
1.303 raeburn 13752: }
1.93 raeburn 13753: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13754: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13755: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13756: if (@{$cancreate{'selfcreate'}} > 0) {
13757: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13758: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13759: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 13760: $chgtext .= '<br />'.
13761: '<span class="LC_warning">'.
13762: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13763: '</span>';
13764: }
1.303 raeburn 13765: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13766: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13767: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13768: } else {
13769: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13770: }
13771: $chgtext .= '<ul>';
13772: foreach my $case (@{$cancreate{$type}}) {
13773: if ($case eq 'default') {
13774: $chgtext .= '<li>'.$othertitle.'</li>';
13775: } else {
1.303 raeburn 13776: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13777: }
13778: }
1.100 raeburn 13779: $chgtext .= '</ul>';
13780: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 13781: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 13782: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13783: '</span>';
1.100 raeburn 13784: }
13785: }
13786: } else {
13787: if (@{$cancreate{$type}} == 0) {
13788: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13789: } else {
13790: $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 13791: }
13792: }
1.303 raeburn 13793: $chgtext .= '<br />';
1.93 raeburn 13794: }
1.236 raeburn 13795: } elsif ($type eq 'selfcreateprocessing') {
13796: my %choices = &Apache::lonlocal::texthash (
13797: automatic => 'Automatic approval',
13798: approval => 'Queued for approval',
13799: );
1.305 raeburn 13800: if (@types) {
13801: if (@statuses) {
1.303 raeburn 13802: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 13803: '<ul>';
1.305 raeburn 13804: foreach my $status (@statuses) {
13805: if ($status eq 'default') {
13806: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13807: } else {
1.305 raeburn 13808: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13809: }
13810: }
13811: $chgtext .= '</ul>';
13812: }
13813: } else {
13814: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13815: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13816: }
13817: } elsif ($type eq 'emailverified') {
13818: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 13819: all => 'Same as e-mail',
13820: first => 'Omit @domain',
13821: free => 'Free to choose',
1.303 raeburn 13822: );
1.305 raeburn 13823: if (@types) {
13824: if (@statuses) {
1.303 raeburn 13825: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13826: '<ul>';
1.305 raeburn 13827: foreach my $status (@statuses) {
1.303 raeburn 13828: if ($type eq 'default') {
1.305 raeburn 13829: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13830: } else {
1.305 raeburn 13831: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13832: }
13833: }
13834: $chgtext .= '</ul>';
13835: }
13836: } else {
1.305 raeburn 13837: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 13838: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 13839: }
1.305 raeburn 13840: } elsif ($type eq 'emailoptions') {
13841: my %options = &Apache::lonlocal::texthash (
13842: any => 'Any e-mail',
13843: inst => 'Institutional only',
13844: noninst => 'Non-institutional only',
13845: custom => 'Custom restrictions',
13846: );
13847: if (@types) {
13848: if (@statuses) {
13849: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13850: '<ul>';
13851: foreach my $status (@statuses) {
13852: if ($type eq 'default') {
13853: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13854: } else {
13855: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 13856: }
13857: }
1.305 raeburn 13858: $chgtext .= '</ul>';
13859: }
13860: } else {
13861: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13862: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13863: } else {
13864: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13865: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 13866: }
1.305 raeburn 13867: }
13868: } elsif ($type eq 'emaildomain') {
13869: my $output;
13870: if (@statuses) {
13871: foreach my $type (@statuses) {
13872: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13873: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13874: if ($type eq 'default') {
13875: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13876: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13877: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13878: } else {
13879: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13880: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13881: }
1.303 raeburn 13882: } else {
1.305 raeburn 13883: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13884: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13885: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13886: } else {
13887: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13888: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13889: }
1.303 raeburn 13890: }
1.305 raeburn 13891: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13892: if ($type eq 'default') {
13893: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13894: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13895: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13896: } else {
13897: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13898: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13899: }
1.303 raeburn 13900: } else {
1.305 raeburn 13901: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13902: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13903: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13904: } else {
13905: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13906: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13907: }
1.303 raeburn 13908: }
13909: }
13910: }
13911: }
1.305 raeburn 13912: }
13913: if ($output ne '') {
13914: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
13915: '<ul>'.$output.'</ul>';
1.236 raeburn 13916: }
1.165 raeburn 13917: } elsif ($type eq 'captcha') {
1.224 raeburn 13918: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 13919: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
13920: } else {
13921: my %captchas = &captcha_phrases();
1.224 raeburn 13922: if ($captchas{$savecaptcha{$type}}) {
13923: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 13924: } else {
1.210 raeburn 13925: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 13926: }
13927: }
13928: } elsif ($type eq 'recaptchakeys') {
13929: my ($privkey,$pubkey);
1.224 raeburn 13930: if (ref($savecaptcha{$type}) eq 'HASH') {
13931: $pubkey = $savecaptcha{$type}{'public'};
13932: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 13933: }
13934: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
13935: if (!$pubkey) {
13936: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
13937: } else {
13938: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13939: }
13940: if (!$privkey) {
13941: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
13942: } else {
13943: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
13944: }
13945: $chgtext .= '</ul>';
1.269 raeburn 13946: } elsif ($type eq 'recaptchaversion') {
13947: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 13948: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 13949: }
1.224 raeburn 13950: } elsif ($type eq 'emailusername') {
13951: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 13952: if (@statuses) {
13953: foreach my $type (@statuses) {
1.228 raeburn 13954: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
13955: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 13956: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 13957: '<ul>';
13958: foreach my $field (@{$infofields}) {
13959: if ($cancreate{'emailusername'}{$type}{$field}) {
13960: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
13961: }
13962: }
1.245 raeburn 13963: $chgtext .= '</ul>';
13964: } else {
1.303 raeburn 13965: $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 13966: }
13967: } else {
1.303 raeburn 13968: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.224 raeburn 13969: }
13970: }
13971: }
13972: }
13973: } elsif ($type eq 'notify') {
1.303 raeburn 13974: my $numapprove = 0;
1.224 raeburn 13975: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13976: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
13977: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 13978: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
13979: $numapprove ++;
1.224 raeburn 13980: }
13981: }
1.43 raeburn 13982: }
1.303 raeburn 13983: unless ($numapprove) {
13984: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
13985: }
1.34 raeburn 13986: }
1.224 raeburn 13987: if ($chgtext) {
13988: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 13989: }
13990: }
13991: }
1.305 raeburn 13992: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 13993: my ($emailrules,$emailruleorder) =
13994: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 13995: foreach my $type (@{$changes{'email_rule'}}) {
13996: if (ref($email_rule{$type}) eq 'ARRAY') {
13997: my $chgtext = '<ul>';
13998: foreach my $rule (@{$email_rule{$type}}) {
13999: if (ref($emailrules->{$rule}) eq 'HASH') {
14000: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
14001: }
14002: }
14003: $chgtext .= '</ul>';
1.310 raeburn 14004: my $typename;
1.305 raeburn 14005: if (@types) {
14006: if ($type eq 'default') {
14007: $typename = $othertitle;
14008: } else {
14009: $typename = $usertypes{$type};
14010: }
14011: $chgtext .= &mt('(Affiliation: [_1])',$typename);
14012: }
14013: if (@{$email_rule{$type}} > 0) {
14014: $resulttext .= '<li>'.
14015: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
14016: $usertypes{$type}).
14017: $chgtext.
14018: '</li>';
14019: } else {
14020: $resulttext .= '<li>'.
1.310 raeburn 14021: &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 14022: '</li>'.
1.310 raeburn 14023: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 14024: }
1.43 raeburn 14025: }
14026: }
1.305 raeburn 14027: }
14028: if (ref($changes{'inststatus'}) eq 'ARRAY') {
14029: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
14030: if (@{$save_inststatus{'inststatusguest'}} > 0) {
14031: my $chgtext = '<ul>';
14032: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
14033: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
14034: }
14035: $chgtext .= '</ul>';
14036: $resulttext .= '<li>'.
14037: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
14038: $chgtext.
14039: '</li>';
14040: } else {
14041: $resulttext .= '<li>'.
14042: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
14043: '</li>';
14044: }
1.43 raeburn 14045: }
14046: }
1.224 raeburn 14047: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
14048: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
14049: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14050: foreach my $type (@{$changes{'selfcreate'}}) {
14051: my $typename = $type;
1.303 raeburn 14052: if (keys(%usertypes) > 0) {
14053: if ($usertypes{$type} ne '') {
14054: $typename = $usertypes{$type};
1.224 raeburn 14055: }
14056: }
14057: my @modifiable;
14058: $resulttext .= '<li>'.
14059: &mt('Self-creation of account by users with status: [_1]',
14060: '<span class="LC_cusr_emph">'.$typename.'</span>').
14061: ' - '.&mt('modifiable fields (if institutional data blank): ');
14062: foreach my $field (@fields) {
14063: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
14064: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 14065: }
14066: }
1.224 raeburn 14067: if (@modifiable > 0) {
14068: $resulttext .= join(', ',@modifiable);
1.43 raeburn 14069: } else {
1.224 raeburn 14070: $resulttext .= &mt('none');
1.43 raeburn 14071: }
1.224 raeburn 14072: $resulttext .= '</li>';
1.28 raeburn 14073: }
1.224 raeburn 14074: $resulttext .= '</ul></li>';
1.28 raeburn 14075: }
1.27 raeburn 14076: $resulttext .= '</ul>';
1.305 raeburn 14077: my $cachetime = 24*60*60;
14078: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
14079: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14080: if (ref($lastactref) eq 'HASH') {
14081: $lastactref->{'domdefaults'} = 1;
14082: }
1.27 raeburn 14083: } else {
1.224 raeburn 14084: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 14085: }
14086: } else {
14087: $resulttext = '<span class="LC_error">'.
1.23 raeburn 14088: &mt('An error occurred: [_1]',$putresult).'</span>';
14089: }
1.43 raeburn 14090: if ($warningmsg ne '') {
14091: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14092: }
1.23 raeburn 14093: return $resulttext;
14094: }
14095:
1.165 raeburn 14096: sub process_captcha {
14097: my ($container,$changes,$newsettings,$current) = @_;
14098: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
14099: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
14100: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
14101: $newsettings->{'captcha'} = 'original';
14102: }
14103: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 14104: if ($container eq 'cancreate') {
1.169 raeburn 14105: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14106: push(@{$changes->{'cancreate'}},'captcha');
14107: } elsif (!defined($changes->{'cancreate'})) {
14108: $changes->{'cancreate'} = ['captcha'];
14109: }
14110: } else {
14111: $changes->{'captcha'} = 1;
1.165 raeburn 14112: }
14113: }
1.269 raeburn 14114: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 14115: if ($newsettings->{'captcha'} eq 'recaptcha') {
14116: $newpub = $env{'form.'.$container.'_recaptchapub'};
14117: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 14118: $newpub =~ s/[^\w\-]//g;
14119: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 14120: $newsettings->{'recaptchakeys'} = {
14121: public => $newpub,
14122: private => $newpriv,
14123: };
1.269 raeburn 14124: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14125: $newversion =~ s/\D//g;
14126: if ($newversion ne '2') {
14127: $newversion = 1;
14128: }
14129: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 14130: }
14131: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
14132: $currpub = $current->{'recaptchakeys'}{'public'};
14133: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 14134: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14135: $newsettings->{'recaptchakeys'} = {
14136: public => '',
14137: private => '',
14138: }
14139: }
1.165 raeburn 14140: }
1.269 raeburn 14141: if ($current->{'captcha'} eq 'recaptcha') {
14142: $currversion = $current->{'recaptchaversion'};
14143: if ($currversion ne '2') {
14144: $currversion = 1;
14145: }
14146: }
14147: if ($currversion ne $newversion) {
14148: if ($container eq 'cancreate') {
14149: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14150: push(@{$changes->{'cancreate'}},'recaptchaversion');
14151: } elsif (!defined($changes->{'cancreate'})) {
14152: $changes->{'cancreate'} = ['recaptchaversion'];
14153: }
14154: } else {
14155: $changes->{'recaptchaversion'} = 1;
14156: }
14157: }
1.165 raeburn 14158: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 14159: if ($container eq 'cancreate') {
14160: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14161: push(@{$changes->{'cancreate'}},'recaptchakeys');
14162: } elsif (!defined($changes->{'cancreate'})) {
14163: $changes->{'cancreate'} = ['recaptchakeys'];
14164: }
14165: } else {
1.210 raeburn 14166: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 14167: }
14168: }
14169: return;
14170: }
14171:
1.33 raeburn 14172: sub modify_usermodification {
14173: my ($dom,%domconfig) = @_;
1.224 raeburn 14174: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14175: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14176: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 14177: if ($key eq 'selfcreate') {
14178: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14179: } else {
14180: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14181: }
1.33 raeburn 14182: }
14183: }
1.224 raeburn 14184: my @contexts = ('author','course');
1.33 raeburn 14185: my %context_title = (
14186: author => 'In author context',
14187: course => 'In course context',
14188: );
14189: my @fields = ('lastname','firstname','middlename','generation',
14190: 'permanentemail','id');
14191: my %roles = (
14192: author => ['ca','aa'],
14193: course => ['st','ep','ta','in','cr'],
14194: );
14195: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14196: foreach my $context (@contexts) {
14197: foreach my $role (@{$roles{$context}}) {
14198: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14199: foreach my $item (@fields) {
14200: if (grep(/^\Q$item\E$/,@modifiable)) {
14201: $modifyhash{$context}{$role}{$item} = 1;
14202: } else {
14203: $modifyhash{$context}{$role}{$item} = 0;
14204: }
14205: }
14206: }
14207: if (ref($curr_usermodification{$context}) eq 'HASH') {
14208: foreach my $role (@{$roles{$context}}) {
14209: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14210: foreach my $field (@fields) {
14211: if ($modifyhash{$context}{$role}{$field} ne
14212: $curr_usermodification{$context}{$role}{$field}) {
14213: push(@{$changes{$context}},$role);
14214: last;
14215: }
14216: }
14217: }
14218: }
14219: } else {
14220: foreach my $context (@contexts) {
14221: foreach my $role (@{$roles{$context}}) {
14222: push(@{$changes{$context}},$role);
14223: }
14224: }
14225: }
14226: }
14227: my %usermodification_hash = (
14228: usermodification => \%modifyhash,
14229: );
14230: my $putresult = &Apache::lonnet::put_dom('configuration',
14231: \%usermodification_hash,$dom);
14232: if ($putresult eq 'ok') {
14233: if (keys(%changes) > 0) {
14234: $resulttext = &mt('Changes made: ').'<ul>';
14235: foreach my $context (@contexts) {
14236: if (ref($changes{$context}) eq 'ARRAY') {
14237: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14238: if (ref($changes{$context}) eq 'ARRAY') {
14239: foreach my $role (@{$changes{$context}}) {
14240: my $rolename;
1.224 raeburn 14241: if ($role eq 'cr') {
14242: $rolename = &mt('Custom');
1.33 raeburn 14243: } else {
1.224 raeburn 14244: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14245: }
14246: my @modifiable;
1.224 raeburn 14247: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14248: foreach my $field (@fields) {
14249: if ($modifyhash{$context}{$role}{$field}) {
14250: push(@modifiable,$fieldtitles{$field});
14251: }
14252: }
14253: if (@modifiable > 0) {
14254: $resulttext .= join(', ',@modifiable);
14255: } else {
14256: $resulttext .= &mt('none');
14257: }
14258: $resulttext .= '</li>';
14259: }
14260: $resulttext .= '</ul></li>';
14261: }
14262: }
14263: }
14264: $resulttext .= '</ul>';
14265: } else {
14266: $resulttext = &mt('No changes made to user modification settings');
14267: }
14268: } else {
14269: $resulttext = '<span class="LC_error">'.
14270: &mt('An error occurred: [_1]',$putresult).'</span>';
14271: }
14272: return $resulttext;
14273: }
14274:
1.43 raeburn 14275: sub modify_defaults {
1.212 raeburn 14276: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14277: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 14278: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 14279: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
14280: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.325 raeburn 14281: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 14282: foreach my $item (@items) {
14283: $newvalues{$item} = $env{'form.'.$item};
14284: if ($item eq 'auth_def') {
14285: if ($newvalues{$item} ne '') {
14286: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14287: push(@errors,$item);
14288: }
14289: }
14290: } elsif ($item eq 'lang_def') {
14291: if ($newvalues{$item} ne '') {
14292: if ($newvalues{$item} =~ /^(\w+)/) {
14293: my $langcode = $1;
1.103 raeburn 14294: if ($langcode ne 'x_chef') {
14295: if (code2language($langcode) eq '') {
14296: push(@errors,$item);
14297: }
1.43 raeburn 14298: }
14299: } else {
14300: push(@errors,$item);
14301: }
14302: }
1.54 raeburn 14303: } elsif ($item eq 'timezone_def') {
14304: if ($newvalues{$item} ne '') {
1.62 raeburn 14305: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14306: push(@errors,$item);
14307: }
14308: }
1.68 raeburn 14309: } elsif ($item eq 'datelocale_def') {
14310: if ($newvalues{$item} ne '') {
14311: my @datelocale_ids = DateTime::Locale->ids();
14312: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14313: push(@errors,$item);
14314: }
14315: }
1.141 raeburn 14316: } elsif ($item eq 'portal_def') {
14317: if ($newvalues{$item} ne '') {
14318: 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])\/?$/) {
14319: push(@errors,$item);
14320: }
14321: }
1.294 raeburn 14322: } elsif ($item eq 'intauth_cost') {
14323: if ($newvalues{$item} ne '') {
14324: if ($newvalues{$item} =~ /\D/) {
14325: push(@errors,$item);
14326: }
14327: }
14328: } elsif ($item eq 'intauth_check') {
14329: if ($newvalues{$item} ne '') {
14330: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14331: push(@errors,$item);
14332: }
14333: }
14334: } elsif ($item eq 'intauth_switch') {
14335: if ($newvalues{$item} ne '') {
14336: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14337: push(@errors,$item);
14338: }
14339: }
1.43 raeburn 14340: }
14341: if (grep(/^\Q$item\E$/,@errors)) {
14342: $newvalues{$item} = $domdefaults{$item};
14343: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14344: $changes{$item} = 1;
14345: }
1.72 raeburn 14346: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14347: }
14348: my %defaults_hash = (
1.72 raeburn 14349: defaults => \%newvalues,
14350: );
1.43 raeburn 14351: my $title = &defaults_titles();
1.236 raeburn 14352:
14353: my $currinststatus;
14354: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14355: $currinststatus = $domconfig{'inststatus'};
14356: } else {
14357: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14358: $currinststatus = {
14359: inststatustypes => $usertypes,
14360: inststatusorder => $types,
14361: inststatusguest => [],
14362: };
14363: }
14364: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14365: my @allpos;
14366: my %alltypes;
1.305 raeburn 14367: my @inststatusguest;
14368: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14369: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14370: unless (grep(/^\Q$type\E$/,@todelete)) {
14371: push(@inststatusguest,$type);
14372: }
14373: }
14374: }
14375: my ($currtitles,$currorder);
1.236 raeburn 14376: if (ref($currinststatus) eq 'HASH') {
14377: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14378: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14379: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14380: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14381: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14382: }
14383: }
14384: unless (grep(/^\Q$type\E$/,@todelete)) {
14385: my $position = $env{'form.inststatus_pos_'.$type};
14386: $position =~ s/\D+//g;
14387: $allpos[$position] = $type;
14388: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14389: $alltypes{$type} =~ s/`//g;
14390: }
14391: }
14392: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14393: $currtitles =~ s/,$//;
14394: }
14395: }
14396: if ($env{'form.addinststatus'}) {
14397: my $newtype = $env{'form.addinststatus'};
14398: $newtype =~ s/\W//g;
14399: unless (exists($alltypes{$newtype})) {
14400: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14401: $alltypes{$newtype} =~ s/`//g;
14402: my $position = $env{'form.addinststatus_pos'};
14403: $position =~ s/\D+//g;
14404: if ($position ne '') {
14405: $allpos[$position] = $newtype;
14406: }
14407: }
14408: }
1.305 raeburn 14409: my @orderedstatus;
1.236 raeburn 14410: foreach my $type (@allpos) {
14411: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14412: push(@orderedstatus,$type);
14413: }
14414: }
14415: foreach my $type (keys(%alltypes)) {
14416: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14417: delete($alltypes{$type});
14418: }
14419: }
14420: $defaults_hash{'inststatus'} = {
14421: inststatustypes => \%alltypes,
14422: inststatusorder => \@orderedstatus,
1.305 raeburn 14423: inststatusguest => \@inststatusguest,
1.236 raeburn 14424: };
14425: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14426: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14427: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14428: }
14429: }
14430: if ($currorder ne join(',',@orderedstatus)) {
14431: $changes{'inststatus'}{'inststatusorder'} = 1;
14432: }
14433: my $newtitles;
14434: foreach my $item (@orderedstatus) {
14435: $newtitles .= $alltypes{$item}.',';
14436: }
14437: $newtitles =~ s/,$//;
14438: if ($currtitles ne $newtitles) {
14439: $changes{'inststatus'}{'inststatustypes'} = 1;
14440: }
1.43 raeburn 14441: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14442: $dom);
14443: if ($putresult eq 'ok') {
14444: if (keys(%changes) > 0) {
14445: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 14446: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14447: 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";
14448: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 14449: if ($item eq 'inststatus') {
14450: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 14451: if (@orderedstatus) {
1.236 raeburn 14452: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14453: foreach my $type (@orderedstatus) {
14454: $resulttext .= $alltypes{$type}.', ';
14455: }
14456: $resulttext =~ s/, $//;
14457: $resulttext .= '</li>';
1.305 raeburn 14458: } else {
14459: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 14460: }
14461: }
14462: } else {
14463: my $value = $env{'form.'.$item};
14464: if ($value eq '') {
14465: $value = &mt('none');
14466: } elsif ($item eq 'auth_def') {
14467: my %authnames = &authtype_names();
14468: my %shortauth = (
14469: internal => 'int',
14470: krb4 => 'krb4',
14471: krb5 => 'krb5',
14472: localauth => 'loc',
1.325 raeburn 14473: lti => 'lti',
1.236 raeburn 14474: );
14475: $value = $authnames{$shortauth{$value}};
1.294 raeburn 14476: } elsif ($item eq 'intauth_switch') {
14477: my %optiondesc = &Apache::lonlocal::texthash (
14478: 0 => 'No',
14479: 1 => 'Yes',
14480: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14481: );
14482: if ($value =~ /^(0|1|2)$/) {
14483: $value = $optiondesc{$value};
14484: } else {
14485: $value = &mt('none -- defaults to No');
14486: }
14487: } elsif ($item eq 'intauth_check') {
14488: my %optiondesc = &Apache::lonlocal::texthash (
14489: 0 => 'No',
14490: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14491: 2 => 'Yes, disallow login if stored cost is less than domain default',
14492: );
14493: if ($value =~ /^(0|1|2)$/) {
14494: $value = $optiondesc{$value};
14495: } else {
14496: $value = &mt('none -- defaults to No');
14497: }
1.236 raeburn 14498: }
14499: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14500: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14501: }
14502: }
14503: $resulttext .= '</ul>';
14504: $mailmsgtext .= "\n";
14505: my $cachetime = 24*60*60;
1.72 raeburn 14506: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14507: if (ref($lastactref) eq 'HASH') {
14508: $lastactref->{'domdefaults'} = 1;
14509: }
1.68 raeburn 14510: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 14511: my $notify = 1;
14512: if (ref($domconfig{'contacts'}) eq 'HASH') {
14513: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14514: $notify = 0;
14515: }
14516: }
14517: if ($notify) {
14518: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14519: "LON-CAPA Domain Settings Change - $dom",
14520: $mailmsgtext);
14521: }
1.54 raeburn 14522: }
1.43 raeburn 14523: } else {
1.54 raeburn 14524: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14525: }
14526: } else {
14527: $resulttext = '<span class="LC_error">'.
14528: &mt('An error occurred: [_1]',$putresult).'</span>';
14529: }
14530: if (@errors > 0) {
14531: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14532: foreach my $item (@errors) {
14533: $resulttext .= ' "'.$title->{$item}.'",';
14534: }
14535: $resulttext =~ s/,$//;
14536: }
14537: return $resulttext;
14538: }
14539:
1.46 raeburn 14540: sub modify_scantron {
1.205 raeburn 14541: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14542: my ($resulttext,%confhash,%changes,$errors);
14543: my $custom = 'custom.tab';
14544: my $default = 'default.tab';
14545: my $servadm = $r->dir_config('lonAdmEMail');
14546: my ($configuserok,$author_ok,$switchserver) =
14547: &config_check($dom,$confname,$servadm);
14548: if ($env{'form.scantronformat.filename'} ne '') {
14549: my $error;
14550: if ($configuserok eq 'ok') {
14551: if ($switchserver) {
1.130 raeburn 14552: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14553: } else {
14554: if ($author_ok eq 'ok') {
14555: my ($result,$scantronurl) =
14556: &publishlogo($r,'upload','scantronformat',$dom,
14557: $confname,'scantron','','',$custom);
14558: if ($result eq 'ok') {
14559: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14560: $changes{'scantronformat'} = 1;
1.46 raeburn 14561: } else {
14562: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14563: }
14564: } else {
14565: $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);
14566: }
14567: }
14568: } else {
14569: $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);
14570: }
14571: if ($error) {
14572: &Apache::lonnet::logthis($error);
14573: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14574: }
14575: }
1.48 raeburn 14576: if (ref($domconfig{'scantron'}) eq 'HASH') {
14577: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14578: if ($env{'form.scantronformat_del'}) {
14579: $confhash{'scantron'}{'scantronformat'} = '';
14580: $changes{'scantronformat'} = 1;
1.46 raeburn 14581: }
14582: }
14583: }
14584: if (keys(%confhash) > 0) {
14585: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14586: $dom);
14587: if ($putresult eq 'ok') {
14588: if (keys(%changes) > 0) {
1.48 raeburn 14589: if (ref($confhash{'scantron'}) eq 'HASH') {
14590: $resulttext = &mt('Changes made:').'<ul>';
14591: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 14592: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 14593: } else {
1.130 raeburn 14594: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 14595: }
1.48 raeburn 14596: $resulttext .= '</ul>';
14597: } else {
1.130 raeburn 14598: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14599: }
14600: $resulttext .= '</ul>';
14601: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14602: if (ref($lastactref) eq 'HASH') {
14603: $lastactref->{'domainconfig'} = 1;
14604: }
1.46 raeburn 14605: } else {
1.130 raeburn 14606: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14607: }
14608: } else {
14609: $resulttext = '<span class="LC_error">'.
14610: &mt('An error occurred: [_1]',$putresult).'</span>';
14611: }
14612: } else {
1.130 raeburn 14613: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14614: }
14615: if ($errors) {
14616: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14617: $errors.'</ul>';
14618: }
14619: return $resulttext;
14620: }
14621:
1.48 raeburn 14622: sub modify_coursecategories {
1.239 raeburn 14623: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14624: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14625: $cathash);
1.48 raeburn 14626: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 14627: my @catitems = ('unauth','auth');
14628: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14629: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14630: $cathash = $domconfig{'coursecategories'}{'cats'};
14631: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14632: $changes{'togglecats'} = 1;
14633: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14634: }
14635: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14636: $changes{'categorize'} = 1;
14637: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14638: }
1.120 raeburn 14639: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14640: $changes{'togglecatscomm'} = 1;
14641: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14642: }
14643: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14644: $changes{'categorizecomm'} = 1;
14645: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 14646:
14647: }
14648: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
14649: $changes{'togglecatsplace'} = 1;
14650: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
14651: }
14652: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
14653: $changes{'categorizeplace'} = 1;
14654: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 14655: }
1.238 raeburn 14656: foreach my $item (@catitems) {
14657: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14658: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14659: $changes{$item} = 1;
14660: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14661: }
14662: }
14663: }
1.57 raeburn 14664: } else {
14665: $changes{'togglecats'} = 1;
14666: $changes{'categorize'} = 1;
1.124 raeburn 14667: $changes{'togglecatscomm'} = 1;
14668: $changes{'categorizecomm'} = 1;
1.272 raeburn 14669: $changes{'togglecatsplace'} = 1;
14670: $changes{'categorizeplace'} = 1;
1.87 raeburn 14671: $domconfig{'coursecategories'} = {
14672: togglecats => $env{'form.togglecats'},
14673: categorize => $env{'form.categorize'},
1.124 raeburn 14674: togglecatscomm => $env{'form.togglecatscomm'},
14675: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 14676: togglecatsplace => $env{'form.togglecatsplace'},
14677: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 14678: };
1.238 raeburn 14679: foreach my $item (@catitems) {
14680: if ($env{'form.coursecat_'.$item} ne 'std') {
14681: $changes{$item} = 1;
14682: }
14683: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14684: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14685: }
14686: }
1.57 raeburn 14687: }
14688: if (ref($cathash) eq 'HASH') {
14689: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14690: push (@deletecategory,'instcode::0');
14691: }
1.120 raeburn 14692: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14693: push(@deletecategory,'communities::0');
14694: }
1.272 raeburn 14695: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
14696: push(@deletecategory,'placement::0');
14697: }
1.48 raeburn 14698: }
1.57 raeburn 14699: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14700: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14701: if (@deletecategory > 0) {
14702: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14703: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14704: foreach my $item (@deletecategory) {
1.57 raeburn 14705: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14706: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14707: $deletions{$item} = 1;
1.57 raeburn 14708: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14709: }
14710: }
14711: }
1.57 raeburn 14712: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14713: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14714: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14715: $reorderings{$item} = 1;
1.57 raeburn 14716: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14717: }
14718: if ($env{'form.addcategory_name_'.$item} ne '') {
14719: my $newcat = $env{'form.addcategory_name_'.$item};
14720: my $newdepth = $depth+1;
14721: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14722: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14723: $adds{$newitem} = 1;
14724: }
14725: if ($env{'form.subcat_'.$item} ne '') {
14726: my $newcat = $env{'form.subcat_'.$item};
14727: my $newdepth = $depth+1;
14728: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14729: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14730: $adds{$newitem} = 1;
14731: }
14732: }
14733: }
14734: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14735: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14736: my $newitem = 'instcode::0';
1.57 raeburn 14737: if ($cathash->{$newitem} eq '') {
14738: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14739: $adds{$newitem} = 1;
14740: }
14741: } else {
14742: my $newitem = 'instcode::0';
1.57 raeburn 14743: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14744: $adds{$newitem} = 1;
14745: }
14746: }
1.120 raeburn 14747: if ($env{'form.communities'} eq '1') {
14748: if (ref($cathash) eq 'HASH') {
14749: my $newitem = 'communities::0';
14750: if ($cathash->{$newitem} eq '') {
14751: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14752: $adds{$newitem} = 1;
14753: }
14754: } else {
14755: my $newitem = 'communities::0';
14756: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14757: $adds{$newitem} = 1;
14758: }
14759: }
1.272 raeburn 14760: if ($env{'form.placement'} eq '1') {
14761: if (ref($cathash) eq 'HASH') {
14762: my $newitem = 'placement::0';
14763: if ($cathash->{$newitem} eq '') {
14764: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14765: $adds{$newitem} = 1;
14766: }
14767: } else {
14768: my $newitem = 'placement::0';
14769: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14770: $adds{$newitem} = 1;
14771: }
14772: }
1.48 raeburn 14773: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14774: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 14775: ($env{'form.addcategory_name'} ne 'communities') &&
14776: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 14777: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14778: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14779: $adds{$newitem} = 1;
14780: }
1.48 raeburn 14781: }
1.57 raeburn 14782: my $putresult;
1.48 raeburn 14783: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14784: if (keys(%deletions) > 0) {
14785: foreach my $key (keys(%deletions)) {
14786: if ($predelallitems{$key} ne '') {
14787: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14788: }
14789: }
14790: }
14791: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14792: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14793: if (ref($chkcats[0]) eq 'ARRAY') {
14794: my $depth = 0;
14795: my $chg = 0;
14796: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14797: my $name = $chkcats[0][$i];
14798: my $item;
14799: if ($name eq '') {
14800: $chg ++;
14801: } else {
14802: $item = &escape($name).'::0';
14803: if ($chg) {
1.57 raeburn 14804: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14805: }
14806: $depth ++;
1.57 raeburn 14807: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14808: $depth --;
14809: }
14810: }
14811: }
1.57 raeburn 14812: }
14813: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14814: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14815: if ($putresult eq 'ok') {
1.57 raeburn 14816: my %title = (
1.120 raeburn 14817: togglecats => 'Show/Hide a course in catalog',
14818: categorize => 'Assign a category to a course',
14819: togglecatscomm => 'Show/Hide a community in catalog',
14820: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14821: );
14822: my %level = (
1.120 raeburn 14823: dom => 'set in Domain ("Modify Course/Community")',
14824: crs => 'set in Course ("Course Configuration")',
14825: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 14826: none => 'No catalog',
14827: std => 'Standard catalog',
14828: domonly => 'Domain-only catalog',
14829: codesrch => 'Code search form',
1.57 raeburn 14830: );
1.48 raeburn 14831: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14832: if ($changes{'togglecats'}) {
14833: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14834: }
14835: if ($changes{'categorize'}) {
14836: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14837: }
1.120 raeburn 14838: if ($changes{'togglecatscomm'}) {
14839: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14840: }
14841: if ($changes{'categorizecomm'}) {
14842: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14843: }
1.238 raeburn 14844: if ($changes{'unauth'}) {
14845: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14846: }
14847: if ($changes{'auth'}) {
14848: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14849: }
1.57 raeburn 14850: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14851: my $cathash;
14852: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14853: $cathash = $domconfig{'coursecategories'}{'cats'};
14854: } else {
14855: $cathash = {};
14856: }
14857: my (@cats,@trails,%allitems);
14858: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
14859: if (keys(%deletions) > 0) {
14860: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
14861: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
14862: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
14863: }
14864: $resulttext .= '</ul></li>';
14865: }
14866: if (keys(%reorderings) > 0) {
14867: my %sort_by_trail;
14868: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
14869: foreach my $key (keys(%reorderings)) {
14870: if ($allitems{$key} ne '') {
14871: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14872: }
1.48 raeburn 14873: }
1.57 raeburn 14874: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14875: $resulttext .= '<li>'.$trails[$trail].'</li>';
14876: }
14877: $resulttext .= '</ul></li>';
1.48 raeburn 14878: }
1.57 raeburn 14879: if (keys(%adds) > 0) {
14880: my %sort_by_trail;
14881: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
14882: foreach my $key (keys(%adds)) {
14883: if ($allitems{$key} ne '') {
14884: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14885: }
14886: }
14887: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14888: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 14889: }
1.57 raeburn 14890: $resulttext .= '</ul></li>';
1.48 raeburn 14891: }
14892: }
14893: $resulttext .= '</ul>';
1.239 raeburn 14894: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 14895: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14896: if ($changes{'auth'}) {
14897: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
14898: }
14899: if ($changes{'unauth'}) {
14900: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
14901: }
14902: my $cachetime = 24*60*60;
14903: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 14904: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 14905: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 14906: }
14907: }
1.48 raeburn 14908: } else {
14909: $resulttext = '<span class="LC_error">'.
1.57 raeburn 14910: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 14911: }
14912: } else {
1.120 raeburn 14913: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 14914: }
14915: return $resulttext;
14916: }
14917:
1.69 raeburn 14918: sub modify_serverstatuses {
14919: my ($dom,%domconfig) = @_;
14920: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
14921: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
14922: %currserverstatus = %{$domconfig{'serverstatuses'}};
14923: }
14924: my @pages = &serverstatus_pages();
14925: foreach my $type (@pages) {
14926: $newserverstatus{$type}{'namedusers'} = '';
14927: $newserverstatus{$type}{'machines'} = '';
14928: if (defined($env{'form.'.$type.'_namedusers'})) {
14929: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
14930: my @okusers;
14931: foreach my $user (@users) {
14932: my ($uname,$udom) = split(/:/,$user);
14933: if (($udom =~ /^$match_domain$/) &&
14934: (&Apache::lonnet::domain($udom)) &&
14935: ($uname =~ /^$match_username$/)) {
14936: if (!grep(/^\Q$user\E/,@okusers)) {
14937: push(@okusers,$user);
14938: }
14939: }
14940: }
14941: if (@okusers > 0) {
14942: @okusers = sort(@okusers);
14943: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
14944: }
14945: }
14946: if (defined($env{'form.'.$type.'_machines'})) {
14947: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
14948: my @okmachines;
14949: foreach my $ip (@machines) {
14950: my @parts = split(/\./,$ip);
14951: next if (@parts < 4);
14952: my $badip = 0;
14953: for (my $i=0; $i<4; $i++) {
14954: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
14955: $badip = 1;
14956: last;
14957: }
14958: }
14959: if (!$badip) {
14960: push(@okmachines,$ip);
14961: }
14962: }
14963: @okmachines = sort(@okmachines);
14964: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
14965: }
14966: }
14967: my %serverstatushash = (
14968: serverstatuses => \%newserverstatus,
14969: );
14970: foreach my $type (@pages) {
1.83 raeburn 14971: foreach my $setting ('namedusers','machines') {
1.84 raeburn 14972: my (@current,@new);
1.83 raeburn 14973: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 14974: if ($currserverstatus{$type}{$setting} ne '') {
14975: @current = split(/,/,$currserverstatus{$type}{$setting});
14976: }
14977: }
14978: if ($newserverstatus{$type}{$setting} ne '') {
14979: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 14980: }
14981: if (@current > 0) {
14982: if (@new > 0) {
14983: foreach my $item (@current) {
14984: if (!grep(/^\Q$item\E$/,@new)) {
14985: $changes{$type}{$setting} = 1;
1.82 raeburn 14986: last;
14987: }
14988: }
1.84 raeburn 14989: foreach my $item (@new) {
14990: if (!grep(/^\Q$item\E$/,@current)) {
14991: $changes{$type}{$setting} = 1;
14992: last;
1.82 raeburn 14993: }
14994: }
14995: } else {
1.83 raeburn 14996: $changes{$type}{$setting} = 1;
1.69 raeburn 14997: }
1.83 raeburn 14998: } elsif (@new > 0) {
14999: $changes{$type}{$setting} = 1;
1.69 raeburn 15000: }
15001: }
15002: }
15003: if (keys(%changes) > 0) {
1.81 raeburn 15004: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 15005: my $putresult = &Apache::lonnet::put_dom('configuration',
15006: \%serverstatushash,$dom);
15007: if ($putresult eq 'ok') {
15008: $resulttext .= &mt('Changes made:').'<ul>';
15009: foreach my $type (@pages) {
1.84 raeburn 15010: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 15011: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 15012: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 15013: if ($newserverstatus{$type}{'namedusers'} eq '') {
15014: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
15015: } else {
15016: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
15017: }
1.84 raeburn 15018: }
15019: if ($changes{$type}{'machines'}) {
1.69 raeburn 15020: if ($newserverstatus{$type}{'machines'} eq '') {
15021: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
15022: } else {
15023: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
15024: }
15025:
15026: }
15027: $resulttext .= '</ul></li>';
15028: }
15029: }
15030: $resulttext .= '</ul>';
15031: } else {
15032: $resulttext = '<span class="LC_error">'.
15033: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
15034:
15035: }
15036: } else {
15037: $resulttext = &mt('No changes made to access to server status pages');
15038: }
15039: return $resulttext;
15040: }
15041:
1.118 jms 15042: sub modify_helpsettings {
1.285 raeburn 15043: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 15044: my ($resulttext,$errors,%changes,%helphash);
15045: my %defaultchecked = ('submitbugs' => 'on');
15046: my @offon = ('off','on');
1.118 jms 15047: my @toggles = ('submitbugs');
1.285 raeburn 15048: my %current = ('submitbugs' => '',
15049: 'adhoc' => {},
15050: );
1.118 jms 15051: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 15052: %current = %{$domconfig{'helpsettings'}};
15053: }
1.285 raeburn 15054: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 15055: foreach my $item (@toggles) {
15056: if ($defaultchecked{$item} eq 'on') {
15057: if ($current{$item} eq '') {
15058: if ($env{'form.'.$item} eq '0') {
15059: $changes{$item} = 1;
15060: }
15061: } elsif ($current{$item} ne $env{'form.'.$item}) {
15062: $changes{$item} = 1;
15063: }
15064: } elsif ($defaultchecked{$item} eq 'off') {
15065: if ($current{$item} eq '') {
15066: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 15067: $changes{$item} = 1;
15068: }
1.282 raeburn 15069: } elsif ($current{$item} ne $env{'form.'.$item}) {
15070: $changes{$item} = 1;
15071: }
15072: }
15073: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
15074: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
15075: }
15076: }
1.285 raeburn 15077: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 15078: my $confname = $dom.'-domainconfig';
15079: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 15080: my (@allpos,%newsettings,%changedprivs,$newrole);
15081: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 15082: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 15083: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 15084: my %lt = &Apache::lonlocal::texthash(
15085: s => 'system',
15086: d => 'domain',
15087: order => 'Display order',
15088: access => 'Role usage',
1.291 raeburn 15089: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 15090: dh => 'All with domain helpdesk role',
15091: da => 'All with domain helpdesk assistant role',
1.285 raeburn 15092: none => 'None',
15093: status => 'Determined based on institutional status',
15094: inc => 'Include all, but exclude specific personnel',
15095: exc => 'Exclude all, but include specific personnel',
15096: );
15097: for (my $num=0; $num<=$maxnum; $num++) {
15098: my ($prefix,$identifier,$rolename,%curr);
15099: if ($num == $maxnum) {
15100: next unless ($env{'form.newcusthelp'} == $maxnum);
15101: $identifier = 'custhelp'.$num;
15102: $prefix = 'helproles_'.$num;
15103: $rolename = $env{'form.custhelpname'.$num};
15104: $rolename=~s/[^A-Za-z0-9]//gs;
15105: next if ($rolename eq '');
15106: next if (exists($existing{'rolesdef_'.$rolename}));
15107: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15108: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15109: $newprivs{'c'},$confname,$dom);
15110: if ($result ne 'ok') {
15111: $errors .= '<li><span class="LC_error">'.
15112: &mt('An error occurred storing the new custom role: [_1]',
15113: $result).'</span></li>';
15114: next;
15115: } else {
15116: $changedprivs{$rolename} = \%newprivs;
15117: $newrole = $rolename;
15118: }
15119: } else {
15120: $prefix = 'helproles_'.$num;
15121: $rolename = $env{'form.'.$prefix};
15122: next if ($rolename eq '');
15123: next unless (exists($existing{'rolesdef_'.$rolename}));
15124: $identifier = 'custhelp'.$num;
15125: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15126: my %currprivs;
1.289 raeburn 15127: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 15128: split(/\_/,$existing{'rolesdef_'.$rolename});
15129: foreach my $level ('c','d','s') {
15130: if ($newprivs{$level} ne $currprivs{$level}) {
15131: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15132: $newprivs{'c'},$confname,$dom);
15133: if ($result ne 'ok') {
15134: $errors .= '<li><span class="LC_error">'.
15135: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15136: $rolename,$result).'</span></li>';
15137: } else {
15138: $changedprivs{$rolename} = \%newprivs;
15139: }
15140: last;
15141: }
15142: }
15143: if (ref($current{'adhoc'}) eq 'HASH') {
15144: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15145: %curr = %{$current{'adhoc'}{$rolename}};
15146: }
15147: }
15148: }
15149: my $newpos = $env{'form.'.$prefix.'_pos'};
15150: $newpos =~ s/\D+//g;
15151: $allpos[$newpos] = $rolename;
15152: my $newdesc = $env{'form.'.$prefix.'_desc'};
15153: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15154: if ($curr{'desc'}) {
15155: if ($curr{'desc'} ne $newdesc) {
15156: $changes{'customrole'}{$rolename}{'desc'} = 1;
15157: $newsettings{$rolename}{'desc'} = $newdesc;
15158: }
15159: } elsif ($newdesc ne '') {
15160: $changes{'customrole'}{$rolename}{'desc'} = 1;
15161: $newsettings{$rolename}{'desc'} = $newdesc;
15162: }
15163: my $access = $env{'form.'.$prefix.'_access'};
15164: if (grep(/^\Q$access\E$/,@accesstypes)) {
15165: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15166: if ($access eq 'status') {
15167: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15168: if (scalar(@statuses) == 0) {
1.289 raeburn 15169: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 15170: } else {
15171: my (@shownstatus,$numtypes);
15172: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15173: if (ref($types) eq 'ARRAY') {
15174: $numtypes = scalar(@{$types});
15175: foreach my $type (sort(@statuses)) {
15176: if ($type eq 'default') {
15177: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15178: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15179: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15180: push(@shownstatus,$usertypes->{$type});
15181: }
15182: }
15183: }
15184: if (grep(/^default$/,@statuses)) {
15185: push(@shownstatus,$othertitle);
15186: }
15187: if (scalar(@shownstatus) == 1+$numtypes) {
15188: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15189: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15190: } else {
15191: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15192: if (ref($curr{'status'}) eq 'ARRAY') {
15193: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15194: if (@diffs) {
15195: $changes{'customrole'}{$rolename}{$access} = 1;
15196: }
15197: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15198: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 15199: }
1.166 raeburn 15200: }
15201: }
1.285 raeburn 15202: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15203: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15204: my @newspecstaff;
15205: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15206: foreach my $person (sort(@personnel)) {
15207: if ($domhelpdesk{$person}) {
15208: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15209: }
15210: }
15211: if (ref($curr{$access}) eq 'ARRAY') {
15212: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15213: if (@diffs) {
15214: $changes{'customrole'}{$rolename}{$access} = 1;
15215: }
15216: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15217: $changes{'customrole'}{$rolename}{$access} = 1;
15218: }
15219: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15220: my ($uname,$udom) = split(/:/,$person);
15221: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15222: }
15223: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 15224: }
1.285 raeburn 15225: } else {
15226: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15227: }
15228: unless ($curr{'access'} eq $access) {
15229: $changes{'customrole'}{$rolename}{'access'} = 1;
15230: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 15231: }
15232: }
1.285 raeburn 15233: if (@allpos > 0) {
15234: my $idx = 0;
15235: foreach my $rolename (@allpos) {
15236: if ($rolename ne '') {
15237: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15238: if (ref($current{'adhoc'}) eq 'HASH') {
15239: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15240: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15241: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 15242: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 15243: }
15244: }
1.282 raeburn 15245: }
1.285 raeburn 15246: $idx ++;
1.166 raeburn 15247: }
15248: }
1.118 jms 15249: }
1.123 jms 15250: my $putresult;
15251: if (keys(%changes) > 0) {
1.166 raeburn 15252: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 15253: if ($putresult eq 'ok') {
1.285 raeburn 15254: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15255: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15256: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15257: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15258: }
15259: }
15260: my $cachetime = 24*60*60;
15261: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15262: if (ref($lastactref) eq 'HASH') {
15263: $lastactref->{'domdefaults'} = 1;
15264: }
15265: } else {
15266: $errors .= '<li><span class="LC_error">'.
15267: &mt('An error occurred storing the settings: [_1]',
15268: $putresult).'</span></li>';
15269: }
15270: }
15271: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15272: $resulttext = &mt('Changes made:').'<ul>';
15273: my (%shownprivs,@levelorder);
15274: @levelorder = ('c','d','s');
15275: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 15276: foreach my $item (sort(keys(%changes))) {
15277: if ($item eq 'submitbugs') {
15278: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15279: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15280: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 15281: } elsif ($item eq 'customrole') {
15282: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 15283: my @keyorder = ('order','desc','access','status','exc','inc');
15284: my %keytext = &Apache::lonlocal::texthash(
15285: order => 'Order',
15286: desc => 'Role description',
15287: access => 'Role usage',
1.300 droeschl 15288: status => 'Allowed institutional types',
1.285 raeburn 15289: exc => 'Allowed personnel',
15290: inc => 'Disallowed personnel',
15291: );
1.282 raeburn 15292: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 15293: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15294: if ($role eq $newrole) {
15295: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15296: $role).'<ul>';
15297: } else {
15298: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15299: $role).'<ul>';
15300: }
15301: foreach my $key (@keyorder) {
15302: if ($changes{'customrole'}{$role}{$key}) {
15303: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15304: $keytext{$key},$newsettings{$role}{$key}).
15305: '</li>';
15306: }
15307: }
15308: if (ref($changedprivs{$role}) eq 'HASH') {
15309: $shownprivs{$role} = 1;
15310: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15311: foreach my $level (@levelorder) {
15312: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15313: next if ($item eq '');
15314: my ($priv) = split(/\&/,$item,2);
15315: if (&Apache::lonnet::plaintext($priv)) {
15316: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15317: unless ($level eq 'c') {
15318: $resulttext .= ' ('.$lt{$level}.')';
15319: }
15320: $resulttext .= '</li>';
15321: }
15322: }
15323: }
15324: $resulttext .= '</ul>';
15325: }
15326: $resulttext .= '</ul></li>';
15327: }
15328: }
15329: }
15330: }
15331: }
15332: }
15333: if (keys(%changedprivs)) {
15334: foreach my $role (sort(keys(%changedprivs))) {
15335: unless ($shownprivs{$role}) {
15336: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15337: $role).'<ul>'.
15338: '<li>'.&mt('Privileges set to :').'<ul>';
15339: foreach my $level (@levelorder) {
15340: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15341: next if ($item eq '');
15342: my ($priv) = split(/\&/,$item,2);
15343: if (&Apache::lonnet::plaintext($priv)) {
15344: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15345: unless ($level eq 'c') {
15346: $resulttext .= ' ('.$lt{$level}.')';
15347: }
15348: $resulttext .= '</li>';
15349: }
1.282 raeburn 15350: }
15351: }
1.285 raeburn 15352: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 15353: }
15354: }
15355: }
1.285 raeburn 15356: $resulttext .= '</ul>';
15357: } else {
15358: $resulttext = &mt('No changes made to help settings');
1.118 jms 15359: }
15360: if ($errors) {
1.168 raeburn 15361: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 15362: $errors.'</ul>';
1.118 jms 15363: }
15364: return $resulttext;
15365: }
15366:
1.121 raeburn 15367: sub modify_coursedefaults {
1.212 raeburn 15368: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15369: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 15370: my %defaultchecked = (
15371: 'canuse_pdfforms' => 'off',
15372: 'uselcmath' => 'on',
15373: 'usejsme' => 'on'
15374: );
15375: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 15376: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 15377: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
15378: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
15379: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 15380: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 15381: my %staticdefaults = (
15382: anonsurvey_threshold => 10,
15383: uploadquota => 500,
1.257 raeburn 15384: postsubmit => 60,
1.276 raeburn 15385: mysqltables => 172800,
1.198 raeburn 15386: );
1.314 raeburn 15387: my %texoptions = (
15388: MathJax => 'MathJax',
15389: mimetex => &mt('Convert to Images'),
15390: tth => &mt('TeX to HTML'),
15391: );
1.121 raeburn 15392: $defaultshash{'coursedefaults'} = {};
15393:
15394: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15395: if ($domconfig{'coursedefaults'} eq '') {
15396: $domconfig{'coursedefaults'} = {};
15397: }
15398: }
15399:
15400: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15401: foreach my $item (@toggles) {
15402: if ($defaultchecked{$item} eq 'on') {
15403: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15404: ($env{'form.'.$item} eq '0')) {
15405: $changes{$item} = 1;
1.192 raeburn 15406: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15407: $changes{$item} = 1;
15408: }
15409: } elsif ($defaultchecked{$item} eq 'off') {
15410: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15411: ($env{'form.'.$item} eq '1')) {
15412: $changes{$item} = 1;
15413: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15414: $changes{$item} = 1;
15415: }
15416: }
15417: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15418: }
1.198 raeburn 15419: foreach my $item (@numbers) {
15420: my ($currdef,$newdef);
1.208 raeburn 15421: $newdef = $env{'form.'.$item};
1.198 raeburn 15422: if ($item eq 'anonsurvey_threshold') {
15423: $currdef = $domconfig{'coursedefaults'}{$item};
15424: $newdef =~ s/\D//g;
15425: if ($newdef eq '' || $newdef < 1) {
15426: $newdef = 1;
15427: }
15428: $defaultshash{'coursedefaults'}{$item} = $newdef;
15429: } else {
1.276 raeburn 15430: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15431: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15432: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 15433: }
15434: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 15435: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 15436: }
15437: if ($currdef ne $newdef) {
15438: my $staticdef;
15439: if ($item eq 'anonsurvey_threshold') {
15440: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15441: $changes{$item} = 1;
15442: }
1.276 raeburn 15443: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 15444: my $setting = $1;
1.276 raeburn 15445: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15446: $changes{$setting} = 1;
1.198 raeburn 15447: }
15448: }
1.139 raeburn 15449: }
15450: }
1.314 raeburn 15451: my $texengine;
15452: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15453: $texengine = $env{'form.texengine'};
15454: if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {
15455: unless ($texengine eq 'MathJax') {
15456: $changes{'texengine'} = 1;
15457: }
15458: } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {
15459: $changes{'texengine'} = 1;
15460: }
15461: }
15462: if ($texengine ne '') {
15463: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15464: }
1.264 raeburn 15465: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15466: my @currclonecode;
15467: if (ref($currclone) eq 'HASH') {
15468: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15469: @currclonecode = @{$currclone->{'instcode'}};
15470: }
15471: }
15472: my $newclone;
1.289 raeburn 15473: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 15474: $newclone = $env{'form.canclone'};
15475: }
15476: if ($newclone eq 'instcode') {
15477: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15478: my (%codedefaults,@code_order,@clonecode);
15479: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15480: \@code_order);
15481: foreach my $item (@code_order) {
15482: if (grep(/^\Q$item\E$/,@newcodes)) {
15483: push(@clonecode,$item);
15484: }
15485: }
15486: if (@clonecode) {
15487: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15488: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15489: if (@diffs) {
15490: $changes{'canclone'} = 1;
15491: }
15492: } else {
15493: $newclone eq '';
15494: }
15495: } elsif ($newclone ne '') {
1.289 raeburn 15496: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15497: }
1.264 raeburn 15498: if ($newclone ne $currclone) {
15499: $changes{'canclone'} = 1;
15500: }
1.257 raeburn 15501: my %credits;
15502: foreach my $type (@types) {
15503: unless ($type eq 'community') {
15504: $credits{$type} = $env{'form.'.$type.'_credits'};
15505: $credits{$type} =~ s/[^\d.]+//g;
15506: }
15507: }
15508: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15509: ($env{'form.coursecredits'} eq '1')) {
15510: $changes{'coursecredits'} = 1;
15511: foreach my $type (keys(%credits)) {
15512: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15513: }
15514: } else {
1.289 raeburn 15515: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 15516: foreach my $type (@types) {
15517: unless ($type eq 'community') {
1.289 raeburn 15518: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 15519: $changes{'coursecredits'} = 1;
15520: }
15521: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15522: }
15523: }
15524: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15525: foreach my $type (@types) {
15526: unless ($type eq 'community') {
15527: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15528: $changes{'coursecredits'} = 1;
15529: last;
15530: }
15531: }
15532: }
15533: }
15534: }
15535: if ($env{'form.postsubmit'} eq '1') {
15536: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15537: my %currtimeout;
15538: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15539: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15540: $changes{'postsubmit'} = 1;
15541: }
15542: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15543: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15544: }
15545: } else {
15546: $changes{'postsubmit'} = 1;
15547: }
15548: foreach my $type (@types) {
15549: my $timeout = $env{'form.'.$type.'_timeout'};
15550: $timeout =~ s/\D//g;
15551: if ($timeout == $staticdefaults{'postsubmit'}) {
15552: $timeout = '';
15553: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15554: $timeout = '0';
15555: }
15556: unless ($timeout eq '') {
15557: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15558: }
15559: if (exists($currtimeout{$type})) {
15560: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 15561: $changes{'postsubmit'} = 1;
1.257 raeburn 15562: }
15563: } elsif ($timeout ne '') {
15564: $changes{'postsubmit'} = 1;
15565: }
15566: }
15567: } else {
15568: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15569: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15570: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15571: $changes{'postsubmit'} = 1;
15572: }
15573: } else {
15574: $changes{'postsubmit'} = 1;
15575: }
1.192 raeburn 15576: }
1.121 raeburn 15577: }
15578: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15579: $dom);
15580: if ($putresult eq 'ok') {
15581: if (keys(%changes) > 0) {
1.213 raeburn 15582: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 15583: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 15584: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 15585: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15586: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 15587: if ($changes{$item}) {
15588: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15589: }
1.289 raeburn 15590: }
1.192 raeburn 15591: if ($changes{'coursecredits'}) {
15592: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 15593: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15594: $domdefaults{$type.'credits'} =
15595: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15596: }
15597: }
15598: }
15599: if ($changes{'postsubmit'}) {
15600: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15601: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15602: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15603: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15604: $domdefaults{$type.'postsubtimeout'} =
15605: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15606: }
15607: }
1.192 raeburn 15608: }
15609: }
1.198 raeburn 15610: if ($changes{'uploadquota'}) {
15611: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15612: foreach my $type (@types) {
15613: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15614: }
15615: }
15616: }
1.264 raeburn 15617: if ($changes{'canclone'}) {
15618: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15619: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15620: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15621: if (@clonecodes) {
15622: $domdefaults{'canclone'} = join('+',@clonecodes);
15623: }
15624: }
15625: } else {
15626: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15627: }
15628: }
1.121 raeburn 15629: my $cachetime = 24*60*60;
15630: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 15631: if (ref($lastactref) eq 'HASH') {
15632: $lastactref->{'domdefaults'} = 1;
15633: }
1.121 raeburn 15634: }
15635: $resulttext = &mt('Changes made:').'<ul>';
15636: foreach my $item (sort(keys(%changes))) {
15637: if ($item eq 'canuse_pdfforms') {
15638: if ($env{'form.'.$item} eq '1') {
15639: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
15640: } else {
15641: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
15642: }
1.257 raeburn 15643: } elsif ($item eq 'uselcmath') {
15644: if ($env{'form.'.$item} eq '1') {
15645: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
15646: } else {
15647: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15648: }
15649: } elsif ($item eq 'usejsme') {
15650: if ($env{'form.'.$item} eq '1') {
15651: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15652: } else {
1.289 raeburn 15653: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 15654: }
1.314 raeburn 15655: } elsif ($item eq 'texengine') {
15656: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15657: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15658: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15659: }
1.139 raeburn 15660: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 15661: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 15662: } elsif ($item eq 'uploadquota') {
15663: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15664: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15665: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15666: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 15667: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 15668: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 15669: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15670: '</ul>'.
15671: '</li>';
15672: } else {
15673: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15674: }
1.276 raeburn 15675: } elsif ($item eq 'mysqltables') {
15676: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15677: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15678: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15679: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15680: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15681: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
15682: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15683: '</ul>'.
15684: '</li>';
15685: } else {
15686: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15687: }
1.257 raeburn 15688: } elsif ($item eq 'postsubmit') {
15689: if ($domdefaults{'postsubmit'} eq 'off') {
15690: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15691: } else {
15692: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 15693: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 15694: $resulttext .= &mt('durations:').'<ul>';
15695: foreach my $type (@types) {
15696: $resulttext .= '<li>';
15697: my $timeout;
15698: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15699: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15700: }
15701: my $display;
15702: if ($timeout eq '0') {
15703: $display = &mt('unlimited');
15704: } elsif ($timeout eq '') {
15705: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15706: } else {
15707: $display = &mt('[quant,_1,second]',$timeout);
15708: }
15709: if ($type eq 'community') {
15710: $resulttext .= &mt('Communities');
15711: } elsif ($type eq 'official') {
15712: $resulttext .= &mt('Official courses');
15713: } elsif ($type eq 'unofficial') {
15714: $resulttext .= &mt('Unofficial courses');
15715: } elsif ($type eq 'textbook') {
15716: $resulttext .= &mt('Textbook courses');
1.271 raeburn 15717: } elsif ($type eq 'placement') {
15718: $resulttext .= &mt('Placement tests');
1.257 raeburn 15719: }
15720: $resulttext .= ' -- '.$display.'</li>';
15721: }
15722: $resulttext .= '</ul>';
15723: }
1.289 raeburn 15724: $resulttext .= '</li>';
1.257 raeburn 15725: }
1.192 raeburn 15726: } elsif ($item eq 'coursecredits') {
15727: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15728: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 15729: ($domdefaults{'unofficialcredits'} eq '') &&
15730: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 15731: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15732: } else {
15733: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15734: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15735: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 15736: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 15737: '</ul>'.
15738: '</li>';
15739: }
15740: } else {
15741: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15742: }
1.264 raeburn 15743: } elsif ($item eq 'canclone') {
15744: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15745: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15746: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15747: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15748: }
15749: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15750: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15751: } else {
1.289 raeburn 15752: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 15753: }
1.140 raeburn 15754: }
1.121 raeburn 15755: }
15756: $resulttext .= '</ul>';
15757: } else {
15758: $resulttext = &mt('No changes made to course defaults');
15759: }
15760: } else {
15761: $resulttext = '<span class="LC_error">'.
15762: &mt('An error occurred: [_1]',$putresult).'</span>';
15763: }
15764: return $resulttext;
15765: }
15766:
1.231 raeburn 15767: sub modify_selfenrollment {
15768: my ($dom,$lastactref,%domconfig) = @_;
15769: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 15770: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 15771: my %titles = &tool_titles();
1.232 raeburn 15772: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15773: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 15774: $ordered{'default'} = ['types','registered','approval','limit'];
15775:
15776: my (%roles,%shown,%toplevel);
15777: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15778:
15779: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15780: if ($domconfig{'selfenrollment'} eq '') {
15781: $domconfig{'selfenrollment'} = {};
15782: }
15783: }
15784: %toplevel = (
15785: admin => 'Configuration Rights',
15786: default => 'Default settings',
15787: validation => 'Validation of self-enrollment requests',
15788: );
1.233 raeburn 15789: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 15790:
15791: if (ref($ordered{'admin'}) eq 'ARRAY') {
15792: foreach my $item (@{$ordered{'admin'}}) {
15793: foreach my $type (@types) {
15794: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15795: $selfenrollhash{'admin'}{$type}{$item} = 1;
15796: } else {
15797: $selfenrollhash{'admin'}{$type}{$item} = 0;
15798: }
15799: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15800: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15801: if ($selfenrollhash{'admin'}{$type}{$item} ne
15802: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15803: push(@{$changes{'admin'}{$type}},$item);
15804: }
15805: } else {
15806: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15807: push(@{$changes{'admin'}{$type}},$item);
15808: }
15809: }
15810: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15811: push(@{$changes{'admin'}{$type}},$item);
15812: }
15813: }
15814: }
15815: }
15816:
15817: foreach my $item (@{$ordered{'default'}}) {
15818: foreach my $type (@types) {
15819: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15820: if ($item eq 'types') {
15821: unless (($value eq 'all') || ($value eq 'dom')) {
15822: $value = '';
15823: }
15824: } elsif ($item eq 'registered') {
15825: unless ($value eq '1') {
15826: $value = 0;
15827: }
15828: } elsif ($item eq 'approval') {
15829: unless ($value =~ /^[012]$/) {
15830: $value = 0;
15831: }
15832: } else {
15833: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15834: $value = 'none';
15835: }
15836: }
15837: $selfenrollhash{'default'}{$type}{$item} = $value;
15838: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15839: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15840: if ($selfenrollhash{'default'}{$type}{$item} ne
15841: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15842: push(@{$changes{'default'}{$type}},$item);
15843: }
15844: } else {
15845: push(@{$changes{'default'}{$type}},$item);
15846: }
15847: } else {
15848: push(@{$changes{'default'}{$type}},$item);
15849: }
15850: if ($item eq 'limit') {
15851: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15852: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15853: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15854: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15855: }
15856: } else {
15857: $selfenrollhash{'default'}{$type}{'cap'} = '';
15858: }
15859: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15860: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15861: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15862: push(@{$changes{'default'}{$type}},'cap');
15863: }
15864: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
15865: push(@{$changes{'default'}{$type}},'cap');
15866: }
15867: }
15868: }
15869: }
15870:
15871: foreach my $item (@{$itemsref}) {
15872: if ($item eq 'fields') {
15873: my @changed;
15874: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
15875: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
15876: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
15877: }
15878: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15879: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
15880: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
15881: $domconfig{'selfenrollment'}{'validation'}{$item});
15882: } else {
15883: @changed = @{$selfenrollhash{'validation'}{$item}};
15884: }
15885: } else {
15886: @changed = @{$selfenrollhash{'validation'}{$item}};
15887: }
15888: if (@changed) {
15889: if ($selfenrollhash{'validation'}{$item}) {
15890: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
15891: } else {
15892: $changes{'validation'}{$item} = &mt('None');
15893: }
15894: }
15895: } else {
15896: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
15897: if ($item eq 'markup') {
15898: if ($env{'form.selfenroll_validation_'.$item}) {
15899: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
15900: }
15901: }
15902: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15903: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
15904: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
15905: }
15906: }
15907: }
15908: }
15909:
15910: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
15911: $dom);
15912: if ($putresult eq 'ok') {
15913: if (keys(%changes) > 0) {
15914: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15915: $resulttext = &mt('Changes made:').'<ul>';
15916: foreach my $key ('admin','default','validation') {
15917: if (ref($changes{$key}) eq 'HASH') {
15918: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
15919: if ($key eq 'validation') {
15920: foreach my $item (@{$itemsref}) {
15921: if (exists($changes{$key}{$item})) {
15922: if ($item eq 'markup') {
15923: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15924: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
15925: } else {
15926: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15927: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
15928: }
15929: }
15930: }
15931: } else {
15932: foreach my $type (@types) {
15933: if ($type eq 'community') {
15934: $roles{'1'} = &mt('Community personnel');
15935: } else {
15936: $roles{'1'} = &mt('Course personnel');
15937: }
15938: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 15939: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15940: if ($key eq 'admin') {
15941: my @mgrdc = ();
15942: if (ref($ordered{$key}) eq 'ARRAY') {
15943: foreach my $item (@{$ordered{'admin'}}) {
15944: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15945: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
15946: push(@mgrdc,$item);
15947: }
15948: }
15949: }
15950: if (@mgrdc) {
15951: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
15952: } else {
15953: delete($domdefaults{$type.'selfenrolladmdc'});
15954: }
15955: }
15956: } else {
15957: if (ref($ordered{$key}) eq 'ARRAY') {
15958: foreach my $item (@{$ordered{$key}}) {
15959: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15960: $domdefaults{$type.'selfenroll'.$item} =
15961: $selfenrollhash{$key}{$type}{$item};
15962: }
15963: }
15964: }
15965: }
15966: }
1.231 raeburn 15967: $resulttext .= '<li>'.$titles{$type}.'<ul>';
15968: foreach my $item (@{$ordered{$key}}) {
15969: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15970: $resulttext .= '<li>';
15971: if ($key eq 'admin') {
15972: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
15973: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
15974: } else {
15975: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
15976: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
15977: }
15978: $resulttext .= '</li>';
15979: }
15980: }
15981: $resulttext .= '</ul></li>';
15982: }
15983: }
15984: $resulttext .= '</ul></li>';
15985: }
15986: }
1.305 raeburn 15987: }
15988: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
15989: my $cachetime = 24*60*60;
15990: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15991: if (ref($lastactref) eq 'HASH') {
15992: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 15993: }
1.231 raeburn 15994: }
15995: $resulttext .= '</ul>';
15996: } else {
15997: $resulttext = &mt('No changes made to self-enrollment settings');
15998: }
15999: } else {
16000: $resulttext = '<span class="LC_error">'.
16001: &mt('An error occurred: [_1]',$putresult).'</span>';
16002: }
16003: return $resulttext;
16004: }
16005:
1.137 raeburn 16006: sub modify_usersessions {
1.212 raeburn 16007: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 16008: my @hostingtypes = ('version','excludedomain','includedomain');
16009: my @offloadtypes = ('primary','default');
16010: my %types = (
16011: remote => \@hostingtypes,
16012: hosted => \@hostingtypes,
16013: spares => \@offloadtypes,
16014: );
16015: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 16016: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 16017: my (%by_ip,%by_location,@intdoms,@instdoms);
16018: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 16019: my @locations = sort(keys(%by_location));
1.137 raeburn 16020: my (%defaultshash,%changes);
16021: foreach my $prefix (@prefixes) {
16022: $defaultshash{'usersessions'}{$prefix} = {};
16023: }
1.212 raeburn 16024: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 16025: my $resulttext;
1.138 raeburn 16026: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 16027: foreach my $prefix (@prefixes) {
1.145 raeburn 16028: next if ($prefix eq 'spares');
16029: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 16030: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16031: if ($type eq 'version') {
16032: my $value = $env{'form.'.$prefix.'_'.$type};
16033: my $okvalue;
16034: if ($value ne '') {
16035: if (grep(/^\Q$value\E$/,@lcversions)) {
16036: $okvalue = $value;
16037: }
16038: }
16039: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16040: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16041: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
16042: if ($inuse == 0) {
16043: $changes{$prefix}{$type} = 1;
16044: } else {
16045: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
16046: $changes{$prefix}{$type} = 1;
16047: }
16048: if ($okvalue ne '') {
16049: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16050: }
16051: }
16052: } else {
16053: if (($inuse == 1) && ($okvalue ne '')) {
16054: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16055: $changes{$prefix}{$type} = 1;
16056: }
16057: }
16058: } else {
16059: if (($inuse == 1) && ($okvalue ne '')) {
16060: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16061: $changes{$prefix}{$type} = 1;
16062: }
16063: }
16064: } else {
16065: if (($inuse == 1) && ($okvalue ne '')) {
16066: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16067: $changes{$prefix}{$type} = 1;
16068: }
16069: }
16070: } else {
16071: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16072: my @okvals;
16073: foreach my $val (@vals) {
1.138 raeburn 16074: if ($val =~ /:/) {
16075: my @items = split(/:/,$val);
16076: foreach my $item (@items) {
16077: if (ref($by_location{$item}) eq 'ARRAY') {
16078: push(@okvals,$item);
16079: }
16080: }
16081: } else {
16082: if (ref($by_location{$val}) eq 'ARRAY') {
16083: push(@okvals,$val);
16084: }
1.137 raeburn 16085: }
16086: }
16087: @okvals = sort(@okvals);
16088: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16089: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16090: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16091: if ($inuse == 0) {
16092: $changes{$prefix}{$type} = 1;
16093: } else {
16094: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16095: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
16096: if (@changed > 0) {
16097: $changes{$prefix}{$type} = 1;
16098: }
16099: }
16100: } else {
16101: if ($inuse == 1) {
16102: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16103: $changes{$prefix}{$type} = 1;
16104: }
16105: }
16106: } else {
16107: if ($inuse == 1) {
16108: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16109: $changes{$prefix}{$type} = 1;
16110: }
16111: }
16112: } else {
16113: if ($inuse == 1) {
16114: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16115: $changes{$prefix}{$type} = 1;
16116: }
16117: }
16118: }
16119: }
16120: }
1.145 raeburn 16121:
16122: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16123: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16124: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16125: my $savespares;
16126:
16127: foreach my $lonhost (sort(keys(%servers))) {
16128: my $serverhomeID =
16129: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16130: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16131: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16132: my %spareschg;
16133: foreach my $type (@{$types{'spares'}}) {
16134: my @okspares;
16135: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16136: foreach my $server (@checked) {
1.152 raeburn 16137: if (&Apache::lonnet::hostname($server) ne '') {
16138: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16139: unless (grep(/^\Q$server\E$/,@okspares)) {
16140: push(@okspares,$server);
16141: }
1.145 raeburn 16142: }
16143: }
16144: }
16145: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16146: my $newspare;
1.152 raeburn 16147: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16148: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16149: $newspare = $new;
16150: }
16151: }
1.152 raeburn 16152: my @spares;
16153: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16154: @spares = sort(@okspares,$newspare);
16155: } else {
16156: @spares = sort(@okspares);
16157: }
16158: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16159: if (ref($spareid{$lonhost}) eq 'HASH') {
16160: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16161: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16162: if (@diffs > 0) {
16163: $spareschg{$type} = 1;
16164: }
16165: }
16166: }
16167: }
16168: if (keys(%spareschg) > 0) {
16169: $changes{'spares'}{$lonhost} = \%spareschg;
16170: }
16171: }
1.261 raeburn 16172: $defaultshash{'usersessions'}{'offloadnow'} = {};
16173: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16174: my @okoffload;
16175: if (@offloadnow) {
16176: foreach my $server (@offloadnow) {
16177: if (&Apache::lonnet::hostname($server) ne '') {
16178: unless (grep(/^\Q$server\E$/,@okoffload)) {
16179: push(@okoffload,$server);
16180: }
16181: }
16182: }
16183: if (@okoffload) {
16184: foreach my $lonhost (@okoffload) {
16185: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16186: }
16187: }
16188: }
1.145 raeburn 16189: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16190: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16191: if (ref($changes{'spares'}) eq 'HASH') {
16192: if (keys(%{$changes{'spares'}}) > 0) {
16193: $savespares = 1;
16194: }
16195: }
16196: } else {
16197: $savespares = 1;
16198: }
1.261 raeburn 16199: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
16200: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
16201: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
16202: $changes{'offloadnow'} = 1;
16203: last;
16204: }
16205: }
16206: unless ($changes{'offloadnow'}) {
1.289 raeburn 16207: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 16208: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
16209: $changes{'offloadnow'} = 1;
16210: last;
16211: }
16212: }
16213: }
16214: } elsif (@okoffload) {
16215: $changes{'offloadnow'} = 1;
16216: }
16217: } elsif (@okoffload) {
16218: $changes{'offloadnow'} = 1;
1.145 raeburn 16219: }
1.147 raeburn 16220: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16221: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16222: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16223: $dom);
16224: if ($putresult eq 'ok') {
16225: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16226: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16227: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16228: }
16229: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16230: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16231: }
1.261 raeburn 16232: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16233: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16234: }
1.137 raeburn 16235: }
16236: my $cachetime = 24*60*60;
16237: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 16238: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 16239: if (ref($lastactref) eq 'HASH') {
16240: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 16241: $lastactref->{'usersessions'} = 1;
1.212 raeburn 16242: }
1.147 raeburn 16243: if (keys(%changes) > 0) {
16244: my %lt = &usersession_titles();
16245: $resulttext = &mt('Changes made:').'<ul>';
16246: foreach my $prefix (@prefixes) {
16247: if (ref($changes{$prefix}) eq 'HASH') {
16248: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16249: if ($prefix eq 'spares') {
16250: if (ref($changes{$prefix}) eq 'HASH') {
16251: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16252: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16253: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 16254: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16255: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16256: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16257: foreach my $type (@{$types{$prefix}}) {
16258: if ($changes{$prefix}{$lonhost}{$type}) {
16259: my $offloadto = &mt('None');
16260: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16261: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16262: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16263: }
1.145 raeburn 16264: }
1.147 raeburn 16265: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16266: }
1.137 raeburn 16267: }
16268: }
1.147 raeburn 16269: $resulttext .= '</li>';
1.137 raeburn 16270: }
16271: }
1.147 raeburn 16272: } else {
16273: foreach my $type (@{$types{$prefix}}) {
16274: if (defined($changes{$prefix}{$type})) {
16275: my $newvalue;
16276: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16277: if (ref($defaultshash{'usersessions'}{$prefix})) {
16278: if ($type eq 'version') {
16279: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
16280: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16281: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16282: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16283: }
1.145 raeburn 16284: }
16285: }
16286: }
1.147 raeburn 16287: if ($newvalue eq '') {
16288: if ($type eq 'version') {
16289: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
16290: } else {
16291: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16292: }
1.145 raeburn 16293: } else {
1.147 raeburn 16294: if ($type eq 'version') {
16295: $newvalue .= ' '.&mt('(or later)');
16296: }
16297: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 16298: }
1.137 raeburn 16299: }
16300: }
16301: }
1.147 raeburn 16302: $resulttext .= '</ul>';
1.137 raeburn 16303: }
16304: }
1.261 raeburn 16305: if ($changes{'offloadnow'}) {
16306: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16307: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
16308: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
16309: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
16310: $resulttext .= '<li>'.$lonhost.'</li>';
16311: }
16312: $resulttext .= '</ul>';
16313: } else {
16314: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
16315: }
16316: } else {
16317: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
16318: }
16319: }
1.147 raeburn 16320: $resulttext .= '</ul>';
16321: } else {
16322: $resulttext = $nochgmsg;
1.137 raeburn 16323: }
16324: } else {
16325: $resulttext = '<span class="LC_error">'.
16326: &mt('An error occurred: [_1]',$putresult).'</span>';
16327: }
16328: } else {
1.147 raeburn 16329: $resulttext = $nochgmsg;
1.137 raeburn 16330: }
16331: return $resulttext;
16332: }
16333:
1.275 raeburn 16334: sub modify_ssl {
16335: my ($dom,$lastactref,%domconfig) = @_;
16336: my (%by_ip,%by_location,@intdoms,@instdoms);
16337: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16338: my @locations = sort(keys(%by_location));
16339: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16340: my (%defaultshash,%changes);
16341: my $action = 'ssl';
1.293 raeburn 16342: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 16343: foreach my $prefix (@prefixes) {
16344: $defaultshash{$action}{$prefix} = {};
16345: }
16346: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16347: my $resulttext;
16348: my %iphost = &Apache::lonnet::get_iphost();
16349: my @reptypes = ('certreq','nocertreq');
16350: my @connecttypes = ('dom','intdom','other');
16351: my %types = (
1.293 raeburn 16352: connto => \@connecttypes,
16353: connfrom => \@connecttypes,
16354: replication => \@reptypes,
1.275 raeburn 16355: );
16356: foreach my $prefix (sort(keys(%types))) {
16357: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 16358: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16359: my $value = 'yes';
16360: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
16361: $value = $env{'form.'.$prefix.'_'.$type};
16362: }
16363: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16364: if ($domconfig{$action}{$prefix}{$type} ne '') {
16365: if ($value ne $domconfig{$action}{$prefix}{$type}) {
16366: $changes{$prefix}{$type} = 1;
16367: }
16368: $defaultshash{$action}{$prefix}{$type} = $value;
16369: } else {
16370: $defaultshash{$action}{$prefix}{$type} = $value;
16371: $changes{$prefix}{$type} = 1;
16372: }
16373: } else {
16374: $defaultshash{$action}{$prefix}{$type} = $value;
16375: $changes{$prefix}{$type} = 1;
16376: }
16377: if (($type eq 'dom') && (keys(%servers) == 1)) {
16378: delete($changes{$prefix}{$type});
16379: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
16380: delete($changes{$prefix}{$type});
16381: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
16382: delete($changes{$prefix}{$type});
16383: }
16384: } elsif ($prefix eq 'replication') {
16385: if (@locations > 0) {
16386: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16387: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16388: my @okvals;
16389: foreach my $val (@vals) {
16390: if ($val =~ /:/) {
16391: my @items = split(/:/,$val);
16392: foreach my $item (@items) {
16393: if (ref($by_location{$item}) eq 'ARRAY') {
16394: push(@okvals,$item);
16395: }
16396: }
16397: } else {
16398: if (ref($by_location{$val}) eq 'ARRAY') {
16399: push(@okvals,$val);
16400: }
16401: }
16402: }
16403: @okvals = sort(@okvals);
16404: if (ref($domconfig{$action}) eq 'HASH') {
16405: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16406: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
16407: if ($inuse == 0) {
16408: $changes{$prefix}{$type} = 1;
16409: } else {
16410: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16411: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
16412: if (@changed > 0) {
16413: $changes{$prefix}{$type} = 1;
16414: }
16415: }
16416: } else {
16417: if ($inuse == 1) {
16418: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16419: $changes{$prefix}{$type} = 1;
16420: }
16421: }
16422: } else {
16423: if ($inuse == 1) {
16424: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16425: $changes{$prefix}{$type} = 1;
16426: }
16427: }
16428: } else {
16429: if ($inuse == 1) {
16430: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16431: $changes{$prefix}{$type} = 1;
16432: }
16433: }
16434: }
16435: }
16436: }
16437: }
16438: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
16439: if (keys(%changes) > 0) {
16440: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16441: $dom);
16442: if ($putresult eq 'ok') {
16443: if (ref($defaultshash{$action}) eq 'HASH') {
16444: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
16445: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
16446: }
1.293 raeburn 16447: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
16448: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
16449: }
16450: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
16451: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 16452: }
16453: }
16454: my $cachetime = 24*60*60;
16455: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16456: if (ref($lastactref) eq 'HASH') {
16457: $lastactref->{'domdefaults'} = 1;
16458: }
16459: if (keys(%changes) > 0) {
16460: my %titles = &ssl_titles();
16461: $resulttext = &mt('Changes made:').'<ul>';
16462: foreach my $prefix (@prefixes) {
16463: if (ref($changes{$prefix}) eq 'HASH') {
16464: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
16465: foreach my $type (@{$types{$prefix}}) {
16466: if (defined($changes{$prefix}{$type})) {
16467: my $newvalue;
16468: if (ref($defaultshash{$action}) eq 'HASH') {
16469: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 16470: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16471: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
16472: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
16473: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
16474: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
16475: }
16476: }
16477: }
16478: if ($newvalue eq '') {
16479: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
16480: } else {
16481: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
16482: }
16483: }
16484: }
16485: }
16486: $resulttext .= '</ul>';
16487: }
16488: }
16489: } else {
16490: $resulttext = $nochgmsg;
16491: }
16492: } else {
16493: $resulttext = '<span class="LC_error">'.
16494: &mt('An error occurred: [_1]',$putresult).'</span>';
16495: }
16496: } else {
16497: $resulttext = $nochgmsg;
16498: }
16499: return $resulttext;
16500: }
16501:
1.279 raeburn 16502: sub modify_trust {
16503: my ($dom,$lastactref,%domconfig) = @_;
16504: my (%by_ip,%by_location,@intdoms,@instdoms);
16505: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16506: my @locations = sort(keys(%by_location));
16507: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
16508: my @types = ('exc','inc');
16509: my (%defaultshash,%changes);
16510: foreach my $prefix (@prefixes) {
16511: $defaultshash{'trust'}{$prefix} = {};
16512: }
16513: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16514: my $resulttext;
16515: foreach my $prefix (@prefixes) {
16516: foreach my $type (@types) {
16517: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16518: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16519: my @okvals;
16520: foreach my $val (@vals) {
16521: if ($val =~ /:/) {
16522: my @items = split(/:/,$val);
16523: foreach my $item (@items) {
16524: if (ref($by_location{$item}) eq 'ARRAY') {
16525: push(@okvals,$item);
16526: }
16527: }
16528: } else {
16529: if (ref($by_location{$val}) eq 'ARRAY') {
16530: push(@okvals,$val);
16531: }
16532: }
16533: }
16534: @okvals = sort(@okvals);
16535: if (ref($domconfig{'trust'}) eq 'HASH') {
16536: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
16537: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16538: if ($inuse == 0) {
16539: $changes{$prefix}{$type} = 1;
16540: } else {
16541: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16542: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
16543: if (@changed > 0) {
16544: $changes{$prefix}{$type} = 1;
16545: }
16546: }
16547: } else {
16548: if ($inuse == 1) {
16549: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16550: $changes{$prefix}{$type} = 1;
16551: }
16552: }
16553: } else {
16554: if ($inuse == 1) {
16555: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16556: $changes{$prefix}{$type} = 1;
16557: }
16558: }
16559: } else {
16560: if ($inuse == 1) {
16561: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16562: $changes{$prefix}{$type} = 1;
16563: }
16564: }
16565: }
16566: }
16567: my $nochgmsg = &mt('No changes made to trust settings.');
16568: if (keys(%changes) > 0) {
16569: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16570: $dom);
16571: if ($putresult eq 'ok') {
16572: if (ref($defaultshash{'trust'}) eq 'HASH') {
16573: foreach my $prefix (@prefixes) {
16574: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
16575: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
16576: }
16577: }
16578: }
16579: my $cachetime = 24*60*60;
16580: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16581: if (ref($lastactref) eq 'HASH') {
16582: $lastactref->{'domdefaults'} = 1;
16583: }
16584: if (keys(%changes) > 0) {
16585: my %lt = &trust_titles();
16586: $resulttext = &mt('Changes made:').'<ul>';
16587: foreach my $prefix (@prefixes) {
16588: if (ref($changes{$prefix}) eq 'HASH') {
16589: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16590: foreach my $type (@types) {
16591: if (defined($changes{$prefix}{$type})) {
16592: my $newvalue;
16593: if (ref($defaultshash{'trust'}) eq 'HASH') {
16594: if (ref($defaultshash{'trust'}{$prefix})) {
16595: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16596: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
16597: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
16598: }
16599: }
16600: }
16601: }
16602: if ($newvalue eq '') {
16603: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16604: } else {
16605: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
16606: }
16607: }
16608: }
16609: $resulttext .= '</ul>';
16610: }
16611: }
16612: $resulttext .= '</ul>';
16613: } else {
16614: $resulttext = $nochgmsg;
16615: }
16616: } else {
16617: $resulttext = '<span class="LC_error">'.
16618: &mt('An error occurred: [_1]',$putresult).'</span>';
16619: }
16620: } else {
16621: $resulttext = $nochgmsg;
16622: }
16623: return $resulttext;
16624: }
16625:
1.150 raeburn 16626: sub modify_loadbalancing {
16627: my ($dom,%domconfig) = @_;
16628: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16629: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16630: my ($othertitle,$usertypes,$types) =
16631: &Apache::loncommon::sorted_inst_types($dom);
16632: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 16633: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 16634: my @sparestypes = ('primary','default');
16635: my %typetitles = &sparestype_titles();
16636: my $resulttext;
1.171 raeburn 16637: my (%currbalancer,%currtargets,%currrules,%existing);
16638: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16639: %existing = %{$domconfig{'loadbalancing'}};
16640: }
16641: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
16642: \%currtargets,\%currrules);
16643: my ($saveloadbalancing,%defaultshash,%changes);
16644: my ($alltypes,$othertypes,$titles) =
16645: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16646: my %ruletitles = &offloadtype_text();
16647: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16648: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16649: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16650: if ($balancer eq '') {
16651: next;
16652: }
1.210 raeburn 16653: if (!exists($servers{$balancer})) {
1.171 raeburn 16654: if (exists($currbalancer{$balancer})) {
16655: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 16656: }
1.171 raeburn 16657: next;
16658: }
16659: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16660: push(@{$changes{'delete'}},$balancer);
16661: next;
16662: }
16663: if (!exists($currbalancer{$balancer})) {
16664: push(@{$changes{'add'}},$balancer);
16665: }
16666: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16667: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16668: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16669: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16670: $saveloadbalancing = 1;
16671: }
16672: foreach my $sparetype (@sparestypes) {
16673: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16674: my @offloadto;
16675: foreach my $target (@targets) {
16676: if (($servers{$target}) && ($target ne $balancer)) {
16677: if ($sparetype eq 'default') {
16678: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16679: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 16680: }
16681: }
1.171 raeburn 16682: unless(grep(/^\Q$target\E$/,@offloadto)) {
16683: push(@offloadto,$target);
16684: }
1.150 raeburn 16685: }
16686: }
1.284 raeburn 16687: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16688: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16689: push(@offloadto,$balancer);
16690: }
16691: }
16692: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 16693: }
1.171 raeburn 16694: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 16695: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16696: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16697: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 16698: if (@targetdiffs > 0) {
1.171 raeburn 16699: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16700: }
1.171 raeburn 16701: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16702: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16703: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16704: }
16705: }
16706: }
16707: } else {
1.171 raeburn 16708: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 16709: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16710: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16711: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16712: $changes{'curr'}{$balancer}{'targets'} = 1;
16713: }
1.150 raeburn 16714: }
16715: }
1.210 raeburn 16716: }
1.150 raeburn 16717: }
16718: my $ishomedom;
1.171 raeburn 16719: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16720: $ishomedom = 1;
1.150 raeburn 16721: }
16722: if (ref($alltypes) eq 'ARRAY') {
16723: foreach my $type (@{$alltypes}) {
16724: my $rule;
1.210 raeburn 16725: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 16726: (!$ishomedom)) {
1.171 raeburn 16727: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16728: }
16729: if ($rule eq 'specific') {
1.255 raeburn 16730: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 16731: if (exists($servers{$specifiedhost})) {
1.255 raeburn 16732: $rule = $specifiedhost;
16733: }
1.150 raeburn 16734: }
1.171 raeburn 16735: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16736: if (ref($currrules{$balancer}) eq 'HASH') {
16737: if ($rule ne $currrules{$balancer}{$type}) {
16738: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16739: }
16740: } elsif ($rule ne '') {
1.171 raeburn 16741: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16742: }
16743: }
16744: }
1.171 raeburn 16745: }
16746: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
16747: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
16748: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
16749: $defaultshash{'loadbalancing'} = {};
16750: }
16751: my $putresult = &Apache::lonnet::put_dom('configuration',
16752: \%defaultshash,$dom);
16753: if ($putresult eq 'ok') {
16754: if (keys(%changes) > 0) {
1.252 raeburn 16755: my %toupdate;
1.171 raeburn 16756: if (ref($changes{'delete'}) eq 'ARRAY') {
16757: foreach my $balancer (sort(@{$changes{'delete'}})) {
16758: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 16759: $toupdate{$balancer} = 1;
1.150 raeburn 16760: }
1.171 raeburn 16761: }
16762: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 16763: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 16764: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 16765: $toupdate{$balancer} = 1;
1.171 raeburn 16766: }
16767: }
16768: if (ref($changes{'curr'}) eq 'HASH') {
16769: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 16770: $toupdate{$balancer} = 1;
1.171 raeburn 16771: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
16772: if ($changes{'curr'}{$balancer}{'targets'}) {
16773: my %offloadstr;
16774: foreach my $sparetype (@sparestypes) {
16775: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16776: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16777: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16778: }
16779: }
1.150 raeburn 16780: }
1.171 raeburn 16781: if (keys(%offloadstr) == 0) {
16782: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 16783: } else {
1.171 raeburn 16784: my $showoffload;
16785: foreach my $sparetype (@sparestypes) {
16786: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
16787: if (defined($offloadstr{$sparetype})) {
16788: $showoffload .= $offloadstr{$sparetype};
16789: } else {
16790: $showoffload .= &mt('None');
16791: }
16792: $showoffload .= (' 'x3);
16793: }
16794: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 16795: }
16796: }
16797: }
1.171 raeburn 16798: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
16799: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
16800: foreach my $type (@{$alltypes}) {
16801: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
16802: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16803: my $balancetext;
16804: if ($rule eq '') {
16805: $balancetext = $ruletitles{'default'};
1.209 raeburn 16806: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 16807: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 16808: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 16809: foreach my $sparetype (@sparestypes) {
16810: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16811: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16812: }
16813: }
1.253 raeburn 16814: foreach my $item (@{$alltypes}) {
16815: next if ($item =~ /^_LC_ipchange/);
16816: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
16817: if ($hasrule eq 'homeserver') {
16818: map { $toupdate{$_} = 1; } (keys(%libraryservers));
16819: } else {
16820: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
16821: if ($servers{$hasrule}) {
16822: $toupdate{$hasrule} = 1;
16823: }
16824: }
16825: }
16826: }
1.254 raeburn 16827: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
16828: $balancetext = $ruletitles{$rule};
16829: } else {
16830: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16831: $balancetext = $ruletitles{'particular'}.' '.$receiver;
16832: if ($receiver) {
16833: $toupdate{$receiver};
16834: }
16835: }
16836: } else {
16837: $balancetext = $ruletitles{$rule};
1.252 raeburn 16838: }
1.171 raeburn 16839: } else {
16840: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
16841: }
1.210 raeburn 16842: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 16843: }
16844: }
16845: }
16846: }
1.252 raeburn 16847: if (keys(%toupdate)) {
16848: my %thismachine;
16849: my $updatedhere;
16850: my $cachetime = 60*60*24;
16851: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
16852: foreach my $lonhost (keys(%toupdate)) {
16853: if ($thismachine{$lonhost}) {
16854: unless ($updatedhere) {
16855: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
16856: $defaultshash{'loadbalancing'},
16857: $cachetime);
16858: $updatedhere = 1;
16859: }
16860: } else {
16861: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
16862: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
16863: }
16864: }
16865: }
1.150 raeburn 16866: }
1.171 raeburn 16867: }
16868: if ($resulttext ne '') {
16869: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 16870: } else {
16871: $resulttext = $nochgmsg;
16872: }
16873: } else {
1.171 raeburn 16874: $resulttext = $nochgmsg;
1.150 raeburn 16875: }
16876: } else {
1.171 raeburn 16877: $resulttext = '<span class="LC_error">'.
16878: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 16879: }
16880: } else {
1.171 raeburn 16881: $resulttext = $nochgmsg;
1.150 raeburn 16882: }
16883: return $resulttext;
16884: }
16885:
1.48 raeburn 16886: sub recurse_check {
16887: my ($chkcats,$categories,$depth,$name) = @_;
16888: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
16889: my $chg = 0;
16890: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
16891: my $category = $chkcats->[$depth]{$name}[$j];
16892: my $item;
16893: if ($category eq '') {
16894: $chg ++;
16895: } else {
16896: my $deeper = $depth + 1;
16897: $item = &escape($category).':'.&escape($name).':'.$depth;
16898: if ($chg) {
16899: $categories->{$item} -= $chg;
16900: }
16901: &recurse_check($chkcats,$categories,$deeper,$category);
16902: $deeper --;
16903: }
16904: }
16905: }
16906: return;
16907: }
16908:
16909: sub recurse_cat_deletes {
16910: my ($item,$coursecategories,$deletions) = @_;
16911: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16912: my $subdepth = $depth + 1;
16913: if (ref($coursecategories) eq 'HASH') {
16914: foreach my $subitem (keys(%{$coursecategories})) {
16915: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
16916: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
16917: delete($coursecategories->{$subitem});
16918: $deletions->{$subitem} = 1;
16919: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 16920: }
1.48 raeburn 16921: }
16922: }
16923: return;
16924: }
16925:
1.125 raeburn 16926: sub active_dc_picker {
1.191 raeburn 16927: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 16928: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 16929: my @domcoord = keys(%domcoords);
16930: if (keys(%currhash)) {
16931: foreach my $dc (keys(%currhash)) {
16932: unless (exists($domcoords{$dc})) {
16933: push(@domcoord,$dc);
16934: }
16935: }
16936: }
16937: @domcoord = sort(@domcoord);
1.210 raeburn 16938: my $numdcs = scalar(@domcoord);
1.191 raeburn 16939: my $rows = 0;
16940: my $table;
1.125 raeburn 16941: if ($numdcs > 1) {
1.191 raeburn 16942: $table = '<table>';
16943: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 16944: my $rem = $i%($numinrow);
16945: if ($rem == 0) {
16946: if ($i > 0) {
1.191 raeburn 16947: $table .= '</tr>';
1.125 raeburn 16948: }
1.191 raeburn 16949: $table .= '<tr>';
16950: $rows ++;
1.125 raeburn 16951: }
1.191 raeburn 16952: my $check = '';
16953: if ($inputtype eq 'radio') {
16954: if (keys(%currhash) == 0) {
16955: if (!$i) {
16956: $check = ' checked="checked"';
16957: }
16958: } elsif (exists($currhash{$domcoord[$i]})) {
16959: $check = ' checked="checked"';
16960: }
16961: } else {
16962: if (exists($currhash{$domcoord[$i]})) {
16963: $check = ' checked="checked"';
1.125 raeburn 16964: }
16965: }
1.191 raeburn 16966: if ($i == @domcoord - 1) {
1.125 raeburn 16967: my $colsleft = $numinrow - $rem;
16968: if ($colsleft > 1) {
1.191 raeburn 16969: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 16970: } else {
1.191 raeburn 16971: $table .= '<td class="LC_left_item">';
1.125 raeburn 16972: }
16973: } else {
1.191 raeburn 16974: $table .= '<td class="LC_left_item">';
16975: }
16976: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
16977: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
16978: $table .= '<span class="LC_nobreak"><label>'.
16979: '<input type="'.$inputtype.'" name="'.$name.'"'.
16980: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
16981: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 16982: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 16983: }
1.219 raeburn 16984: $table .= '</label></span></td>';
1.191 raeburn 16985: }
16986: $table .= '</tr></table>';
16987: } elsif ($numdcs == 1) {
1.219 raeburn 16988: my ($dcname,$dcdom) = split(':',$domcoord[0]);
16989: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 16990: if ($inputtype eq 'radio') {
1.247 raeburn 16991: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 16992: if ($user ne $dcname.':'.$dcdom) {
16993: $table .= ' ('.$dcname.':'.$dcdom.')';
16994: }
1.191 raeburn 16995: } else {
16996: my $check;
16997: if (exists($currhash{$domcoord[0]})) {
16998: $check = ' checked="checked"';
1.125 raeburn 16999: }
1.247 raeburn 17000: $table = '<span class="LC_nobreak"><label>'.
17001: '<input type="checkbox" name="'.$name.'" '.
17002: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 17003: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 17004: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 17005: }
1.220 raeburn 17006: $table .= '</label></span>';
1.191 raeburn 17007: $rows ++;
1.125 raeburn 17008: }
17009: }
1.191 raeburn 17010: return ($numdcs,$table,$rows);
1.125 raeburn 17011: }
17012:
1.137 raeburn 17013: sub usersession_titles {
17014: return &Apache::lonlocal::texthash(
17015: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
17016: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 17017: spares => 'Servers offloaded to, when busy',
1.137 raeburn 17018: version => 'LON-CAPA version requirement',
1.138 raeburn 17019: excludedomain => 'Allow all, but exclude specific domains',
17020: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 17021: primary => 'Primary (checked first)',
1.154 raeburn 17022: default => 'Default',
1.137 raeburn 17023: );
17024: }
17025:
1.152 raeburn 17026: sub id_for_thisdom {
17027: my (%servers) = @_;
17028: my %altids;
17029: foreach my $server (keys(%servers)) {
17030: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17031: if ($serverhome ne $server) {
17032: $altids{$serverhome} = $server;
17033: }
17034: }
17035: return %altids;
17036: }
17037:
1.150 raeburn 17038: sub count_servers {
17039: my ($currbalancer,%servers) = @_;
17040: my (@spares,$numspares);
17041: foreach my $lonhost (sort(keys(%servers))) {
17042: next if ($currbalancer eq $lonhost);
17043: push(@spares,$lonhost);
17044: }
17045: if ($currbalancer) {
17046: $numspares = scalar(@spares);
17047: } else {
17048: $numspares = scalar(@spares) - 1;
17049: }
17050: return ($numspares,@spares);
17051: }
17052:
17053: sub lonbalance_targets_js {
1.171 raeburn 17054: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 17055: my $select = &mt('Select');
17056: my ($alltargets,$allishome,$allinsttypes,@alltypes);
17057: if (ref($servers) eq 'HASH') {
17058: $alltargets = join("','",sort(keys(%{$servers})));
17059: my @homedoms;
17060: foreach my $server (sort(keys(%{$servers}))) {
17061: if (&Apache::lonnet::host_domain($server) eq $dom) {
17062: push(@homedoms,'1');
17063: } else {
17064: push(@homedoms,'0');
17065: }
17066: }
17067: $allishome = join("','",@homedoms);
17068: }
17069: if (ref($types) eq 'ARRAY') {
17070: if (@{$types} > 0) {
17071: @alltypes = @{$types};
17072: }
17073: }
17074: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
17075: $allinsttypes = join("','",@alltypes);
1.171 raeburn 17076: my (%currbalancer,%currtargets,%currrules,%existing);
17077: if (ref($settings) eq 'HASH') {
17078: %existing = %{$settings};
17079: }
17080: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
17081: \%currtargets,\%currrules);
1.210 raeburn 17082: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 17083: return <<"END";
17084:
17085: <script type="text/javascript">
17086: // <![CDATA[
17087:
1.171 raeburn 17088: currBalancers = new Array('$balancers');
17089:
17090: function toggleTargets(balnum) {
17091: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17092: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
17093: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
17094: var prevbalancer = prevhostitem.value;
17095: var baltotal = document.getElementById('loadbalancing_total').value;
17096: prevhostitem.value = balancer;
17097: if (prevbalancer != '') {
17098: var prevIdx = currBalancers.indexOf(prevbalancer);
17099: if (prevIdx != -1) {
17100: currBalancers.splice(prevIdx,1);
17101: }
17102: }
1.150 raeburn 17103: if (balancer == '') {
1.171 raeburn 17104: hideSpares(balnum);
1.150 raeburn 17105: } else {
1.171 raeburn 17106: var currIdx = currBalancers.indexOf(balancer);
17107: if (currIdx == -1) {
17108: currBalancers.push(balancer);
17109: }
1.150 raeburn 17110: var homedoms = new Array('$allishome');
1.171 raeburn 17111: var ishomedom = homedoms[lonhostitem.selectedIndex];
17112: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 17113: }
1.171 raeburn 17114: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 17115: return;
17116: }
17117:
1.171 raeburn 17118: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 17119: var alltargets = new Array('$alltargets');
17120: var insttypes = new Array('$allinsttypes');
1.151 raeburn 17121: var offloadtypes = new Array('primary','default');
17122:
1.171 raeburn 17123: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17124: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 17125:
1.151 raeburn 17126: for (var i=0; i<offloadtypes.length; i++) {
17127: var count = 0;
17128: for (var j=0; j<alltargets.length; j++) {
17129: if (alltargets[j] != balancer) {
1.171 raeburn 17130: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17131: item.value = alltargets[j];
17132: item.style.textAlign='left';
17133: item.style.textFace='normal';
17134: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17135: if (currBalancers.indexOf(alltargets[j]) == -1) {
17136: item.disabled = '';
17137: } else {
17138: item.disabled = 'disabled';
17139: item.checked = false;
17140: }
1.151 raeburn 17141: count ++;
17142: }
1.150 raeburn 17143: }
17144: }
1.151 raeburn 17145: for (var k=0; k<insttypes.length; k++) {
17146: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 17147: if (ishomedom == 1) {
1.171 raeburn 17148: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17149: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17150: } else {
1.171 raeburn 17151: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17152: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 17153: }
17154: } else {
1.171 raeburn 17155: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17156: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17157: }
1.151 raeburn 17158: if ((insttypes[k] != '_LC_external') &&
17159: ((insttypes[k] != '_LC_internetdom') ||
17160: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 17161: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17162: item.options.length = 0;
17163: item.options[0] = new Option("","",true,true);
1.210 raeburn 17164: var idx = 0;
1.151 raeburn 17165: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 17166: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17167: idx ++;
17168: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 17169: }
17170: }
17171: }
17172: }
17173: return;
17174: }
17175:
1.171 raeburn 17176: function hideSpares(balnum) {
1.150 raeburn 17177: var alltargets = new Array('$alltargets');
17178: var insttypes = new Array('$allinsttypes');
17179: var offloadtypes = new Array('primary','default');
17180:
1.171 raeburn 17181: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17182: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 17183:
17184: var total = alltargets.length - 1;
17185: for (var i=0; i<offloadtypes; i++) {
17186: for (var j=0; j<total; j++) {
1.171 raeburn 17187: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17188: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17189: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 17190: }
1.150 raeburn 17191: }
17192: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 17193: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17194: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 17195: if (insttypes[k] != '_LC_external') {
1.171 raeburn 17196: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17197: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 17198: }
17199: }
17200: return;
17201: }
17202:
1.171 raeburn 17203: function checkOffloads(item,balnum,type) {
1.150 raeburn 17204: var alltargets = new Array('$alltargets');
17205: var offloadtypes = new Array('primary','default');
17206: if (item.checked) {
17207: var total = alltargets.length - 1;
17208: var other;
17209: if (type == offloadtypes[0]) {
1.151 raeburn 17210: other = offloadtypes[1];
1.150 raeburn 17211: } else {
1.151 raeburn 17212: other = offloadtypes[0];
1.150 raeburn 17213: }
17214: for (var i=0; i<total; i++) {
1.171 raeburn 17215: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 17216: if (server == item.value) {
1.171 raeburn 17217: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17218: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 17219: }
17220: }
17221: }
17222: }
17223: return;
17224: }
17225:
1.171 raeburn 17226: function singleServerToggle(balnum,type) {
17227: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 17228: if (offloadtoSelIdx == 0) {
1.171 raeburn 17229: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17230: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17231:
17232: } else {
1.171 raeburn 17233: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17234: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 17235: }
17236: return;
17237: }
17238:
1.171 raeburn 17239: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 17240: if (type == '_LC_external') {
1.171 raeburn 17241: return;
1.150 raeburn 17242: }
1.171 raeburn 17243: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 17244: for (var i=0; i<typesRules.length; i++) {
17245: if (formname.elements[typesRules[i]].checked) {
17246: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 17247: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17248: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17249: } else {
1.171 raeburn 17250: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17251: }
17252: }
17253: }
17254: return;
17255: }
17256:
17257: function balancerDeleteChange(balnum) {
17258: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17259: var baltotal = document.getElementById('loadbalancing_total').value;
17260: var addtarget;
17261: var removetarget;
17262: var action = 'delete';
17263: if (document.getElementById('loadbalancing_delete_'+balnum)) {
17264: var lonhost = hostitem.value;
17265: var currIdx = currBalancers.indexOf(lonhost);
17266: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
17267: if (currIdx != -1) {
17268: currBalancers.splice(currIdx,1);
17269: }
17270: addtarget = lonhost;
17271: } else {
17272: if (currIdx == -1) {
17273: currBalancers.push(lonhost);
17274: }
17275: removetarget = lonhost;
17276: action = 'undelete';
17277: }
17278: balancerChange(balnum,baltotal,action,addtarget,removetarget);
17279: }
17280: return;
17281: }
17282:
17283: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
17284: if (baltotal > 1) {
17285: var offloadtypes = new Array('primary','default');
17286: var alltargets = new Array('$alltargets');
17287: var insttypes = new Array('$allinsttypes');
17288: for (var i=0; i<baltotal; i++) {
17289: if (i != balnum) {
17290: for (var j=0; j<offloadtypes.length; j++) {
17291: var total = alltargets.length - 1;
17292: for (var k=0; k<total; k++) {
17293: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
17294: var server = serveritem.value;
17295: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17296: if (server == addtarget) {
17297: serveritem.disabled = '';
17298: }
17299: }
17300: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17301: if (server == removetarget) {
17302: serveritem.disabled = 'disabled';
17303: serveritem.checked = false;
17304: }
17305: }
17306: }
17307: }
17308: for (var j=0; j<insttypes.length; j++) {
17309: if (insttypes[j] != '_LC_external') {
17310: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
17311: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
17312: var currSel = singleserver.selectedIndex;
17313: var currVal = singleserver.options[currSel].value;
17314: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17315: var numoptions = singleserver.options.length;
17316: var needsnew = 1;
17317: for (var k=0; k<numoptions; k++) {
17318: if (singleserver.options[k] == addtarget) {
17319: needsnew = 0;
17320: break;
17321: }
17322: }
17323: if (needsnew == 1) {
17324: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
17325: }
17326: }
17327: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17328: singleserver.options.length = 0;
17329: if ((currVal) && (currVal != removetarget)) {
17330: singleserver.options[0] = new Option("","",false,false);
17331: } else {
17332: singleserver.options[0] = new Option("","",true,true);
17333: }
17334: var idx = 0;
17335: for (var m=0; m<alltargets.length; m++) {
17336: if (currBalancers.indexOf(alltargets[m]) == -1) {
17337: idx ++;
17338: if (currVal == alltargets[m]) {
17339: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17340: } else {
17341: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17342: }
17343: }
17344: }
17345: }
17346: }
17347: }
17348: }
1.150 raeburn 17349: }
17350: }
17351: }
17352: return;
17353: }
17354:
1.152 raeburn 17355: // ]]>
17356: </script>
17357:
17358: END
17359: }
17360:
17361: sub new_spares_js {
17362: my @sparestypes = ('primary','default');
17363: my $types = join("','",@sparestypes);
17364: my $select = &mt('Select');
17365: return <<"END";
17366:
17367: <script type="text/javascript">
17368: // <![CDATA[
17369:
17370: function updateNewSpares(formname,lonhost) {
17371: var types = new Array('$types');
17372: var include = new Array();
17373: var exclude = new Array();
17374: for (var i=0; i<types.length; i++) {
17375: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17376: for (var j=0; j<spareboxes.length; j++) {
17377: if (formname.elements[spareboxes[j]].checked) {
17378: exclude.push(formname.elements[spareboxes[j]].value);
17379: } else {
17380: include.push(formname.elements[spareboxes[j]].value);
17381: }
17382: }
17383: }
17384: for (var i=0; i<types.length; i++) {
17385: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17386: var selIdx = newSpare.selectedIndex;
17387: var currnew = newSpare.options[selIdx].value;
17388: var okSpares = new Array();
17389: for (var j=0; j<newSpare.options.length; j++) {
17390: var possible = newSpare.options[j].value;
17391: if (possible != '') {
17392: if (exclude.indexOf(possible) == -1) {
17393: okSpares.push(possible);
17394: } else {
17395: if (currnew == possible) {
17396: selIdx = 0;
17397: }
17398: }
17399: }
17400: }
17401: for (var k=0; k<include.length; k++) {
17402: if (okSpares.indexOf(include[k]) == -1) {
17403: okSpares.push(include[k]);
17404: }
17405: }
17406: okSpares.sort();
17407: newSpare.options.length = 0;
17408: if (selIdx == 0) {
17409: newSpare.options[0] = new Option("$select","",true,true);
17410: } else {
17411: newSpare.options[0] = new Option("$select","",false,false);
17412: }
17413: for (var m=0; m<okSpares.length; m++) {
17414: var idx = m+1;
17415: var selThis = 0;
17416: if (selIdx != 0) {
17417: if (okSpares[m] == currnew) {
17418: selThis = 1;
17419: }
17420: }
17421: if (selThis == 1) {
17422: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17423: } else {
17424: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17425: }
17426: }
17427: }
17428: return;
17429: }
17430:
17431: function checkNewSpares(lonhost,type) {
17432: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17433: var chosen = newSpare.options[newSpare.selectedIndex].value;
17434: if (chosen != '') {
17435: var othertype;
17436: var othernewSpare;
17437: if (type == 'primary') {
17438: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17439: }
17440: if (type == 'default') {
17441: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17442: }
17443: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17444: othernewSpare.selectedIndex = 0;
17445: }
17446: }
17447: return;
17448: }
17449:
17450: // ]]>
17451: </script>
17452:
17453: END
17454:
17455: }
17456:
17457: sub common_domprefs_js {
17458: return <<"END";
17459:
17460: <script type="text/javascript">
17461: // <![CDATA[
17462:
1.150 raeburn 17463: function getIndicesByName(formname,item) {
1.152 raeburn 17464: var group = new Array();
1.150 raeburn 17465: for (var i=0;i<formname.elements.length;i++) {
17466: if (formname.elements[i].name == item) {
1.152 raeburn 17467: group.push(formname.elements[i].id);
1.150 raeburn 17468: }
17469: }
1.152 raeburn 17470: return group;
1.150 raeburn 17471: }
17472:
17473: // ]]>
17474: </script>
17475:
17476: END
1.152 raeburn 17477:
1.150 raeburn 17478: }
17479:
1.165 raeburn 17480: sub recaptcha_js {
17481: my %lt = &captcha_phrases();
17482: return <<"END";
17483:
17484: <script type="text/javascript">
17485: // <![CDATA[
17486:
17487: function updateCaptcha(caller,context) {
17488: var privitem;
17489: var pubitem;
17490: var privtext;
17491: var pubtext;
1.269 raeburn 17492: var versionitem;
17493: var versiontext;
1.165 raeburn 17494: if (document.getElementById(context+'_recaptchapub')) {
17495: pubitem = document.getElementById(context+'_recaptchapub');
17496: } else {
17497: return;
17498: }
17499: if (document.getElementById(context+'_recaptchapriv')) {
17500: privitem = document.getElementById(context+'_recaptchapriv');
17501: } else {
17502: return;
17503: }
17504: if (document.getElementById(context+'_recaptchapubtxt')) {
17505: pubtext = document.getElementById(context+'_recaptchapubtxt');
17506: } else {
17507: return;
17508: }
17509: if (document.getElementById(context+'_recaptchaprivtxt')) {
17510: privtext = document.getElementById(context+'_recaptchaprivtxt');
17511: } else {
17512: return;
17513: }
1.269 raeburn 17514: if (document.getElementById(context+'_recaptchaversion')) {
17515: versionitem = document.getElementById(context+'_recaptchaversion');
17516: } else {
17517: return;
17518: }
17519: if (document.getElementById(context+'_recaptchavertxt')) {
17520: versiontext = document.getElementById(context+'_recaptchavertxt');
17521: } else {
17522: return;
17523: }
1.165 raeburn 17524: if (caller.checked) {
17525: if (caller.value == 'recaptcha') {
17526: pubitem.type = 'text';
17527: privitem.type = 'text';
17528: pubitem.size = '40';
17529: privitem.size = '40';
17530: pubtext.innerHTML = "$lt{'pub'}";
17531: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 17532: versionitem.type = 'text';
17533: versionitem.size = '3';
1.289 raeburn 17534: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 17535: } else {
17536: pubitem.type = 'hidden';
17537: privitem.type = 'hidden';
1.269 raeburn 17538: versionitem.type = 'hidden';
1.165 raeburn 17539: pubtext.innerHTML = '';
17540: privtext.innerHTML = '';
1.269 raeburn 17541: versiontext.innerHTML = '';
1.165 raeburn 17542: }
17543: }
17544: return;
17545: }
17546:
17547: // ]]>
17548: </script>
17549:
17550: END
17551:
17552: }
17553:
1.236 raeburn 17554: sub toggle_display_js {
1.192 raeburn 17555: return <<"END";
17556:
17557: <script type="text/javascript">
17558: // <![CDATA[
17559:
1.236 raeburn 17560: function toggleDisplay(domForm,caller) {
17561: if (document.getElementById(caller)) {
17562: var divitem = document.getElementById(caller);
17563: var optionsElement = domForm.coursecredits;
1.264 raeburn 17564: var checkval = 1;
17565: var dispval = 'block';
1.303 raeburn 17566: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 17567: if (caller == 'emailoptions') {
17568: optionsElement = domForm.cancreate_email;
17569: }
1.257 raeburn 17570: if (caller == 'studentsubmission') {
17571: optionsElement = domForm.postsubmit;
17572: }
1.264 raeburn 17573: if (caller == 'cloneinstcode') {
17574: optionsElement = domForm.canclone;
17575: checkval = 'instcode';
17576: }
1.303 raeburn 17577: if (selfcreateRegExp.test(caller)) {
17578: optionsElement = domForm.elements[caller];
17579: checkval = 'other';
17580: dispval = 'inline'
17581: }
1.236 raeburn 17582: if (optionsElement.length) {
1.192 raeburn 17583: var currval;
1.236 raeburn 17584: for (var i=0; i<optionsElement.length; i++) {
17585: if (optionsElement[i].checked) {
17586: currval = optionsElement[i].value;
1.192 raeburn 17587: }
17588: }
1.264 raeburn 17589: if (currval == checkval) {
17590: divitem.style.display = dispval;
1.192 raeburn 17591: } else {
1.236 raeburn 17592: divitem.style.display = 'none';
1.192 raeburn 17593: }
17594: }
17595: }
17596: return;
17597: }
17598:
17599: // ]]>
17600: </script>
17601:
17602: END
17603:
17604: }
17605:
1.165 raeburn 17606: sub captcha_phrases {
17607: return &Apache::lonlocal::texthash (
17608: priv => 'Private key',
17609: pub => 'Public key',
17610: original => 'original (CAPTCHA)',
17611: recaptcha => 'successor (ReCAPTCHA)',
17612: notused => 'unused',
1.289 raeburn 17613: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 17614: );
17615: }
17616:
1.205 raeburn 17617: sub devalidate_remote_domconfs {
1.212 raeburn 17618: my ($dom,$cachekeys) = @_;
17619: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 17620: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17621: my %thismachine;
17622: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 17623: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 17624: if (keys(%servers)) {
1.205 raeburn 17625: foreach my $server (keys(%servers)) {
17626: next if ($thismachine{$server});
1.212 raeburn 17627: my @cached;
17628: foreach my $name (@posscached) {
17629: if ($cachekeys->{$name}) {
17630: push(@cached,&escape($name).':'.&escape($dom));
17631: }
17632: }
17633: if (@cached) {
17634: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17635: }
1.205 raeburn 17636: }
17637: }
17638: return;
17639: }
17640:
1.3 raeburn 17641: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>