Annotation of loncom/interface/domainprefs.pm, revision 1.325
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.325 ! raeburn 4: # $Id: domainprefs.pm,v 1.324 2018/01/01 01:29:38 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 ! raeburn 107: (official, unofficial, community, textbook, placement, and lti).
1.271 raeburn 108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.1 raeburn 179:
1.155 raeburn 180: my $registered_cleanup;
181: my $modified_urls;
182:
1.1 raeburn 183: sub handler {
184: my $r=shift;
185: if ($r->header_only) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: return OK;
189: }
190:
1.91 raeburn 191: my $context = 'domain';
1.1 raeburn 192: my $dom = $env{'request.role.domain'};
1.5 albertel 193: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 194: if (&Apache::lonnet::allowed('mau',$dom)) {
195: &Apache::loncommon::content_type($r,'text/html');
196: $r->send_http_header;
197: } else {
198: $env{'user.error.msg'}=
199: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
200: return HTTP_NOT_ACCEPTABLE;
201: }
1.155 raeburn 202:
203: $registered_cleanup=0;
204: @{$modified_urls}=();
205:
1.1 raeburn 206: &Apache::lonhtmlcommon::clear_breadcrumbs();
207: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 208: ['phase','actions']);
1.30 raeburn 209: my $phase = 'pickactions';
1.3 raeburn 210: if ( exists($env{'form.phase'}) ) {
211: $phase = $env{'form.phase'};
212: }
1.150 raeburn 213: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 214: my %domconfig =
1.6 raeburn 215: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 216: 'quotas','autoenroll','autoupdate','autocreate',
217: 'directorysrch','usercreation','usermodification',
218: 'contacts','defaults','scantron','coursecategories',
219: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 220: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 221: 'requestauthor','selfenrollment','inststatus',
1.320 raeburn 222: 'ltitools','ssl','trust','lti'],$dom);
223: my %encconfig =
224: &Apache::lonnet::get_dom('encconfig',['ltitools','lti'],$dom);
1.297 raeburn 225: if (ref($domconfig{'ltitools'}) eq 'HASH') {
226: if (ref($encconfig{'ltitools'}) eq 'HASH') {
227: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 228: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
229: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297 raeburn 230: foreach my $item ('key','secret') {
231: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
232: }
233: }
234: }
235: }
236: }
1.320 raeburn 237: if (ref($domconfig{'lti'}) eq 'HASH') {
238: if (ref($encconfig{'lti'}) eq 'HASH') {
239: foreach my $id (keys(%{$domconfig{'lti'}})) {
240: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
241: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
242: foreach my $item ('key','secret') {
243: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
244: }
245: }
246: }
247: }
248: }
1.43 raeburn 249: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 250: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 251: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 252: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 253: 'serverstatuses','helpsettings','coursedefaults',
1.320 raeburn 254: 'ltitools','selfenrollment','usersessions','ssl','trust','lti');
1.171 raeburn 255: my %existing;
256: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
257: %existing = %{$domconfig{'loadbalancing'}};
258: }
259: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 260: push(@prefs_order,'loadbalancing');
261: }
1.30 raeburn 262: my %prefs = (
263: 'rolecolors' =>
264: { text => 'Default color schemes',
1.67 raeburn 265: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 266: header => [{col1 => 'Student Settings',
267: col2 => '',},
268: {col1 => 'Coordinator Settings',
269: col2 => '',},
270: {col1 => 'Author Settings',
271: col2 => '',},
272: {col1 => 'Administrator Settings',
273: col2 => '',}],
1.230 raeburn 274: print => \&print_rolecolors,
275: modify => \&modify_rolecolors,
1.30 raeburn 276: },
1.110 raeburn 277: 'login' =>
1.30 raeburn 278: { text => 'Log-in page options',
1.67 raeburn 279: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 280: header => [{col1 => 'Log-in Page Items',
281: col2 => '',},
282: {col1 => 'Log-in Help',
1.256 raeburn 283: col2 => 'Value'},
284: {col1 => 'Custom HTML in document head',
1.168 raeburn 285: col2 => 'Value'}],
1.230 raeburn 286: print => \&print_login,
287: modify => \&modify_login,
1.30 raeburn 288: },
1.43 raeburn 289: 'defaults' =>
1.236 raeburn 290: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 291: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 292: header => [{col1 => 'Setting',
1.236 raeburn 293: col2 => 'Value'},
1.294 raeburn 294: {col1 => 'Internal Authentication',
295: col2 => 'Value'},
1.236 raeburn 296: {col1 => 'Institutional user types',
1.305 raeburn 297: col2 => 'Name displayed'}],
1.230 raeburn 298: print => \&print_defaults,
299: modify => \&modify_defaults,
1.43 raeburn 300: },
1.30 raeburn 301: 'quotas' =>
1.197 raeburn 302: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 303: help => 'Domain_Configuration_Quotas',
1.77 raeburn 304: header => [{col1 => 'User affiliation',
1.72 raeburn 305: col2 => 'Available tools',
1.213 raeburn 306: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 307: print => \&print_quotas,
308: modify => \&modify_quotas,
1.30 raeburn 309: },
310: 'autoenroll' =>
311: { text => 'Auto-enrollment settings',
1.67 raeburn 312: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 313: header => [{col1 => 'Configuration setting',
314: col2 => 'Value(s)'}],
1.230 raeburn 315: print => \&print_autoenroll,
316: modify => \&modify_autoenroll,
1.30 raeburn 317: },
318: 'autoupdate' =>
319: { text => 'Auto-update settings',
1.67 raeburn 320: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 321: header => [{col1 => 'Setting',
322: col2 => 'Value',},
1.131 raeburn 323: {col1 => 'Setting',
324: col2 => 'Affiliation'},
1.43 raeburn 325: {col1 => 'User population',
1.227 bisitz 326: col2 => 'Updatable user data'}],
1.230 raeburn 327: print => \&print_autoupdate,
328: modify => \&modify_autoupdate,
1.30 raeburn 329: },
1.125 raeburn 330: 'autocreate' =>
331: { text => 'Auto-course creation settings',
332: help => 'Domain_Configuration_Auto_Creation',
333: header => [{col1 => 'Configuration Setting',
334: col2 => 'Value',}],
1.230 raeburn 335: print => \&print_autocreate,
336: modify => \&modify_autocreate,
1.125 raeburn 337: },
1.30 raeburn 338: 'directorysrch' =>
1.277 raeburn 339: { text => 'Directory searches',
1.67 raeburn 340: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 341: header => [{col1 => 'Institutional Directory Setting',
342: col2 => 'Value',},
343: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 344: col2 => 'Value',}],
1.230 raeburn 345: print => \&print_directorysrch,
346: modify => \&modify_directorysrch,
1.30 raeburn 347: },
348: 'contacts' =>
1.286 raeburn 349: { text => 'E-mail addresses and helpform',
1.67 raeburn 350: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 351: header => [{col1 => 'Default e-mail addresses',
352: col2 => 'Value',},
353: {col1 => 'Recipient(s) for notifications',
354: col2 => 'Value',},
355: {col1 => 'Ask helpdesk form settings',
356: col2 => 'Value',},],
1.230 raeburn 357: print => \&print_contacts,
358: modify => \&modify_contacts,
1.30 raeburn 359: },
360: 'usercreation' =>
361: { text => 'User creation',
1.67 raeburn 362: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 363: header => [{col1 => 'Format rule type',
364: col2 => 'Format rules in force'},
1.34 raeburn 365: {col1 => 'User account creation',
366: col2 => 'Usernames which may be created',},
1.30 raeburn 367: {col1 => 'Context',
1.43 raeburn 368: col2 => 'Assignable authentication types'}],
1.230 raeburn 369: print => \&print_usercreation,
370: modify => \&modify_usercreation,
1.30 raeburn 371: },
1.224 raeburn 372: 'selfcreation' =>
373: { text => 'Users self-creating accounts',
374: help => 'Domain_Configuration_Self_Creation',
375: header => [{col1 => 'Self-creation with institutional username',
376: col2 => 'Enabled?'},
377: {col1 => 'Institutional user type (login/SSO self-creation)',
378: col2 => 'Information user can enter'},
1.303 raeburn 379: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 380: col2 => 'Settings'}],
1.230 raeburn 381: print => \&print_selfcreation,
382: modify => \&modify_selfcreation,
1.224 raeburn 383: },
1.69 raeburn 384: 'usermodification' =>
1.33 raeburn 385: { text => 'User modification',
1.67 raeburn 386: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 387: header => [{col1 => 'Target user has role',
1.227 bisitz 388: col2 => 'User information updatable in author context'},
1.33 raeburn 389: {col1 => 'Target user has role',
1.227 bisitz 390: col2 => 'User information updatable in course context'}],
1.230 raeburn 391: print => \&print_usermodification,
392: modify => \&modify_usermodification,
1.33 raeburn 393: },
1.69 raeburn 394: 'scantron' =>
1.95 www 395: { text => 'Bubblesheet format file',
1.67 raeburn 396: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 397: header => [ {col1 => 'Item',
398: col2 => '',
399: }],
1.230 raeburn 400: print => \&print_scantron,
401: modify => \&modify_scantron,
1.46 raeburn 402: },
1.86 raeburn 403: 'requestcourses' =>
404: {text => 'Request creation of courses',
405: help => 'Domain_Configuration_Request_Courses',
406: header => [{col1 => 'User affiliation',
1.102 raeburn 407: col2 => 'Availability/Processing of requests',},
408: {col1 => 'Setting',
1.216 raeburn 409: col2 => 'Value'},
410: {col1 => 'Available textbooks',
1.235 raeburn 411: col2 => ''},
1.242 raeburn 412: {col1 => 'Available templates',
413: col2 => ''},
1.235 raeburn 414: {col1 => 'Validation (not official courses)',
415: col2 => 'Value'},],
1.230 raeburn 416: print => \&print_quotas,
417: modify => \&modify_quotas,
1.86 raeburn 418: },
1.163 raeburn 419: 'requestauthor' =>
1.223 bisitz 420: {text => 'Request Authoring Space',
1.163 raeburn 421: help => 'Domain_Configuration_Request_Author',
422: header => [{col1 => 'User affiliation',
423: col2 => 'Availability/Processing of requests',},
424: {col1 => 'Setting',
425: col2 => 'Value'}],
1.230 raeburn 426: print => \&print_quotas,
427: modify => \&modify_quotas,
1.163 raeburn 428: },
1.69 raeburn 429: 'coursecategories' =>
1.120 raeburn 430: { text => 'Cataloging of courses/communities',
1.67 raeburn 431: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 432: header => [{col1 => 'Catalog type/availability',
433: col2 => '',},
434: {col1 => 'Category settings for standard catalog',
1.57 raeburn 435: col2 => '',},
436: {col1 => 'Categories',
437: col2 => '',
438: }],
1.230 raeburn 439: print => \&print_coursecategories,
440: modify => \&modify_coursecategories,
1.69 raeburn 441: },
442: 'serverstatuses' =>
1.77 raeburn 443: {text => 'Access to server status pages',
1.69 raeburn 444: help => 'Domain_Configuration_Server_Status',
445: header => [{col1 => 'Status Page',
446: col2 => 'Other named users',
447: col3 => 'Specific IPs',
448: }],
1.230 raeburn 449: print => \&print_serverstatuses,
450: modify => \&modify_serverstatuses,
1.69 raeburn 451: },
1.118 jms 452: 'helpsettings' =>
1.282 raeburn 453: {text => 'Support settings',
1.118 jms 454: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 455: header => [{col1 => 'Help Page Settings (logged-in users)',
456: col2 => 'Value'},
457: {col1 => 'Helpdesk Roles',
458: col2 => 'Settings'},],
1.230 raeburn 459: print => \&print_helpsettings,
460: modify => \&modify_helpsettings,
1.118 jms 461: },
1.121 raeburn 462: 'coursedefaults' =>
463: {text => 'Course/Community defaults',
464: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 465: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
466: col2 => 'Value',},
467: {col1 => 'Defaults which can be overridden for each course by a DC',
468: col2 => 'Value',},],
1.230 raeburn 469: print => \&print_coursedefaults,
470: modify => \&modify_coursedefaults,
1.121 raeburn 471: },
1.231 raeburn 472: 'selfenrollment' =>
473: {text => 'Self-enrollment in Course/Community',
474: help => 'Domain_Configuration_Selfenrollment',
475: header => [{col1 => 'Configuration Rights',
476: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
477: {col1 => 'Defaults',
478: col2 => 'Value'},
479: {col1 => 'Self-enrollment validation (optional)',
480: col2 => 'Value'},],
481: print => \&print_selfenrollment,
482: modify => \&modify_selfenrollment,
483: },
1.120 raeburn 484: 'privacy' =>
485: {text => 'User Privacy',
486: help => 'Domain_Configuration_User_Privacy',
487: header => [{col1 => 'Setting',
488: col2 => 'Value',}],
1.230 raeburn 489: print => \&print_privacy,
490: modify => \&modify_privacy,
1.120 raeburn 491: },
1.141 raeburn 492: 'usersessions' =>
1.145 raeburn 493: {text => 'User session hosting/offloading',
1.137 raeburn 494: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 495: header => [{col1 => 'Domain server',
496: col2 => 'Servers to offload sessions to when busy'},
497: {col1 => 'Hosting of users from other domains',
1.137 raeburn 498: col2 => 'Rules'},
499: {col1 => "Hosting domain's own users elsewhere",
500: col2 => 'Rules'}],
1.230 raeburn 501: print => \&print_usersessions,
502: modify => \&modify_usersessions,
1.137 raeburn 503: },
1.279 raeburn 504: 'loadbalancing' =>
1.185 raeburn 505: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 506: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 507: header => [{col1 => 'Balancers',
1.150 raeburn 508: col2 => 'Default destinations',
1.183 bisitz 509: col3 => 'User affiliation',
1.150 raeburn 510: col4 => 'Overrides'},
511: ],
1.230 raeburn 512: print => \&print_loadbalancing,
513: modify => \&modify_loadbalancing,
1.150 raeburn 514: },
1.279 raeburn 515: 'ltitools' =>
1.267 raeburn 516: {text => 'External Tools (LTI)',
1.296 raeburn 517: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 518: header => [{col1 => 'Setting',
519: col2 => 'Value',}],
520: print => \&print_ltitools,
521: modify => \&modify_ltitools,
522: },
1.279 raeburn 523: 'ssl' =>
1.275 raeburn 524: {text => 'LON-CAPA Network (SSL)',
525: help => 'Domain_Configuration_Network_SSL',
526: header => [{col1 => 'Server',
527: col2 => 'Certificate Status'},
528: {col1 => 'Connections to other servers',
529: col2 => 'Rules'},
1.293 raeburn 530: {col1 => 'Connections from other servers',
531: col2 => 'Rules'},
1.275 raeburn 532: {col1 => "Replicating domain's published content",
533: col2 => 'Rules'}],
534: print => \&print_ssl,
535: modify => \&modify_ssl,
536: },
1.279 raeburn 537: 'trust' =>
538: {text => 'Trust Settings',
539: help => 'Domain_Configuration_Trust',
540: header => [{col1 => "Access to this domain's content by others",
541: col2 => 'Rules'},
542: {col1 => "Access to other domain's content by this domain",
543: col2 => 'Rules'},
544: {col1 => "Enrollment in this domain's courses by others",
545: col2 => 'Rules',},
546: {col1 => "Co-author roles in this domain for others",
547: col2 => 'Rules',},
548: {col1 => "Co-author roles for this domain's users elsewhere",
549: col2 => 'Rules',},
550: {col1 => "Domain roles in this domain assignable to others",
551: col2 => 'Rules'},
552: {col1 => "Course catalog for this domain displayed elsewhere",
553: col2 => 'Rules'},
554: {col1 => "Requests for creation of courses in this domain by others",
555: col2 => 'Rules'},
556: {col1 => "Users in other domains can send messages to this domain",
557: col2 => 'Rules'},],
558: print => \&print_trust,
559: modify => \&modify_trust,
560: },
1.320 raeburn 561: 'lti' =>
562: {text => 'LTI Provider',
563: help => 'Domain_Configuration_LTI_Provider',
564: header => [{col1 => 'Setting',
565: col2 => 'Value',}],
566: print => \&print_lti,
567: modify => \&modify_lti,
568: },
1.3 raeburn 569: );
1.110 raeburn 570: if (keys(%servers) > 1) {
571: $prefs{'login'} = { text => 'Log-in page options',
572: help => 'Domain_Configuration_Login_Page',
573: header => [{col1 => 'Log-in Service',
574: col2 => 'Server Setting',},
575: {col1 => 'Log-in Page Items',
1.168 raeburn 576: col2 => ''},
577: {col1 => 'Log-in Help',
1.256 raeburn 578: col2 => 'Value'},
579: {col1 => 'Custom HTML in document head',
1.168 raeburn 580: col2 => 'Value'}],
1.230 raeburn 581: print => \&print_login,
582: modify => \&modify_login,
1.110 raeburn 583: };
584: }
1.174 foxr 585:
1.6 raeburn 586: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 587: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 588: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 589: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 590: text=>"Settings to display/modify"});
1.9 raeburn 591: my $confname = $dom.'-domainconfig';
1.174 foxr 592:
1.3 raeburn 593: if ($phase eq 'process') {
1.212 raeburn 594: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
595: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 596: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 597: $r->rflush();
1.212 raeburn 598: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 599: }
1.30 raeburn 600: } elsif ($phase eq 'display') {
1.192 raeburn 601: my $js = &recaptcha_js().
1.236 raeburn 602: &toggle_display_js();
1.171 raeburn 603: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 604: my ($othertitle,$usertypes,$types) =
605: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 606: $js .= &lonbalance_targets_js($dom,$types,\%servers,
607: $domconfig{'loadbalancing'}).
1.170 raeburn 608: &new_spares_js().
609: &common_domprefs_js().
610: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 611: }
1.216 raeburn 612: if (grep(/^requestcourses$/,@actions)) {
613: my $javascript_validations;
614: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
615: $js .= <<END;
616: <script type="text/javascript">
617: $javascript_validations
618: </script>
619: $coursebrowserjs
620: END
621: }
1.305 raeburn 622: if (grep(/^selfcreation$/,@actions)) {
623: $js .= &selfcreate_javascript();
624: }
1.286 raeburn 625: if (grep(/^contacts$/,@actions)) {
626: $js .= &contacts_javascript();
627: }
1.150 raeburn 628: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 629: } else {
1.180 raeburn 630: # check if domconfig user exists for the domain.
631: my $servadm = $r->dir_config('lonAdmEMail');
632: my ($configuserok,$author_ok,$switchserver) =
633: &config_check($dom,$confname,$servadm);
634: unless ($configuserok eq 'ok') {
1.181 raeburn 635: &Apache::lonconfigsettings::print_header($r,$phase,$context);
636: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 637: $confname).
1.181 raeburn 638: '<br />'
639: );
1.180 raeburn 640: if ($switchserver) {
1.181 raeburn 641: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
642: '<br />'.
643: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
644: '<br />'.
645: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
646: '<br />'.
647: &mt('To do that now, use the following link: [_1]',$switchserver)
648: );
649: } else {
650: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
651: '<br />'.
652: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
653: );
1.180 raeburn 654: }
655: $r->print(&Apache::loncommon::end_page());
656: return OK;
657: }
1.21 raeburn 658: if (keys(%domconfig) == 0) {
659: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 660: my @ids=&Apache::lonnet::current_machine_ids();
661: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 662: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 663: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 664: my $custom_img_count = 0;
665: foreach my $img (@loginimages) {
666: if ($designhash{$dom.'.login.'.$img} ne '') {
667: $custom_img_count ++;
668: }
669: }
670: foreach my $role (@roles) {
671: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
672: $custom_img_count ++;
673: }
674: }
675: if ($custom_img_count > 0) {
1.94 raeburn 676: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 677: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 678: $r->print(
679: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
680: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
681: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
682: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
683: if ($switch_server) {
1.30 raeburn 684: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 685: }
1.91 raeburn 686: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 687: return OK;
688: }
689: }
690: }
1.91 raeburn 691: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 692: }
693: return OK;
694: }
695:
696: sub process_changes {
1.205 raeburn 697: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 698: my %domconfig;
699: if (ref($values) eq 'HASH') {
700: %domconfig = %{$values};
701: }
1.3 raeburn 702: my $output;
703: if ($action eq 'login') {
1.205 raeburn 704: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 705: } elsif ($action eq 'rolecolors') {
1.9 raeburn 706: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 707: $lastactref,%domconfig);
1.3 raeburn 708: } elsif ($action eq 'quotas') {
1.216 raeburn 709: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 710: } elsif ($action eq 'autoenroll') {
1.205 raeburn 711: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 712: } elsif ($action eq 'autoupdate') {
713: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 714: } elsif ($action eq 'autocreate') {
715: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 716: } elsif ($action eq 'directorysrch') {
1.295 raeburn 717: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 718: } elsif ($action eq 'usercreation') {
1.28 raeburn 719: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 720: } elsif ($action eq 'selfcreation') {
1.305 raeburn 721: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 722: } elsif ($action eq 'usermodification') {
723: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 724: } elsif ($action eq 'contacts') {
1.205 raeburn 725: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 726: } elsif ($action eq 'defaults') {
1.212 raeburn 727: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 728: } elsif ($action eq 'scantron') {
1.205 raeburn 729: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 730: } elsif ($action eq 'coursecategories') {
1.239 raeburn 731: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 732: } elsif ($action eq 'serverstatuses') {
733: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 734: } elsif ($action eq 'requestcourses') {
1.216 raeburn 735: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 736: } elsif ($action eq 'requestauthor') {
1.216 raeburn 737: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 738: } elsif ($action eq 'helpsettings') {
1.285 raeburn 739: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 740: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 741: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 742: } elsif ($action eq 'selfenrollment') {
743: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 744: } elsif ($action eq 'usersessions') {
1.212 raeburn 745: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 746: } elsif ($action eq 'loadbalancing') {
747: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 748: } elsif ($action eq 'ltitools') {
749: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 750: } elsif ($action eq 'ssl') {
751: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 752: } elsif ($action eq 'trust') {
753: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 754: } elsif ($action eq 'lti') {
755: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 756: }
757: return $output;
758: }
759:
760: sub print_config_box {
1.9 raeburn 761: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 762: my $rowtotal = 0;
1.49 raeburn 763: my $output;
764: if ($action eq 'coursecategories') {
765: $output = &coursecategories_javascript($settings);
1.236 raeburn 766: } elsif ($action eq 'defaults') {
767: $output = &defaults_javascript($settings);
1.282 raeburn 768: } elsif ($action eq 'helpsettings') {
769: my (%privs,%levelscurrent);
770: my %full=();
771: my %levels=(
772: course => {},
773: domain => {},
774: system => {},
775: );
776: my $context = 'domain';
777: my $crstype = 'Course';
778: my $formname = 'display';
779: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
780: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
781: $output =
782: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
783: \@templateroles);
1.91 raeburn 784: }
1.236 raeburn 785: $output .=
1.30 raeburn 786: '<table class="LC_nested_outer">
1.3 raeburn 787: <tr>
1.306 raeburn 788: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 789: &mt($item->{text}).' '.
790: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
791: '</tr>';
1.30 raeburn 792: $rowtotal ++;
1.110 raeburn 793: my $numheaders = 1;
794: if (ref($item->{'header'}) eq 'ARRAY') {
795: $numheaders = scalar(@{$item->{'header'}});
796: }
797: if ($numheaders > 1) {
1.64 raeburn 798: my $colspan = '';
1.145 raeburn 799: my $rightcolspan = '';
1.238 raeburn 800: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 801: ($action eq 'directorysrch') ||
1.256 raeburn 802: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 803: $colspan = ' colspan="2"';
804: }
1.145 raeburn 805: if ($action eq 'usersessions') {
806: $rightcolspan = ' colspan="3"';
807: }
1.30 raeburn 808: $output .= '
1.3 raeburn 809: <tr>
810: <td>
811: <table class="LC_nested">
812: <tr class="LC_info_row">
1.59 bisitz 813: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 814: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 815: </tr>';
1.69 raeburn 816: $rowtotal ++;
1.230 raeburn 817: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 818: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 819: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 820: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
821: ($action eq 'contacts')) {
1.230 raeburn 822: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 823: } elsif ($action eq 'coursecategories') {
1.230 raeburn 824: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 825: } elsif ($action eq 'login') {
1.256 raeburn 826: if ($numheaders == 4) {
1.168 raeburn 827: $colspan = ' colspan="2"';
828: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
829: } else {
830: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
831: }
1.230 raeburn 832: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 833: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 834: } elsif ($action eq 'rolecolors') {
1.30 raeburn 835: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 836: }
1.30 raeburn 837: $output .= '
1.6 raeburn 838: </table>
839: </td>
840: </tr>
841: <tr>
842: <td>
843: <table class="LC_nested">
844: <tr class="LC_info_row">
1.230 raeburn 845: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 846: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 847: </tr>';
848: $rowtotal ++;
1.230 raeburn 849: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
850: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 851: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.294 raeburn 852: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {
1.238 raeburn 853: if ($action eq 'coursecategories') {
854: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
855: $colspan = ' colspan="2"';
1.279 raeburn 856: } elsif ($action eq 'trust') {
857: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 858: } else {
859: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
860: }
1.279 raeburn 861: if ($action eq 'trust') {
862: $output .= '
863: </table>
864: </td>
865: </tr>';
866: my @trusthdrs = qw(2 3 4 5 6 7);
867: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
868: for (my $i=0; $i<@trusthdrs; $i++) {
869: $output .= '
870: <tr>
871: <td>
872: <table class="LC_nested">
873: <tr class="LC_info_row">
874: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
875: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
876: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
877: </table>
878: </td>
879: </tr>';
880: }
881: $output .= '
882: <tr>
883: <td>
884: <table class="LC_nested">
885: <tr class="LC_info_row">
886: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
887: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
888: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
889: } else {
890: $output .= '
1.63 raeburn 891: </table>
892: </td>
893: </tr>
894: <tr>
895: <td>
896: <table class="LC_nested">
897: <tr class="LC_info_row">
898: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 899: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 900: </tr>'."\n";
1.279 raeburn 901: if ($action eq 'coursecategories') {
902: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
903: } else {
904: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
905: }
1.238 raeburn 906: }
1.63 raeburn 907: $rowtotal ++;
1.236 raeburn 908: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 909: ($action eq 'defaults') || ($action eq 'directorysrch') ||
910: ($action eq 'helpsettings')) {
1.230 raeburn 911: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.293 raeburn 912: } elsif ($action eq 'ssl') {
913: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
914: </table>
915: </td>
916: </tr>
917: <tr>
918: <td>
919: <table class="LC_nested">
920: <tr class="LC_info_row">
921: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
922: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
923: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
924: </table>
925: </td>
926: </tr>
927: <tr>
928: <td>
929: <table class="LC_nested">
930: <tr class="LC_info_row">
931: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
932: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
933: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 934: } elsif ($action eq 'login') {
1.256 raeburn 935: if ($numheaders == 4) {
1.168 raeburn 936: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
937: </table>
938: </td>
939: </tr>
940: <tr>
941: <td>
942: <table class="LC_nested">
943: <tr class="LC_info_row">
944: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 945: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 946: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
947: $rowtotal ++;
948: } else {
949: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
950: }
1.256 raeburn 951: $output .= '
952: </table>
953: </td>
954: </tr>
955: <tr>
956: <td>
957: <table class="LC_nested">
958: <tr class="LC_info_row">';
959: if ($numheaders == 4) {
960: $output .= '
961: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
962: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
963: </tr>';
964: } else {
965: $output .= '
966: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
967: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
968: </tr>';
969: }
970: $rowtotal ++;
971: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 972: } elsif ($action eq 'requestcourses') {
1.247 raeburn 973: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
974: $rowtotal ++;
975: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 976: </table>
977: </td>
978: </tr>
979: <tr>
980: <td>
981: <table class="LC_nested">
982: <tr class="LC_info_row">
983: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
984: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 985: &textbookcourses_javascript($settings).
986: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
987: </table>
988: </td>
989: </tr>
990: <tr>
991: <td>
992: <table class="LC_nested">
993: <tr class="LC_info_row">
994: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
995: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
996: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 997: </table>
998: </td>
999: </tr>
1000: <tr>
1001: <td>
1002: <table class="LC_nested">
1003: <tr class="LC_info_row">
1.306 raeburn 1004: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1005: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1006: </tr>'.
1007: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1008: } elsif ($action eq 'requestauthor') {
1009: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1010: $rowtotal ++;
1.122 jms 1011: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1012: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1013: </table>
1014: </td>
1015: </tr>
1016: <tr>
1017: <td>
1018: <table class="LC_nested">
1019: <tr class="LC_info_row">
1.306 raeburn 1020: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1021: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1022: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1023: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1024: </tr>'.
1.30 raeburn 1025: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1026: </table>
1027: </td>
1028: </tr>
1029: <tr>
1030: <td>
1031: <table class="LC_nested">
1032: <tr class="LC_info_row">
1.59 bisitz 1033: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1034: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1035: </tr>'.
1.30 raeburn 1036: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1037: $rowtotal += 2;
1.6 raeburn 1038: }
1.3 raeburn 1039: } else {
1.30 raeburn 1040: $output .= '
1.3 raeburn 1041: <tr>
1042: <td>
1043: <table class="LC_nested">
1.30 raeburn 1044: <tr class="LC_info_row">';
1.277 raeburn 1045: if ($action eq 'login') {
1.30 raeburn 1046: $output .= '
1.59 bisitz 1047: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1048: } elsif ($action eq 'serverstatuses') {
1049: $output .= '
1.306 raeburn 1050: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1051: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1052:
1.6 raeburn 1053: } else {
1.30 raeburn 1054: $output .= '
1.306 raeburn 1055: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1056: }
1.72 raeburn 1057: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1058: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1059: &mt($item->{'header'}->[0]->{'col2'});
1060: if ($action eq 'serverstatuses') {
1061: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1062: }
1.69 raeburn 1063: } else {
1.306 raeburn 1064: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1065: &mt($item->{'header'}->[0]->{'col2'});
1066: }
1067: $output .= '</td>';
1068: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1069: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1070: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1071: &mt($item->{'header'}->[0]->{'col3'});
1072: } else {
1.306 raeburn 1073: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1074: &mt($item->{'header'}->[0]->{'col3'});
1075: }
1.69 raeburn 1076: if ($action eq 'serverstatuses') {
1077: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1078: }
1079: $output .= '</td>';
1.6 raeburn 1080: }
1.150 raeburn 1081: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1082: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1083: &mt($item->{'header'}->[0]->{'col4'});
1084: }
1.69 raeburn 1085: $output .= '</tr>';
1.48 raeburn 1086: $rowtotal ++;
1.168 raeburn 1087: if ($action eq 'quotas') {
1.86 raeburn 1088: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1089: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1090: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.320 raeburn 1091: ($action eq 'ltitools') || ($action eq 'lti')) {
1.230 raeburn 1092: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1093: } elsif ($action eq 'scantron') {
1094: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1095: }
1.3 raeburn 1096: }
1.30 raeburn 1097: $output .= '
1.3 raeburn 1098: </table>
1099: </td>
1100: </tr>
1.30 raeburn 1101: </table><br />';
1102: return ($output,$rowtotal);
1.1 raeburn 1103: }
1104:
1.3 raeburn 1105: sub print_login {
1.168 raeburn 1106: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1107: my ($css_class,$datatable);
1.6 raeburn 1108: my %choices = &login_choices();
1.110 raeburn 1109:
1.168 raeburn 1110: if ($caller eq 'service') {
1.149 raeburn 1111: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1112: my $choice = $choices{'disallowlogin'};
1113: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1114: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1115: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1116: '<th>'.$choices{'server'}.'</th>'.
1117: '<th>'.$choices{'serverpath'}.'</th>'.
1118: '<th>'.$choices{'custompath'}.'</th>'.
1119: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1120: my %disallowed;
1121: if (ref($settings) eq 'HASH') {
1122: if (ref($settings->{'loginvia'}) eq 'HASH') {
1123: %disallowed = %{$settings->{'loginvia'}};
1124: }
1125: }
1126: foreach my $lonhost (sort(keys(%servers))) {
1127: my $direct = 'selected="selected"';
1.128 raeburn 1128: if (ref($disallowed{$lonhost}) eq 'HASH') {
1129: if ($disallowed{$lonhost}{'server'} ne '') {
1130: $direct = '';
1131: }
1.110 raeburn 1132: }
1.115 raeburn 1133: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1134: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1135: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1136: '</option>';
1.184 raeburn 1137: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1138: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1139: my $selected = '';
1.128 raeburn 1140: if (ref($disallowed{$lonhost}) eq 'HASH') {
1141: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1142: $selected = 'selected="selected"';
1143: }
1.110 raeburn 1144: }
1145: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1146: $servers{$hostid}.'</option>';
1147: }
1.128 raeburn 1148: $datatable .= '</select></td>'.
1149: '<td><select name="'.$lonhost.'_serverpath">';
1150: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1151: my $pathname = $path;
1152: if ($path eq 'custom') {
1153: $pathname = &mt('Custom Path').' ->';
1154: }
1155: my $selected = '';
1156: if (ref($disallowed{$lonhost}) eq 'HASH') {
1157: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1158: $selected = 'selected="selected"';
1159: }
1160: } elsif ($path eq '') {
1161: $selected = 'selected="selected"';
1162: }
1163: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1164: }
1165: $datatable .= '</select></td>';
1166: my ($custom,$exempt);
1167: if (ref($disallowed{$lonhost}) eq 'HASH') {
1168: $custom = $disallowed{$lonhost}{'custompath'};
1169: $exempt = $disallowed{$lonhost}{'exempt'};
1170: }
1171: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1172: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1173: '</tr>';
1.110 raeburn 1174: }
1175: $datatable .= '</table></td></tr>';
1176: return $datatable;
1.168 raeburn 1177: } elsif ($caller eq 'page') {
1178: my %defaultchecked = (
1179: 'coursecatalog' => 'on',
1.188 raeburn 1180: 'helpdesk' => 'on',
1.168 raeburn 1181: 'adminmail' => 'off',
1182: 'newuser' => 'off',
1183: );
1.188 raeburn 1184: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1185: my (%checkedon,%checkedoff);
1.42 raeburn 1186: foreach my $item (@toggles) {
1.168 raeburn 1187: if ($defaultchecked{$item} eq 'on') {
1188: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1189: $checkedoff{$item} = ' ';
1.168 raeburn 1190: } elsif ($defaultchecked{$item} eq 'off') {
1191: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1192: $checkedon{$item} = ' ';
1193: }
1.1 raeburn 1194: }
1.168 raeburn 1195: my @images = ('img','logo','domlogo','login');
1196: my @logintext = ('textcol','bgcol');
1197: my @bgs = ('pgbg','mainbg','sidebg');
1198: my @links = ('link','alink','vlink');
1199: my %designhash = &Apache::loncommon::get_domainconf($dom);
1200: my %defaultdesign = %Apache::loncommon::defaultdesign;
1201: my (%is_custom,%designs);
1202: my %defaults = (
1203: font => $defaultdesign{'login.font'},
1204: );
1.6 raeburn 1205: foreach my $item (@images) {
1.168 raeburn 1206: $defaults{$item} = $defaultdesign{'login.'.$item};
1207: $defaults{'showlogo'}{$item} = 1;
1208: }
1209: foreach my $item (@bgs) {
1210: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1211: }
1.41 raeburn 1212: foreach my $item (@logintext) {
1.168 raeburn 1213: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1214: }
1.168 raeburn 1215: foreach my $item (@links) {
1216: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1217: }
1.168 raeburn 1218: if (ref($settings) eq 'HASH') {
1219: foreach my $item (@toggles) {
1220: if ($settings->{$item} eq '1') {
1221: $checkedon{$item} = ' checked="checked" ';
1222: $checkedoff{$item} = ' ';
1223: } elsif ($settings->{$item} eq '0') {
1224: $checkedoff{$item} = ' checked="checked" ';
1225: $checkedon{$item} = ' ';
1226: }
1227: }
1228: foreach my $item (@images) {
1229: if (defined($settings->{$item})) {
1230: $designs{$item} = $settings->{$item};
1231: $is_custom{$item} = 1;
1232: }
1233: if (defined($settings->{'showlogo'}{$item})) {
1234: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1235: }
1236: }
1237: foreach my $item (@logintext) {
1238: if ($settings->{$item} ne '') {
1239: $designs{'logintext'}{$item} = $settings->{$item};
1240: $is_custom{$item} = 1;
1241: }
1242: }
1243: if ($settings->{'font'} ne '') {
1244: $designs{'font'} = $settings->{'font'};
1245: $is_custom{'font'} = 1;
1246: }
1247: foreach my $item (@bgs) {
1248: if ($settings->{$item} ne '') {
1249: $designs{'bgs'}{$item} = $settings->{$item};
1250: $is_custom{$item} = 1;
1251: }
1252: }
1253: foreach my $item (@links) {
1254: if ($settings->{$item} ne '') {
1255: $designs{'links'}{$item} = $settings->{$item};
1256: $is_custom{$item} = 1;
1257: }
1258: }
1259: } else {
1260: if ($designhash{$dom.'.login.font'} ne '') {
1261: $designs{'font'} = $designhash{$dom.'.login.font'};
1262: $is_custom{'font'} = 1;
1263: }
1264: foreach my $item (@images) {
1265: if ($designhash{$dom.'.login.'.$item} ne '') {
1266: $designs{$item} = $designhash{$dom.'.login.'.$item};
1267: $is_custom{$item} = 1;
1268: }
1269: }
1270: foreach my $item (@bgs) {
1271: if ($designhash{$dom.'.login.'.$item} ne '') {
1272: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1273: $is_custom{$item} = 1;
1274: }
1.6 raeburn 1275: }
1.168 raeburn 1276: foreach my $item (@links) {
1277: if ($designhash{$dom.'.login.'.$item} ne '') {
1278: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1279: $is_custom{$item} = 1;
1280: }
1.6 raeburn 1281: }
1282: }
1.168 raeburn 1283: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1284: logo => 'Institution Logo',
1285: domlogo => 'Domain Logo',
1286: login => 'Login box');
1287: my $itemcount = 1;
1288: foreach my $item (@toggles) {
1289: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1290: $datatable .=
1291: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1292: '</td><td>'.
1293: '<span class="LC_nobreak"><label><input type="radio" name="'.
1294: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1295: '</label> <label><input type="radio" name="'.$item.'"'.
1296: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1297: '</tr>';
1298: $itemcount ++;
1.6 raeburn 1299: }
1.168 raeburn 1300: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1301: $datatable .= '</tr></table></td></tr>';
1302: } elsif ($caller eq 'help') {
1303: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1304: my $switchserver = &check_switchserver($dom,$confname);
1305: my $itemcount = 1;
1306: $defaulturl = '/adm/loginproblems.html';
1307: $defaulttype = 'default';
1308: %lt = &Apache::lonlocal::texthash (
1309: del => 'Delete?',
1310: rep => 'Replace:',
1311: upl => 'Upload:',
1312: default => 'Default',
1313: custom => 'Custom',
1314: );
1315: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1316: my @currlangs;
1317: if (ref($settings) eq 'HASH') {
1318: if (ref($settings->{'helpurl'}) eq 'HASH') {
1319: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1320: next if ($settings->{'helpurl'}{$key} eq '');
1321: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1322: $type{$key} = 'custom';
1323: unless ($key eq 'nolang') {
1324: push(@currlangs,$key);
1325: }
1326: }
1327: } elsif ($settings->{'helpurl'} ne '') {
1328: $type{'nolang'} = 'custom';
1329: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1330: }
1331: }
1.168 raeburn 1332: foreach my $lang ('nolang',sort(@currlangs)) {
1333: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1334: $datatable .= '<tr'.$css_class.'>';
1335: if ($url{$lang} eq '') {
1336: $url{$lang} = $defaulturl;
1337: }
1338: if ($type{$lang} eq '') {
1339: $type{$lang} = $defaulttype;
1340: }
1341: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1342: if ($lang eq 'nolang') {
1343: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1344: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1345: } else {
1346: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1347: $langchoices{$lang},
1348: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1349: }
1350: $datatable .= '</span></td>'."\n".
1351: '<td class="LC_left_item">';
1352: if ($type{$lang} eq 'custom') {
1353: $datatable .= '<span class="LC_nobreak"><label>'.
1354: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1355: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1356: } else {
1357: $datatable .= $lt{'upl'};
1358: }
1359: $datatable .='<br />';
1360: if ($switchserver) {
1361: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1362: } else {
1363: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1364: }
1.168 raeburn 1365: $datatable .= '</td></tr>';
1366: $itemcount ++;
1.6 raeburn 1367: }
1.168 raeburn 1368: my @addlangs;
1369: foreach my $lang (sort(keys(%langchoices))) {
1370: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1371: push(@addlangs,$lang);
1372: }
1373: if (@addlangs > 0) {
1374: my %toadd;
1375: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1376: $toadd{''} = &mt('Select');
1377: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1378: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1379: &mt('Add log-in help page for a specific language:').' '.
1380: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1381: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1382: if ($switchserver) {
1383: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1384: } else {
1385: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1386: }
1.168 raeburn 1387: $datatable .= '</td></tr>';
1.169 raeburn 1388: $itemcount ++;
1.6 raeburn 1389: }
1.169 raeburn 1390: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1391: } elsif ($caller eq 'headtag') {
1392: my %domservers = &Apache::lonnet::get_servers($dom);
1393: my $choice = $choices{'headtag'};
1394: $css_class = ' class="LC_odd_row"';
1395: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1396: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1397: '<th>'.$choices{'current'}.'</th>'.
1398: '<th>'.$choices{'action'}.'</th>'.
1399: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1400: my (%currurls,%currexempt);
1401: if (ref($settings) eq 'HASH') {
1402: if (ref($settings->{'headtag'}) eq 'HASH') {
1403: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1404: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1405: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1406: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1407: }
1408: }
1409: }
1410: }
1411: my %lt = &Apache::lonlocal::texthash(
1412: del => 'Delete?',
1413: rep => 'Replace:',
1414: upl => 'Upload:',
1415: curr => 'View contents',
1416: none => 'None',
1417: );
1418: my $switchserver = &check_switchserver($dom,$confname);
1419: foreach my $lonhost (sort(keys(%domservers))) {
1420: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1421: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1422: if ($currurls{$lonhost}) {
1423: $datatable .= '<td class="LC_right_item"><a href="'.
1424: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1425: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1426: '">'.$lt{'curr'}.'</a></td>'.
1427: '<td><span class="LC_nobreak"><label>'.
1428: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1429: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1430: } else {
1431: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1432: }
1433: $datatable .='<br />';
1434: if ($switchserver) {
1435: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1436: } else {
1437: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1438: }
1439: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1440: }
1441: $datatable .= '</table></td></tr>';
1.1 raeburn 1442: }
1.6 raeburn 1443: return $datatable;
1444: }
1445:
1446: sub login_choices {
1447: my %choices =
1448: &Apache::lonlocal::texthash (
1.116 bisitz 1449: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1450: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1451: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1452: disallowlogin => "Login page requests redirected",
1453: hostid => "Server",
1.128 raeburn 1454: server => "Redirect to:",
1455: serverpath => "Path",
1456: custompath => "Custom",
1457: exempt => "Exempt IP(s)",
1.110 raeburn 1458: directlogin => "No redirect",
1459: newuser => "Link to create a user account",
1460: img => "Header",
1461: logo => "Main Logo",
1462: domlogo => "Domain Logo",
1463: login => "Log-in Header",
1464: textcol => "Text color",
1465: bgcol => "Box color",
1466: bgs => "Background colors",
1467: links => "Link colors",
1468: font => "Font color",
1469: pgbg => "Header",
1470: mainbg => "Page",
1471: sidebg => "Login box",
1472: link => "Link",
1473: alink => "Active link",
1474: vlink => "Visited link",
1.256 raeburn 1475: headtag => "Custom markup",
1476: action => "Action",
1477: current => "Current",
1.6 raeburn 1478: );
1479: return %choices;
1480: }
1481:
1482: sub print_rolecolors {
1.30 raeburn 1483: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1484: my %choices = &color_font_choices();
1485: my @bgs = ('pgbg','tabbg','sidebg');
1486: my @links = ('link','alink','vlink');
1487: my @images = ('img');
1488: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1489: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1490: my %defaultdesign = %Apache::loncommon::defaultdesign;
1491: my (%is_custom,%designs);
1.200 raeburn 1492: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1493: if (ref($settings) eq 'HASH') {
1494: if (ref($settings->{$role}) eq 'HASH') {
1495: if ($settings->{$role}->{'img'} ne '') {
1496: $designs{'img'} = $settings->{$role}->{'img'};
1497: $is_custom{'img'} = 1;
1498: }
1499: if ($settings->{$role}->{'font'} ne '') {
1500: $designs{'font'} = $settings->{$role}->{'font'};
1501: $is_custom{'font'} = 1;
1502: }
1.97 tempelho 1503: if ($settings->{$role}->{'fontmenu'} ne '') {
1504: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1505: $is_custom{'fontmenu'} = 1;
1506: }
1.6 raeburn 1507: foreach my $item (@bgs) {
1508: if ($settings->{$role}->{$item} ne '') {
1509: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1510: $is_custom{$item} = 1;
1511: }
1512: }
1513: foreach my $item (@links) {
1514: if ($settings->{$role}->{$item} ne '') {
1515: $designs{'links'}{$item} = $settings->{$role}->{$item};
1516: $is_custom{$item} = 1;
1517: }
1518: }
1519: }
1520: } else {
1521: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1522: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1523: $is_custom{'img'} = 1;
1524: }
1.97 tempelho 1525: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1526: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1527: $is_custom{'fontmenu'} = 1;
1528: }
1.6 raeburn 1529: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1530: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1531: $is_custom{'font'} = 1;
1532: }
1533: foreach my $item (@bgs) {
1534: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1535: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1536: $is_custom{$item} = 1;
1537:
1538: }
1539: }
1540: foreach my $item (@links) {
1541: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1542: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1543: $is_custom{$item} = 1;
1544: }
1545: }
1546: }
1547: my $itemcount = 1;
1.30 raeburn 1548: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1549: $datatable .= '</tr></table></td></tr>';
1550: return $datatable;
1551: }
1552:
1.200 raeburn 1553: sub role_defaults {
1554: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1555: my %defaults;
1556: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1557: return %defaults;
1558: }
1559: my %defaultdesign = %Apache::loncommon::defaultdesign;
1560: if ($role eq 'login') {
1561: %defaults = (
1562: font => $defaultdesign{$role.'.font'},
1563: );
1564: if (ref($logintext) eq 'ARRAY') {
1565: foreach my $item (@{$logintext}) {
1566: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1567: }
1568: }
1569: foreach my $item (@{$images}) {
1570: $defaults{'showlogo'}{$item} = 1;
1571: }
1572: } else {
1573: %defaults = (
1574: img => $defaultdesign{$role.'.img'},
1575: font => $defaultdesign{$role.'.font'},
1576: fontmenu => $defaultdesign{$role.'.fontmenu'},
1577: );
1578: }
1579: foreach my $item (@{$bgs}) {
1580: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1581: }
1582: foreach my $item (@{$links}) {
1583: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1584: }
1585: foreach my $item (@{$images}) {
1586: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1587: }
1588: return %defaults;
1589: }
1590:
1.6 raeburn 1591: sub display_color_options {
1.9 raeburn 1592: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1593: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1594: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1595: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1596: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1597: '<td>'.$choices->{'font'}.'</td>';
1598: if (!$is_custom->{'font'}) {
1.30 raeburn 1599: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1600: } else {
1601: $datatable .= '<td> </td>';
1602: }
1.174 foxr 1603: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1604:
1.8 raeburn 1605: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1606: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1607: ' value="'.$current_color.'" /> '.
1.174 foxr 1608: ' </td></tr>';
1.107 raeburn 1609: unless ($role eq 'login') {
1610: $datatable .= '<tr'.$css_class.'>'.
1611: '<td>'.$choices->{'fontmenu'}.'</td>';
1612: if (!$is_custom->{'fontmenu'}) {
1613: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1614: } else {
1615: $datatable .= '<td> </td>';
1616: }
1.202 raeburn 1617: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1618: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1619: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1620: '<input class="colorchooser" type="text" size="10" name="'
1621: .$role.'_fontmenu"'.
1622: ' value="'.$current_color.'" /> '.
1623: ' </td></tr>';
1.97 tempelho 1624: }
1.9 raeburn 1625: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1626: foreach my $img (@{$images}) {
1.18 albertel 1627: $itemcount ++;
1.6 raeburn 1628: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1629: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1630: '<td>'.$choices->{$img};
1.41 raeburn 1631: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1632: if ($role eq 'login') {
1633: if ($img eq 'login') {
1634: $login_hdr_pick =
1.135 bisitz 1635: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1636: $logincolors =
1637: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1638: $designs,$defaults);
1.70 raeburn 1639: } elsif ($img ne 'domlogo') {
1640: $datatable.= &logo_display_options($img,$defaults,$designs);
1641: }
1642: }
1643: $datatable .= '</td>';
1.6 raeburn 1644: if ($designs->{$img} ne '') {
1645: $imgfile = $designs->{$img};
1.18 albertel 1646: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1647: } else {
1648: $imgfile = $defaults->{$img};
1649: }
1650: if ($imgfile) {
1.9 raeburn 1651: my ($showfile,$fullsize);
1652: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1653: my $urldir = $1;
1654: my $filename = $2;
1655: my @info = &Apache::lonnet::stat_file($designs->{$img});
1656: if (@info) {
1657: my $thumbfile = 'tn-'.$filename;
1658: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1659: if (@thumb) {
1660: $showfile = $urldir.'/'.$thumbfile;
1661: } else {
1662: $showfile = $imgfile;
1663: }
1664: } else {
1665: $showfile = '';
1666: }
1667: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1668: $showfile = $imgfile;
1.6 raeburn 1669: my $imgdir = $1;
1670: my $filename = $2;
1.159 raeburn 1671: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1672: $showfile = "/$imgdir/tn-".$filename;
1673: } else {
1.159 raeburn 1674: my $input = $londocroot.$imgfile;
1675: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1676: if (!-e $output) {
1.9 raeburn 1677: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1678: my ($fullwidth,$fullheight) = &check_dimensions($input);
1679: if ($fullwidth ne '' && $fullheight ne '') {
1680: if ($fullwidth > $width && $fullheight > $height) {
1681: my $size = $width.'x'.$height;
1.316 raeburn 1682: my @args = ('convert','-sample',$size,$input,$output);
1683: system({$args[0]} @args);
1.159 raeburn 1684: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1685: }
1686: }
1.6 raeburn 1687: }
1688: }
1.16 raeburn 1689: }
1.6 raeburn 1690: if ($showfile) {
1.40 raeburn 1691: if ($showfile =~ m{^/(adm|res)/}) {
1692: if ($showfile =~ m{^/res/}) {
1693: my $local_showfile =
1694: &Apache::lonnet::filelocation('',$showfile);
1695: &Apache::lonnet::repcopy($local_showfile);
1696: }
1697: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1698: }
1699: if ($imgfile) {
1700: if ($imgfile =~ m{^/(adm|res)/}) {
1701: if ($imgfile =~ m{^/res/}) {
1702: my $local_imgfile =
1703: &Apache::lonnet::filelocation('',$imgfile);
1704: &Apache::lonnet::repcopy($local_imgfile);
1705: }
1706: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1707: } else {
1708: $fullsize = $imgfile;
1709: }
1710: }
1.41 raeburn 1711: $datatable .= '<td>';
1712: if ($img eq 'login') {
1.135 bisitz 1713: $datatable .= $login_hdr_pick;
1714: }
1.41 raeburn 1715: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1716: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1717: } else {
1.201 raeburn 1718: $datatable .= '<td> </td><td class="LC_left_item">'.
1719: &mt('Upload:').'<br />';
1.6 raeburn 1720: }
1721: } else {
1.201 raeburn 1722: $datatable .= '<td> </td><td class="LC_left_item">'.
1723: &mt('Upload:').'<br />';
1.6 raeburn 1724: }
1.9 raeburn 1725: if ($switchserver) {
1726: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1727: } else {
1.135 bisitz 1728: if ($img ne 'login') { # suppress file selection for Log-in header
1729: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1730: }
1.9 raeburn 1731: }
1732: $datatable .= '</td></tr>';
1.6 raeburn 1733: }
1734: $itemcount ++;
1735: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1736: $datatable .= '<tr'.$css_class.'>'.
1737: '<td>'.$choices->{'bgs'}.'</td>';
1738: my $bgs_def;
1739: foreach my $item (@{$bgs}) {
1740: if (!$is_custom->{$item}) {
1.70 raeburn 1741: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1742: }
1743: }
1744: if ($bgs_def) {
1.8 raeburn 1745: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1746: } else {
1747: $datatable .= '<td> </td>';
1748: }
1749: $datatable .= '<td class="LC_right_item">'.
1750: '<table border="0"><tr>';
1.174 foxr 1751:
1.6 raeburn 1752: foreach my $item (@{$bgs}) {
1.306 raeburn 1753: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1754: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1755: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1756: $datatable .= ' ';
1.6 raeburn 1757: }
1.174 foxr 1758: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1759: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1760: }
1761: $datatable .= '</tr></table></td></tr>';
1762: $itemcount ++;
1763: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1764: $datatable .= '<tr'.$css_class.'>'.
1765: '<td>'.$choices->{'links'}.'</td>';
1766: my $links_def;
1767: foreach my $item (@{$links}) {
1768: if (!$is_custom->{$item}) {
1.30 raeburn 1769: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1770: }
1771: }
1772: if ($links_def) {
1.8 raeburn 1773: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1774: } else {
1775: $datatable .= '<td> </td>';
1776: }
1777: $datatable .= '<td class="LC_right_item">'.
1778: '<table border="0"><tr>';
1779: foreach my $item (@{$links}) {
1.234 raeburn 1780: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1781: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1782: if ($designs->{'links'}{$item}) {
1.174 foxr 1783: $datatable.=' ';
1.6 raeburn 1784: }
1.174 foxr 1785: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1786: '" /></td>';
1787: }
1.30 raeburn 1788: $$rowtotal += $itemcount;
1.3 raeburn 1789: return $datatable;
1790: }
1791:
1.70 raeburn 1792: sub logo_display_options {
1793: my ($img,$defaults,$designs) = @_;
1794: my $checkedon;
1795: if (ref($defaults) eq 'HASH') {
1796: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1797: if ($defaults->{'showlogo'}{$img}) {
1798: $checkedon = 'checked="checked" ';
1799: }
1800: }
1801: }
1802: if (ref($designs) eq 'HASH') {
1803: if (ref($designs->{'showlogo'}) eq 'HASH') {
1804: if (defined($designs->{'showlogo'}{$img})) {
1805: if ($designs->{'showlogo'}{$img} == 0) {
1806: $checkedon = '';
1807: } elsif ($designs->{'showlogo'}{$img} == 1) {
1808: $checkedon = 'checked="checked" ';
1809: }
1810: }
1811: }
1812: }
1813: return '<br /><label> <input type="checkbox" name="'.
1814: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1815: &mt('show').'</label>'."\n";
1816: }
1817:
1.41 raeburn 1818: sub login_header_options {
1.135 bisitz 1819: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1820: my $output = '';
1.41 raeburn 1821: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1822: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1823: if (!$is_custom->{'textcol'}) {
1824: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1825: ' ';
1826: }
1827: if (!$is_custom->{'bgcol'}) {
1828: $output .= $choices->{'bgcol'}.': '.
1829: '<span id="css_'.$role.'_font" style="background-color: '.
1830: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1831: }
1832: $output .= '<br />';
1833: }
1834: $output .='<br />';
1835: return $output;
1836: }
1837:
1838: sub login_text_colors {
1.201 raeburn 1839: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1840: my $color_menu = '<table border="0"><tr>';
1841: foreach my $item (@{$logintext}) {
1.306 raeburn 1842: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1843: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1844: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1845: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1846: }
1847: $color_menu .= '</tr></table><br />';
1848: return $color_menu;
1849: }
1850:
1851: sub image_changes {
1852: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1853: my $output;
1.135 bisitz 1854: if ($img eq 'login') {
1855: # suppress image for Log-in header
1856: } elsif (!$is_custom) {
1.70 raeburn 1857: if ($img ne 'domlogo') {
1.41 raeburn 1858: $output .= &mt('Default image:').'<br />';
1859: } else {
1860: $output .= &mt('Default in use:').'<br />';
1861: }
1862: }
1.135 bisitz 1863: if ($img eq 'login') { # suppress image for Log-in header
1864: $output .= '<td>'.$logincolors;
1.41 raeburn 1865: } else {
1.135 bisitz 1866: if ($img_import) {
1867: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1868: }
1869: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1870: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1871: if ($is_custom) {
1872: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1873: '<input type="checkbox" name="'.
1874: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1875: '</label> '.&mt('Replace:').'</span><br />';
1876: } else {
1.306 raeburn 1877: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1878: }
1.41 raeburn 1879: }
1880: return $output;
1881: }
1882:
1.3 raeburn 1883: sub print_quotas {
1.86 raeburn 1884: my ($dom,$settings,$rowtotal,$action) = @_;
1885: my $context;
1886: if ($action eq 'quotas') {
1887: $context = 'tools';
1888: } else {
1889: $context = $action;
1890: }
1.197 raeburn 1891: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1892: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1893: my $typecount = 0;
1.101 raeburn 1894: my ($css_class,%titles);
1.86 raeburn 1895: if ($context eq 'requestcourses') {
1.325 ! raeburn 1896: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 1897: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1898: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1899: %titles = &courserequest_titles();
1.163 raeburn 1900: } elsif ($context eq 'requestauthor') {
1901: @usertools = ('author');
1902: @options = ('norequest','approval','automatic');
1.210 raeburn 1903: %titles = &authorrequest_titles();
1.86 raeburn 1904: } else {
1.162 raeburn 1905: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1906: %titles = &tool_titles();
1.86 raeburn 1907: }
1.26 raeburn 1908: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1909: foreach my $type (@{$types}) {
1.197 raeburn 1910: my ($currdefquota,$currauthorquota);
1.163 raeburn 1911: unless (($context eq 'requestcourses') ||
1912: ($context eq 'requestauthor')) {
1.86 raeburn 1913: if (ref($settings) eq 'HASH') {
1914: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1915: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1916: } else {
1917: $currdefquota = $settings->{$type};
1918: }
1.197 raeburn 1919: if (ref($settings->{authorquota}) eq 'HASH') {
1920: $currauthorquota = $settings->{authorquota}->{$type};
1921: }
1.78 raeburn 1922: }
1.72 raeburn 1923: }
1.3 raeburn 1924: if (defined($usertypes->{$type})) {
1925: $typecount ++;
1926: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1927: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1928: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1929: '<td class="LC_left_item">';
1.101 raeburn 1930: if ($context eq 'requestcourses') {
1931: $datatable .= '<table><tr>';
1932: }
1933: my %cell;
1.72 raeburn 1934: foreach my $item (@usertools) {
1.101 raeburn 1935: if ($context eq 'requestcourses') {
1936: my ($curroption,$currlimit);
1937: if (ref($settings) eq 'HASH') {
1938: if (ref($settings->{$item}) eq 'HASH') {
1939: $curroption = $settings->{$item}->{$type};
1940: if ($curroption =~ /^autolimit=(\d*)$/) {
1941: $currlimit = $1;
1942: }
1943: }
1944: }
1945: if (!$curroption) {
1946: $curroption = 'norequest';
1947: }
1948: $datatable .= '<th>'.$titles{$item}.'</th>';
1949: foreach my $option (@options) {
1950: my $val = $option;
1951: if ($option eq 'norequest') {
1952: $val = 0;
1953: }
1954: if ($option eq 'validate') {
1955: my $canvalidate = 0;
1956: if (ref($validations{$item}) eq 'HASH') {
1957: if ($validations{$item}{$type}) {
1958: $canvalidate = 1;
1959: }
1960: }
1961: next if (!$canvalidate);
1962: }
1963: my $checked = '';
1964: if ($option eq $curroption) {
1965: $checked = ' checked="checked"';
1966: } elsif ($option eq 'autolimit') {
1967: if ($curroption =~ /^autolimit/) {
1968: $checked = ' checked="checked"';
1969: }
1970: }
1971: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1972: '<input type="radio" name="crsreq_'.$item.
1973: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1974: $titles{$option}.'</label>';
1.101 raeburn 1975: if ($option eq 'autolimit') {
1.127 raeburn 1976: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1977: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1978: 'value="'.$currlimit.'" />';
1.101 raeburn 1979: }
1.127 raeburn 1980: $cell{$item} .= '</span> ';
1.103 raeburn 1981: if ($option eq 'autolimit') {
1.127 raeburn 1982: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1983: }
1.101 raeburn 1984: }
1.163 raeburn 1985: } elsif ($context eq 'requestauthor') {
1986: my $curroption;
1987: if (ref($settings) eq 'HASH') {
1988: $curroption = $settings->{$type};
1989: }
1990: if (!$curroption) {
1991: $curroption = 'norequest';
1992: }
1993: foreach my $option (@options) {
1994: my $val = $option;
1995: if ($option eq 'norequest') {
1996: $val = 0;
1997: }
1998: my $checked = '';
1999: if ($option eq $curroption) {
2000: $checked = ' checked="checked"';
2001: }
2002: $datatable .= '<span class="LC_nobreak"><label>'.
2003: '<input type="radio" name="authorreq_'.$type.
2004: '" value="'.$val.'"'.$checked.' />'.
2005: $titles{$option}.'</label></span> ';
2006: }
1.101 raeburn 2007: } else {
2008: my $checked = 'checked="checked" ';
2009: if (ref($settings) eq 'HASH') {
2010: if (ref($settings->{$item}) eq 'HASH') {
2011: if ($settings->{$item}->{$type} == 0) {
2012: $checked = '';
2013: } elsif ($settings->{$item}->{$type} == 1) {
2014: $checked = 'checked="checked" ';
2015: }
1.78 raeburn 2016: }
1.72 raeburn 2017: }
1.101 raeburn 2018: $datatable .= '<span class="LC_nobreak"><label>'.
2019: '<input type="checkbox" name="'.$context.'_'.$item.
2020: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2021: '</label></span> ';
1.72 raeburn 2022: }
1.101 raeburn 2023: }
2024: if ($context eq 'requestcourses') {
2025: $datatable .= '</tr><tr>';
2026: foreach my $item (@usertools) {
1.106 raeburn 2027: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2028: }
2029: $datatable .= '</tr></table>';
1.72 raeburn 2030: }
1.86 raeburn 2031: $datatable .= '</td>';
1.163 raeburn 2032: unless (($context eq 'requestcourses') ||
2033: ($context eq 'requestauthor')) {
1.86 raeburn 2034: $datatable .=
1.197 raeburn 2035: '<td class="LC_right_item">'.
2036: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2037: '<input type="text" name="quota_'.$type.
1.72 raeburn 2038: '" value="'.$currdefquota.
1.197 raeburn 2039: '" size="5" /></span>'.(' ' x 2).
2040: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2041: '<input type="text" name="authorquota_'.$type.
2042: '" value="'.$currauthorquota.
2043: '" size="5" /></span></td>';
1.86 raeburn 2044: }
2045: $datatable .= '</tr>';
1.3 raeburn 2046: }
2047: }
2048: }
1.163 raeburn 2049: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2050: $defaultquota = '20';
1.197 raeburn 2051: $authorquota = '500';
1.86 raeburn 2052: if (ref($settings) eq 'HASH') {
2053: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2054: $defaultquota = $settings->{'defaultquota'}->{'default'};
2055: } elsif (defined($settings->{'default'})) {
2056: $defaultquota = $settings->{'default'};
2057: }
1.197 raeburn 2058: if (ref($settings->{'authorquota'}) eq 'HASH') {
2059: $authorquota = $settings->{'authorquota'}->{'default'};
2060: }
1.3 raeburn 2061: }
2062: }
2063: $typecount ++;
2064: $css_class = $typecount%2?' class="LC_odd_row"':'';
2065: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2066: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2067: '<td class="LC_left_item">';
1.101 raeburn 2068: if ($context eq 'requestcourses') {
2069: $datatable .= '<table><tr>';
2070: }
2071: my %defcell;
1.72 raeburn 2072: foreach my $item (@usertools) {
1.101 raeburn 2073: if ($context eq 'requestcourses') {
2074: my ($curroption,$currlimit);
2075: if (ref($settings) eq 'HASH') {
2076: if (ref($settings->{$item}) eq 'HASH') {
2077: $curroption = $settings->{$item}->{'default'};
2078: if ($curroption =~ /^autolimit=(\d*)$/) {
2079: $currlimit = $1;
2080: }
2081: }
2082: }
2083: if (!$curroption) {
2084: $curroption = 'norequest';
2085: }
2086: $datatable .= '<th>'.$titles{$item}.'</th>';
2087: foreach my $option (@options) {
2088: my $val = $option;
2089: if ($option eq 'norequest') {
2090: $val = 0;
2091: }
2092: if ($option eq 'validate') {
2093: my $canvalidate = 0;
2094: if (ref($validations{$item}) eq 'HASH') {
2095: if ($validations{$item}{'default'}) {
2096: $canvalidate = 1;
2097: }
2098: }
2099: next if (!$canvalidate);
2100: }
2101: my $checked = '';
2102: if ($option eq $curroption) {
2103: $checked = ' checked="checked"';
2104: } elsif ($option eq 'autolimit') {
2105: if ($curroption =~ /^autolimit/) {
2106: $checked = ' checked="checked"';
2107: }
2108: }
2109: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2110: '<input type="radio" name="crsreq_'.$item.
2111: '_default" value="'.$val.'"'.$checked.' />'.
2112: $titles{$option}.'</label>';
2113: if ($option eq 'autolimit') {
1.127 raeburn 2114: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2115: $item.'_limit_default" size="1" '.
2116: 'value="'.$currlimit.'" />';
2117: }
1.127 raeburn 2118: $defcell{$item} .= '</span> ';
1.104 raeburn 2119: if ($option eq 'autolimit') {
1.127 raeburn 2120: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2121: }
1.101 raeburn 2122: }
1.163 raeburn 2123: } elsif ($context eq 'requestauthor') {
2124: my $curroption;
2125: if (ref($settings) eq 'HASH') {
1.172 raeburn 2126: $curroption = $settings->{'default'};
1.163 raeburn 2127: }
2128: if (!$curroption) {
2129: $curroption = 'norequest';
2130: }
2131: foreach my $option (@options) {
2132: my $val = $option;
2133: if ($option eq 'norequest') {
2134: $val = 0;
2135: }
2136: my $checked = '';
2137: if ($option eq $curroption) {
2138: $checked = ' checked="checked"';
2139: }
2140: $datatable .= '<span class="LC_nobreak"><label>'.
2141: '<input type="radio" name="authorreq_default"'.
2142: ' value="'.$val.'"'.$checked.' />'.
2143: $titles{$option}.'</label></span> ';
2144: }
1.101 raeburn 2145: } else {
2146: my $checked = 'checked="checked" ';
2147: if (ref($settings) eq 'HASH') {
2148: if (ref($settings->{$item}) eq 'HASH') {
2149: if ($settings->{$item}->{'default'} == 0) {
2150: $checked = '';
2151: } elsif ($settings->{$item}->{'default'} == 1) {
2152: $checked = 'checked="checked" ';
2153: }
1.78 raeburn 2154: }
1.72 raeburn 2155: }
1.101 raeburn 2156: $datatable .= '<span class="LC_nobreak"><label>'.
2157: '<input type="checkbox" name="'.$context.'_'.$item.
2158: '" value="default" '.$checked.'/>'.$titles{$item}.
2159: '</label></span> ';
2160: }
2161: }
2162: if ($context eq 'requestcourses') {
2163: $datatable .= '</tr><tr>';
2164: foreach my $item (@usertools) {
1.106 raeburn 2165: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2166: }
1.101 raeburn 2167: $datatable .= '</tr></table>';
1.72 raeburn 2168: }
1.86 raeburn 2169: $datatable .= '</td>';
1.163 raeburn 2170: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2171: $datatable .= '<td class="LC_right_item">'.
2172: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2173: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2174: $defaultquota.'" size="5" /></span>'.(' ' x2).
2175: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2176: '<input type="text" name="authorquota" value="'.
2177: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2178: }
2179: $datatable .= '</tr>';
1.72 raeburn 2180: $typecount ++;
2181: $css_class = $typecount%2?' class="LC_odd_row"':'';
2182: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2183: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2184: if ($context eq 'requestcourses') {
1.109 raeburn 2185: $datatable .= &mt('(overrides affiliation, if set)').
2186: '</td>'.
2187: '<td class="LC_left_item">'.
2188: '<table><tr>';
1.101 raeburn 2189: } else {
1.109 raeburn 2190: $datatable .= &mt('(overrides affiliation, if checked)').
2191: '</td>'.
2192: '<td class="LC_left_item" colspan="2">'.
2193: '<br />';
1.101 raeburn 2194: }
2195: my %advcell;
1.72 raeburn 2196: foreach my $item (@usertools) {
1.101 raeburn 2197: if ($context eq 'requestcourses') {
2198: my ($curroption,$currlimit);
2199: if (ref($settings) eq 'HASH') {
2200: if (ref($settings->{$item}) eq 'HASH') {
2201: $curroption = $settings->{$item}->{'_LC_adv'};
2202: if ($curroption =~ /^autolimit=(\d*)$/) {
2203: $currlimit = $1;
2204: }
2205: }
2206: }
2207: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2208: my $checked = '';
2209: if ($curroption eq '') {
2210: $checked = ' checked="checked"';
2211: }
2212: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2213: '<input type="radio" name="crsreq_'.$item.
2214: '__LC_adv" value=""'.$checked.' />'.
2215: &mt('No override set').'</label></span> ';
1.101 raeburn 2216: foreach my $option (@options) {
2217: my $val = $option;
2218: if ($option eq 'norequest') {
2219: $val = 0;
2220: }
2221: if ($option eq 'validate') {
2222: my $canvalidate = 0;
2223: if (ref($validations{$item}) eq 'HASH') {
2224: if ($validations{$item}{'_LC_adv'}) {
2225: $canvalidate = 1;
2226: }
2227: }
2228: next if (!$canvalidate);
2229: }
2230: my $checked = '';
1.104 raeburn 2231: if ($val eq $curroption) {
1.101 raeburn 2232: $checked = ' checked="checked"';
2233: } elsif ($option eq 'autolimit') {
2234: if ($curroption =~ /^autolimit/) {
2235: $checked = ' checked="checked"';
2236: }
2237: }
2238: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2239: '<input type="radio" name="crsreq_'.$item.
2240: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2241: $titles{$option}.'</label>';
2242: if ($option eq 'autolimit') {
1.127 raeburn 2243: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2244: $item.'_limit__LC_adv" size="1" '.
2245: 'value="'.$currlimit.'" />';
2246: }
1.127 raeburn 2247: $advcell{$item} .= '</span> ';
1.104 raeburn 2248: if ($option eq 'autolimit') {
1.127 raeburn 2249: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2250: }
1.101 raeburn 2251: }
1.163 raeburn 2252: } elsif ($context eq 'requestauthor') {
2253: my $curroption;
2254: if (ref($settings) eq 'HASH') {
2255: $curroption = $settings->{'_LC_adv'};
2256: }
2257: my $checked = '';
2258: if ($curroption eq '') {
2259: $checked = ' checked="checked"';
2260: }
2261: $datatable .= '<span class="LC_nobreak"><label>'.
2262: '<input type="radio" name="authorreq__LC_adv"'.
2263: ' value=""'.$checked.' />'.
2264: &mt('No override set').'</label></span> ';
2265: foreach my $option (@options) {
2266: my $val = $option;
2267: if ($option eq 'norequest') {
2268: $val = 0;
2269: }
2270: my $checked = '';
2271: if ($val eq $curroption) {
2272: $checked = ' checked="checked"';
2273: }
2274: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2275: '<input type="radio" name="authorreq__LC_adv"'.
2276: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2277: $titles{$option}.'</label></span> ';
2278: }
1.101 raeburn 2279: } else {
2280: my $checked = 'checked="checked" ';
2281: if (ref($settings) eq 'HASH') {
2282: if (ref($settings->{$item}) eq 'HASH') {
2283: if ($settings->{$item}->{'_LC_adv'} == 0) {
2284: $checked = '';
2285: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2286: $checked = 'checked="checked" ';
2287: }
1.79 raeburn 2288: }
1.72 raeburn 2289: }
1.101 raeburn 2290: $datatable .= '<span class="LC_nobreak"><label>'.
2291: '<input type="checkbox" name="'.$context.'_'.$item.
2292: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2293: '</label></span> ';
2294: }
2295: }
2296: if ($context eq 'requestcourses') {
2297: $datatable .= '</tr><tr>';
2298: foreach my $item (@usertools) {
1.106 raeburn 2299: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2300: }
1.101 raeburn 2301: $datatable .= '</tr></table>';
1.72 raeburn 2302: }
1.98 raeburn 2303: $datatable .= '</td></tr>';
1.30 raeburn 2304: $$rowtotal += $typecount;
1.3 raeburn 2305: return $datatable;
2306: }
2307:
1.163 raeburn 2308: sub print_requestmail {
1.305 raeburn 2309: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2310: my ($now,$datatable,%currapp);
1.102 raeburn 2311: $now = time;
2312: if (ref($settings) eq 'HASH') {
2313: if (ref($settings->{'notify'}) eq 'HASH') {
2314: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2315: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2316: }
2317: }
2318: }
1.191 raeburn 2319: my $numinrow = 2;
1.224 raeburn 2320: my $css_class;
1.305 raeburn 2321: if ($$rowtotal%2) {
2322: $css_class = 'LC_odd_row';
2323: }
2324: if ($customcss) {
2325: $css_class .= " $customcss";
2326: }
2327: $css_class =~ s/^\s+//;
2328: if ($css_class) {
2329: $css_class = ' class="'.$css_class.'"';
2330: }
2331: if ($rowstyle) {
2332: $css_class .= ' style="'.$rowstyle.'"';
2333: }
1.163 raeburn 2334: my $text;
2335: if ($action eq 'requestcourses') {
2336: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2337: } elsif ($action eq 'requestauthor') {
2338: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2339: } else {
1.224 raeburn 2340: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2341: }
1.224 raeburn 2342: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2343: ' <td>'.$text.'</td>'.
1.102 raeburn 2344: ' <td class="LC_left_item">';
1.191 raeburn 2345: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2346: $action.'notifyapproval',%currapp);
1.191 raeburn 2347: if ($numdc > 0) {
2348: $datatable .= $table;
1.102 raeburn 2349: } else {
2350: $datatable .= &mt('There are no active Domain Coordinators');
2351: }
2352: $datatable .='</td></tr>';
2353: return $datatable;
2354: }
2355:
1.216 raeburn 2356: sub print_studentcode {
2357: my ($settings,$rowtotal) = @_;
2358: my $rownum = 0;
1.218 raeburn 2359: my ($output,%current);
1.325 ! raeburn 2360: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2361: if (ref($settings) eq 'HASH') {
2362: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2363: foreach my $type (@crstypes) {
2364: $current{$type} = $settings->{'uniquecode'}{$type};
2365: }
1.218 raeburn 2366: }
2367: }
2368: $output .= '<tr>'.
2369: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2370: '<td class="LC_left_item">';
2371: foreach my $type (@crstypes) {
2372: my $check = ' ';
2373: if ($current{$type}) {
2374: $check = ' checked="checked" ';
2375: }
2376: $output .= '<span class="LC_nobreak"><label>'.
2377: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2378: &mt($type).'</label></span>'.(' 'x2).' ';
2379: }
2380: $output .= '</td></tr>';
2381: $$rowtotal ++;
2382: return $output;
1.216 raeburn 2383: }
2384:
2385: sub print_textbookcourses {
1.242 raeburn 2386: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2387: my $rownum = 0;
2388: my $css_class;
2389: my $itemcount = 1;
2390: my $maxnum = 0;
2391: my $bookshash;
2392: if (ref($settings) eq 'HASH') {
1.242 raeburn 2393: $bookshash = $settings->{$type};
1.216 raeburn 2394: }
2395: my %ordered;
2396: if (ref($bookshash) eq 'HASH') {
2397: foreach my $item (keys(%{$bookshash})) {
2398: if (ref($bookshash->{$item}) eq 'HASH') {
2399: my $num = $bookshash->{$item}{'order'};
2400: $ordered{$num} = $item;
2401: }
2402: }
2403: }
2404: my $confname = $dom.'-domainconfig';
2405: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2406: my $maxnum = scalar(keys(%ordered));
2407: my $datatable;
1.216 raeburn 2408: if (keys(%ordered)) {
2409: my @items = sort { $a <=> $b } keys(%ordered);
2410: for (my $i=0; $i<@items; $i++) {
2411: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2412: my $key = $ordered{$items[$i]};
2413: my %coursehash=&Apache::lonnet::coursedescription($key);
2414: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2415: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2416: if (ref($bookshash->{$key}) eq 'HASH') {
2417: $subject = $bookshash->{$key}->{'subject'};
2418: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2419: if ($type eq 'textbooks') {
1.243 raeburn 2420: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2421: $author = $bookshash->{$key}->{'author'};
2422: $image = $bookshash->{$key}->{'image'};
2423: if ($image ne '') {
2424: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2425: my $imagethumb = "$path/tn-".$imagefile;
2426: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2427: }
1.216 raeburn 2428: }
2429: }
1.242 raeburn 2430: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2431: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2432: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2433: for (my $k=0; $k<=$maxnum; $k++) {
2434: my $vpos = $k+1;
2435: my $selstr;
2436: if ($k == $i) {
2437: $selstr = ' selected="selected" ';
2438: }
2439: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2440: }
2441: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2442: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2443: &mt('Delete?').'</label></span></td>'.
2444: '<td colspan="2">'.
1.242 raeburn 2445: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2446: (' 'x2).
1.242 raeburn 2447: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2448: if ($type eq 'textbooks') {
2449: $datatable .= (' 'x2).
1.243 raeburn 2450: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2451: (' 'x2).
1.242 raeburn 2452: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2453: (' 'x2).
2454: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2455: if ($image) {
1.267 raeburn 2456: $datatable .= $imgsrc.
1.242 raeburn 2457: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2458: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2459: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2460: }
2461: if ($switchserver) {
2462: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2463: } else {
2464: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2465: }
1.216 raeburn 2466: }
1.242 raeburn 2467: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2468: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2469: $coursetitle.'</span></td></tr>'."\n";
2470: $itemcount ++;
2471: }
2472: }
2473: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2474: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2475: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2476: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2477: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2478: for (my $k=0; $k<$maxnum+1; $k++) {
2479: my $vpos = $k+1;
2480: my $selstr;
2481: if ($k == $maxnum) {
2482: $selstr = ' selected="selected" ';
2483: }
2484: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2485: }
2486: $datatable .= '</select> '."\n".
1.242 raeburn 2487: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2488: '<td colspan="2">'.
1.242 raeburn 2489: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2490: (' 'x2).
1.242 raeburn 2491: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2492: (' 'x2);
2493: if ($type eq 'textbooks') {
1.243 raeburn 2494: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2495: (' 'x2).
2496: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2497: (' 'x2).
2498: '<span class="LC_nobreak">'.&mt('Image:').' ';
2499: if ($switchserver) {
2500: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2501: } else {
2502: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2503: }
1.216 raeburn 2504: }
2505: $datatable .= '</span>'."\n".
2506: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2507: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2508: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2509: &Apache::loncommon::selectcourse_link
1.242 raeburn 2510: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2511: '</span></td>'."\n".
2512: '</tr>'."\n";
2513: $itemcount ++;
2514: return $datatable;
2515: }
2516:
1.217 raeburn 2517: sub textbookcourses_javascript {
1.242 raeburn 2518: my ($settings) = @_;
2519: return unless(ref($settings) eq 'HASH');
2520: my (%ordered,%total,%jstext);
2521: foreach my $type ('textbooks','templates') {
2522: $total{$type} = 0;
2523: if (ref($settings->{$type}) eq 'HASH') {
2524: foreach my $item (keys(%{$settings->{$type}})) {
2525: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2526: my $num = $settings->{$type}->{$item}{'order'};
2527: $ordered{$type}{$num} = $item;
2528: }
2529: }
2530: $total{$type} = scalar(keys(%{$settings->{$type}}));
2531: }
2532: my @jsarray = ();
2533: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2534: push(@jsarray,$ordered{$type}{$item});
2535: }
2536: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2537: }
2538: return <<"ENDSCRIPT";
2539: <script type="text/javascript">
2540: // <![CDATA[
1.242 raeburn 2541: function reorderBooks(form,item,caller) {
1.217 raeburn 2542: var changedVal;
1.242 raeburn 2543: $jstext{'textbooks'};
2544: $jstext{'templates'};
2545: var newpos;
2546: var maxh;
2547: if (caller == 'textbooks') {
2548: newpos = 'textbooks_addbook_pos';
2549: maxh = 1 + $total{'textbooks'};
2550: } else {
2551: newpos = 'templates_addbook_pos';
2552: maxh = 1 + $total{'templates'};
2553: }
1.217 raeburn 2554: var current = new Array;
2555: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2556: if (item == newpos) {
2557: changedVal = newitemVal;
2558: } else {
2559: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2560: current[newitemVal] = newpos;
2561: }
1.242 raeburn 2562: if (caller == 'textbooks') {
2563: for (var i=0; i<textbooks.length; i++) {
2564: var elementName = 'textbooks_'+textbooks[i];
2565: if (elementName != item) {
2566: if (form.elements[elementName]) {
2567: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2568: current[currVal] = elementName;
2569: }
2570: }
2571: }
2572: }
2573: if (caller == 'templates') {
2574: for (var i=0; i<templates.length; i++) {
2575: var elementName = 'templates_'+templates[i];
2576: if (elementName != item) {
2577: if (form.elements[elementName]) {
2578: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2579: current[currVal] = elementName;
2580: }
1.217 raeburn 2581: }
2582: }
2583: }
2584: var oldVal;
2585: for (var j=0; j<maxh; j++) {
2586: if (current[j] == undefined) {
2587: oldVal = j;
2588: }
2589: }
2590: if (oldVal < changedVal) {
2591: for (var k=oldVal+1; k<=changedVal ; k++) {
2592: var elementName = current[k];
2593: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2594: }
2595: } else {
2596: for (var k=changedVal; k<oldVal; k++) {
2597: var elementName = current[k];
2598: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2599: }
2600: }
2601: return;
2602: }
2603:
2604: // ]]>
2605: </script>
2606:
2607: ENDSCRIPT
2608: }
2609:
1.267 raeburn 2610: sub ltitools_javascript {
2611: my ($settings) = @_;
1.319 raeburn 2612: my $togglejs = <itools_toggle_js();
2613: unless (ref($settings) eq 'HASH') {
2614: return $togglejs;
2615: }
1.267 raeburn 2616: my (%ordered,$total,%jstext);
2617: $total = 0;
2618: foreach my $item (keys(%{$settings})) {
2619: if (ref($settings->{$item}) eq 'HASH') {
2620: my $num = $settings->{$item}{'order'};
2621: $ordered{$num} = $item;
2622: }
2623: }
2624: $total = scalar(keys(%{$settings}));
2625: my @jsarray = ();
2626: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2627: push(@jsarray,$ordered{$item});
2628: }
2629: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2630: return <<"ENDSCRIPT";
2631: <script type="text/javascript">
2632: // <![CDATA[
1.319 raeburn 2633: function reorderLTITools(form,item) {
1.267 raeburn 2634: var changedVal;
2635: $jstext
2636: var newpos = 'ltitools_add_pos';
2637: var maxh = 1 + $total;
2638: var current = new Array;
2639: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2640: if (item == newpos) {
2641: changedVal = newitemVal;
2642: } else {
2643: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2644: current[newitemVal] = newpos;
2645: }
2646: for (var i=0; i<ltitools.length; i++) {
2647: var elementName = 'ltitools_'+ltitools[i];
2648: if (elementName != item) {
2649: if (form.elements[elementName]) {
2650: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2651: current[currVal] = elementName;
2652: }
2653: }
2654: }
2655: var oldVal;
2656: for (var j=0; j<maxh; j++) {
2657: if (current[j] == undefined) {
2658: oldVal = j;
2659: }
2660: }
2661: if (oldVal < changedVal) {
2662: for (var k=oldVal+1; k<=changedVal ; k++) {
2663: var elementName = current[k];
2664: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2665: }
2666: } else {
2667: for (var k=changedVal; k<oldVal; k++) {
2668: var elementName = current[k];
2669: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2670: }
2671: }
2672: return;
2673: }
2674:
2675: // ]]>
2676: </script>
2677:
1.319 raeburn 2678: $togglejs
2679:
2680: ENDSCRIPT
2681: }
2682:
2683: sub ltitools_toggle_js {
2684: return <<"ENDSCRIPT";
2685: <script type="text/javascript">
2686: // <![CDATA[
2687:
2688: function toggleLTITools(form,setting,item) {
2689: var radioname = '';
2690: var divid = '';
2691: if ((setting == 'passback') || (setting == 'roster')) {
2692: radioname = 'ltitools_'+setting+'_'+item;
2693: divid = 'ltitools_'+setting+'time_'+item;
2694: var num = form.elements[radioname].length;
2695: if (num) {
2696: var setvis = '';
2697: for (var i=0; i<num; i++) {
2698: if (form.elements[radioname][i].checked) {
2699: if (form.elements[radioname][i].value == '1') {
2700: if (document.getElementById(divid)) {
2701: document.getElementById(divid).style.display = 'inline-block';
2702: }
2703: setvis = 1;
2704: }
2705: break;
2706: }
2707: }
2708: }
2709: if (!setvis) {
2710: if (document.getElementById(divid)) {
2711: document.getElementById(divid).style.display = 'none';
2712: }
2713: }
2714: }
1.324 raeburn 2715: if (setting == 'user') {
2716: divid = 'ltitools_'+setting+'_div_'+item;
2717: var checkid = 'ltitools_'+setting+'_field_'+item;
2718: if (document.getElementById(divid)) {
2719: if (document.getElementById(checkid)) {
2720: if (document.getElementById(checkid).checked) {
2721: document.getElementById(divid).style.display = 'inline-block';
2722: } else {
2723: document.getElementById(divid).style.display = 'none';
2724: }
2725: }
2726: }
2727: }
1.319 raeburn 2728: return;
2729: }
2730: // ]]>
2731: </script>
2732:
1.267 raeburn 2733: ENDSCRIPT
2734: }
2735:
1.320 raeburn 2736: sub lti_javascript {
2737: my ($settings) = @_;
2738: my $togglejs = <i_toggle_js();
2739: unless (ref($settings) eq 'HASH') {
2740: return $togglejs;
2741: }
2742: my (%ordered,$total,%jstext);
2743: $total = 0;
2744: foreach my $item (keys(%{$settings})) {
2745: if (ref($settings->{$item}) eq 'HASH') {
2746: my $num = $settings->{$item}{'order'};
2747: $ordered{$num} = $item;
2748: }
2749: }
2750: $total = scalar(keys(%{$settings}));
2751: my @jsarray = ();
2752: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2753: push(@jsarray,$ordered{$item});
2754: }
2755: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
2756: return <<"ENDSCRIPT";
2757: <script type="text/javascript">
2758: // <![CDATA[
2759: function reorderLTI(form,item) {
2760: var changedVal;
2761: $jstext
2762: var newpos = 'lti_pos_add';
2763: var maxh = 1 + $total;
2764: var current = new Array;
2765: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2766: if (item == newpos) {
2767: changedVal = newitemVal;
2768: } else {
2769: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2770: current[newitemVal] = newpos;
2771: }
2772: for (var i=0; i<lti.length; i++) {
2773: var elementName = 'lti_pos_'+lti[i];
2774: if (elementName != item) {
2775: if (form.elements[elementName]) {
2776: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2777: current[currVal] = elementName;
2778: }
2779: }
2780: }
2781: var oldVal;
2782: for (var j=0; j<maxh; j++) {
2783: if (current[j] == undefined) {
2784: oldVal = j;
2785: }
2786: }
2787: if (oldVal < changedVal) {
2788: for (var k=oldVal+1; k<=changedVal ; k++) {
2789: var elementName = current[k];
2790: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2791: }
2792: } else {
2793: for (var k=changedVal; k<oldVal; k++) {
2794: var elementName = current[k];
2795: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2796: }
2797: }
2798: return;
2799: }
2800: // ]]>
2801: </script>
2802:
2803: $togglejs
2804:
2805: ENDSCRIPT
2806: }
2807:
2808: sub lti_toggle_js {
1.325 ! raeburn 2809: my %lcauthparmtext = &Apache::lonlocal::texthash (
! 2810: localauth => 'Local auth argument',
! 2811: krb => 'Kerberos domain',
! 2812: );
1.320 raeburn 2813: return <<"ENDSCRIPT";
2814: <script type="text/javascript">
2815: // <![CDATA[
2816:
2817: function toggleLTI(form,setting,item) {
2818: if ((setting == 'user') || (setting == 'crs')) {
2819: var radioname = '';
2820: var divid = '';
2821: if (setting == 'user') {
2822: radioname = 'lti_mapuser_'+item;
2823: divid = 'lti_userfield_'+item;
2824: } else {
2825: radioname = 'lti_mapcrs_'+item;
2826: divid = 'lti_crsfield_'+item;
2827: }
2828: var num = form.elements[radioname].length;
2829: if (num) {
2830: var setvis = '';
2831: for (var i=0; i<num; i++) {
2832: if (form.elements[radioname][i].checked) {
2833: if (form.elements[radioname][i].value == 'other') {
2834: if (document.getElementById(divid)) {
2835: document.getElementById(divid).style.display = 'inline-block';
2836: }
2837: setvis = 1;
2838: break;
2839: }
2840: }
2841: }
2842: if (!setvis) {
2843: if (document.getElementById(divid)) {
2844: document.getElementById(divid).style.display = 'none';
2845: }
2846: }
2847: }
2848: } else if ((setting == 'sec') || (setting == 'secsrc')) {
2849: var numsec = form.elements['lti_crssec_'+item].length;
2850: if (numsec) {
2851: var setvis = '';
2852: for (var i=0; i<numsec; i++) {
2853: if (form.elements['lti_crssec_'+item][i].checked) {
2854: if (form.elements['lti_crssec_'+item][i].value == '1') {
2855: if (document.getElementById('lti_crssecfield_'+item)) {
2856: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
2857: setvis = 1;
2858: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
2859: if (numsrcsec) {
2860: var setsrcvis = '';
2861: for (var j=0; j<numsrcsec; j++) {
2862: if (form.elements['lti_crssecsrc_'+item][j].checked) {
2863: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
2864: if (document.getElementById('lti_secsrcfield_'+item)) {
2865: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
2866: setsrcvis = 1;
2867: }
2868: }
2869: }
2870: }
2871: if (!setsrcvis) {
2872: if (document.getElementById('lti_secsrcfield_'+item)) {
2873: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2874: }
2875: }
2876: }
2877: }
2878: }
2879: }
2880: }
2881: if (!setvis) {
2882: if (document.getElementById('lti_crssecfield_'+item)) {
2883: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
2884: }
2885: if (document.getElementById('lti_secsrcfield_'+item)) {
2886: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2887: }
2888: }
2889: }
1.325 ! raeburn 2890: } else if (setting == 'lcauth') {
! 2891: var numauth = form.elements['lti_lcauth_'+item].length;
! 2892: if (numauth) {
! 2893: for (var i=0; i<numauth; i++) {
! 2894: if (form.elements['lti_lcauth_'+item][i].checked) {
! 2895: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
! 2896: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
! 2897: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
! 2898: } else {
! 2899: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
! 2900: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
! 2901: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
! 2902: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
! 2903: } else {
! 2904: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
! 2905: }
! 2906: }
! 2907: }
! 2908: }
! 2909: }
! 2910: }
! 2911: }
1.320 raeburn 2912: }
2913: return;
2914: }
2915: // ]]>
2916: </script>
2917:
2918: ENDSCRIPT
2919: }
2920:
1.3 raeburn 2921: sub print_autoenroll {
1.30 raeburn 2922: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2923: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2924: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2925: if (ref($settings) eq 'HASH') {
2926: if (exists($settings->{'run'})) {
2927: if ($settings->{'run'} eq '0') {
2928: $runoff = ' checked="checked" ';
2929: $runon = ' ';
2930: } else {
2931: $runon = ' checked="checked" ';
2932: $runoff = ' ';
2933: }
2934: } else {
2935: if ($autorun) {
2936: $runon = ' checked="checked" ';
2937: $runoff = ' ';
2938: } else {
2939: $runoff = ' checked="checked" ';
2940: $runon = ' ';
2941: }
2942: }
1.129 raeburn 2943: if (exists($settings->{'co-owners'})) {
2944: if ($settings->{'co-owners'} eq '0') {
2945: $coownersoff = ' checked="checked" ';
2946: $coownerson = ' ';
2947: } else {
2948: $coownerson = ' checked="checked" ';
2949: $coownersoff = ' ';
2950: }
2951: } else {
2952: $coownersoff = ' checked="checked" ';
2953: $coownerson = ' ';
2954: }
1.3 raeburn 2955: if (exists($settings->{'sender_domain'})) {
2956: $defdom = $settings->{'sender_domain'};
2957: }
1.274 raeburn 2958: if (exists($settings->{'autofailsafe'})) {
2959: $failsafe = $settings->{'autofailsafe'};
2960: }
1.14 raeburn 2961: } else {
2962: if ($autorun) {
2963: $runon = ' checked="checked" ';
2964: $runoff = ' ';
2965: } else {
2966: $runoff = ' checked="checked" ';
2967: $runon = ' ';
2968: }
1.3 raeburn 2969: }
2970: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2971: my $notif_sender;
2972: if (ref($settings) eq 'HASH') {
2973: $notif_sender = $settings->{'sender_uname'};
2974: }
1.3 raeburn 2975: my $datatable='<tr class="LC_odd_row">'.
2976: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2977: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2978: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2979: $runon.' value="1" />'.&mt('Yes').'</label> '.
2980: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2981: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2982: '</tr><tr>'.
2983: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2984: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2985: &mt('username').': '.
2986: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2987: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2988: ': '.$domform.'</span></td></tr>'.
2989: '<tr class="LC_odd_row">'.
2990: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2991: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2992: '<input type="radio" name="autoassign_coowners"'.
2993: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2994: '<label><input type="radio" name="autoassign_coowners"'.
2995: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2996: '</tr><tr>'.
2997: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2998: '<td class="LC_right_item"><span class="LC_nobreak">'.
2999: '<input type="text" name="autoenroll_failsafe"'.
3000: ' value="'.$failsafe.'" size="4" /></td></tr>';
3001: $$rowtotal += 4;
1.3 raeburn 3002: return $datatable;
3003: }
3004:
3005: sub print_autoupdate {
1.30 raeburn 3006: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 3007: my $datatable;
3008: if ($position eq 'top') {
3009: my $updateon = ' ';
3010: my $updateoff = ' checked="checked" ';
3011: my $classlistson = ' ';
3012: my $classlistsoff = ' checked="checked" ';
3013: if (ref($settings) eq 'HASH') {
3014: if ($settings->{'run'} eq '1') {
3015: $updateon = $updateoff;
3016: $updateoff = ' ';
3017: }
3018: if ($settings->{'classlists'} eq '1') {
3019: $classlistson = $classlistsoff;
3020: $classlistsoff = ' ';
3021: }
3022: }
3023: my %title = (
3024: run => 'Auto-update active?',
3025: classlists => 'Update information in classlists?',
3026: );
3027: $datatable = '<tr class="LC_odd_row">'.
3028: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 3029: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3030: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 3031: $updateon.' value="1" />'.&mt('Yes').'</label> '.
3032: '<label><input type="radio" name="autoupdate_run"'.
3033: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3034: '</tr><tr>'.
3035: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 3036: '<td class="LC_right_item"><span class="LC_nobreak">'.
3037: '<label><input type="radio" name="classlists"'.
3038: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3039: '<label><input type="radio" name="classlists"'.
3040: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3041: '</tr>';
1.30 raeburn 3042: $$rowtotal += 2;
1.131 raeburn 3043: } elsif ($position eq 'middle') {
3044: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3045: my $numinrow = 3;
3046: my $locknamesettings;
3047: $datatable .= &insttypes_row($settings,$types,$usertypes,
3048: $dom,$numinrow,$othertitle,
1.305 raeburn 3049: 'lockablenames',$rowtotal);
1.131 raeburn 3050: $$rowtotal ++;
1.3 raeburn 3051: } else {
1.44 raeburn 3052: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3053: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3054: 'permanentemail','id');
1.33 raeburn 3055: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3056: my $numrows = 0;
1.26 raeburn 3057: if (ref($types) eq 'ARRAY') {
3058: if (@{$types} > 0) {
3059: $datatable =
3060: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3061: \@fields,$types,\$numrows);
1.30 raeburn 3062: $$rowtotal += @{$types};
1.26 raeburn 3063: }
1.3 raeburn 3064: }
3065: $datatable .=
3066: &usertype_update_row($settings,{'default' => $othertitle},
3067: \%fieldtitles,\@fields,['default'],
3068: \$numrows);
1.30 raeburn 3069: $$rowtotal ++;
1.3 raeburn 3070: }
3071: return $datatable;
3072: }
3073:
1.125 raeburn 3074: sub print_autocreate {
3075: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3076: my (%createon,%createoff,%currhash);
1.125 raeburn 3077: my @types = ('xml','req');
3078: if (ref($settings) eq 'HASH') {
3079: foreach my $item (@types) {
3080: $createoff{$item} = ' checked="checked" ';
3081: $createon{$item} = ' ';
3082: if (exists($settings->{$item})) {
3083: if ($settings->{$item}) {
3084: $createon{$item} = ' checked="checked" ';
3085: $createoff{$item} = ' ';
3086: }
3087: }
3088: }
1.210 raeburn 3089: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3090: $currhash{$settings->{'xmldc'}} = 1;
3091: }
1.125 raeburn 3092: } else {
3093: foreach my $item (@types) {
3094: $createoff{$item} = ' checked="checked" ';
3095: $createon{$item} = ' ';
3096: }
3097: }
3098: $$rowtotal += 2;
1.191 raeburn 3099: my $numinrow = 2;
1.125 raeburn 3100: my $datatable='<tr class="LC_odd_row">'.
3101: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3102: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3103: '<input type="radio" name="autocreate_xml"'.
3104: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3105: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3106: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3107: '</td></tr><tr>'.
3108: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3109: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3110: '<input type="radio" name="autocreate_req"'.
3111: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3112: '<label><input type="radio" name="autocreate_req"'.
3113: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3114: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3115: 'autocreate_xmldc',%currhash);
1.247 raeburn 3116: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3117: if ($numdc > 1) {
1.247 raeburn 3118: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3119: '</td><td class="LC_left_item">';
1.125 raeburn 3120: } else {
1.247 raeburn 3121: $datatable .= &mt('Course creation processed as:').
3122: '</td><td class="LC_right_item">';
1.125 raeburn 3123: }
1.247 raeburn 3124: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3125: $$rowtotal += $rows;
1.125 raeburn 3126: return $datatable;
3127: }
3128:
1.23 raeburn 3129: sub print_directorysrch {
1.277 raeburn 3130: my ($position,$dom,$settings,$rowtotal) = @_;
3131: my $datatable;
3132: if ($position eq 'top') {
3133: my $instsrchon = ' ';
3134: my $instsrchoff = ' checked="checked" ';
3135: my ($exacton,$containson,$beginson);
3136: my $instlocalon = ' ';
3137: my $instlocaloff = ' checked="checked" ';
3138: if (ref($settings) eq 'HASH') {
3139: if ($settings->{'available'} eq '1') {
3140: $instsrchon = $instsrchoff;
3141: $instsrchoff = ' ';
3142: }
3143: if ($settings->{'localonly'} eq '1') {
3144: $instlocalon = $instlocaloff;
3145: $instlocaloff = ' ';
3146: }
3147: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3148: foreach my $type (@{$settings->{'searchtypes'}}) {
3149: if ($type eq 'exact') {
3150: $exacton = ' checked="checked" ';
3151: } elsif ($type eq 'contains') {
3152: $containson = ' checked="checked" ';
3153: } elsif ($type eq 'begins') {
3154: $beginson = ' checked="checked" ';
3155: }
3156: }
3157: } else {
3158: if ($settings->{'searchtypes'} eq 'exact') {
3159: $exacton = ' checked="checked" ';
3160: } elsif ($settings->{'searchtypes'} eq 'contains') {
3161: $containson = ' checked="checked" ';
3162: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3163: $exacton = ' checked="checked" ';
3164: $containson = ' checked="checked" ';
3165: }
3166: }
1.277 raeburn 3167: }
3168: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3169: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3170:
3171: my $numinrow = 4;
3172: my $cansrchrow = 0;
3173: $datatable='<tr class="LC_odd_row">'.
3174: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3175: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3176: '<input type="radio" name="dirsrch_available"'.
3177: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3178: '<label><input type="radio" name="dirsrch_available"'.
3179: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3180: '</tr><tr>'.
3181: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3182: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3183: '<input type="radio" name="dirsrch_instlocalonly"'.
3184: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3185: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3186: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3187: '</tr>';
3188: $$rowtotal += 2;
3189: if (ref($usertypes) eq 'HASH') {
3190: if (keys(%{$usertypes}) > 0) {
3191: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3192: $numinrow,$othertitle,'cansearch',
3193: $rowtotal);
1.277 raeburn 3194: $cansrchrow = 1;
1.25 raeburn 3195: }
1.23 raeburn 3196: }
1.277 raeburn 3197: if ($cansrchrow) {
3198: $$rowtotal ++;
3199: $datatable .= '<tr>';
3200: } else {
3201: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3202: }
1.277 raeburn 3203: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3204: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3205: foreach my $title (@{$titleorder}) {
3206: if (defined($searchtitles->{$title})) {
3207: my $check = ' ';
3208: if (ref($settings) eq 'HASH') {
3209: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3210: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3211: $check = ' checked="checked" ';
3212: }
1.39 raeburn 3213: }
1.25 raeburn 3214: }
1.277 raeburn 3215: $datatable .= '<td class="LC_left_item">'.
3216: '<span class="LC_nobreak"><label>'.
3217: '<input type="checkbox" name="searchby" '.
3218: 'value="'.$title.'"'.$check.'/>'.
3219: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3220: }
3221: }
1.277 raeburn 3222: $datatable .= '</tr></table></td></tr>';
3223: $$rowtotal ++;
3224: if ($cansrchrow) {
3225: $datatable .= '<tr class="LC_odd_row">';
3226: } else {
3227: $datatable .= '<tr>';
3228: }
3229: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3230: '<td class="LC_left_item" colspan="2">'.
3231: '<span class="LC_nobreak"><label>'.
3232: '<input type="checkbox" name="searchtypes" '.
3233: $exacton.' value="exact" />'.&mt('Exact match').
3234: '</label> '.
3235: '<label><input type="checkbox" name="searchtypes" '.
3236: $beginson.' value="begins" />'.&mt('Begins with').
3237: '</label> '.
3238: '<label><input type="checkbox" name="searchtypes" '.
3239: $containson.' value="contains" />'.&mt('Contains').
3240: '</label></span></td></tr>';
3241: $$rowtotal ++;
1.26 raeburn 3242: } else {
1.277 raeburn 3243: my $domsrchon = ' checked="checked" ';
3244: my $domsrchoff = ' ';
3245: my $domlocalon = ' ';
3246: my $domlocaloff = ' checked="checked" ';
3247: if (ref($settings) eq 'HASH') {
3248: if ($settings->{'lclocalonly'} eq '1') {
3249: $domlocalon = $domlocaloff;
3250: $domlocaloff = ' ';
3251: }
3252: if ($settings->{'lcavailable'} eq '0') {
3253: $domsrchoff = $domsrchon;
3254: $domsrchon = ' ';
3255: }
3256: }
3257: $datatable='<tr class="LC_odd_row">'.
3258: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3259: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3260: '<input type="radio" name="dirsrch_domavailable"'.
3261: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3262: '<label><input type="radio" name="dirsrch_domavailable"'.
3263: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3264: '</tr><tr>'.
3265: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3266: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3267: '<input type="radio" name="dirsrch_domlocalonly"'.
3268: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3269: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3270: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3271: '</tr>';
3272: $$rowtotal += 2;
1.26 raeburn 3273: }
1.25 raeburn 3274: return $datatable;
3275: }
3276:
1.28 raeburn 3277: sub print_contacts {
1.286 raeburn 3278: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3279: my $datatable;
3280: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3281: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
3282: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
3283: if ($position eq 'top') {
3284: if (ref($settings) eq 'HASH') {
3285: foreach my $item (@contacts) {
3286: if (exists($settings->{$item})) {
3287: $to{$item} = $settings->{$item};
3288: }
3289: }
3290: }
3291: } elsif ($position eq 'middle') {
3292: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3293: 'updatesmail','idconflictsmail');
1.288 raeburn 3294: foreach my $type (@mailings) {
3295: $otheremails{$type} = '';
3296: }
1.286 raeburn 3297: } else {
3298: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3299: foreach my $type (@mailings) {
3300: $otheremails{$type} = '';
3301: }
1.286 raeburn 3302: $bccemails{'helpdeskmail'} = '';
3303: $bccemails{'otherdomsmail'} = '';
3304: $includestr{'helpdeskmail'} = '';
3305: $includestr{'otherdomsmail'} = '';
3306: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3307: }
1.28 raeburn 3308: if (ref($settings) eq 'HASH') {
1.286 raeburn 3309: unless ($position eq 'top') {
3310: foreach my $type (@mailings) {
3311: if (exists($settings->{$type})) {
3312: if (ref($settings->{$type}) eq 'HASH') {
3313: foreach my $item (@contacts) {
3314: if ($settings->{$type}{$item}) {
3315: $checked{$type}{$item} = ' checked="checked" ';
3316: }
3317: }
3318: $otheremails{$type} = $settings->{$type}{'others'};
3319: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3320: $bccemails{$type} = $settings->{$type}{'bcc'};
3321: if ($settings->{$type}{'include'} ne '') {
3322: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3323: $includestr{$type} = &unescape($includestr{$type});
3324: }
3325: }
3326: }
3327: } elsif ($type eq 'lonstatusmail') {
3328: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3329: }
1.28 raeburn 3330: }
3331: }
1.286 raeburn 3332: if ($position eq 'bottom') {
3333: foreach my $type (@mailings) {
3334: $bccemails{$type} = $settings->{$type}{'bcc'};
3335: if ($settings->{$type}{'include'} ne '') {
3336: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3337: $includestr{$type} = &unescape($includestr{$type});
3338: }
3339: }
3340: if (ref($settings->{'helpform'}) eq 'HASH') {
3341: if (ref($fields) eq 'ARRAY') {
3342: foreach my $field (@{$fields}) {
3343: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3344: }
1.286 raeburn 3345: }
3346: if (exists($settings->{'helpform'}{'maxsize'})) {
3347: $maxsize = $settings->{'helpform'}{'maxsize'};
3348: } else {
1.289 raeburn 3349: $maxsize = '1.0';
1.286 raeburn 3350: }
3351: } else {
3352: if (ref($fields) eq 'ARRAY') {
3353: foreach my $field (@{$fields}) {
3354: $currfield{$field} = 'yes';
1.134 raeburn 3355: }
1.28 raeburn 3356: }
1.286 raeburn 3357: $maxsize = '1.0';
1.28 raeburn 3358: }
3359: }
3360: } else {
1.286 raeburn 3361: if ($position eq 'top') {
3362: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3363: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3364: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3365: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3366: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3367: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3368: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3369: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3370: } elsif ($position eq 'bottom') {
3371: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3372: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3373: if (ref($fields) eq 'ARRAY') {
3374: foreach my $field (@{$fields}) {
3375: $currfield{$field} = 'yes';
3376: }
3377: }
3378: $maxsize = '1.0';
3379: }
1.28 raeburn 3380: }
3381: my ($titles,$short_titles) = &contact_titles();
3382: my $rownum = 0;
3383: my $css_class;
1.286 raeburn 3384: if ($position eq 'top') {
3385: foreach my $item (@contacts) {
3386: $css_class = $rownum%2?' class="LC_odd_row"':'';
3387: $datatable .= '<tr'.$css_class.'>'.
3388: '<td><span class="LC_nobreak">'.$titles->{$item}.
3389: '</span></td><td class="LC_right_item">'.
3390: '<input type="text" name="'.$item.'" value="'.
3391: $to{$item}.'" /></td></tr>';
3392: $rownum ++;
3393: }
1.315 raeburn 3394: } elsif ($position eq 'bottom') {
3395: $css_class = $rownum%2?' class="LC_odd_row"':'';
3396: $datatable .= '<tr'.$css_class.'>'.
3397: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3398: &mt('(e-mail, subject, and description always shown)').
3399: '</td><td class="LC_left_item">';
3400: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3401: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3402: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3403: foreach my $field (@{$fields}) {
3404: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3405: if (($field eq 'screenshot') || ($field eq 'cc')) {
3406: $datatable .= ' '.&mt('(logged-in users)');
3407: }
3408: $datatable .='</td><td>';
3409: my $clickaction;
3410: if ($field eq 'screenshot') {
3411: $clickaction = ' onclick="screenshotSize(this);"';
3412: }
3413: if (ref($possoptions->{$field}) eq 'ARRAY') {
3414: foreach my $option (@{$possoptions->{$field}}) {
3415: my $checked;
3416: if ($currfield{$field} eq $option) {
3417: $checked = ' checked="checked"';
3418: }
3419: $datatable .= '<span class="LC_nobreak"><label>'.
3420: '<input type="radio" name="helpform_'.$field.'" '.
3421: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3422: '</label></span>'.(' 'x2);
3423: }
3424: }
3425: if ($field eq 'screenshot') {
3426: my $display;
3427: if ($currfield{$field} eq 'no') {
3428: $display = ' style="display:none"';
3429: }
3430: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3431: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3432: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3433: }
3434: $datatable .= '</td></tr>';
3435: }
3436: $datatable .= '</table>';
3437: }
3438: $datatable .= '</td></tr>'."\n";
3439: $rownum ++;
3440: }
3441: unless ($position eq 'top') {
1.286 raeburn 3442: foreach my $type (@mailings) {
3443: $css_class = $rownum%2?' class="LC_odd_row"':'';
3444: $datatable .= '<tr'.$css_class.'>'.
3445: '<td><span class="LC_nobreak">'.
3446: $titles->{$type}.': </span></td>'.
3447: '<td class="LC_left_item">';
3448: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3449: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3450: }
3451: $datatable .= '<span class="LC_nobreak">';
3452: foreach my $item (@contacts) {
3453: $datatable .= '<label>'.
3454: '<input type="checkbox" name="'.$type.'"'.
3455: $checked{$type}{$item}.
3456: ' value="'.$item.'" />'.$short_titles->{$item}.
3457: '</label> ';
3458: }
3459: $datatable .= '</span><br />'.&mt('Others').': '.
3460: '<input type="text" name="'.$type.'_others" '.
3461: 'value="'.$otheremails{$type}.'" />';
3462: my %locchecked;
3463: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3464: foreach my $loc ('s','b') {
3465: if ($includeloc{$type} eq $loc) {
3466: $locchecked{$loc} = ' checked="checked"';
3467: last;
3468: }
3469: }
3470: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3471: '<input type="text" name="'.$type.'_bcc" '.
3472: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3473: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3474: &mt('Text automatically added to e-mail:').' '.
3475: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3476: '<span class="LC_nobreak">'.&mt('Location:').' '.
3477: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3478: (' 'x2).
3479: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3480: '</span></fieldset>';
3481: }
3482: $datatable .= '</td></tr>'."\n";
3483: $rownum ++;
3484: }
1.28 raeburn 3485: }
1.286 raeburn 3486: if ($position eq 'middle') {
3487: my %choices;
3488: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
1.289 raeburn 3489: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3490: &mt('LON-CAPA core group - MSU'),600,500));
1.286 raeburn 3491: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3492: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3493: &mt('LON-CAPA core group - MSU'),600,500));
3494: my @toggles = ('reporterrors','reportupdates');
3495: my %defaultchecked = ('reporterrors' => 'on',
3496: 'reportupdates' => 'on');
3497: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3498: \%choices,$rownum);
3499: $datatable .= $reports;
3500: } elsif ($position eq 'bottom') {
1.315 raeburn 3501: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3502: my (@posstypes,%usertypeshash);
3503: if (ref($types) eq 'ARRAY') {
3504: @posstypes = @{$types};
3505: }
3506: if (@posstypes) {
3507: if (ref($usertypes) eq 'HASH') {
3508: %usertypeshash = %{$usertypes};
3509: }
3510: my @overridden;
3511: my $numinrow = 4;
3512: if (ref($settings) eq 'HASH') {
3513: if (ref($settings->{'overrides'}) eq 'HASH') {
3514: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3515: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3516: push(@overridden,$key);
3517: foreach my $item (@contacts) {
3518: if ($settings->{'overrides'}{$key}{$item}) {
3519: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3520: }
3521: }
3522: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3523: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3524: $includeloc{'override_'.$key} = '';
3525: $includestr{'override_'.$key} = '';
3526: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3527: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3528: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3529: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3530: }
1.286 raeburn 3531: }
3532: }
3533: }
1.315 raeburn 3534: }
3535: my $customclass = 'LC_helpdesk_override';
3536: my $optionsprefix = 'LC_options_helpdesk_';
3537:
3538: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3539:
3540: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3541: $numinrow,$othertitle,'overrides',
3542: \$rownum,$onclicktypes,$customclass);
3543: $rownum ++;
3544: $usertypeshash{'default'} = $othertitle;
3545: foreach my $status (@posstypes) {
3546: my $css_class;
3547: if ($rownum%2) {
3548: $css_class = 'LC_odd_row ';
3549: }
3550: $css_class .= $customclass;
3551: my $rowid = $optionsprefix.$status;
3552: my $hidden = 1;
3553: my $currstyle = 'display:none';
3554: if (grep(/^\Q$status\E$/,@overridden)) {
3555: $currstyle = 'display:table-row';
3556: $hidden = 0;
3557: }
3558: my $key = 'override_'.$status;
3559: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3560: $includeloc{$key},$includestr{$key},$status,$rowid,
3561: $usertypeshash{$status},$css_class,$currstyle,
3562: \@contacts,$short_titles);
3563: unless ($hidden) {
3564: $rownum ++;
1.286 raeburn 3565: }
3566: }
1.134 raeburn 3567: }
1.28 raeburn 3568: }
1.30 raeburn 3569: $$rowtotal += $rownum;
1.28 raeburn 3570: return $datatable;
3571: }
3572:
1.315 raeburn 3573: sub overridden_helpdesk {
3574: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3575: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3576: my $class = 'LC_left_item';
3577: if ($css_class) {
3578: $css_class = ' class="'.$css_class.'"';
3579: }
3580: if ($rowid) {
3581: $rowid = ' id="'.$rowid.'"';
3582: }
3583: if ($rowstyle) {
3584: $rowstyle = ' style="'.$rowstyle.'"';
3585: }
3586: my ($output,$description);
3587: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3588: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3589: "<td>$description</td>\n".
3590: '<td class="'.$class.'" colspan="2">'.
3591: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3592: '<span class="LC_nobreak">';
3593: if (ref($contacts) eq 'ARRAY') {
3594: foreach my $item (@{$contacts}) {
3595: my $check;
3596: if (ref($checked) eq 'HASH') {
3597: $check = $checked->{$item};
3598: }
3599: my $title;
3600: if (ref($short_titles) eq 'HASH') {
3601: $title = $short_titles->{$item};
3602: }
3603: $output .= '<label>'.
3604: '<input type="checkbox" name="override_'.$type.'"'.$check.
3605: ' value="'.$item.'" />'.$title.'</label> ';
3606: }
3607: }
3608: $output .= '</span><br />'.&mt('Others').': '.
3609: '<input type="text" name="override_'.$type.'_others" '.
3610: 'value="'.$otheremails.'" />';
3611: my %locchecked;
3612: foreach my $loc ('s','b') {
3613: if ($includeloc eq $loc) {
3614: $locchecked{$loc} = ' checked="checked"';
3615: last;
3616: }
3617: }
3618: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3619: '<input type="text" name="override_'.$type.'_bcc" '.
3620: 'value="'.$bccemails.'" /></fieldset>'.
3621: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3622: &mt('Text automatically added to e-mail:').' '.
3623: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br >'.
3624: '<span class="LC_nobreak">'.&mt('Location:').' '.
3625: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3626: (' 'x2).
3627: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3628: '</span></fieldset>'.
3629: '</td></tr>'."\n";
3630: return $output;
3631: }
3632:
1.286 raeburn 3633: sub contacts_javascript {
3634: return <<"ENDSCRIPT";
3635:
3636: <script type="text/javascript">
3637: // <![CDATA[
3638:
3639: function screenshotSize(field) {
3640: if (document.getElementById('help_screenshotsize')) {
3641: if (field.value == 'no') {
1.289 raeburn 3642: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3643: } else {
3644: document.getElementById('help_screenshotsize').style.display="";
3645: }
3646: }
3647: return;
3648: }
3649:
1.315 raeburn 3650: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3651: if (form.elements[checkbox].length != undefined) {
3652: var count = 0;
3653: if (docount) {
3654: for (var i=0; i<form.elements[checkbox].length; i++) {
3655: if (form.elements[checkbox][i].checked) {
3656: count ++;
3657: }
3658: }
3659: }
3660: for (var i=0; i<form.elements[checkbox].length; i++) {
3661: var type = form.elements[checkbox][i].value;
3662: if (document.getElementById(prefix+type)) {
3663: if (form.elements[checkbox][i].checked) {
3664: document.getElementById(prefix+type).style.display = 'table-row';
3665: if (count % 2 == 1) {
3666: document.getElementById(prefix+type).className = target+' LC_odd_row';
3667: } else {
3668: document.getElementById(prefix+type).className = target;
3669: }
3670: count ++;
3671: } else {
3672: document.getElementById(prefix+type).style.display = 'none';
3673: }
3674: }
3675: }
3676: }
3677: return;
3678: }
3679:
3680:
1.286 raeburn 3681: // ]]>
3682: </script>
3683:
3684: ENDSCRIPT
3685: }
3686:
1.118 jms 3687: sub print_helpsettings {
1.282 raeburn 3688: my ($position,$dom,$settings,$rowtotal) = @_;
3689: my $confname = $dom.'-domainconfig';
1.285 raeburn 3690: my $formname = 'display';
1.168 raeburn 3691: my ($datatable,$itemcount);
1.282 raeburn 3692: if ($position eq 'top') {
3693: $itemcount = 1;
3694: my (%choices,%defaultchecked,@toggles);
3695: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3696: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3697: &mt('LON-CAPA bug tracker'),600,500));
3698: %defaultchecked = ('submitbugs' => 'on');
3699: @toggles = ('submitbugs');
3700: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3701: \%choices,$itemcount);
3702: $$rowtotal ++;
3703: } else {
3704: my $css_class;
3705: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3706: my (%customroles,%ordered,%current);
1.301 raeburn 3707: if (ref($settings) eq 'HASH') {
3708: if (ref($settings->{'adhoc'}) eq 'HASH') {
3709: %current = %{$settings->{'adhoc'}};
3710: }
1.285 raeburn 3711: }
3712: my $count = 0;
3713: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3714: if ($key=~/^rolesdef\_(\w+)$/) {
3715: my $rolename = $1;
1.285 raeburn 3716: my (%privs,$order);
1.282 raeburn 3717: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3718: $customroles{$rolename} = \%privs;
1.285 raeburn 3719: if (ref($current{$rolename}) eq 'HASH') {
3720: $order = $current{$rolename}{'order'};
3721: }
3722: if ($order eq '') {
3723: $order = $count;
3724: }
3725: $ordered{$order} = $rolename;
3726: $count++;
3727: }
3728: }
3729: my $maxnum = scalar(keys(%ordered));
3730: my @roles_by_num = ();
3731: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3732: push(@roles_by_num,$item);
3733: }
3734: my $context = 'domprefs';
3735: my $crstype = 'Course';
3736: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3737: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3738: my ($numstatustypes,@jsarray);
3739: if (ref($types) eq 'ARRAY') {
3740: if (@{$types} > 0) {
3741: $numstatustypes = scalar(@{$types});
3742: push(@accesstypes,'status');
3743: @jsarray = ('bystatus');
1.282 raeburn 3744: }
3745: }
1.290 raeburn 3746: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3747: if (keys(%domhelpdesk)) {
3748: push(@accesstypes,('inc','exc'));
3749: push(@jsarray,('notinc','notexc'));
3750: }
3751: my $hiddenstr = join("','",@jsarray);
3752: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.282 raeburn 3753: my $context = 'domprefs';
3754: my $crstype = 'Course';
1.285 raeburn 3755: my $prefix = 'helproles_';
3756: my $add_class = 'LC_hidden';
3757: foreach my $num (@roles_by_num) {
3758: my $role = $ordered{$num};
3759: my ($desc,$access,@statuses);
3760: if (ref($current{$role}) eq 'HASH') {
3761: $desc = $current{$role}{'desc'};
3762: $access = $current{$role}{'access'};
3763: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3764: @statuses = @{$current{$role}{'insttypes'}};
3765: }
3766: }
3767: if ($desc eq '') {
3768: $desc = $role;
3769: }
3770: my $identifier = 'custhelp'.$num;
1.282 raeburn 3771: my %full=();
3772: my %levels= (
3773: course => {},
3774: domain => {},
3775: system => {},
3776: );
3777: my %levelscurrent=(
3778: course => {},
3779: domain => {},
3780: system => {},
3781: );
3782: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3783: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3784: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3785: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 3786: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 3787: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3788: for (my $k=0; $k<=$maxnum; $k++) {
3789: my $vpos = $k+1;
3790: my $selstr;
3791: if ($k == $num) {
3792: $selstr = ' selected="selected" ';
3793: }
3794: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3795: }
3796: $datatable .= '</select>'.(' 'x2).
3797: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3798: '</td>'.
3799: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3800: &mt('Name shown to users:').
3801: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3802: '</fieldset>'.
3803: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3804: $othertitle,$usertypes,$types,\%domhelpdesk).
3805: '<fieldset>'.
3806: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3807: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3808: \%levelscurrent,$identifier,
3809: 'LC_hidden',$prefix.$num.'_privs').
3810: '</fieldset></td>';
1.282 raeburn 3811: $itemcount ++;
3812: }
3813: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3814: my $newcust = 'custhelp'.$count;
3815: my (%privs,%levelscurrent);
3816: my %full=();
3817: my %levels= (
3818: course => {},
3819: domain => {},
3820: system => {},
3821: );
3822: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3823: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3824: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 3825: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 3826: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3827: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3828: for (my $k=0; $k<$maxnum+1; $k++) {
3829: my $vpos = $k+1;
3830: my $selstr;
3831: if ($k == $maxnum) {
3832: $selstr = ' selected="selected" ';
3833: }
3834: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3835: }
3836: $datatable .= '</select> '."\n".
1.282 raeburn 3837: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3838: '</label></span></td>'.
1.285 raeburn 3839: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3840: '<span class="LC_nobreak">'.
3841: &mt('Internal name:').
3842: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3843: '</span>'.(' 'x4).
3844: '<span class="LC_nobreak">'.
3845: &mt('Name shown to users:').
3846: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3847: '</span></fieldset>'.
3848: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3849: $usertypes,$types,\%domhelpdesk).
3850: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3851: &Apache::lonuserutils::custom_role_header($context,$crstype,
3852: \@templateroles,$newcust).
3853: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3854: \%levelscurrent,$newcust).
1.285 raeburn 3855: '</fieldset></td></tr>';
1.282 raeburn 3856: $count ++;
3857: $$rowtotal += $count;
3858: }
1.166 raeburn 3859: return $datatable;
1.121 raeburn 3860: }
3861:
1.285 raeburn 3862: sub adhocbutton {
3863: my ($prefix,$num,$field,$visibility) = @_;
3864: my %lt = &Apache::lonlocal::texthash(
3865: show => 'Show details',
3866: hide => 'Hide details',
3867: );
3868: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3869: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3870: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3871: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3872: }
3873:
3874: sub helpsettings_javascript {
3875: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3876: return unless(ref($roles_by_num) eq 'ARRAY');
3877: my %html_js_lt = &Apache::lonlocal::texthash(
3878: show => 'Show details',
3879: hide => 'Hide details',
3880: );
3881: &html_escape(\%html_js_lt);
3882: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3883: return <<"ENDSCRIPT";
3884: <script type="text/javascript">
3885: // <![CDATA[
3886:
3887: function reorderHelpRoles(form,item) {
3888: var changedVal;
3889: $jstext
3890: var newpos = 'helproles_${total}_pos';
3891: var maxh = 1 + $total;
3892: var current = new Array();
3893: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3894: if (item == newpos) {
3895: changedVal = newitemVal;
3896: } else {
3897: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3898: current[newitemVal] = newpos;
3899: }
3900: for (var i=0; i<helproles.length; i++) {
3901: var elementName = 'helproles_'+helproles[i]+'_pos';
3902: if (elementName != item) {
3903: if (form.elements[elementName]) {
3904: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3905: current[currVal] = elementName;
3906: }
3907: }
3908: }
3909: var oldVal;
3910: for (var j=0; j<maxh; j++) {
3911: if (current[j] == undefined) {
3912: oldVal = j;
3913: }
3914: }
3915: if (oldVal < changedVal) {
3916: for (var k=oldVal+1; k<=changedVal ; k++) {
3917: var elementName = current[k];
3918: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3919: }
3920: } else {
3921: for (var k=changedVal; k<oldVal; k++) {
3922: var elementName = current[k];
3923: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3924: }
3925: }
3926: return;
3927: }
3928:
3929: function helpdeskAccess(num) {
3930: var curraccess = null;
3931: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3932: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3933: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3934: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3935: }
3936: }
3937: }
3938: var shown = Array();
3939: var hidden = Array();
3940: if (curraccess == 'none') {
3941: hidden = Array('$hiddenstr');
3942: } else {
3943: if (curraccess == 'status') {
3944: shown = Array('bystatus');
3945: hidden = Array('notinc','notexc');
3946: } else {
3947: if (curraccess == 'exc') {
3948: shown = Array('notexc');
3949: hidden = Array('notinc','bystatus');
3950: }
3951: if (curraccess == 'inc') {
3952: shown = Array('notinc');
3953: hidden = Array('notexc','bystatus');
3954: }
1.293 raeburn 3955: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 3956: hidden = Array('notinc','notexc','bystatus');
3957: }
3958: }
3959: }
3960: if (hidden.length > 0) {
3961: for (var i=0; i<hidden.length; i++) {
3962: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3963: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3964: }
3965: }
3966: }
3967: if (shown.length > 0) {
3968: for (var i=0; i<shown.length; i++) {
3969: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3970: if (shown[i] == 'privs') {
3971: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3972: } else {
3973: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3974: }
3975: }
3976: }
3977: }
3978: return;
3979: }
3980:
3981: function toggleHelpdeskItem(num,field) {
3982: if (document.getElementById('helproles_'+num+'_'+field)) {
3983: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 3984: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 3985: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3986: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3987: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3988: }
3989: } else {
3990: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3991: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3992: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3993: }
3994: }
3995: }
3996: return;
3997: }
3998:
3999: // ]]>
4000: </script>
4001:
4002: ENDSCRIPT
4003: }
4004:
4005: sub helpdeskroles_access {
4006: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4007: $usertypes,$types,$domhelpdesk) = @_;
4008: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4009: my %lt = &Apache::lonlocal::texthash(
4010: 'rou' => 'Role usage',
4011: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4012: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4013: 'dh' => 'All with domain helpdesk role',
4014: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4015: 'none' => 'None',
4016: 'status' => 'Determined based on institutional status',
4017: 'inc' => 'Include all, but exclude specific personnel',
4018: 'exc' => 'Exclude all, but include specific personnel',
4019: );
4020: my %usecheck = (
4021: all => ' checked="checked"',
4022: );
4023: my %displaydiv = (
4024: status => 'none',
4025: inc => 'none',
4026: exc => 'none',
4027: priv => 'block',
4028: );
4029: my $output;
4030: if (ref($current) eq 'HASH') {
4031: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4032: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4033: $usecheck{$current->{access}} = $usecheck{'all'};
4034: delete($usecheck{'all'});
4035: if ($current->{access} =~ /^(status|inc|exc)$/) {
4036: my $access = $1;
4037: $displaydiv{$access} = 'inline';
4038: } elsif ($current->{access} eq 'none') {
4039: $displaydiv{'priv'} = 'none';
4040: }
4041: }
4042: }
4043: }
4044: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4045: '<p>'.$lt{'whi'}.'</p>';
4046: foreach my $access (@{$accesstypes}) {
4047: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4048: ' onclick="helpdeskAccess('."'$num'".');" />'.
4049: $lt{$access}.'</label>';
4050: if ($access eq 'status') {
4051: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4052: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4053: $othertitle,$usertypes,$types).
4054: '</div>';
4055: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4056: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4057: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4058: '</div>';
4059: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4060: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4061: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4062: '</div>';
4063: }
4064: $output .= '</p>';
4065: }
4066: $output .= '</fieldset>';
4067: return $output;
4068: }
4069:
1.121 raeburn 4070: sub radiobutton_prefs {
1.192 raeburn 4071: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4072: $additional,$align) = @_;
1.121 raeburn 4073: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4074: (ref($choices) eq 'HASH'));
4075:
1.170 raeburn 4076: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4077:
4078: foreach my $item (@{$toggles}) {
4079: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4080: $checkedon{$item} = ' checked="checked" ';
4081: $checkedoff{$item} = ' ';
1.121 raeburn 4082: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4083: $checkedoff{$item} = ' checked="checked" ';
4084: $checkedon{$item} = ' ';
4085: }
4086: }
4087: if (ref($settings) eq 'HASH') {
1.121 raeburn 4088: foreach my $item (@{$toggles}) {
1.118 jms 4089: if ($settings->{$item} eq '1') {
4090: $checkedon{$item} = ' checked="checked" ';
4091: $checkedoff{$item} = ' ';
4092: } elsif ($settings->{$item} eq '0') {
4093: $checkedoff{$item} = ' checked="checked" ';
4094: $checkedon{$item} = ' ';
4095: }
4096: }
1.121 raeburn 4097: }
1.192 raeburn 4098: if ($onclick) {
4099: $onclick = ' onclick="'.$onclick.'"';
4100: }
1.121 raeburn 4101: foreach my $item (@{$toggles}) {
1.118 jms 4102: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4103: $datatable .=
1.306 raeburn 4104: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4105: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4106: '</span></td>';
4107: if ($align eq 'left') {
4108: $datatable .= '<td class="LC_left_item">';
4109: } else {
4110: $datatable .= '<td class="LC_right_item">';
4111: }
1.289 raeburn 4112: $datatable .=
1.257 raeburn 4113: '<span class="LC_nobreak">'.
1.118 jms 4114: '<label><input type="radio" name="'.
1.192 raeburn 4115: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4116: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4117: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4118: '</span>'.$additional.
4119: '</td>'.
1.118 jms 4120: '</tr>';
4121: $itemcount ++;
1.121 raeburn 4122: }
4123: return ($datatable,$itemcount);
4124: }
4125:
1.267 raeburn 4126: sub print_ltitools {
4127: my ($dom,$settings,$rowtotal) = @_;
4128: my $rownum = 0;
4129: my $css_class;
4130: my $itemcount = 1;
4131: my $maxnum = 0;
4132: my %ordered;
4133: if (ref($settings) eq 'HASH') {
4134: foreach my $item (keys(%{$settings})) {
4135: if (ref($settings->{$item}) eq 'HASH') {
4136: my $num = $settings->{$item}{'order'};
4137: $ordered{$num} = $item;
4138: }
4139: }
4140: }
4141: my $confname = $dom.'-domainconfig';
4142: my $switchserver = &check_switchserver($dom,$confname);
4143: my $maxnum = scalar(keys(%ordered));
4144: my $datatable = <itools_javascript($settings);
4145: my %lt = <itools_names();
4146: my @courseroles = ('cc','in','ta','ep','st');
4147: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4148: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4149: if (keys(%ordered)) {
4150: my @items = sort { $a <=> $b } keys(%ordered);
4151: for (my $i=0; $i<@items; $i++) {
4152: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4153: my $item = $ordered{$items[$i]};
1.323 raeburn 4154: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4155: if (ref($settings->{$item}) eq 'HASH') {
4156: $title = $settings->{$item}->{'title'};
4157: $url = $settings->{$item}->{'url'};
4158: $key = $settings->{$item}->{'key'};
4159: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4160: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4161: my $image = $settings->{$item}->{'image'};
4162: if ($image ne '') {
4163: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4164: }
1.323 raeburn 4165: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4166: $sigsel{'HMAC-256'} = ' selected="selected"';
4167: } else {
4168: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4169: }
1.267 raeburn 4170: }
1.319 raeburn 4171: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4172: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4173: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4174: for (my $k=0; $k<=$maxnum; $k++) {
4175: my $vpos = $k+1;
4176: my $selstr;
4177: if ($k == $i) {
4178: $selstr = ' selected="selected" ';
4179: }
4180: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4181: }
4182: $datatable .= '</select>'.(' 'x2).
4183: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4184: &mt('Delete?').'</label></span></td>'.
4185: '<td colspan="2">'.
4186: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4187: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4188: (' 'x2).
4189: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4190: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4191: (' 'x2).
4192: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4193: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4194: (' 'x2).
4195: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4196: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4197: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4198: '<br /><br />'.
1.323 raeburn 4199: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4200: ' value="'.$url.'" /></span>'.
4201: (' 'x2).
1.319 raeburn 4202: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4203: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4204: (' 'x2).
1.322 raeburn 4205: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4206: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4207: (' 'x2).
1.267 raeburn 4208: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4209: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4210: '<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>'.
4211: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4212: '</fieldset>'.
4213: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4214: '<span class="LC_nobreak">'.&mt('Display target:');
4215: my %currdisp;
4216: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4217: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4218: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4219: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4220: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4221: } else {
4222: $currdisp{'iframe'} = ' checked="checked"';
4223: }
4224: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4225: $currdisp{'width'} = $1;
4226: }
4227: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4228: $currdisp{'height'} = $1;
4229: }
1.296 raeburn 4230: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4231: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4232: } else {
4233: $currdisp{'iframe'} = ' checked="checked"';
4234: }
1.298 raeburn 4235: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4236: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4237: $lt{$disp}.'</label>'.(' 'x2);
4238: }
4239: $datatable .= (' 'x4);
4240: foreach my $dimen ('width','height') {
4241: $datatable .= '<label>'.$lt{$dimen}.' '.
4242: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4243: (' 'x2);
4244: }
1.296 raeburn 4245: $datatable .= '<br />'.
4246: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4247: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
4248: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4249: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4250: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4251: my %units = (
4252: 'passback' => 'days',
4253: 'roster' => 'seconds',
4254: );
1.267 raeburn 4255: foreach my $extra ('passback','roster') {
1.319 raeburn 4256: my $validsty = 'none';
4257: my $currvalid;
1.267 raeburn 4258: my $checkedon = '';
4259: my $checkedoff = ' checked="checked"';
4260: if ($settings->{$item}->{$extra}) {
4261: $checkedon = $checkedoff;
4262: $checkedoff = '';
1.319 raeburn 4263: $validsty = 'inline-block';
4264: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4265: $currvalid = $settings->{$item}->{$extra.'valid'};
4266: }
4267: }
4268: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4269: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4270: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4271: &mt('No').'</label>'.(' 'x2).
4272: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4273: &mt('Yes').'</label></span></div>'.
4274: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4275: '<span class="LC_nobreak">'.
4276: &mt("at least [_1] $units{$extra} after launch",
4277: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4278: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4279: }
1.319 raeburn 4280: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4281: if ($imgsrc) {
4282: $datatable .= $imgsrc.
4283: '<label><input type="checkbox" name="ltitools_image_del"'.
4284: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4285: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4286: } else {
4287: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4288: }
4289: if ($switchserver) {
4290: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4291: } else {
4292: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4293: }
4294: $datatable .= '</span></fieldset>';
1.324 raeburn 4295: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4296: if (ref($settings->{$item}) eq 'HASH') {
4297: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4298: %checkedfields = %{$settings->{$item}->{'fields'}};
4299: }
1.324 raeburn 4300: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4301: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4302: %rolemaps = %{$settings->{$item}->{'roles'}};
4303: $checkedfields{'roles'} = 1;
4304: }
4305: }
4306: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4307: '<span class="LC_nobreak">';
1.324 raeburn 4308: my $userfieldstyle = 'display:none;';
4309: my $seluserdom = '';
4310: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4311: foreach my $field (@fields) {
1.324 raeburn 4312: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4313: if ($checkedfields{$field}) {
4314: $checked = ' checked="checked"';
4315: }
1.324 raeburn 4316: if ($field eq 'user') {
4317: $id = ' id="ltitools_user_field_'.$i.'"';
4318: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4319: if ($checked) {
4320: $userfieldstyle = 'display:inline-block';
4321: if ($userincdom) {
4322: $seluserdom = $unseluserdom;
4323: $unseluserdom = '';
4324: }
4325: }
4326: } else {
4327: $spacer = (' ' x2);
4328: }
1.267 raeburn 4329: $datatable .= '<label>'.
1.324 raeburn 4330: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4331: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4332: }
1.324 raeburn 4333: $datatable .= '</span>';
4334: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4335: '<span class="LC_nobreak"> : '.
4336: '<select name="ltitools_userincdom_'.$i.'">'.
4337: '<option value="">'.&mt('Select').'</option>'.
4338: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4339: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4340: '</select></span></div>';
4341: $datatable .= '</fieldset>'.
1.267 raeburn 4342: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4343: foreach my $role (@courseroles) {
4344: my ($selected,$selectnone);
4345: if (!$rolemaps{$role}) {
4346: $selectnone = ' selected="selected"';
4347: }
1.306 raeburn 4348: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4349: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4350: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4351: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4352: foreach my $ltirole (@ltiroles) {
4353: unless ($selectnone) {
4354: if ($rolemaps{$role} eq $ltirole) {
4355: $selected = ' selected="selected"';
4356: } else {
4357: $selected = '';
4358: }
4359: }
4360: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4361: }
4362: $datatable .= '</select></td>';
4363: }
1.273 raeburn 4364: $datatable .= '</tr></table></fieldset>';
4365: my %courseconfig;
4366: if (ref($settings->{$item}) eq 'HASH') {
4367: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4368: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4369: }
4370: }
4371: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4372: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4373: my $checked;
4374: if ($courseconfig{$item}) {
4375: $checked = ' checked="checked"';
4376: }
4377: $datatable .= '<label>'.
4378: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4379: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4380: }
4381: $datatable .= '</span></fieldset>'.
1.267 raeburn 4382: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4383: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4384: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4385: my %custom = %{$settings->{$item}->{'custom'}};
4386: if (keys(%custom) > 0) {
4387: foreach my $key (sort(keys(%custom))) {
4388: $datatable .= '<tr><td><span class="LC_nobreak">'.
4389: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4390: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4391: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4392: ' value="'.$custom{$key}.'" /></td></tr>';
4393: }
4394: }
4395: }
4396: $datatable .= '<tr><td><span class="LC_nobreak">'.
4397: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4398: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4399: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4400: $datatable .= '</table></fieldset></td></tr>'."\n";
4401: $itemcount ++;
4402: }
4403: }
4404: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4405: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4406: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4407: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4408: '<select name="ltitools_add_pos"'.$chgstr.'>';
4409: for (my $k=0; $k<$maxnum+1; $k++) {
4410: my $vpos = $k+1;
4411: my $selstr;
4412: if ($k == $maxnum) {
4413: $selstr = ' selected="selected" ';
4414: }
4415: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4416: }
4417: $datatable .= '</select> '."\n".
4418: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
4419: '<td colspan="2">'.
4420: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4421: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4422: (' 'x2).
4423: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4424: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4425: (' 'x2).
4426: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4427: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4428: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4429: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4430: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4431: '<br />'.
1.323 raeburn 4432: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4433: (' 'x2).
4434: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4435: (' 'x2).
1.322 raeburn 4436: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4437: (' 'x2).
1.267 raeburn 4438: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4439: '<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".
4440: '</fieldset>'.
4441: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4442: '<span class="LC_nobreak">'.&mt('Display target:');
4443: my %defaultdisp;
4444: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4445: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4446: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4447: $lt{$disp}.'</label>'.(' 'x2);
4448: }
4449: $datatable .= (' 'x4);
4450: foreach my $dimen ('width','height') {
4451: $datatable .= '<label>'.$lt{$dimen}.' '.
4452: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4453: (' 'x2);
4454: }
1.296 raeburn 4455: $datatable .= '<br />'.
4456: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4457: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
4458: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4459: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4460: '</div><div style=""></div><br />';
1.319 raeburn 4461: my %units = (
4462: 'passback' => 'days',
4463: 'roster' => 'seconds',
4464: );
4465: my %defaulttimes = (
4466: 'passback' => '7',
1.322 raeburn 4467: 'roster' => '300',
1.319 raeburn 4468: );
1.267 raeburn 4469: foreach my $extra ('passback','roster') {
1.319 raeburn 4470: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4471: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4472: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4473: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4474: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4475: &mt('Yes').'</label></span></div>'.
4476: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4477: '<span class="LC_nobreak">'.
4478: &mt("at least [_1] $units{$extra} after launch",
4479: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4480: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4481: }
1.319 raeburn 4482: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4483: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4484: if ($switchserver) {
4485: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4486: } else {
4487: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4488: }
4489: $datatable .= '</span></fieldset>'.
4490: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4491: '<span class="LC_nobreak">';
4492: foreach my $field (@fields) {
1.324 raeburn 4493: my ($id,$onclick,$spacer);
4494: if ($field eq 'user') {
4495: $id = ' id="ltitools_user_field_add"';
4496: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4497: } else {
4498: $spacer = (' ' x2);
4499: }
1.267 raeburn 4500: $datatable .= '<label>'.
1.324 raeburn 4501: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4502: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4503: }
1.324 raeburn 4504: $datatable .= '</span>'.
4505: '<div style="display:none;" id="ltitools_user_div_add">'.
4506: '<span class="LC_nobreak"> : '.
4507: '<select name="ltitools_userincdom_add">'.
4508: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4509: '<option value="0">'.&mt('username').'</option>'.
4510: '<option value="1">'.&mt('username:domain').'</option>'.
4511: '</select></span></div></fieldset>';
4512: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 4513: foreach my $role (@courseroles) {
4514: my ($checked,$checkednone);
1.306 raeburn 4515: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4516: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4517: '<select name="ltitools_add_roles_'.$role.'">'.
4518: '<option value="" selected="selected">'.&mt('Select').'</option>';
4519: foreach my $ltirole (@ltiroles) {
4520: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4521: }
4522: $datatable .= '</select></td>';
4523: }
4524: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4525: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4526: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4527: $datatable .= '<label>'.
4528: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4529: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4530: }
4531: $datatable .= '</span></fieldset>'.
1.267 raeburn 4532: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4533: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4534: '<tr><td><span class="LC_nobreak">'.
4535: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4536: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4537: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4538: '</table></fieldset></td></tr>'."\n".
4539: '</td>'."\n".
4540: '</tr>'."\n";
4541: $itemcount ++;
4542: return $datatable;
4543: }
4544:
4545: sub ltitools_names {
4546: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4547: 'title' => 'Title',
4548: 'version' => 'Version',
4549: 'msgtype' => 'Message Type',
1.323 raeburn 4550: 'sigmethod' => 'Signature Method',
1.296 raeburn 4551: 'url' => 'URL',
4552: 'key' => 'Key',
1.322 raeburn 4553: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4554: 'secret' => 'Secret',
4555: 'icon' => 'Icon',
1.324 raeburn 4556: 'user' => 'User',
1.296 raeburn 4557: 'fullname' => 'Full Name',
4558: 'firstname' => 'First Name',
4559: 'lastname' => 'Last Name',
4560: 'email' => 'E-mail',
4561: 'roles' => 'Role',
1.298 raeburn 4562: 'window' => 'Window',
4563: 'tab' => 'Tab',
1.296 raeburn 4564: 'iframe' => 'iFrame',
4565: 'height' => 'Height',
4566: 'width' => 'Width',
4567: 'linktext' => 'Default Link Text',
4568: 'explanation' => 'Default Explanation',
4569: 'passback' => 'Tool can return grades:',
4570: 'roster' => 'Tool can retrieve roster:',
4571: 'crstarget' => 'Display target',
4572: 'crslabel' => 'Course label',
4573: 'crstitle' => 'Course title',
4574: 'crslinktext' => 'Link Text',
4575: 'crsexplanation' => 'Explanation',
1.318 raeburn 4576: 'crsappend' => 'Provider URL',
1.267 raeburn 4577: );
4578: return %lt;
4579: }
4580:
1.320 raeburn 4581: sub print_lti {
4582: my ($dom,$settings,$rowtotal) = @_;
4583: my $itemcount = 1;
4584: my $maxnum = 0;
4585: my $css_class;
4586: my %ordered;
4587: if (ref($settings) eq 'HASH') {
4588: foreach my $item (keys(%{$settings})) {
4589: if (ref($settings->{$item}) eq 'HASH') {
4590: my $num = $settings->{$item}{'order'};
4591: $ordered{$num} = $item;
4592: }
4593: }
4594: }
4595: my $maxnum = scalar(keys(%ordered));
4596: my $datatable = <i_javascript($settings);
4597: my %lt = <i_names();
4598: if (keys(%ordered)) {
4599: my @items = sort { $a <=> $b } keys(%ordered);
4600: for (my $i=0; $i<@items; $i++) {
4601: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4602: my $item = $ordered{$items[$i]};
4603: my ($key,$secret,$lifetime,$consumer,$current);
4604: if (ref($settings->{$item}) eq 'HASH') {
4605: $key = $settings->{$item}->{'key'};
4606: $secret = $settings->{$item}->{'secret'};
4607: $lifetime = $settings->{$item}->{'lifetime'};
4608: $consumer = $settings->{$item}->{'consumer'};
4609: $current = $settings->{$item};
4610: }
4611: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
4612: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4613: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
4614: for (my $k=0; $k<=$maxnum; $k++) {
4615: my $vpos = $k+1;
4616: my $selstr;
4617: if ($k == $i) {
4618: $selstr = ' selected="selected" ';
4619: }
4620: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4621: }
4622: $datatable .= '</select>'.(' 'x2).
4623: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
4624: &mt('Delete?').'</label></span></td>'.
4625: '<td colspan="2">'.
4626: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4627: '<span class="LC_nobreak">'.$lt{'consumer'}.
4628: ':<input type="text" size="20" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
4629: (' 'x2).
4630: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
4631: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4632: (' 'x2).
4633: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
4634: 'value="'.$lifetime.'" size="5" /></span>'.
4635: '<br /><br />'.
4636: '<span class="LC_nobreak">'.$lt{'key'}.
4637: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
4638: (' 'x2).
4639: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4640: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
4641: '<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>'.
4642: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 ! raeburn 4643: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 4644: $itemcount ++;
4645: }
4646: }
4647: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4648: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
4649: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4650: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
4651: '<select name="lti_pos_add"'.$chgstr.'>';
4652: for (my $k=0; $k<$maxnum+1; $k++) {
4653: my $vpos = $k+1;
4654: my $selstr;
4655: if ($k == $maxnum) {
4656: $selstr = ' selected="selected" ';
4657: }
4658: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4659: }
4660: $datatable .= '</select> '."\n".
4661: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</td>'."\n".
4662: '<td colspan="2">'.
4663: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4664: '<span class="LC_nobreak">'.$lt{'consumer'}.
4665: ':<input type="text" size="20" name="lti_consumer_add" value="" /></span> '."\n".
4666: (' 'x2).
4667: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
4668: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4669: (' 'x2).
1.322 raeburn 4670: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="lti_lifetime_add" value="300" /></span> '."\n".
1.320 raeburn 4671: '<br /><br />'.
4672: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
4673: (' 'x2).
4674: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
4675: '<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 4676: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 4677: '</td>'."\n".
4678: '</tr>'."\n";
4679: $$rowtotal ++;
4680: return $datatable;;
4681: }
4682:
4683: sub lti_names {
4684: my %lt = &Apache::lonlocal::texthash(
4685: 'version' => 'LTI Version',
4686: 'url' => 'URL',
4687: 'key' => 'Key',
1.322 raeburn 4688: 'lifetime' => 'Nonce lifetime (s)',
1.320 raeburn 4689: 'consumer' => 'LTI Consumer',
4690: 'secret' => 'Secret',
4691: 'email' => 'Email address',
4692: 'sourcedid' => 'User ID',
4693: 'other' => 'Other',
4694: 'passback' => 'Can return grades to Consumer:',
4695: 'roster' => 'Can retrieve roster from Consumer:',
4696: );
4697: return %lt;
4698: }
4699:
4700: sub lti_options {
1.325 ! raeburn 4701: my ($num,$current,$itemcount,%lt) = @_;
1.320 raeburn 4702: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);
4703: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
4704: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
4705: $checked{'makecrs'}{'N'} = ' checked="checked"';
4706: $checked{'mapcrstype'} = {};
4707: $checked{'makeuser'} = {};
4708: $checked{'selfenroll'} = {};
4709: $checked{'crssec'} = {};
4710: $checked{'crssecsrc'} = {};
1.325 ! raeburn 4711: $checked{'lcauth'} = {};
! 4712: if ($num eq 'add') {
! 4713: $checked{'lcauth'}{'lti'} = ' checked="checked"';
! 4714: }
1.320 raeburn 4715: my $userfieldsty = 'none';
4716: my $crsfieldsty = 'none';
4717: my $crssecfieldsty = 'none';
4718: my $secsrcfieldsty = 'none';
1.325 ! raeburn 4719: my $lcauthparm;
! 4720: my $lcauthparmstyle = 'display:none';
! 4721: my $lcauthparmtext;
! 4722: my $numinrow = 4;
1.320 raeburn 4723:
4724: if (ref($current) eq 'HASH') {
4725: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
4726: $checked{'mapuser'}{'sourcedid'} = '';
4727: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
4728: $checked{'mapuser'}{'email'} = ' checked="checked"';
4729: } else {
4730: $checked{'mapuser'}{'other'} = ' checked="checked"';
4731: $userfield = $current->{'mapuser'};
4732: $userfieldsty = 'inline-block';
4733: }
4734: }
4735: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
4736: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
4737: if ($current->{'mapcrs'} eq 'context_id') {
4738: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
4739: } else {
4740: $checked{'mapcrs'}{'other'} = ' checked="checked"';
4741: $cidfield = $current->{'mapcrs'};
4742: $crsfieldsty = 'inline-block';
4743: }
4744: }
4745: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
4746: foreach my $type (@{$current->{'mapcrstype'}}) {
4747: $checked{'mapcrstype'}{$type} = ' checked="checked"';
4748: }
4749: }
4750: if ($current->{'makecrs'}) {
4751: $checked{'makecrs'}{'Y'} = ' checked="checked"';
4752: }
4753: if (ref($current->{'makeuser'}) eq 'ARRAY') {
4754: foreach my $role (@{$current->{'makeuser'}}) {
4755: $checked{'makeuser'}{$role} = ' checked="checked"';
4756: }
4757: }
1.325 ! raeburn 4758: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
! 4759: $checked{'lcauth'}{$1} = ' checked="checked"';
! 4760: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
! 4761: $lcauthparm = $current->{'lcauthparm'};
! 4762: $lcauthparmstyle = 'display:table-row';
! 4763: if ($current->{'lcauth'} eq 'localauth') {
! 4764: $lcauthparmtext = &mt('Local auth argument');
! 4765: } else {
! 4766: $lcauthparmtext = &mt('Kerberos domain');
! 4767: }
! 4768: }
! 4769: }
1.320 raeburn 4770: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
4771: foreach my $role (@{$current->{'selfenroll'}}) {
4772: $checked{'selfenroll'}{$role} = ' checked="checked"';
4773: }
4774: }
4775: if (ref($current->{'maproles'}) eq 'HASH') {
4776: %rolemaps = %{$current->{'maproles'}};
4777: }
4778: if ($current->{'section'} ne '') {
4779: $checked{'crssec'}{'Y'} = ' checked="checked"';
4780: $crssecfieldsty = 'inline-block';
4781: if ($current->{'section'} eq 'course_section_sourcedid') {
4782: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
4783: } else {
4784: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
4785: $crssecsrc = $current->{'section'};
4786: $secsrcfieldsty = 'inline-block';
4787: }
4788: } else {
4789: $checked{'crssec'}{'N'} = ' checked="checked"';
4790: }
4791: } else {
4792: $checked{'makecrs'}{'N'} = ' checked="checked"';
4793: $checked{'crssec'}{'N'} = ' checked="checked"';
1.325 ! raeburn 4794: #FIXME
1.320 raeburn 4795: }
1.325 ! raeburn 4796: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 4797: my %coursetypetitles = &Apache::lonlocal::texthash (
4798: official => 'Official',
4799: unofficial => 'Unofficial',
4800: community => 'Community',
4801: textbook => 'Textbook',
4802: placement => 'Placement Test',
1.325 ! raeburn 4803: lti => 'LTI Provider',
1.320 raeburn 4804: );
1.325 ! raeburn 4805: my @authtypes = ('internal','krb4','krb5','localauth');
! 4806: my %shortauth = (
! 4807: internal => 'int',
! 4808: krb4 => 'krb4',
! 4809: krb5 => 'krb5',
! 4810: localauth => 'loc'
! 4811: );
! 4812: my %authnames = &authtype_names();
1.320 raeburn 4813: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
4814: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
4815: my @courseroles = ('cc','in','ta','ep','st');
4816: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
4817: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
4818: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
4819: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 ! raeburn 4820: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.320 raeburn 4821: my $output = '<fieldset><legend>'.&mt('Mapping users').'</legend>'.
4822: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
4823: foreach my $option ('sourcedid','email','other') {
4824: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
4825: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
4826: ($option eq 'other' ? '' : (' 'x2) );
4827: }
4828: $output .= '</span></div>'.
4829: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
4830: '<input type="text" name="lti_customuser_'.$num.'" '.
4831: 'value="'.$userfield.'" /></div></fieldset>'.
4832: '<fieldset><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
4833: foreach my $ltirole (@lticourseroles) {
4834: my ($selected,$selectnone);
4835: if ($rolemaps{$ltirole} eq '') {
4836: $selectnone = ' selected="selected"';
4837: }
4838: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
4839: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
4840: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4841: foreach my $role (@courseroles) {
4842: unless ($selectnone) {
4843: if ($rolemaps{$ltirole} eq $role) {
4844: $selected = ' selected="selected"';
4845: } else {
4846: $selected = '';
4847: }
4848: }
4849: $output .= '<option value="'.$role.'"'.$selected.'>'.
4850: &Apache::lonnet::plaintext($role,'Course').
4851: '</option>';
4852: }
4853: $output .= '</select></td>';
4854: }
4855: $output .= '</tr></table></fieldset>'.
4856: '<fieldset><legend>'.&mt('Roles which may create user accounts').'</legend>';
4857: foreach my $ltirole (@ltiroles) {
4858: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
4859: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
4860: }
4861: $output .= '</fieldset>'.
1.325 ! raeburn 4862: '<fieldset><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
! 4863: '<table>'.
! 4864: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
! 4865: '</table>'.
! 4866: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
! 4867: '<td class="LC_left_item">';
! 4868: foreach my $auth ('lti',@authtypes) {
! 4869: my $authtext;
! 4870: if ($auth eq 'lti') {
! 4871: $authtext = &mt('None');
! 4872: } else {
! 4873: $authtext = $authnames{$shortauth{$auth}};
! 4874: }
! 4875: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
! 4876: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
! 4877: $authtext.'</label></span> ';
! 4878: }
! 4879: $output .= '</td></tr>'.
! 4880: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
! 4881: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
! 4882: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
! 4883: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
! 4884: '</table></fieldset>'.
1.320 raeburn 4885: '<fieldset><legend>'.&mt('Mapping courses').'</legend>'.
4886: '<div class="LC_floatleft"><span class="LC_nobreak">'.
4887: &mt('Unique course identifier').': ';
4888: foreach my $option ('course_offering_sourcedid','context_id','other') {
4889: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
4890: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
4891: ($option eq 'other' ? '' : (' 'x2) );
4892: }
4893: $output .= '</div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'".>'.
4894: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
4895: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
4896: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
4897: foreach my $type (@coursetypes) {
4898: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
4899: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
4900: (' 'x2);
4901: }
4902: $output .= '</span></fieldset>'.
4903: '<fieldset><legend>'.&mt('Creating courses').'</legend>'.
4904: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
4905: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
4906: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
4907: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
4908: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
4909: '</fieldset>'.
4910: '<fieldset><legend>'.&mt('Roles which may self-enroll').'</legend>';
4911: foreach my $lticrsrole (@lticourseroles) {
4912: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
4913: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
4914: }
4915: $output .= '</fieldset>'.
4916: '<fieldset><legend>'.&mt('Course options').'</legend>'.
4917: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
4918: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
4919: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
4920: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
4921: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label><span></div>'.
4922: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
4923: '<span class="LC_nobreak">'.&mt('From').':<label>'.
4924: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
4925: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
4926: &mt('Standard field').'</label>'.(' 'x2).
4927: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
4928: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
4929: '</label></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
4930: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
4931: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
4932: foreach my $extra ('passback','roster') {
4933: my $checkedon = '';
4934: my $checkedoff = ' checked="checked"';
4935: if (ref($current) eq 'HASH') {
4936: if (($current->{$extra})) {
4937: $checkedon = $checkedoff;
4938: $checkedoff = '';
4939: }
4940: }
4941: $output .= $lt{$extra}.' '.
4942: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.' />'.
4943: &mt('No').'</label>'.(' 'x2).
4944: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.' />'.
4945: &mt('Yes').'</label><br />';
4946: }
4947: $output .= '</span></fieldset>';
4948: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
4949: #
4950: # $output .= '</fieldset>'.
4951: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
4952: return $output;
4953: }
4954:
1.121 raeburn 4955: sub print_coursedefaults {
1.139 raeburn 4956: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 4957: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4958: my $itemcount = 1;
1.192 raeburn 4959: my %choices = &Apache::lonlocal::texthash (
4960: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 4961: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 4962: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4963: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 4964: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4965: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 4966: texengine => 'Default method to display mathematics',
1.257 raeburn 4967: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 4968: canclone => "People who may clone a course (besides course's owner and coordinators)",
4969: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 4970: );
1.198 raeburn 4971: my %staticdefaults = (
1.314 raeburn 4972: texengine => 'MathJax',
1.198 raeburn 4973: anonsurvey_threshold => 10,
4974: uploadquota => 500,
1.257 raeburn 4975: postsubmit => 60,
1.276 raeburn 4976: mysqltables => 172800,
1.198 raeburn 4977: );
1.139 raeburn 4978: if ($position eq 'top') {
1.257 raeburn 4979: %defaultchecked = (
4980: 'canuse_pdfforms' => 'off',
4981: 'uselcmath' => 'on',
4982: 'usejsme' => 'on',
1.289 raeburn 4983: 'canclone' => 'none',
1.257 raeburn 4984: );
4985: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.314 raeburn 4986: my $deftex = $staticdefaults{'texengine'};
4987: if (ref($settings) eq 'HASH') {
4988: if ($settings->{'texengine'}) {
4989: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4990: $deftex = $settings->{'texengine'};
4991: }
4992: }
4993: }
4994: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4995: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4996: '<span class="LC_nobreak">'.$choices{'texengine'}.
4997: '</span></td><td class="LC_right_item">'.
4998: '<select name="texengine">'."\n";
4999: my %texoptions = (
5000: MathJax => 'MathJax',
5001: mimetex => &mt('Convert to Images'),
5002: tth => &mt('TeX to HTML'),
5003: );
5004: foreach my $renderer ('MathJax','mimetex','tth') {
5005: my $selected = '';
5006: if ($renderer eq $deftex) {
5007: $selected = ' selected="selected"';
5008: }
5009: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5010: }
5011: $mathdisp .= '</select></td></tr>'."\n";
5012: $itemcount ++;
1.139 raeburn 5013: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 5014: \%choices,$itemcount);
1.314 raeburn 5015: $datatable = $mathdisp.$datatable;
1.264 raeburn 5016: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5017: $datatable .=
1.306 raeburn 5018: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 5019: '<span class="LC_nobreak">'.$choices{'canclone'}.
5020: '</span></td><td class="LC_left_item">';
5021: my $currcanclone = 'none';
5022: my $onclick;
5023: my @cloneoptions = ('none','domain');
5024: my %clonetitles = (
5025: none => 'No additional course requesters',
5026: domain => "Any course requester in course's domain",
5027: instcode => 'Course requests for official courses ...',
5028: );
5029: my (%codedefaults,@code_order,@posscodes);
5030: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5031: \@code_order) eq 'ok') {
5032: if (@code_order > 0) {
5033: push(@cloneoptions,'instcode');
5034: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5035: }
5036: }
5037: if (ref($settings) eq 'HASH') {
5038: if ($settings->{'canclone'}) {
5039: if (ref($settings->{'canclone'}) eq 'HASH') {
5040: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5041: if (@code_order > 0) {
5042: $currcanclone = 'instcode';
5043: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5044: }
5045: }
5046: } elsif ($settings->{'canclone'} eq 'domain') {
5047: $currcanclone = $settings->{'canclone'};
5048: }
5049: }
1.289 raeburn 5050: }
1.264 raeburn 5051: foreach my $option (@cloneoptions) {
5052: my ($checked,$additional);
5053: if ($currcanclone eq $option) {
5054: $checked = ' checked="checked"';
5055: }
5056: if ($option eq 'instcode') {
5057: if (@code_order) {
5058: my $show = 'none';
5059: if ($checked) {
5060: $show = 'block';
5061: }
1.317 raeburn 5062: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 5063: &mt('Institutional codes for new and cloned course have identical:').
5064: '<br />';
5065: foreach my $item (@code_order) {
5066: my $codechk;
5067: if ($checked) {
5068: if (grep(/^\Q$item\E$/,@posscodes)) {
5069: $codechk = ' checked="checked"';
5070: }
5071: }
5072: $additional .= '<label>'.
5073: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5074: $item.'</label>';
5075: }
5076: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5077: }
5078: }
5079: $datatable .=
5080: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5081: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5082: '</label> '.$additional.'</span><br />';
5083: }
5084: $datatable .= '</td>'.
5085: '</tr>';
5086: $itemcount ++;
1.139 raeburn 5087: } else {
5088: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 5089: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 5090: my $currusecredits = 0;
1.257 raeburn 5091: my $postsubmitclient = 1;
1.271 raeburn 5092: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 5093: if (ref($settings) eq 'HASH') {
5094: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 5095: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5096: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5097: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5098: }
5099: }
1.192 raeburn 5100: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 5101: foreach my $type (@types) {
5102: next if ($type eq 'community');
5103: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5104: if ($defcredits{$type} ne '') {
5105: $currusecredits = 1;
5106: }
5107: }
5108: }
5109: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5110: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5111: $postsubmitclient = 0;
5112: foreach my $type (@types) {
5113: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5114: }
5115: } else {
5116: foreach my $type (@types) {
5117: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5118: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 5119: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 5120: } else {
5121: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5122: }
5123: } else {
5124: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5125: }
5126: }
5127: }
5128: } else {
5129: foreach my $type (@types) {
5130: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 5131: }
5132: }
1.276 raeburn 5133: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5134: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5135: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5136: }
5137: } else {
5138: foreach my $type (@types) {
5139: $currmysql{$type} = $staticdefaults{'mysqltables'};
5140: }
5141: }
1.258 raeburn 5142: } else {
5143: foreach my $type (@types) {
5144: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5145: }
1.139 raeburn 5146: }
5147: if (!$currdefresponder) {
1.198 raeburn 5148: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5149: } elsif ($currdefresponder < 1) {
5150: $currdefresponder = 1;
5151: }
1.198 raeburn 5152: foreach my $type (@types) {
5153: if ($curruploadquota{$type} eq '') {
5154: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5155: }
5156: }
1.139 raeburn 5157: $datatable .=
1.192 raeburn 5158: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5159: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5160: '</span></td>'.
5161: '<td class="LC_right_item"><span class="LC_nobreak">'.
5162: '<input type="text" name="anonsurvey_threshold"'.
5163: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5164: '</td></tr>'."\n";
5165: $itemcount ++;
5166: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5167: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5168: $choices{'uploadquota'}.
5169: '</span></td>'.
1.306 raeburn 5170: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5171: '<table><tr>';
1.198 raeburn 5172: foreach my $type (@types) {
1.306 raeburn 5173: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5174: '<input type="text" name="uploadquota_'.$type.'"'.
5175: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5176: }
5177: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5178: $itemcount ++;
1.236 raeburn 5179: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5180: my $display = 'none';
1.192 raeburn 5181: if ($currusecredits) {
5182: $display = 'block';
5183: }
5184: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5185: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5186: foreach my $type (@types) {
5187: next if ($type eq 'community');
1.306 raeburn 5188: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5189: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5190: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5191: }
5192: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5193: %defaultchecked = ('coursecredits' => 'off');
5194: @toggles = ('coursecredits');
5195: my $current = {
5196: 'coursecredits' => $currusecredits,
5197: };
5198: (my $table,$itemcount) =
5199: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5200: \%choices,$itemcount,$onclick,$additional,'left');
5201: $datatable .= $table;
5202: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5203: my $display = 'none';
5204: if ($postsubmitclient) {
5205: $display = 'block';
5206: }
5207: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5208: &mt('Number of seconds submit is disabled').'<br />'.
5209: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5210: '<table><tr>';
1.257 raeburn 5211: foreach my $type (@types) {
1.306 raeburn 5212: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5213: '<input type="text" name="'.$type.'_timeout" value="'.
5214: $deftimeout{$type}.'" size="5" /></td>';
5215: }
5216: $additional .= '</tr></table></div>'."\n";
5217: %defaultchecked = ('postsubmit' => 'on');
5218: @toggles = ('postsubmit');
1.280 raeburn 5219: $current = {
5220: 'postsubmit' => $postsubmitclient,
5221: };
1.257 raeburn 5222: ($table,$itemcount) =
5223: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5224: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5225: $datatable .= $table;
1.276 raeburn 5226: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5227: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5228: $choices{'mysqltables'}.
5229: '</span></td>'.
1.306 raeburn 5230: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5231: '<table><tr>';
5232: foreach my $type (@types) {
1.306 raeburn 5233: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5234: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5235: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5236: }
5237: $datatable .= '</tr></table></td></tr>'."\n";
5238: $itemcount ++;
5239:
1.139 raeburn 5240: }
1.192 raeburn 5241: $$rowtotal += $itemcount;
1.121 raeburn 5242: return $datatable;
1.118 jms 5243: }
5244:
1.231 raeburn 5245: sub print_selfenrollment {
5246: my ($position,$dom,$settings,$rowtotal) = @_;
5247: my ($css_class,$datatable);
5248: my $itemcount = 1;
1.271 raeburn 5249: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5250: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5251: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5252: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5253: my @rows;
5254: my $key;
5255: if ($position eq 'top') {
5256: $key = 'admin';
5257: if (ref($rowsref) eq 'ARRAY') {
5258: @rows = @{$rowsref};
5259: }
5260: } elsif ($position eq 'middle') {
5261: $key = 'default';
5262: @rows = ('types','registered','approval','limit');
5263: }
5264: foreach my $row (@rows) {
5265: if (defined($titlesref->{$row})) {
5266: $itemcount ++;
5267: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5268: $datatable .= '<tr'.$css_class.'>'.
5269: '<td>'.$titlesref->{$row}.'</td>'.
5270: '<td class="LC_left_item">'.
5271: '<table><tr>';
5272: my (%current,%currentcap);
5273: if (ref($settings) eq 'HASH') {
5274: if (ref($settings->{$key}) eq 'HASH') {
5275: foreach my $type (@types) {
5276: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5277: $current{$type} = $settings->{$key}->{$type}->{$row};
5278: }
5279: if (($row eq 'limit') && ($key eq 'default')) {
5280: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5281: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5282: }
5283: }
5284: }
5285: }
5286: }
5287: my %roles = (
5288: '0' => &Apache::lonnet::plaintext('dc'),
5289: );
5290:
5291: foreach my $type (@types) {
5292: unless (($row eq 'registered') && ($key eq 'default')) {
5293: $datatable .= '<th>'.&mt($type).'</th>';
5294: }
5295: }
5296: unless (($row eq 'registered') && ($key eq 'default')) {
5297: $datatable .= '</tr><tr>';
5298: }
5299: foreach my $type (@types) {
5300: if ($type eq 'community') {
5301: $roles{'1'} = &mt('Community personnel');
5302: } else {
5303: $roles{'1'} = &mt('Course personnel');
5304: }
5305: $datatable .= '<td style="vertical-align: top">';
5306: if ($position eq 'top') {
5307: my %checked;
5308: if ($current{$type} eq '0') {
5309: $checked{'0'} = ' checked="checked"';
5310: } else {
5311: $checked{'1'} = ' checked="checked"';
5312: }
5313: foreach my $role ('1','0') {
5314: $datatable .= '<span class="LC_nobreak"><label>'.
5315: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5316: 'value="'.$role.'"'.$checked{$role}.' />'.
5317: $roles{$role}.'</label></span> ';
5318: }
5319: } else {
5320: if ($row eq 'types') {
5321: my %checked;
5322: if ($current{$type} =~ /^(all|dom)$/) {
5323: $checked{$1} = ' checked="checked"';
5324: } else {
5325: $checked{''} = ' checked="checked"';
5326: }
5327: foreach my $val ('','dom','all') {
5328: $datatable .= '<span class="LC_nobreak"><label>'.
5329: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5330: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5331: }
5332: } elsif ($row eq 'registered') {
5333: my %checked;
5334: if ($current{$type} eq '1') {
5335: $checked{'1'} = ' checked="checked"';
5336: } else {
5337: $checked{'0'} = ' checked="checked"';
5338: }
5339: foreach my $val ('0','1') {
5340: $datatable .= '<span class="LC_nobreak"><label>'.
5341: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5342: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5343: }
5344: } elsif ($row eq 'approval') {
5345: my %checked;
5346: if ($current{$type} =~ /^([12])$/) {
5347: $checked{$1} = ' checked="checked"';
5348: } else {
5349: $checked{'0'} = ' checked="checked"';
5350: }
5351: for my $val (0..2) {
5352: $datatable .= '<span class="LC_nobreak"><label>'.
5353: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5354: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5355: }
5356: } elsif ($row eq 'limit') {
5357: my %checked;
5358: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5359: $checked{$1} = ' checked="checked"';
5360: } else {
5361: $checked{'none'} = ' checked="checked"';
5362: }
5363: my $cap;
5364: if ($currentcap{$type} =~ /^\d+$/) {
5365: $cap = $currentcap{$type};
5366: }
5367: foreach my $val ('none','allstudents','selfenrolled') {
5368: $datatable .= '<span class="LC_nobreak"><label>'.
5369: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5370: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5371: }
5372: $datatable .= '<br />'.
5373: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5374: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5375: '</span>';
5376: }
5377: }
5378: $datatable .= '</td>';
5379: }
5380: $datatable .= '</tr>';
5381: }
5382: $datatable .= '</table></td></tr>';
5383: }
5384: } elsif ($position eq 'bottom') {
1.235 raeburn 5385: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5386: }
5387: $$rowtotal += $itemcount;
5388: return $datatable;
5389: }
5390:
5391: sub print_validation_rows {
5392: my ($caller,$dom,$settings,$rowtotal) = @_;
5393: my ($itemsref,$namesref,$fieldsref);
5394: if ($caller eq 'selfenroll') {
5395: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5396: } elsif ($caller eq 'requestcourses') {
5397: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5398: }
5399: my %currvalidation;
5400: if (ref($settings) eq 'HASH') {
5401: if (ref($settings->{'validation'}) eq 'HASH') {
5402: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5403: }
1.235 raeburn 5404: }
5405: my $datatable;
5406: my $itemcount = 0;
5407: foreach my $item (@{$itemsref}) {
5408: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5409: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5410: $namesref->{$item}.
5411: '</span></td>'.
5412: '<td class="LC_left_item">';
5413: if (($item eq 'url') || ($item eq 'button')) {
5414: $datatable .= '<span class="LC_nobreak">'.
5415: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5416: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5417: } elsif ($item eq 'fields') {
5418: my @currfields;
5419: if (ref($currvalidation{$item}) eq 'ARRAY') {
5420: @currfields = @{$currvalidation{$item}};
5421: }
5422: foreach my $field (@{$fieldsref}) {
5423: my $check = '';
5424: if (grep(/^\Q$field\E$/,@currfields)) {
5425: $check = ' checked="checked"';
5426: }
5427: $datatable .= '<span class="LC_nobreak"><label>'.
5428: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5429: ' value="'.$field.'"'.$check.' />'.$field.
5430: '</label></span> ';
5431: }
5432: } elsif ($item eq 'markup') {
5433: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
5434: $currvalidation{$item}.
1.231 raeburn 5435: '</textarea>';
1.235 raeburn 5436: }
5437: $datatable .= '</td></tr>'."\n";
5438: if (ref($rowtotal)) {
1.231 raeburn 5439: $itemcount ++;
5440: }
5441: }
1.235 raeburn 5442: if ($caller eq 'requestcourses') {
5443: my %currhash;
1.248 raeburn 5444: if (ref($settings) eq 'HASH') {
5445: if (ref($settings->{'validation'}) eq 'HASH') {
5446: if ($settings->{'validation'}{'dc'} ne '') {
5447: $currhash{$settings->{'validation'}{'dc'}} = 1;
5448: }
1.235 raeburn 5449: }
5450: }
5451: my $numinrow = 2;
5452: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5453: 'validationdc',%currhash);
1.247 raeburn 5454: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5455: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 5456: if ($numdc > 1) {
1.247 raeburn 5457: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5458: } else {
1.247 raeburn 5459: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5460: }
1.247 raeburn 5461: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5462: $itemcount ++;
5463: }
5464: if (ref($rowtotal)) {
5465: $$rowtotal += $itemcount;
5466: }
1.231 raeburn 5467: return $datatable;
5468: }
5469:
1.137 raeburn 5470: sub print_usersessions {
5471: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 5472: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 5473: my (%by_ip,%by_location,@intdoms,@instdoms);
5474: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 5475:
5476: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5477: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5478: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5479: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5480: if ($position eq 'top') {
1.152 raeburn 5481: if (keys(%serverhomes) > 1) {
1.145 raeburn 5482: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 5483: my $curroffloadnow;
5484: if (ref($settings) eq 'HASH') {
5485: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5486: $curroffloadnow = $settings->{'offloadnow'};
5487: }
5488: }
5489: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 5490: } else {
1.140 raeburn 5491: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 5492: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
5493: '</td></tr>';
1.140 raeburn 5494: }
1.137 raeburn 5495: } else {
1.279 raeburn 5496: my %titles = &usersession_titles();
5497: my ($prefix,@types);
5498: if ($position eq 'bottom') {
5499: $prefix = 'remote';
5500: @types = ('version','excludedomain','includedomain');
1.145 raeburn 5501: } else {
1.279 raeburn 5502: $prefix = 'hosted';
5503: @types = ('excludedomain','includedomain');
5504: }
5505: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5506: }
5507: $$rowtotal += $itemcount;
5508: return $datatable;
5509: }
5510:
5511: sub rules_by_location {
5512: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
5513: my ($datatable,$itemcount,$css_class);
5514: if (keys(%{$by_location}) == 0) {
5515: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5516: $datatable = '<tr'.$css_class.'><td colspan="2">'.
5517: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
5518: '</td></tr>';
5519: $itemcount = 1;
5520: } else {
5521: $itemcount = 0;
5522: my $numinrow = 5;
5523: my (%current,%checkedon,%checkedoff);
5524: my @locations = sort(keys(%{$by_location}));
5525: foreach my $type (@{$types}) {
5526: $checkedon{$type} = '';
5527: $checkedoff{$type} = ' checked="checked"';
5528: }
5529: if (ref($settings) eq 'HASH') {
5530: if (ref($settings->{$prefix}) eq 'HASH') {
5531: foreach my $key (keys(%{$settings->{$prefix}})) {
5532: $current{$key} = $settings->{$prefix}{$key};
5533: if ($key eq 'version') {
5534: if ($current{$key} ne '') {
1.145 raeburn 5535: $checkedon{$key} = ' checked="checked"';
5536: $checkedoff{$key} = '';
5537: }
1.279 raeburn 5538: } elsif (ref($current{$key}) eq 'ARRAY') {
5539: $checkedon{$key} = ' checked="checked"';
5540: $checkedoff{$key} = '';
1.137 raeburn 5541: }
5542: }
5543: }
1.279 raeburn 5544: }
5545: foreach my $type (@{$types}) {
5546: next if ($type ne 'version' && !@locations);
5547: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5548: $datatable .= '<tr'.$css_class.'>
5549: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
5550: <span class="LC_nobreak">
5551: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5552: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5553: if ($type eq 'version') {
5554: my @lcversions = &Apache::lonnet::all_loncaparevs();
5555: my $selector = '<select name="'.$prefix.'_version">';
5556: foreach my $version (@lcversions) {
5557: my $selected = '';
5558: if ($current{'version'} eq $version) {
5559: $selected = ' selected="selected"';
1.145 raeburn 5560: }
1.279 raeburn 5561: $selector .= ' <option value="'.$version.'"'.
5562: $selected.'>'.$version.'</option>';
5563: }
5564: $selector .= '</select> ';
5565: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5566: } else {
5567: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5568: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5569: ' />'.(' 'x2).
5570: '<input type="button" value="'.&mt('uncheck all').'" '.
5571: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5572: "\n".
5573: '</div><div><table>';
5574: my $rem;
5575: for (my $i=0; $i<@locations; $i++) {
5576: my ($showloc,$value,$checkedtype);
5577: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
5578: my $ip = $by_location->{$locations[$i]}->[0];
5579: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5580: $value = join(':',@{$by_ip->{$ip}});
5581: $showloc = join(', ',@{$by_ip->{$ip}});
5582: if (ref($current{$type}) eq 'ARRAY') {
5583: foreach my $loc (@{$by_ip->{$ip}}) {
5584: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5585: $checkedtype = ' checked="checked"';
5586: last;
1.145 raeburn 5587: }
1.138 raeburn 5588: }
5589: }
5590: }
1.137 raeburn 5591: }
1.279 raeburn 5592: $rem = $i%($numinrow);
5593: if ($rem == 0) {
5594: if ($i > 0) {
5595: $datatable .= '</tr>';
5596: }
5597: $datatable .= '<tr>';
5598: }
5599: $datatable .= '<td class="LC_left_item">'.
5600: '<span class="LC_nobreak"><label>'.
5601: '<input type="checkbox" name="'.$prefix.'_'.$type.
5602: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5603: '</label></span></td>';
5604: }
5605: $rem = @locations%($numinrow);
5606: my $colsleft = $numinrow - $rem;
5607: if ($colsleft > 1 ) {
5608: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5609: ' </td>';
5610: } elsif ($colsleft == 1) {
5611: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5612: }
1.279 raeburn 5613: $datatable .= '</tr></table>';
1.137 raeburn 5614: }
1.279 raeburn 5615: $datatable .= '</td></tr>';
5616: $itemcount ++;
1.137 raeburn 5617: }
5618: }
1.279 raeburn 5619: return ($datatable,$itemcount);
1.137 raeburn 5620: }
5621:
1.275 raeburn 5622: sub print_ssl {
5623: my ($position,$dom,$settings,$rowtotal) = @_;
5624: my ($css_class,$datatable);
5625: my $itemcount = 1;
5626: if ($position eq 'top') {
1.281 raeburn 5627: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5628: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5629: my $same_institution;
5630: if ($intdom ne '') {
5631: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
5632: if (ref($internet_names) eq 'ARRAY') {
5633: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5634: $same_institution = 1;
5635: }
5636: }
5637: }
1.275 raeburn 5638: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 5639: $datatable = '<tr'.$css_class.'><td colspan="2">';
5640: if ($same_institution) {
5641: my %domservers = &Apache::lonnet::get_servers($dom);
5642: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
5643: } else {
5644: $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.");
5645: }
5646: $datatable .= '</td></tr>';
1.275 raeburn 5647: $itemcount ++;
5648: } else {
5649: my %titles = &ssl_titles();
5650: my (%by_ip,%by_location,@intdoms,@instdoms);
5651: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5652: my @alldoms = &Apache::lonnet::all_domains();
5653: my %serverhomes = %Apache::lonnet::serverhomeIDs;
5654: my @domservers = &Apache::lonnet::get_servers($dom);
5655: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5656: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 5657: if (($position eq 'connto') || ($position eq 'connfrom')) {
5658: my $legacy;
5659: unless (ref($settings) eq 'HASH') {
5660: my $name;
5661: if ($position eq 'connto') {
5662: $name = 'loncAllowInsecure';
5663: } else {
5664: $name = 'londAllowInsecure';
5665: }
5666: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
5667: my @ids=&Apache::lonnet::current_machine_ids();
5668: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
5669: my %what = (
5670: $name => 1,
5671: );
5672: my ($result,$returnhash) =
5673: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
5674: if ($result eq 'ok') {
5675: if (ref($returnhash) eq 'HASH') {
5676: $legacy = $returnhash->{$name};
5677: }
5678: }
5679: } else {
5680: $legacy = $Apache::lonnet::perlvar{$name};
5681: }
5682: }
1.275 raeburn 5683: foreach my $type ('dom','intdom','other') {
5684: my %checked;
5685: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5686: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
5687: '<td class="LC_right_item">';
5688: my $skip;
5689: if ($type eq 'dom') {
5690: unless (keys(%servers) > 1) {
5691: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
5692: $skip = 1;
5693: }
5694: }
5695: if ($type eq 'intdom') {
5696: unless (@instdoms > 1) {
5697: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
5698: $skip = 1;
5699: }
5700: } elsif ($type eq 'other') {
5701: if (keys(%by_location) == 0) {
5702: $datatable .= &mt('Nothing to set here, as there are no other institutions');
5703: $skip = 1;
5704: }
5705: }
5706: unless ($skip) {
5707: $checked{'yes'} = ' checked="checked"';
5708: if (ref($settings) eq 'HASH') {
1.293 raeburn 5709: if (ref($settings->{$position}) eq 'HASH') {
5710: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 5711: $checked{$1} = $checked{'yes'};
5712: delete($checked{'yes'});
5713: }
5714: }
1.293 raeburn 5715: } else {
5716: if ($legacy == 0) {
5717: $checked{'req'} = $checked{'yes'};
5718: delete($checked{'yes'});
5719: }
1.275 raeburn 5720: }
5721: foreach my $option ('no','yes','req') {
5722: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 5723: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 5724: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
5725: '</label></span>'.(' 'x2);
5726: }
5727: }
5728: $datatable .= '</td></tr>';
5729: $itemcount ++;
5730: }
5731: } else {
5732: my $prefix = 'replication';
5733: my @types = ('certreq','nocertreq');
1.279 raeburn 5734: if (keys(%by_location) == 0) {
5735: $datatable .= '<tr'.$css_class.'><td>'.
5736: &mt('Nothing to set here, as there are no other institutions').
5737: '</td></tr>';
5738: $itemcount ++;
1.275 raeburn 5739: } else {
1.279 raeburn 5740: ($datatable,$itemcount) =
5741: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 5742: }
5743: }
5744: }
5745: $$rowtotal += $itemcount;
5746: return $datatable;
5747: }
5748:
5749: sub ssl_titles {
5750: return &Apache::lonlocal::texthash (
5751: dom => 'LON-CAPA servers/VMs from same domain',
5752: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
5753: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 5754: connto => 'Connections to other servers',
5755: connfrom => 'Connections from other servers',
1.275 raeburn 5756: replication => 'Replicating content to other institutions',
5757: certreq => 'Client certificate required, but specific domains exempt',
5758: nocertreq => 'No client certificate required, except for specific domains',
5759: no => 'SSL not used',
5760: yes => 'SSL Optional (used if available)',
5761: req => 'SSL Required',
5762: );
1.279 raeburn 5763: }
5764:
5765: sub print_trust {
5766: my ($prefix,$dom,$settings,$rowtotal) = @_;
5767: my ($css_class,$datatable,%checked,%choices);
5768: my (%by_ip,%by_location,@intdoms,@instdoms);
5769: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5770: my $itemcount = 1;
5771: my %titles = &trust_titles();
5772: my @types = ('exc','inc');
5773: if ($prefix eq 'top') {
5774: $prefix = 'content';
5775: } elsif ($prefix eq 'bottom') {
5776: $prefix = 'msg';
5777: }
5778: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5779: $$rowtotal += $itemcount;
5780: return $datatable;
5781: }
5782:
5783: sub trust_titles {
5784: return &Apache::lonlocal::texthash(
5785: content => "Access to this domain's content by others",
5786: shared => "Access to other domain's content by this domain",
5787: enroll => "Enrollment in this domain's courses by others",
5788: othcoau => "Co-author roles in this domain for others",
5789: coaurem => "Co-author roles for this domain's users elsewhere",
5790: domroles => "Domain roles in this domain assignable to others",
5791: catalog => "Course Catalog for this domain displayed elsewhere",
5792: reqcrs => "Requests for creation of courses in this domain by others",
5793: msg => "Users in other domains can send messages to this domain",
5794: exc => "Allow all, but exclude specific domains",
5795: inc => "Deny all, but include specific domains",
5796: );
1.275 raeburn 5797: }
5798:
1.138 raeburn 5799: sub build_location_hashes {
1.275 raeburn 5800: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 5801: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 5802: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 5803: my %iphost = &Apache::lonnet::get_iphost();
5804: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5805: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5806: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5807: foreach my $id (@{$iphost{$primary_ip}}) {
5808: my $intdom = &Apache::lonnet::internet_dom($id);
5809: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5810: push(@{$intdoms},$intdom);
5811: }
5812: }
5813: }
5814: foreach my $ip (keys(%iphost)) {
5815: if (ref($iphost{$ip}) eq 'ARRAY') {
5816: foreach my $id (@{$iphost{$ip}}) {
5817: my $location = &Apache::lonnet::internet_dom($id);
5818: if ($location) {
1.275 raeburn 5819: if (grep(/^\Q$location\E$/,@{$intdoms})) {
5820: my $dom = &Apache::lonnet::host_domain($id);
5821: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
5822: push(@{$instdoms},$dom);
5823: }
5824: next;
5825: }
1.138 raeburn 5826: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5827: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5828: push(@{$by_ip->{$ip}},$location);
5829: }
5830: } else {
5831: $by_ip->{$ip} = [$location];
5832: }
5833: }
5834: }
5835: }
5836: }
5837: foreach my $ip (sort(keys(%{$by_ip}))) {
5838: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5839: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5840: my $first = $by_ip->{$ip}->[0];
5841: if (ref($by_location->{$first}) eq 'ARRAY') {
5842: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5843: push(@{$by_location->{$first}},$ip);
5844: }
5845: } else {
5846: $by_location->{$first} = [$ip];
5847: }
5848: }
5849: }
5850: return;
5851: }
5852:
1.145 raeburn 5853: sub current_offloads_to {
5854: my ($dom,$settings,$servers) = @_;
5855: my (%spareid,%otherdomconfigs);
1.152 raeburn 5856: if (ref($servers) eq 'HASH') {
1.145 raeburn 5857: foreach my $lonhost (sort(keys(%{$servers}))) {
5858: my $gotspares;
1.152 raeburn 5859: if (ref($settings) eq 'HASH') {
5860: if (ref($settings->{'spares'}) eq 'HASH') {
5861: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5862: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5863: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5864: $gotspares = 1;
5865: }
1.145 raeburn 5866: }
5867: }
5868: unless ($gotspares) {
5869: my $gotspares;
5870: my $serverhomeID =
5871: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5872: my $serverhomedom =
5873: &Apache::lonnet::host_domain($serverhomeID);
5874: if ($serverhomedom ne $dom) {
5875: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5876: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5877: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5878: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5879: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5880: $gotspares = 1;
5881: }
5882: }
5883: } else {
5884: $otherdomconfigs{$serverhomedom} =
5885: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5886: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5887: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5888: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5889: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5890: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5891: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5892: $gotspares = 1;
5893: }
5894: }
5895: }
5896: }
5897: }
5898: }
5899: }
5900: unless ($gotspares) {
5901: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5902: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5903: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5904: } else {
5905: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5906: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5907: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5908: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5909: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5910: } else {
1.150 raeburn 5911: my %what = (
5912: spareid => 1,
5913: );
5914: my ($result,$returnhash) =
5915: &Apache::lonnet::get_remote_globals($lonhost,\%what);
5916: if ($result eq 'ok') {
5917: if (ref($returnhash) eq 'HASH') {
5918: if (ref($returnhash->{'spareid'}) eq 'HASH') {
5919: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5920: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5921: }
5922: }
1.145 raeburn 5923: }
5924: }
5925: }
5926: }
5927: }
5928: }
5929: return %spareid;
5930: }
5931:
5932: sub spares_row {
1.261 raeburn 5933: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 5934: my $css_class;
5935: my $numinrow = 4;
5936: my $itemcount = 1;
5937: my $datatable;
1.152 raeburn 5938: my %typetitles = &sparestype_titles();
5939: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5940: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5941: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5942: my ($othercontrol,$serverdom);
5943: if ($serverhome ne $server) {
5944: $serverdom = &Apache::lonnet::host_domain($serverhome);
5945: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5946: } else {
5947: $serverdom = &Apache::lonnet::host_domain($server);
5948: if ($serverdom ne $dom) {
5949: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5950: }
5951: }
5952: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 5953: my $checkednow;
5954: if (ref($curroffloadnow) eq 'HASH') {
5955: if ($curroffloadnow->{$server}) {
5956: $checkednow = ' checked="checked"';
5957: }
5958: }
1.145 raeburn 5959: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5960: $datatable .= '<tr'.$css_class.'>
5961: <td rowspan="2">
1.183 bisitz 5962: <span class="LC_nobreak">'.
5963: &mt('[_1] when busy, offloads to:'
1.261 raeburn 5964: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 5965: '<span class="LC_nobreak">'."\n".
1.261 raeburn 5966: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
5967: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 5968: "\n";
1.145 raeburn 5969: my (%current,%canselect);
1.152 raeburn 5970: my @choices =
5971: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5972: foreach my $type ('primary','default') {
5973: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5974: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5975: my @spares = @{$spareid->{$server}{$type}};
5976: if (@spares > 0) {
1.152 raeburn 5977: if ($othercontrol) {
5978: $current{$type} = join(', ',@spares);
5979: } else {
5980: $current{$type} .= '<table>';
5981: my $numspares = scalar(@spares);
5982: for (my $i=0; $i<@spares; $i++) {
5983: my $rem = $i%($numinrow);
5984: if ($rem == 0) {
5985: if ($i > 0) {
5986: $current{$type} .= '</tr>';
5987: }
5988: $current{$type} .= '<tr>';
1.145 raeburn 5989: }
1.152 raeburn 5990: $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'".');" /> '.
5991: $spareid->{$server}{$type}[$i].
5992: '</label></td>'."\n";
5993: }
5994: my $rem = @spares%($numinrow);
5995: my $colsleft = $numinrow - $rem;
5996: if ($colsleft > 1 ) {
5997: $current{$type} .= '<td colspan="'.$colsleft.
5998: '" class="LC_left_item">'.
5999: ' </td>';
6000: } elsif ($colsleft == 1) {
6001: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6002: }
1.152 raeburn 6003: $current{$type} .= '</tr></table>';
1.150 raeburn 6004: }
1.145 raeburn 6005: }
6006: }
6007: if ($current{$type} eq '') {
6008: $current{$type} = &mt('None specified');
6009: }
1.152 raeburn 6010: if ($othercontrol) {
6011: if ($type eq 'primary') {
6012: $canselect{$type} = $othercontrol;
6013: }
6014: } else {
6015: $canselect{$type} =
6016: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6017: '<select name="newspare_'.$type.'_'.$server.'" '.
6018: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6019: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6020: if (@choices > 0) {
6021: foreach my $lonhost (@choices) {
6022: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6023: }
6024: }
6025: $canselect{$type} .= '</select>'."\n";
6026: }
6027: } else {
6028: $current{$type} = &mt('Could not be determined');
6029: if ($type eq 'primary') {
6030: $canselect{$type} = $othercontrol;
6031: }
1.145 raeburn 6032: }
1.152 raeburn 6033: if ($type eq 'default') {
6034: $datatable .= '<tr'.$css_class.'>';
6035: }
6036: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6037: '<td>'.$current{$type}.'</td>'."\n".
6038: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6039: }
6040: $itemcount ++;
6041: }
6042: }
6043: $$rowtotal += $itemcount;
6044: return $datatable;
6045: }
6046:
1.152 raeburn 6047: sub possible_newspares {
6048: my ($server,$currspares,$serverhomes,$altids) = @_;
6049: my $serverhostname = &Apache::lonnet::hostname($server);
6050: my %excluded;
6051: if ($serverhostname ne '') {
6052: %excluded = (
6053: $serverhostname => 1,
6054: );
6055: }
6056: if (ref($currspares) eq 'HASH') {
6057: foreach my $type (keys(%{$currspares})) {
6058: if (ref($currspares->{$type}) eq 'ARRAY') {
6059: if (@{$currspares->{$type}} > 0) {
6060: foreach my $curr (@{$currspares->{$type}}) {
6061: my $hostname = &Apache::lonnet::hostname($curr);
6062: $excluded{$hostname} = 1;
6063: }
6064: }
6065: }
6066: }
6067: }
6068: my @choices;
6069: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6070: if (keys(%{$serverhomes}) > 1) {
6071: foreach my $name (sort(keys(%{$serverhomes}))) {
6072: unless ($excluded{$name}) {
6073: if (exists($altids->{$serverhomes->{$name}})) {
6074: push(@choices,$altids->{$serverhomes->{$name}});
6075: } else {
6076: push(@choices,$serverhomes->{$name});
1.145 raeburn 6077: }
6078: }
6079: }
6080: }
6081: }
1.152 raeburn 6082: return sort(@choices);
1.145 raeburn 6083: }
6084:
1.150 raeburn 6085: sub print_loadbalancing {
6086: my ($dom,$settings,$rowtotal) = @_;
6087: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6088: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6089: my $numinrow = 1;
6090: my $datatable;
6091: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 6092: my (%currbalancer,%currtargets,%currrules,%existing);
6093: if (ref($settings) eq 'HASH') {
6094: %existing = %{$settings};
6095: }
6096: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6097: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
6098: \%currtargets,\%currrules);
1.150 raeburn 6099: } else {
6100: return;
6101: }
6102: my ($othertitle,$usertypes,$types) =
6103: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 6104: my $rownum = 8;
1.150 raeburn 6105: if (ref($types) eq 'ARRAY') {
6106: $rownum += scalar(@{$types});
6107: }
1.171 raeburn 6108: my @css_class = ('LC_odd_row','LC_even_row');
6109: my $balnum = 0;
6110: my $islast;
6111: my (@toshow,$disabledtext);
6112: if (keys(%currbalancer) > 0) {
6113: @toshow = sort(keys(%currbalancer));
6114: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6115: push(@toshow,'');
6116: }
6117: } else {
6118: @toshow = ('');
6119: $disabledtext = &mt('No existing load balancer');
6120: }
6121: foreach my $lonhost (@toshow) {
6122: if ($balnum == scalar(@toshow)-1) {
6123: $islast = 1;
6124: } else {
6125: $islast = 0;
6126: }
6127: my $cssidx = $balnum%2;
6128: my $targets_div_style = 'display: none';
6129: my $disabled_div_style = 'display: block';
6130: my $homedom_div_style = 'display: none';
6131: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 6132: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6133: '<p>';
6134: if ($lonhost eq '') {
1.210 raeburn 6135: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 6136: if (keys(%currbalancer) > 0) {
6137: $datatable .= &mt('Add balancer:');
6138: } else {
6139: $datatable .= &mt('Enable balancer:');
6140: }
6141: $datatable .= ' '.
6142: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6143: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6144: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6145: '<option value="" selected="selected">'.&mt('None').
6146: '</option>'."\n";
6147: foreach my $server (sort(keys(%servers))) {
6148: next if ($currbalancer{$server});
6149: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6150: }
1.210 raeburn 6151: $datatable .=
1.171 raeburn 6152: '</select>'."\n".
6153: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6154: } else {
6155: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6156: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6157: &mt('Stop balancing').'</label>'.
6158: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6159: $targets_div_style = 'display: block';
6160: $disabled_div_style = 'display: none';
6161: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6162: $homedom_div_style = 'display: block';
6163: }
6164: }
1.306 raeburn 6165: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6166: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6167: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6168: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6169: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6170: my @sparestypes = ('primary','default');
6171: my %typetitles = &sparestype_titles();
1.284 raeburn 6172: my %hostherechecked = (
6173: no => ' checked="checked"',
6174: );
1.171 raeburn 6175: foreach my $sparetype (@sparestypes) {
6176: my $targettable;
6177: for (my $i=0; $i<$numspares; $i++) {
6178: my $checked;
6179: if (ref($currtargets{$lonhost}) eq 'HASH') {
6180: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6181: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6182: $checked = ' checked="checked"';
6183: }
6184: }
6185: }
6186: my ($chkboxval,$disabled);
6187: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6188: $chkboxval = $spares[$i];
6189: }
6190: if (exists($currbalancer{$spares[$i]})) {
6191: $disabled = ' disabled="disabled"';
6192: }
1.210 raeburn 6193: $targettable .=
1.253 raeburn 6194: '<td><span class="LC_nobreak"><label>'.
6195: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 6196: $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 6197: '</span></label></span></td>';
1.171 raeburn 6198: my $rem = $i%($numinrow);
6199: if ($rem == 0) {
6200: if (($i > 0) && ($i < $numspares-1)) {
6201: $targettable .= '</tr>';
6202: }
6203: if ($i < $numspares-1) {
6204: $targettable .= '<tr>';
1.150 raeburn 6205: }
6206: }
6207: }
1.171 raeburn 6208: if ($targettable ne '') {
6209: my $rem = $numspares%($numinrow);
6210: my $colsleft = $numinrow - $rem;
6211: if ($colsleft > 1 ) {
6212: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6213: ' </td>';
6214: } elsif ($colsleft == 1) {
6215: $targettable .= '<td class="LC_left_item"> </td>';
6216: }
6217: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6218: '<table><tr>'.$targettable.'</tr></table><br />';
6219: }
1.284 raeburn 6220: $hostherechecked{$sparetype} = '';
6221: if (ref($currtargets{$lonhost}) eq 'HASH') {
6222: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6223: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6224: $hostherechecked{$sparetype} = ' checked="checked"';
6225: $hostherechecked{'no'} = '';
6226: }
6227: }
6228: }
6229: }
6230: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6231: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6232: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6233: foreach my $sparetype (@sparestypes) {
6234: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6235: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6236: '</i></label><br />';
1.171 raeburn 6237: }
6238: $datatable .= '</div></td></tr>'.
6239: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6240: $othertitle,$usertypes,$types,\%servers,
6241: \%currbalancer,$lonhost,
6242: $targets_div_style,$homedom_div_style,
6243: $css_class[$cssidx],$balnum,$islast);
6244: $$rowtotal += $rownum;
6245: $balnum ++;
6246: }
6247: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6248: return $datatable;
6249: }
6250:
6251: sub get_loadbalancers_config {
6252: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
6253: return unless ((ref($servers) eq 'HASH') &&
6254: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
6255: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
6256: if (keys(%{$existing}) > 0) {
6257: my $oldlonhost;
6258: foreach my $key (sort(keys(%{$existing}))) {
6259: if ($key eq 'lonhost') {
6260: $oldlonhost = $existing->{'lonhost'};
6261: $currbalancer->{$oldlonhost} = 1;
6262: } elsif ($key eq 'targets') {
6263: if ($oldlonhost) {
6264: $currtargets->{$oldlonhost} = $existing->{'targets'};
6265: }
6266: } elsif ($key eq 'rules') {
6267: if ($oldlonhost) {
6268: $currrules->{$oldlonhost} = $existing->{'rules'};
6269: }
6270: } elsif (ref($existing->{$key}) eq 'HASH') {
6271: $currbalancer->{$key} = 1;
6272: $currtargets->{$key} = $existing->{$key}{'targets'};
6273: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 6274: }
6275: }
1.171 raeburn 6276: } else {
6277: my ($balancerref,$targetsref) =
6278: &Apache::lonnet::get_lonbalancer_config($servers);
6279: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6280: foreach my $server (sort(keys(%{$balancerref}))) {
6281: $currbalancer->{$server} = 1;
6282: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6283: }
6284: }
6285: }
1.171 raeburn 6286: return;
1.150 raeburn 6287: }
6288:
6289: sub loadbalancing_rules {
6290: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 6291: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6292: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6293: my $output;
1.171 raeburn 6294: my $num = 0;
1.210 raeburn 6295: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6296: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6297: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6298: foreach my $type (@{$alltypes}) {
1.171 raeburn 6299: $num ++;
1.150 raeburn 6300: my $current;
6301: if (ref($currrules) eq 'HASH') {
6302: $current = $currrules->{$type};
6303: }
1.253 raeburn 6304: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 6305: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6306: $current = '';
6307: }
6308: }
6309: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 6310: $servers,$currbalancer,$lonhost,$dom,
6311: $targets_div_style,$homedom_div_style,
6312: $css_class,$balnum,$num,$islast);
1.150 raeburn 6313: }
6314: }
6315: return $output;
6316: }
6317:
6318: sub loadbalancing_titles {
6319: my ($dom,$intdom,$usertypes,$types) = @_;
6320: my %othertypes = (
6321: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6322: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6323: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6324: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 6325: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6326: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6327: );
1.209 raeburn 6328: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 6329: my @available;
1.150 raeburn 6330: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6331: @available = @{$types};
1.150 raeburn 6332: }
1.302 raeburn 6333: unless (grep(/^default$/,@available)) {
6334: push(@available,'default');
6335: }
6336: unshift(@alltypes,@available);
1.150 raeburn 6337: my %titles;
6338: foreach my $type (@alltypes) {
6339: if ($type =~ /^_LC_/) {
6340: $titles{$type} = $othertypes{$type};
6341: } elsif ($type eq 'default') {
6342: $titles{$type} = &mt('All users from [_1]',$dom);
6343: if (ref($types) eq 'ARRAY') {
6344: if (@{$types} > 0) {
6345: $titles{$type} = &mt('Other users from [_1]',$dom);
6346: }
6347: }
6348: } elsif (ref($usertypes) eq 'HASH') {
6349: $titles{$type} = $usertypes->{$type};
6350: }
6351: }
6352: return (\@alltypes,\%othertypes,\%titles);
6353: }
6354:
6355: sub loadbalance_rule_row {
1.171 raeburn 6356: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6357: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 6358: my @rulenames;
1.150 raeburn 6359: my %ruletitles = &offloadtype_text();
1.209 raeburn 6360: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 6361: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6362: } else {
1.209 raeburn 6363: @rulenames = ('default','homeserver');
6364: if ($type eq '_LC_external') {
6365: push(@rulenames,'externalbalancer');
6366: } else {
6367: push(@rulenames,'specific');
6368: }
6369: push(@rulenames,'none');
1.150 raeburn 6370: }
6371: my $style = $targets_div_style;
1.253 raeburn 6372: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6373: $style = $homedom_div_style;
6374: }
1.171 raeburn 6375: my $space;
6376: if ($islast && $num == 1) {
1.317 raeburn 6377: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 6378: }
1.210 raeburn 6379: my $output =
1.306 raeburn 6380: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 6381: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6382: '<td valaign="top">'.$space.
6383: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6384: for (my $i=0; $i<@rulenames; $i++) {
6385: my $rule = $rulenames[$i];
6386: my ($checked,$extra);
6387: if ($rulenames[$i] eq 'default') {
6388: $rule = '';
6389: }
6390: if ($rulenames[$i] eq 'specific') {
6391: if (ref($servers) eq 'HASH') {
6392: my $default;
6393: if (($current ne '') && (exists($servers->{$current}))) {
6394: $checked = ' checked="checked"';
6395: }
6396: unless ($checked) {
6397: $default = ' selected="selected"';
6398: }
1.210 raeburn 6399: $extra =
1.171 raeburn 6400: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6401: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6402: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6403: '<option value=""'.$default.'></option>'."\n";
6404: foreach my $server (sort(keys(%{$servers}))) {
6405: if (ref($currbalancer) eq 'HASH') {
6406: next if (exists($currbalancer->{$server}));
6407: }
1.150 raeburn 6408: my $selected;
1.171 raeburn 6409: if ($server eq $current) {
1.150 raeburn 6410: $selected = ' selected="selected"';
6411: }
1.171 raeburn 6412: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6413: }
6414: $extra .= '</select>';
6415: }
6416: } elsif ($rule eq $current) {
6417: $checked = ' checked="checked"';
6418: }
6419: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 6420: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6421: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6422: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 6423: ')"'.$checked.' /> ';
6424: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
6425: $output .= $ruletitles{'particular'};
6426: } else {
6427: $output .= $ruletitles{$rulenames[$i]};
6428: }
6429: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6430: }
6431: $output .= '</div></td></tr>'."\n";
6432: return $output;
6433: }
6434:
6435: sub offloadtype_text {
6436: my %ruletitles = &Apache::lonlocal::texthash (
6437: 'default' => 'Offloads to default destinations',
6438: 'homeserver' => "Offloads to user's home server",
6439: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6440: 'specific' => 'Offloads to specific server',
1.161 raeburn 6441: 'none' => 'No offload',
1.209 raeburn 6442: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6443: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 6444: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6445: );
6446: return %ruletitles;
6447: }
6448:
6449: sub sparestype_titles {
6450: my %typestitles = &Apache::lonlocal::texthash (
6451: 'primary' => 'primary',
6452: 'default' => 'default',
6453: );
6454: return %typestitles;
6455: }
6456:
1.28 raeburn 6457: sub contact_titles {
6458: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 6459: 'supportemail' => 'Support E-mail address',
6460: 'adminemail' => 'Default Server Admin E-mail address',
6461: 'errormail' => 'Error reports to be e-mailed to',
6462: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 6463: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6464: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 6465: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6466: 'requestsmail' => 'E-mail from course requests requiring approval',
6467: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 6468: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 6469: );
6470: my %short_titles = &Apache::lonlocal::texthash (
6471: adminemail => 'Admin E-mail address',
6472: supportemail => 'Support E-mail',
6473: );
6474: return (\%titles,\%short_titles);
6475: }
6476:
1.286 raeburn 6477: sub helpform_fields {
6478: my %titles = &Apache::lonlocal::texthash (
6479: 'username' => 'Name',
6480: 'user' => 'Username/domain',
6481: 'phone' => 'Phone',
6482: 'cc' => 'Cc e-mail',
6483: 'course' => 'Course Details',
6484: 'section' => 'Sections',
1.289 raeburn 6485: 'screenshot' => 'File upload',
1.286 raeburn 6486: );
6487: my @fields = ('username','phone','user','course','section','cc','screenshot');
6488: my %possoptions = (
6489: username => ['yes','no','req'],
1.289 raeburn 6490: phone => ['yes','no','req'],
1.286 raeburn 6491: user => ['yes','no'],
1.289 raeburn 6492: cc => ['yes','no'],
1.286 raeburn 6493: course => ['yes','no'],
6494: section => ['yes','no'],
6495: screenshot => ['yes','no'],
6496: );
6497: my %fieldoptions = &Apache::lonlocal::texthash (
6498: 'yes' => 'Optional',
6499: 'req' => 'Required',
6500: 'no' => "Not shown",
6501: );
6502: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6503: }
6504:
1.72 raeburn 6505: sub tool_titles {
6506: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 6507: aboutme => 'Personal web page',
1.86 raeburn 6508: blog => 'Blog',
1.162 raeburn 6509: webdav => 'WebDAV',
1.86 raeburn 6510: portfolio => 'Portfolio',
1.88 bisitz 6511: official => 'Official courses (with institutional codes)',
6512: unofficial => 'Unofficial courses',
1.98 raeburn 6513: community => 'Communities',
1.216 raeburn 6514: textbook => 'Textbook courses',
1.271 raeburn 6515: placement => 'Placement tests',
1.86 raeburn 6516: );
1.72 raeburn 6517: return %titles;
6518: }
6519:
1.101 raeburn 6520: sub courserequest_titles {
6521: my %titles = &Apache::lonlocal::texthash (
6522: official => 'Official',
6523: unofficial => 'Unofficial',
6524: community => 'Communities',
1.216 raeburn 6525: textbook => 'Textbook',
1.271 raeburn 6526: placement => 'Placement tests',
1.325 ! raeburn 6527: lti => 'LTI Provider',
1.101 raeburn 6528: norequest => 'Not allowed',
1.325 ! raeburn 6529: approval => 'Approval by DC',
1.101 raeburn 6530: validate => 'With validation',
6531: autolimit => 'Numerical limit',
1.103 raeburn 6532: unlimited => '(blank for unlimited)',
1.101 raeburn 6533: );
6534: return %titles;
6535: }
6536:
1.163 raeburn 6537: sub authorrequest_titles {
6538: my %titles = &Apache::lonlocal::texthash (
6539: norequest => 'Not allowed',
6540: approval => 'Approval by Dom. Coord.',
6541: automatic => 'Automatic approval',
6542: );
6543: return %titles;
1.210 raeburn 6544: }
1.163 raeburn 6545:
1.101 raeburn 6546: sub courserequest_conditions {
6547: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6548: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 6549: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6550: );
6551: return %conditions;
6552: }
6553:
6554:
1.27 raeburn 6555: sub print_usercreation {
1.30 raeburn 6556: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6557: my $numinrow = 4;
1.28 raeburn 6558: my $datatable;
6559: if ($position eq 'top') {
1.30 raeburn 6560: $$rowtotal ++;
1.34 raeburn 6561: my $rowcount = 0;
1.32 raeburn 6562: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6563: if (ref($rules) eq 'HASH') {
6564: if (keys(%{$rules}) > 0) {
1.32 raeburn 6565: $datatable .= &user_formats_row('username',$settings,$rules,
6566: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6567: $$rowtotal ++;
1.32 raeburn 6568: $rowcount ++;
6569: }
6570: }
6571: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6572: if (ref($idrules) eq 'HASH') {
6573: if (keys(%{$idrules}) > 0) {
6574: $datatable .= &user_formats_row('id',$settings,$idrules,
6575: $idruleorder,$numinrow,$rowcount);
6576: $$rowtotal ++;
6577: $rowcount ++;
1.28 raeburn 6578: }
6579: }
1.39 raeburn 6580: if ($rowcount == 0) {
6581: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6582: $$rowtotal ++;
6583: $rowcount ++;
6584: }
1.34 raeburn 6585: } elsif ($position eq 'middle') {
1.224 raeburn 6586: my @creators = ('author','course','requestcrs');
1.37 raeburn 6587: my ($rules,$ruleorder) =
6588: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6589: my %lt = &usercreation_types();
6590: my %checked;
6591: if (ref($settings) eq 'HASH') {
6592: if (ref($settings->{'cancreate'}) eq 'HASH') {
6593: foreach my $item (@creators) {
6594: $checked{$item} = $settings->{'cancreate'}{$item};
6595: }
6596: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6597: foreach my $item (@creators) {
6598: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6599: $checked{$item} = 'none';
6600: }
6601: }
6602: }
6603: }
6604: my $rownum = 0;
6605: foreach my $item (@creators) {
6606: $rownum ++;
1.224 raeburn 6607: if ($checked{$item} eq '') {
6608: $checked{$item} = 'any';
1.34 raeburn 6609: }
6610: my $css_class;
6611: if ($rownum%2) {
6612: $css_class = '';
6613: } else {
6614: $css_class = ' class="LC_odd_row" ';
6615: }
6616: $datatable .= '<tr'.$css_class.'>'.
6617: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 6618: '</span></td><td style="text-align: right">';
1.224 raeburn 6619: my @options = ('any');
6620: if (ref($rules) eq 'HASH') {
6621: if (keys(%{$rules}) > 0) {
6622: push(@options,('official','unofficial'));
1.37 raeburn 6623: }
6624: }
1.224 raeburn 6625: push(@options,'none');
1.37 raeburn 6626: foreach my $option (@options) {
1.50 raeburn 6627: my $type = 'radio';
1.34 raeburn 6628: my $check = ' ';
1.224 raeburn 6629: if ($checked{$item} eq $option) {
6630: $check = ' checked="checked" ';
1.34 raeburn 6631: }
6632: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6633: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6634: $item.'" value="'.$option.'"'.$check.'/> '.
6635: $lt{$option}.'</label> </span>';
6636: }
6637: $datatable .= '</td></tr>';
6638: }
1.28 raeburn 6639: } else {
6640: my @contexts = ('author','course','domain');
1.325 ! raeburn 6641: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 6642: my %checked;
6643: if (ref($settings) eq 'HASH') {
6644: if (ref($settings->{'authtypes'}) eq 'HASH') {
6645: foreach my $item (@contexts) {
6646: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6647: foreach my $auth (@authtypes) {
6648: if ($settings->{'authtypes'}{$item}{$auth}) {
6649: $checked{$item}{$auth} = ' checked="checked" ';
6650: }
6651: }
6652: }
6653: }
1.27 raeburn 6654: }
1.35 raeburn 6655: } else {
6656: foreach my $item (@contexts) {
1.36 raeburn 6657: foreach my $auth (@authtypes) {
1.35 raeburn 6658: $checked{$item}{$auth} = ' checked="checked" ';
6659: }
6660: }
1.27 raeburn 6661: }
1.28 raeburn 6662: my %title = &context_names();
6663: my %authname = &authtype_names();
6664: my $rownum = 0;
6665: my $css_class;
6666: foreach my $item (@contexts) {
6667: if ($rownum%2) {
6668: $css_class = '';
6669: } else {
6670: $css_class = ' class="LC_odd_row" ';
6671: }
1.30 raeburn 6672: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6673: '<td>'.$title{$item}.
6674: '</td><td class="LC_left_item">'.
6675: '<span class="LC_nobreak">';
6676: foreach my $auth (@authtypes) {
6677: $datatable .= '<label>'.
6678: '<input type="checkbox" name="'.$item.'_auth" '.
6679: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6680: $authname{$auth}.'</label> ';
6681: }
6682: $datatable .= '</span></td></tr>';
6683: $rownum ++;
1.27 raeburn 6684: }
1.30 raeburn 6685: $$rowtotal += $rownum;
1.27 raeburn 6686: }
6687: return $datatable;
6688: }
6689:
1.224 raeburn 6690: sub print_selfcreation {
6691: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 6692: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6693: $emaildomain,$datatable);
1.224 raeburn 6694: if (ref($settings) eq 'HASH') {
6695: if (ref($settings->{'cancreate'}) eq 'HASH') {
6696: $createsettings = $settings->{'cancreate'};
1.236 raeburn 6697: if (ref($createsettings) eq 'HASH') {
6698: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6699: @selfcreate = @{$createsettings->{'selfcreate'}};
6700: } elsif ($createsettings->{'selfcreate'} ne '') {
6701: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6702: @selfcreate = ('email','login','sso');
6703: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6704: @selfcreate = ($createsettings->{'selfcreate'});
6705: }
6706: }
6707: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6708: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 6709: }
1.305 raeburn 6710: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6711: $emailoptions = $createsettings->{'emailoptions'};
6712: }
1.303 raeburn 6713: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6714: $emailverified = $createsettings->{'emailverified'};
6715: }
6716: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6717: $emaildomain = $createsettings->{'emaildomain'};
6718: }
1.224 raeburn 6719: }
6720: }
6721: }
6722: my %radiohash;
6723: my $numinrow = 4;
6724: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 6725: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 6726: if ($position eq 'top') {
6727: my %choices = &Apache::lonlocal::texthash (
6728: cancreate_login => 'Institutional Login',
6729: cancreate_sso => 'Institutional Single Sign On',
6730: );
6731: my @toggles = sort(keys(%choices));
6732: my %defaultchecked = (
6733: 'cancreate_login' => 'off',
6734: 'cancreate_sso' => 'off',
6735: );
1.228 raeburn 6736: my ($onclick,$itemcount);
1.224 raeburn 6737: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6738: \%choices,$itemcount,$onclick);
1.228 raeburn 6739: $$rowtotal += $itemcount;
6740:
1.224 raeburn 6741: if (ref($usertypes) eq 'HASH') {
6742: if (keys(%{$usertypes}) > 0) {
6743: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6744: $dom,$numinrow,$othertitle,
1.305 raeburn 6745: 'statustocreate',$rowtotal);
1.224 raeburn 6746: $$rowtotal ++;
6747: }
6748: }
1.240 raeburn 6749: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6750: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6751: $fieldtitles{'inststatus'} = &mt('Institutional status');
6752: my $rem;
6753: my $numperrow = 2;
6754: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6755: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 6756: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 6757: '<td class="LC_left_item">'."\n".
6758: '<table><tr><td>'."\n";
6759: for (my $i=0; $i<@fields; $i++) {
6760: $rem = $i%($numperrow);
6761: if ($rem == 0) {
6762: if ($i > 0) {
6763: $datatable .= '</tr>';
6764: }
6765: $datatable .= '<tr>';
6766: }
6767: my $currval;
1.248 raeburn 6768: if (ref($createsettings) eq 'HASH') {
6769: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6770: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6771: }
1.240 raeburn 6772: }
6773: $datatable .= '<td class="LC_left_item">'.
6774: '<span class="LC_nobreak">'.
6775: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6776: 'value="'.$currval.'" size="10" /> '.
6777: $fieldtitles{$fields[$i]}.'</span></td>';
6778: }
6779: my $colsleft = $numperrow - $rem;
6780: if ($colsleft > 1 ) {
6781: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6782: ' </td>';
6783: } elsif ($colsleft == 1) {
6784: $datatable .= '<td class="LC_left_item"> </td>';
6785: }
6786: $datatable .= '</tr></table></td></tr>';
6787: $$rowtotal ++;
1.224 raeburn 6788: } elsif ($position eq 'middle') {
6789: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 6790: my @posstypes;
1.224 raeburn 6791: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6792: @posstypes = @{$types};
6793: }
6794: unless (grep(/^default$/,@posstypes)) {
6795: push(@posstypes,'default');
6796: }
6797: my %usertypeshash;
6798: if (ref($usertypes) eq 'HASH') {
6799: %usertypeshash = %{$usertypes};
6800: }
6801: $usertypeshash{'default'} = $othertitle;
6802: foreach my $status (@posstypes) {
6803: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6804: $numinrow,$$rowtotal,\%usertypeshash);
6805: $$rowtotal ++;
1.224 raeburn 6806: }
6807: } else {
1.236 raeburn 6808: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 6809: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 6810: );
6811: my @toggles = sort(keys(%choices));
6812: my %defaultchecked = (
6813: 'cancreate_email' => 'off',
6814: );
1.305 raeburn 6815: my $customclass = 'LC_selfcreate_email';
6816: my $classprefix = 'LC_canmodify_emailusername_';
6817: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 6818: my $display = 'none';
1.305 raeburn 6819: my $rowstyle = 'display:none';
1.236 raeburn 6820: if (grep(/^\Qemail\E$/,@selfcreate)) {
6821: $display = 'block';
1.305 raeburn 6822: $rowstyle = 'display:table-row';
1.236 raeburn 6823: }
1.305 raeburn 6824: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6825: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6826: \%choices,$$rowtotal,$onclick);
6827: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6828: $rowstyle);
6829: $$rowtotal ++;
6830: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6831: $rowstyle);
6832: $$rowtotal ++;
6833: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 6834: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 6835: my ($emailrules,$emailruleorder) =
6836: &Apache::lonnet::inst_userrules($dom,'email');
6837: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6838: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6839: if (ref($types) eq 'ARRAY') {
6840: @posstypes = @{$types};
6841: }
6842: if (@posstypes) {
6843: unless (grep(/^default$/,@posstypes)) {
6844: push(@posstypes,'default');
1.302 raeburn 6845: }
6846: if (ref($usertypes) eq 'HASH') {
6847: %usertypeshash = %{$usertypes};
6848: }
1.305 raeburn 6849: my $currassign;
6850: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6851: $currassign = {
6852: selfassign => $domdefaults{'inststatusguest'},
6853: };
6854: @ordered = @{$domdefaults{'inststatusguest'}};
6855: } else {
6856: $currassign = { selfassign => [] };
6857: }
6858: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6859: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6860: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6861: $numinrow,$othertitle,'selfassign',
6862: $rowtotal,$onclicktypes,$customclass,
6863: $rowstyle);
6864: $$rowtotal ++;
1.302 raeburn 6865: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6866: foreach my $status (@posstypes) {
6867: my $css_class;
6868: if ($$rowtotal%2) {
6869: $css_class = 'LC_odd_row ';
6870: }
6871: $css_class .= $customclass;
6872: my $rowid = $optionsprefix.$status;
6873: my $hidden = 1;
6874: my $currstyle = 'display:none';
6875: if (grep(/^\Q$status\E$/,@ordered)) {
6876: $currstyle = $rowstyle;
6877: $hidden = 0;
6878: }
6879: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6880: $emailrules,$emailruleorder,$settings,$status,$rowid,
6881: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6882: unless ($hidden) {
6883: $$rowtotal ++;
6884: }
1.224 raeburn 6885: }
1.302 raeburn 6886: } else {
1.305 raeburn 6887: my $css_class;
6888: if ($$rowtotal%2) {
6889: $css_class = 'LC_odd_row ';
6890: }
6891: $css_class .= $customclass;
1.302 raeburn 6892: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6893: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6894: $emailrules,$emailruleorder,$settings,'default','',
6895: $othertitle,$css_class,$rowstyle,$intdom);
6896: $$rowtotal ++;
1.224 raeburn 6897: }
6898: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 6899: $numinrow = 1;
1.305 raeburn 6900: if (@posstypes) {
6901: foreach my $status (@posstypes) {
6902: my $rowid = $classprefix.$status;
6903: my $datarowstyle = 'display:none';
6904: if (grep(/^\Q$status\E$/,@ordered)) {
6905: $datarowstyle = $rowstyle;
6906: }
6907: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6908: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6909: $infotitles,$rowid,$customclass,$datarowstyle);
6910: unless ($datarowstyle eq 'display:none') {
6911: $$rowtotal ++;
6912: }
1.224 raeburn 6913: }
1.305 raeburn 6914: } else {
6915: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
6916: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6917: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 6918: }
6919: }
6920: return $datatable;
6921: }
6922:
1.305 raeburn 6923: sub selfcreate_javascript {
6924: return <<"ENDSCRIPT";
6925:
6926: <script type="text/javascript">
6927: // <![CDATA[
6928:
6929: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6930: var x = document.getElementsByClassName(target);
6931: var insttypes = 0;
6932: var insttypeRegExp = new RegExp(prefix);
6933: if ((x.length != undefined) && (x.length > 0)) {
6934: if (form.elements[radio].length != undefined) {
6935: for (var i=0; i<form.elements[radio].length; i++) {
6936: if (form.elements[radio][i].checked) {
6937: if (form.elements[radio][i].value == 1) {
6938: for (var j=0; j<x.length; j++) {
6939: if (x[j].id == 'undefined') {
6940: x[j].style.display = 'table-row';
6941: } else if (insttypeRegExp.test(x[j].id)) {
6942: insttypes ++;
6943: } else {
6944: x[j].style.display = 'table-row';
6945: }
6946: }
6947: } else {
6948: for (var j=0; j<x.length; j++) {
6949: x[j].style.display = 'none';
6950: }
1.236 raeburn 6951: }
1.305 raeburn 6952: break;
6953: }
6954: }
6955: if (insttypes > 0) {
6956: toggleDataRow(form,checkbox,target,altprefix);
6957: toggleDataRow(form,checkbox,target,prefix,1);
6958: }
6959: }
6960: }
6961: return;
6962: }
6963:
6964: function toggleDataRow(form,checkbox,target,prefix,docount) {
6965: if (form.elements[checkbox].length != undefined) {
6966: var count = 0;
6967: if (docount) {
6968: for (var i=0; i<form.elements[checkbox].length; i++) {
6969: if (form.elements[checkbox][i].checked) {
6970: count ++;
1.236 raeburn 6971: }
1.305 raeburn 6972: }
6973: }
6974: for (var i=0; i<form.elements[checkbox].length; i++) {
6975: var type = form.elements[checkbox][i].value;
6976: if (document.getElementById(prefix+type)) {
6977: if (form.elements[checkbox][i].checked) {
6978: document.getElementById(prefix+type).style.display = 'table-row';
6979: if (count % 2 == 1) {
6980: document.getElementById(prefix+type).className = target+' LC_odd_row';
6981: } else {
6982: document.getElementById(prefix+type).className = target;
1.236 raeburn 6983: }
1.305 raeburn 6984: count ++;
1.236 raeburn 6985: } else {
1.305 raeburn 6986: document.getElementById(prefix+type).style.display = 'none';
6987: }
6988: }
6989: }
6990: }
6991: return;
6992: }
6993:
6994: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
6995: var caller = radio+'_'+status;
6996: if (form.elements[caller].length != undefined) {
6997: for (var i=0; i<form.elements[caller].length; i++) {
6998: if (form.elements[caller][i].checked) {
6999: if (document.getElementById(altprefix+'_inst_'+status)) {
7000: var curr = form.elements[caller][i].value;
7001: if (prefix) {
7002: document.getElementById(prefix+'_'+status).style.display = 'none';
7003: }
7004: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7005: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7006: if (curr == 'custom') {
7007: if (prefix) {
7008: document.getElementById(prefix+'_'+status).style.display = 'inline';
7009: }
7010: } else if (curr == 'inst') {
7011: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7012: } else if (curr == 'noninst') {
7013: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 7014: }
1.305 raeburn 7015: break;
1.236 raeburn 7016: }
7017: }
7018: }
7019: }
7020: }
7021:
1.305 raeburn 7022: // ]]>
7023: </script>
7024:
7025: ENDSCRIPT
7026: }
7027:
7028: sub noninst_users {
7029: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7030: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7031: my $class = 'LC_left_item';
7032: if ($css_class) {
7033: $css_class = ' class="'.$css_class.'"';
7034: }
7035: if ($rowid) {
7036: $rowid = ' id="'.$rowid.'"';
7037: }
7038: if ($rowstyle) {
7039: $rowstyle = ' style="'.$rowstyle.'"';
7040: }
7041: my ($output,$description);
7042: if ($type eq 'default') {
7043: $description = &mt('Requests for: [_1]',$typetitle);
7044: } else {
7045: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7046: }
7047: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7048: "<td>$description</td>\n".
7049: '<td class="'.$class.'" colspan="2">'.
7050: '<table><tr>';
7051: my %headers = &Apache::lonlocal::texthash(
7052: approve => 'Processing',
7053: email => 'E-mail',
7054: username => 'Username',
7055: );
7056: foreach my $item ('approve','email','username') {
7057: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 7058: }
1.305 raeburn 7059: $output .= '</tr><tr>';
7060: foreach my $item ('approve','email','username') {
1.306 raeburn 7061: $output .= '<td style="vertical-align: top">';
1.305 raeburn 7062: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7063: if ($item eq 'approve') {
7064: %choices = &Apache::lonlocal::texthash (
7065: automatic => 'Automatically approved',
7066: approval => 'Queued for approval',
7067: );
7068: @options = ('automatic','approval');
7069: $hashref = $processing;
7070: $defoption = 'automatic';
7071: $name = 'cancreate_emailprocess_'.$type;
7072: } elsif ($item eq 'email') {
7073: %choices = &Apache::lonlocal::texthash (
7074: any => 'Any e-mail',
7075: inst => 'Institutional only',
7076: noninst => 'Non-institutional only',
7077: custom => 'Custom restrictions',
7078: );
7079: @options = ('any','inst','noninst');
7080: my $showcustom;
7081: if (ref($emailrules) eq 'HASH') {
7082: if (keys(%{$emailrules}) > 0) {
7083: push(@options,'custom');
7084: $showcustom = 'cancreate_emailrule';
7085: if (ref($settings) eq 'HASH') {
7086: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7087: foreach my $rule (@{$settings->{'email_rule'}}) {
7088: if (exists($emailrules->{$rule})) {
7089: $hascustom ++;
7090: }
7091: }
7092: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7093: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7094: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7095: if (exists($emailrules->{$rule})) {
7096: $hascustom ++;
7097: }
7098: }
7099: }
7100: }
7101: }
7102: }
7103: }
7104: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7105: "'cancreate_emaildomain','$type'".');"';
7106: $hashref = $emailoptions;
7107: $defoption = 'any';
7108: $name = 'cancreate_emailoptions_'.$type;
7109: } elsif ($item eq 'username') {
7110: %choices = &Apache::lonlocal::texthash (
7111: all => 'Same as e-mail',
7112: first => 'Omit @domain',
7113: free => 'Free to choose',
7114: );
7115: @options = ('all','first','free');
7116: $hashref = $emailverified;
7117: $defoption = 'all';
7118: $name = 'cancreate_usernameoptions_'.$type;
7119: }
7120: foreach my $option (@options) {
7121: my $checked;
7122: if (ref($hashref) eq 'HASH') {
7123: if ($type eq '') {
7124: if (!exists($hashref->{'default'})) {
7125: if ($option eq $defoption) {
7126: $checked = ' checked="checked"';
7127: }
7128: } else {
7129: if ($hashref->{'default'} eq $option) {
7130: $checked = ' checked="checked"';
7131: }
1.303 raeburn 7132: }
7133: } else {
1.305 raeburn 7134: if (!exists($hashref->{$type})) {
7135: if ($option eq $defoption) {
7136: $checked = ' checked="checked"';
7137: }
7138: } else {
7139: if ($hashref->{$type} eq $option) {
7140: $checked = ' checked="checked"';
7141: }
1.303 raeburn 7142: }
7143: }
1.305 raeburn 7144: } elsif (($item eq 'email') && ($hascustom)) {
7145: if ($option eq 'custom') {
7146: $checked = ' checked="checked"';
7147: }
7148: } elsif ($option eq $defoption) {
7149: $checked = ' checked="checked"';
7150: }
7151: $output .= '<span class="LC_nobreak"><label>'.
7152: '<input type="radio" name="'.$name.'"'.
7153: $checked.' value="'.$option.'"'.$onclick.' />'.
7154: $choices{$option}.'</label></span><br />';
7155: if ($item eq 'email') {
7156: if ($option eq 'custom') {
7157: my $id = 'cancreate_emailrule_'.$type;
7158: my $display = 'none';
7159: if ($checked) {
7160: $display = 'inline';
1.303 raeburn 7161: }
1.305 raeburn 7162: my $numinrow = 2;
7163: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7164: '<legend>'.&mt('Disallow').'</legend><table>'.
7165: &user_formats_row('email',$settings,$emailrules,
7166: $emailruleorder,$numinrow,'',$type);
7167: '</table></fieldset>';
7168: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7169: my %text = &Apache::lonlocal::texthash (
7170: inst => 'must end:',
7171: noninst => 'cannot end:',
7172: );
7173: my $value;
7174: if (ref($emaildomain) eq 'HASH') {
7175: if (ref($emaildomain->{$type}) eq 'HASH') {
7176: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 7177: }
7178: }
1.305 raeburn 7179: if ($value eq '') {
7180: $value = '@'.$intdom;
7181: }
7182: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7183: my $display = 'none';
7184: if ($checked) {
7185: $display = 'inline';
7186: }
7187: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7188: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7189: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7190: '</div>';
1.303 raeburn 7191: }
7192: }
7193: }
1.305 raeburn 7194: $output .= '</td>'."\n";
1.303 raeburn 7195: }
1.305 raeburn 7196: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 7197: return $output;
7198: }
7199:
1.165 raeburn 7200: sub captcha_choice {
1.305 raeburn 7201: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 7202: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7203: $vertext,$currver);
1.165 raeburn 7204: my %lt = &captcha_phrases();
7205: $keyentry = 'hidden';
7206: if ($context eq 'cancreate') {
1.224 raeburn 7207: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 7208: } elsif ($context eq 'login') {
7209: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 7210: }
7211: if (ref($settings) eq 'HASH') {
7212: if ($settings->{'captcha'}) {
7213: $checked{$settings->{'captcha'}} = ' checked="checked"';
7214: } else {
7215: $checked{'original'} = ' checked="checked"';
7216: }
7217: if ($settings->{'captcha'} eq 'recaptcha') {
7218: $pubtext = $lt{'pub'};
7219: $privtext = $lt{'priv'};
7220: $keyentry = 'text';
1.269 raeburn 7221: $vertext = $lt{'ver'};
7222: $currver = $settings->{'recaptchaversion'};
7223: if ($currver ne '2') {
7224: $currver = 1;
7225: }
1.165 raeburn 7226: }
7227: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7228: $currpub = $settings->{'recaptchakeys'}{'public'};
7229: $currpriv = $settings->{'recaptchakeys'}{'private'};
7230: }
7231: } else {
7232: $checked{'original'} = ' checked="checked"';
7233: }
1.305 raeburn 7234: my $css_class;
7235: if ($itemcount%2) {
7236: $css_class = 'LC_odd_row';
7237: }
7238: if ($customcss) {
7239: $css_class .= " $customcss";
7240: }
7241: $css_class =~ s/^\s+//;
7242: if ($css_class) {
7243: $css_class = ' class="'.$css_class.'"';
7244: }
7245: if ($rowstyle) {
7246: $css_class .= ' style="'.$rowstyle.'"';
7247: }
1.169 raeburn 7248: my $output = '<tr'.$css_class.'>'.
7249: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 7250: '<table><tr><td>'."\n";
7251: foreach my $option ('original','recaptcha','notused') {
7252: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7253: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7254: $lt{$option}.'</label></span>';
7255: unless ($option eq 'notused') {
7256: $output .= (' 'x2)."\n";
7257: }
7258: }
7259: #
7260: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7261: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 7262: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 7263: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 7264: #
1.165 raeburn 7265: $output .= '</td></tr>'."\n".
1.305 raeburn 7266: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 7267: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7268: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7269: $currpub.'" size="40" /></span><br />'."\n".
7270: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7271: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 7272: $currpriv.'" size="40" /></span><br />'.
7273: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7274: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7275: $currver.'" size="3" /></span><br />'.
7276: '</td></tr></table>'."\n".
1.165 raeburn 7277: '</td></tr>';
7278: return $output;
7279: }
7280:
1.32 raeburn 7281: sub user_formats_row {
1.305 raeburn 7282: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7283: my $output;
7284: my %text = (
7285: 'username' => 'new usernames',
7286: 'id' => 'IDs',
7287: );
1.305 raeburn 7288: unless ($type eq 'email') {
7289: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7290: $output = '<tr '.$css_class.'>'.
7291: '<td><span class="LC_nobreak">'.
7292: &mt("Format rules to check for $text{$type}: ").
7293: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7294: }
1.27 raeburn 7295: my $rem;
7296: if (ref($ruleorder) eq 'ARRAY') {
7297: for (my $i=0; $i<@{$ruleorder}; $i++) {
7298: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7299: my $rem = $i%($numinrow);
7300: if ($rem == 0) {
7301: if ($i > 0) {
7302: $output .= '</tr>';
7303: }
7304: $output .= '<tr>';
7305: }
7306: my $check = ' ';
1.39 raeburn 7307: if (ref($settings) eq 'HASH') {
7308: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7309: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7310: $check = ' checked="checked" ';
7311: }
1.305 raeburn 7312: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7313: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7314: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7315: $check = ' checked="checked" ';
7316: }
7317: }
1.27 raeburn 7318: }
7319: }
1.305 raeburn 7320: my $name = $type.'_rule';
7321: if ($type eq 'email') {
7322: $name .= '_'.$status;
7323: }
1.27 raeburn 7324: $output .= '<td class="LC_left_item">'.
7325: '<span class="LC_nobreak"><label>'.
1.311 raeburn 7326: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7327: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7328: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7329: }
7330: }
7331: $rem = @{$ruleorder}%($numinrow);
7332: }
1.305 raeburn 7333: my $colsleft;
7334: if ($rem) {
7335: $colsleft = $numinrow - $rem;
7336: }
1.27 raeburn 7337: if ($colsleft > 1 ) {
7338: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7339: ' </td>';
7340: } elsif ($colsleft == 1) {
7341: $output .= '<td class="LC_left_item"> </td>';
7342: }
1.305 raeburn 7343: $output .= '</tr></table>';
7344: unless ($type eq 'email') {
7345: $output .= '</td></tr>';
7346: }
1.27 raeburn 7347: return $output;
7348: }
7349:
1.34 raeburn 7350: sub usercreation_types {
7351: my %lt = &Apache::lonlocal::texthash (
7352: author => 'When adding a co-author',
7353: course => 'When adding a user to a course',
1.100 raeburn 7354: requestcrs => 'When requesting a course',
1.34 raeburn 7355: any => 'Any',
7356: official => 'Institutional only ',
7357: unofficial => 'Non-institutional only',
7358: none => 'None',
7359: );
7360: return %lt;
1.48 raeburn 7361: }
1.34 raeburn 7362:
1.224 raeburn 7363: sub selfcreation_types {
7364: my %lt = &Apache::lonlocal::texthash (
7365: selfcreate => 'User creates own account',
7366: any => 'Any',
7367: official => 'Institutional only ',
7368: unofficial => 'Non-institutional only',
7369: email => 'E-mail address',
7370: login => 'Institutional Login',
7371: sso => 'SSO',
7372: );
7373: }
7374:
1.28 raeburn 7375: sub authtype_names {
7376: my %lt = &Apache::lonlocal::texthash(
7377: int => 'Internal',
7378: krb4 => 'Kerberos 4',
7379: krb5 => 'Kerberos 5',
7380: loc => 'Local',
1.325 ! raeburn 7381: lti => 'LTI',
1.28 raeburn 7382: );
7383: return %lt;
7384: }
7385:
7386: sub context_names {
7387: my %context_title = &Apache::lonlocal::texthash(
7388: author => 'Creating users when an Author',
7389: course => 'Creating users when in a course',
7390: domain => 'Creating users when a Domain Coordinator',
7391: );
7392: return %context_title;
7393: }
7394:
1.33 raeburn 7395: sub print_usermodification {
7396: my ($position,$dom,$settings,$rowtotal) = @_;
7397: my $numinrow = 4;
7398: my ($context,$datatable,$rowcount);
7399: if ($position eq 'top') {
7400: $rowcount = 0;
7401: $context = 'author';
7402: foreach my $role ('ca','aa') {
7403: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7404: $numinrow,$rowcount);
7405: $$rowtotal ++;
7406: $rowcount ++;
7407: }
1.230 raeburn 7408: } elsif ($position eq 'bottom') {
1.33 raeburn 7409: $context = 'course';
7410: $rowcount = 0;
7411: foreach my $role ('st','ep','ta','in','cr') {
7412: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7413: $numinrow,$rowcount);
7414: $$rowtotal ++;
7415: $rowcount ++;
7416: }
7417: }
7418: return $datatable;
7419: }
7420:
1.43 raeburn 7421: sub print_defaults {
1.236 raeburn 7422: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7423: my $rownum = 0;
1.294 raeburn 7424: my ($datatable,$css_class,$titles);
7425: unless ($position eq 'bottom') {
7426: $titles = &defaults_titles($dom);
7427: }
1.236 raeburn 7428: if ($position eq 'top') {
7429: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7430: 'datelocale_def','portal_def');
7431: my %defaults;
7432: if (ref($settings) eq 'HASH') {
7433: %defaults = %{$settings};
1.43 raeburn 7434: } else {
1.236 raeburn 7435: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7436: foreach my $item (@items) {
7437: $defaults{$item} = $domdefaults{$item};
7438: }
1.43 raeburn 7439: }
1.236 raeburn 7440: foreach my $item (@items) {
7441: if ($rownum%2) {
7442: $css_class = '';
7443: } else {
7444: $css_class = ' class="LC_odd_row" ';
7445: }
7446: $datatable .= '<tr'.$css_class.'>'.
7447: '<td><span class="LC_nobreak">'.$titles->{$item}.
7448: '</span></td><td class="LC_right_item" colspan="3">';
7449: if ($item eq 'auth_def') {
1.325 ! raeburn 7450: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 7451: my %shortauth = (
7452: internal => 'int',
7453: krb4 => 'krb4',
7454: krb5 => 'krb5',
1.325 ! raeburn 7455: localauth => 'loc',
! 7456: lti => 'lti',
1.236 raeburn 7457: );
7458: my %authnames = &authtype_names();
7459: foreach my $auth (@authtypes) {
7460: my $checked = ' ';
7461: if ($defaults{$item} eq $auth) {
7462: $checked = ' checked="checked" ';
7463: }
7464: $datatable .= '<label><input type="radio" name="'.$item.
7465: '" value="'.$auth.'"'.$checked.'/>'.
7466: $authnames{$shortauth{$auth}}.'</label> ';
7467: }
7468: } elsif ($item eq 'timezone_def') {
7469: my $includeempty = 1;
7470: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7471: } elsif ($item eq 'datelocale_def') {
7472: my $includeempty = 1;
7473: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7474: } elsif ($item eq 'lang_def') {
1.263 raeburn 7475: my $includeempty = 1;
7476: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 7477: } else {
7478: my $size;
7479: if ($item eq 'portal_def') {
7480: $size = ' size="25"';
7481: }
7482: $datatable .= '<input type="text" name="'.$item.'" value="'.
7483: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 7484: }
1.236 raeburn 7485: $datatable .= '</td></tr>';
7486: $rownum ++;
7487: }
1.294 raeburn 7488: } elsif ($position eq 'middle') {
7489: my @items = ('intauth_cost','intauth_check','intauth_switch');
7490: my %defaults;
7491: if (ref($settings) eq 'HASH') {
7492: %defaults = %{$settings};
7493: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7494: $defaults{'intauth_cost'} = 10;
7495: }
7496: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7497: $defaults{'intauth_check'} = 0;
7498: }
7499: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7500: $defaults{'intauth_switch'} = 0;
7501: }
7502: } else {
7503: %defaults = (
7504: 'intauth_cost' => 10,
7505: 'intauth_check' => 0,
7506: 'intauth_switch' => 0,
7507: );
7508: }
7509: foreach my $item (@items) {
7510: if ($rownum%2) {
7511: $css_class = '';
7512: } else {
7513: $css_class = ' class="LC_odd_row" ';
7514: }
7515: $datatable .= '<tr'.$css_class.'>'.
7516: '<td><span class="LC_nobreak">'.$titles->{$item}.
7517: '</span></td><td class="LC_left_item" colspan="3">';
7518: if ($item eq 'intauth_switch') {
7519: my @options = (0,1,2);
7520: my %optiondesc = &Apache::lonlocal::texthash (
7521: 0 => 'No',
7522: 1 => 'Yes',
7523: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7524: );
7525: $datatable .= '<table width="100%">';
7526: foreach my $option (@options) {
7527: my $checked = ' ';
7528: if ($defaults{$item} eq $option) {
7529: $checked = ' checked="checked"';
7530: }
7531: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7532: '<label><input type="radio" name="'.$item.
7533: '" value="'.$option.'"'.$checked.' />'.
7534: $optiondesc{$option}.'</label></span></td></tr>';
7535: }
7536: $datatable .= '</table>';
7537: } elsif ($item eq 'intauth_check') {
7538: my @options = (0,1,2);
7539: my %optiondesc = &Apache::lonlocal::texthash (
7540: 0 => 'No',
7541: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7542: 2 => 'Yes, disallow login if stored cost is less than domain default',
7543: );
7544: $datatable .= '<table wisth="100%">';
7545: foreach my $option (@options) {
7546: my $checked = ' ';
7547: my $onclick;
7548: if ($defaults{$item} eq $option) {
7549: $checked = ' checked="checked"';
7550: }
7551: if ($option == 2) {
7552: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7553: }
7554: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7555: '<label><input type="radio" name="'.$item.
7556: '" value="'.$option.'"'.$checked.$onclick.' />'.
7557: $optiondesc{$option}.'</label></span></td></tr>';
7558: }
7559: $datatable .= '</table>';
7560: } else {
7561: $datatable .= '<input type="text" name="'.$item.'" value="'.
7562: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7563: }
7564: $datatable .= '</td></tr>';
7565: $rownum ++;
7566: }
1.236 raeburn 7567: } else {
1.294 raeburn 7568: my %defaults;
1.236 raeburn 7569: if (ref($settings) eq 'HASH') {
1.305 raeburn 7570: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.236 raeburn 7571: my $maxnum = @{$settings->{'inststatusorder'}};
7572: for (my $i=0; $i<$maxnum; $i++) {
7573: $css_class = $rownum%2?' class="LC_odd_row"':'';
7574: my $item = $settings->{'inststatusorder'}->[$i];
7575: my $title = $settings->{'inststatustypes'}->{$item};
7576: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7577: $datatable .= '<tr'.$css_class.'>'.
7578: '<td><span class="LC_nobreak">'.
7579: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7580: for (my $k=0; $k<=$maxnum; $k++) {
7581: my $vpos = $k+1;
7582: my $selstr;
7583: if ($k == $i) {
7584: $selstr = ' selected="selected" ';
7585: }
7586: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7587: }
7588: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7589: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7590: &mt('delete').'</span></td>'.
1.305 raeburn 7591: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.236 raeburn 7592: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.305 raeburn 7593: '</span></td></tr>';
1.236 raeburn 7594: }
7595: $css_class = $rownum%2?' class="LC_odd_row"':'';
7596: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7597: $datatable .= '<tr '.$css_class.'>'.
7598: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7599: for (my $k=0; $k<=$maxnum; $k++) {
7600: my $vpos = $k+1;
7601: my $selstr;
7602: if ($k == $maxnum) {
7603: $selstr = ' selected="selected" ';
7604: }
7605: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7606: }
7607: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 7608: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 7609: ' '.&mt('(new)').
1.305 raeburn 7610: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.236 raeburn 7611: &mt('Name displayed:').
7612: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7613: '</tr>'."\n";
7614: $rownum ++;
1.141 raeburn 7615: }
1.43 raeburn 7616: }
7617: }
7618: $$rowtotal += $rownum;
7619: return $datatable;
7620: }
7621:
1.168 raeburn 7622: sub get_languages_hash {
7623: my %langchoices;
7624: foreach my $id (&Apache::loncommon::languageids()) {
7625: my $code = &Apache::loncommon::supportedlanguagecode($id);
7626: if ($code ne '') {
7627: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7628: }
7629: }
7630: return %langchoices;
7631: }
7632:
1.43 raeburn 7633: sub defaults_titles {
1.141 raeburn 7634: my ($dom) = @_;
1.43 raeburn 7635: my %titles = &Apache::lonlocal::texthash (
7636: 'auth_def' => 'Default authentication type',
7637: 'auth_arg_def' => 'Default authentication argument',
7638: 'lang_def' => 'Default language',
1.54 raeburn 7639: 'timezone_def' => 'Default timezone',
1.68 raeburn 7640: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7641: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 7642: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7643: 'intauth_check' => 'Check bcrypt cost if authenticated',
7644: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7645: );
1.141 raeburn 7646: if ($dom) {
7647: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7648: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7649: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7650: $protocol = 'http' if ($protocol ne 'https');
7651: if ($uint_dom) {
7652: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7653: $uint_dom);
7654: }
7655: }
1.43 raeburn 7656: return (\%titles);
7657: }
7658:
1.46 raeburn 7659: sub print_scantronformat {
7660: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7661: my $itemcount = 1;
1.60 raeburn 7662: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7663: %confhash);
1.46 raeburn 7664: my $switchserver = &check_switchserver($dom,$confname);
7665: my %lt = &Apache::lonlocal::texthash (
1.95 www 7666: default => 'Default bubblesheet format file error',
7667: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7668: );
7669: my %scantronfiles = (
7670: default => 'default.tab',
7671: custom => 'custom.tab',
7672: );
7673: foreach my $key (keys(%scantronfiles)) {
7674: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7675: .$scantronfiles{$key};
7676: }
7677: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7678: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7679: if (!$switchserver) {
7680: my $servadm = $r->dir_config('lonAdmEMail');
7681: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7682: if ($configuserok eq 'ok') {
7683: if ($author_ok eq 'ok') {
7684: my %legacyfile = (
7685: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7686: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
7687: );
7688: my %md5chk;
7689: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7690: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7691: chomp($md5chk{$type});
1.46 raeburn 7692: }
7693: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7694: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7695: ($scantronurls{$type},my $error) =
1.46 raeburn 7696: &legacy_scantronformat($r,$dom,$confname,
7697: $type,$legacyfile{$type},
7698: $scantronurls{$type},
7699: $scantronfiles{$type});
1.60 raeburn 7700: if ($error ne '') {
7701: $error{$type} = $error;
7702: }
7703: }
7704: if (keys(%error) == 0) {
7705: $is_custom = 1;
7706: $confhash{'scantron'}{'scantronformat'} =
7707: $scantronurls{'custom'};
7708: my $putresult =
7709: &Apache::lonnet::put_dom('configuration',
7710: \%confhash,$dom);
7711: if ($putresult ne 'ok') {
7712: $error{'custom'} =
7713: '<span class="LC_error">'.
7714: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7715: }
1.46 raeburn 7716: }
7717: } else {
1.60 raeburn 7718: ($scantronurls{'default'},my $error) =
1.46 raeburn 7719: &legacy_scantronformat($r,$dom,$confname,
7720: 'default',$legacyfile{'default'},
7721: $scantronurls{'default'},
7722: $scantronfiles{'default'});
1.60 raeburn 7723: if ($error eq '') {
7724: $confhash{'scantron'}{'scantronformat'} = '';
7725: my $putresult =
7726: &Apache::lonnet::put_dom('configuration',
7727: \%confhash,$dom);
7728: if ($putresult ne 'ok') {
7729: $error{'default'} =
7730: '<span class="LC_error">'.
7731: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7732: }
7733: } else {
7734: $error{'default'} = $error;
7735: }
1.46 raeburn 7736: }
7737: }
7738: }
7739: } else {
1.95 www 7740: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7741: }
7742: }
7743: if (ref($settings) eq 'HASH') {
7744: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7745: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7746: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7747: $scantronurl = '';
7748: } else {
7749: $scantronurl = $settings->{'scantronformat'};
7750: }
7751: $is_custom = 1;
7752: } else {
7753: $scantronurl = $scantronurls{'default'};
7754: }
7755: } else {
1.60 raeburn 7756: if ($is_custom) {
7757: $scantronurl = $scantronurls{'custom'};
7758: } else {
7759: $scantronurl = $scantronurls{'default'};
7760: }
1.46 raeburn 7761: }
7762: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7763: $datatable .= '<tr'.$css_class.'>';
7764: if (!$is_custom) {
1.65 raeburn 7765: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7766: '<span class="LC_nobreak">';
1.46 raeburn 7767: if ($scantronurl) {
1.199 raeburn 7768: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7769: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7770: } else {
7771: $datatable = &mt('File unavailable for display');
7772: }
1.65 raeburn 7773: $datatable .= '</span></td>';
1.60 raeburn 7774: if (keys(%error) == 0) {
1.306 raeburn 7775: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 7776: if (!$switchserver) {
7777: $datatable .= &mt('Upload:').'<br />';
7778: }
7779: } else {
7780: my $errorstr;
7781: foreach my $key (sort(keys(%error))) {
7782: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7783: }
7784: $datatable .= '<td>'.$errorstr;
7785: }
1.46 raeburn 7786: } else {
7787: if (keys(%error) > 0) {
7788: my $errorstr;
7789: foreach my $key (sort(keys(%error))) {
7790: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7791: }
1.60 raeburn 7792: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7793: } elsif ($scantronurl) {
1.199 raeburn 7794: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
7795: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7796: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 7797: $link.
7798: '<label><input type="checkbox" name="scantronformat_del"'.
7799: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7800: '<td><span class="LC_nobreak"> '.
7801: &mt('Replace:').'</span><br />';
1.46 raeburn 7802: }
7803: }
7804: if (keys(%error) == 0) {
7805: if ($switchserver) {
7806: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7807: } else {
1.65 raeburn 7808: $datatable .='<span class="LC_nobreak"> '.
7809: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7810: }
7811: }
7812: $datatable .= '</td></tr>';
7813: $$rowtotal ++;
7814: return $datatable;
7815: }
7816:
7817: sub legacy_scantronformat {
7818: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7819: my ($url,$error);
7820: my @statinfo = &Apache::lonnet::stat_file($newurl);
7821: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7822: (my $result,$url) =
7823: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7824: '','',$newfile);
7825: if ($result ne 'ok') {
1.130 raeburn 7826: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7827: }
7828: }
7829: return ($url,$error);
7830: }
1.43 raeburn 7831:
1.49 raeburn 7832: sub print_coursecategories {
1.57 raeburn 7833: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7834: my $datatable;
7835: if ($position eq 'top') {
1.238 raeburn 7836: my (%checked);
7837: my @catitems = ('unauth','auth');
7838: my @cattypes = ('std','domonly','codesrch','none');
7839: $checked{'unauth'} = 'std';
7840: $checked{'auth'} = 'std';
7841: if (ref($settings) eq 'HASH') {
7842: foreach my $type (@cattypes) {
7843: if ($type eq $settings->{'unauth'}) {
7844: $checked{'unauth'} = $type;
7845: }
7846: if ($type eq $settings->{'auth'}) {
7847: $checked{'auth'} = $type;
7848: }
7849: }
7850: }
7851: my %lt = &Apache::lonlocal::texthash (
7852: unauth => 'Catalog type for unauthenticated users',
7853: auth => 'Catalog type for authenticated users',
7854: none => 'No catalog',
7855: std => 'Standard catalog',
7856: domonly => 'Domain-only catalog',
7857: codesrch => "Code search form",
7858: );
7859: my $itemcount = 0;
7860: foreach my $item (@catitems) {
7861: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7862: $datatable .= '<tr '.$css_class.'>'.
7863: '<td>'.$lt{$item}.'</td>'.
7864: '<td class="LC_right_item"><span class="LC_nobreak">';
7865: foreach my $type (@cattypes) {
7866: my $ischecked;
7867: if ($checked{$item} eq $type) {
7868: $ischecked=' checked="checked"';
7869: }
7870: $datatable .= '<label>'.
7871: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
7872: ' />'.$lt{$type}.'</label> ';
7873: }
7874: $datatable .= '</td></tr>';
7875: $itemcount ++;
7876: }
7877: $$rowtotal += $itemcount;
7878: } elsif ($position eq 'middle') {
1.57 raeburn 7879: my $toggle_cats_crs = ' ';
7880: my $toggle_cats_dom = ' checked="checked" ';
7881: my $can_cat_crs = ' ';
7882: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 7883: my $toggle_catscomm_comm = ' ';
7884: my $toggle_catscomm_dom = ' checked="checked" ';
7885: my $can_catcomm_comm = ' ';
7886: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 7887: my $toggle_catsplace_place = ' ';
7888: my $toggle_catsplace_dom = ' checked="checked" ';
7889: my $can_catplace_place = ' ';
7890: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 7891:
1.57 raeburn 7892: if (ref($settings) eq 'HASH') {
7893: if ($settings->{'togglecats'} eq 'crs') {
7894: $toggle_cats_crs = $toggle_cats_dom;
7895: $toggle_cats_dom = ' ';
7896: }
7897: if ($settings->{'categorize'} eq 'crs') {
7898: $can_cat_crs = $can_cat_dom;
7899: $can_cat_dom = ' ';
7900: }
1.120 raeburn 7901: if ($settings->{'togglecatscomm'} eq 'comm') {
7902: $toggle_catscomm_comm = $toggle_catscomm_dom;
7903: $toggle_catscomm_dom = ' ';
7904: }
7905: if ($settings->{'categorizecomm'} eq 'comm') {
7906: $can_catcomm_comm = $can_catcomm_dom;
7907: $can_catcomm_dom = ' ';
7908: }
1.272 raeburn 7909: if ($settings->{'togglecatsplace'} eq 'place') {
7910: $toggle_catsplace_place = $toggle_catsplace_dom;
7911: $toggle_catsplace_dom = ' ';
7912: }
7913: if ($settings->{'categorizeplace'} eq 'place') {
7914: $can_catplace_place = $can_catplace_dom;
7915: $can_catplace_dom = ' ';
7916: }
1.57 raeburn 7917: }
7918: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 7919: togglecats => 'Show/Hide a course in catalog',
7920: togglecatscomm => 'Show/Hide a community in catalog',
7921: togglecatsplace => 'Show/Hide a placement test in catalog',
7922: categorize => 'Assign a category to a course',
7923: categorizecomm => 'Assign a category to a community',
7924: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 7925: );
7926: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 7927: dom => 'Set in Domain',
7928: crs => 'Set in Course',
7929: comm => 'Set in Community',
7930: place => 'Set in Placement Test',
1.57 raeburn 7931: );
7932: $datatable = '<tr class="LC_odd_row">'.
7933: '<td>'.$title{'togglecats'}.'</td>'.
7934: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7935: '<input type="radio" name="togglecats"'.
7936: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7937: '<label><input type="radio" name="togglecats"'.
7938: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
7939: '</tr><tr>'.
7940: '<td>'.$title{'categorize'}.'</td>'.
7941: '<td class="LC_right_item"><span class="LC_nobreak">'.
7942: '<label><input type="radio" name="categorize"'.
7943: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7944: '<label><input type="radio" name="categorize"'.
7945: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 7946: '</tr><tr class="LC_odd_row">'.
7947: '<td>'.$title{'togglecatscomm'}.'</td>'.
7948: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7949: '<input type="radio" name="togglecatscomm"'.
7950: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7951: '<label><input type="radio" name="togglecatscomm"'.
7952: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
7953: '</tr><tr>'.
7954: '<td>'.$title{'categorizecomm'}.'</td>'.
7955: '<td class="LC_right_item"><span class="LC_nobreak">'.
7956: '<label><input type="radio" name="categorizecomm"'.
7957: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7958: '<label><input type="radio" name="categorizecomm"'.
7959: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 7960: '</tr><tr>'.
7961: '<td>'.$title{'togglecatsplace'}.'</td>'.
7962: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7963: '<input type="radio" name="togglecatsplace"'.
7964: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7965: '<label><input type="radio" name="togglecatscomm"'.
7966: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
7967: '</tr><tr>'.
7968: '<td>'.$title{'categorizeplace'}.'</td>'.
7969: '<td class="LC_right_item"><span class="LC_nobreak">'.
7970: '<label><input type="radio" name="categorizeplace"'.
7971: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7972: '<label><input type="radio" name="categorizeplace"'.
7973: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 7974: '</tr>';
1.272 raeburn 7975: $$rowtotal += 6;
1.57 raeburn 7976: } else {
7977: my $css_class;
7978: my $itemcount = 1;
7979: my $cathash;
7980: if (ref($settings) eq 'HASH') {
7981: $cathash = $settings->{'cats'};
7982: }
7983: if (ref($cathash) eq 'HASH') {
7984: my (@cats,@trails,%allitems,%idx,@jsarray);
7985: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
7986: \%allitems,\%idx,\@jsarray);
7987: my $maxdepth = scalar(@cats);
7988: my $colattrib = '';
7989: if ($maxdepth > 2) {
7990: $colattrib = ' colspan="2" ';
7991: }
7992: my @path;
7993: if (@cats > 0) {
7994: if (ref($cats[0]) eq 'ARRAY') {
7995: my $numtop = @{$cats[0]};
7996: my $maxnum = $numtop;
1.120 raeburn 7997: my %default_names = (
7998: instcode => &mt('Official courses'),
7999: communities => &mt('Communities'),
1.272 raeburn 8000: placement => &mt('Placement Tests'),
1.120 raeburn 8001: );
8002:
8003: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8004: ($cathash->{'instcode::0'} eq '') ||
8005: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 8006: ($cathash->{'communities::0'} eq '') ||
8007: (!grep(/^placement$/,@{$cats[0]})) ||
8008: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 8009: $maxnum ++;
8010: }
8011: my $lastidx;
8012: for (my $i=0; $i<$numtop; $i++) {
8013: my $parent = $cats[0][$i];
8014: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8015: my $item = &escape($parent).'::0';
8016: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8017: $lastidx = $idx{$item};
8018: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8019: .'<select name="'.$item.'"'.$chgstr.'>';
8020: for (my $k=0; $k<=$maxnum; $k++) {
8021: my $vpos = $k+1;
8022: my $selstr;
8023: if ($k == $i) {
8024: $selstr = ' selected="selected" ';
8025: }
8026: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8027: }
1.214 raeburn 8028: $datatable .= '</select></span></td><td>';
1.272 raeburn 8029: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 8030: $datatable .= '<span class="LC_nobreak">'
8031: .$default_names{$parent}.'</span>';
8032: if ($parent eq 'instcode') {
8033: $datatable .= '<br /><span class="LC_nobreak">('
8034: .&mt('with institutional codes')
8035: .')</span></td><td'.$colattrib.'>';
8036: } else {
8037: $datatable .= '<table><tr><td>';
8038: }
8039: $datatable .= '<span class="LC_nobreak">'
8040: .'<label><input type="radio" name="'
8041: .$parent.'" value="1" checked="checked" />'
8042: .&mt('Display').'</label>';
8043: if ($parent eq 'instcode') {
8044: $datatable .= ' ';
8045: } else {
8046: $datatable .= '</span></td></tr><tr><td>'
8047: .'<span class="LC_nobreak">';
8048: }
8049: $datatable .= '<label><input type="radio" name="'
8050: .$parent.'" value="0" />'
8051: .&mt('Do not display').'</label></span>';
1.272 raeburn 8052: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 8053: $datatable .= '</td></tr></table>';
8054: }
8055: $datatable .= '</td>';
1.57 raeburn 8056: } else {
8057: $datatable .= $parent
1.214 raeburn 8058: .' <span class="LC_nobreak"><label>'
8059: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8060: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8061: }
8062: my $depth = 1;
8063: push(@path,$parent);
8064: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8065: pop(@path);
8066: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8067: $itemcount ++;
8068: }
1.48 raeburn 8069: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8070: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8071: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8072: for (my $k=0; $k<=$maxnum; $k++) {
8073: my $vpos = $k+1;
8074: my $selstr;
1.57 raeburn 8075: if ($k == $numtop) {
1.48 raeburn 8076: $selstr = ' selected="selected" ';
8077: }
8078: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8079: }
1.59 bisitz 8080: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8081: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8082: .'</tr>'."\n";
1.48 raeburn 8083: $itemcount ++;
1.272 raeburn 8084: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8085: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8086: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8087: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8088: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8089: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8090: for (my $k=0; $k<=$maxnum; $k++) {
8091: my $vpos = $k+1;
8092: my $selstr;
8093: if ($k == $maxnum) {
8094: $selstr = ' selected="selected" ';
8095: }
8096: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8097: }
1.120 raeburn 8098: $datatable .= '</select></span></td>'.
8099: '<td><span class="LC_nobreak">'.
8100: $default_names{$default}.'</span>';
8101: if ($default eq 'instcode') {
8102: $datatable .= '<br /><span class="LC_nobreak">('
8103: .&mt('with institutional codes').')</span>';
8104: }
8105: $datatable .= '</td>'
8106: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8107: .&mt('Display').'</label> '
8108: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8109: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8110: }
8111: }
8112: }
1.57 raeburn 8113: } else {
8114: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8115: }
8116: } else {
1.238 raeburn 8117: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 8118: .&initialize_categories($itemcount);
1.48 raeburn 8119: }
1.57 raeburn 8120: $$rowtotal += $itemcount;
1.48 raeburn 8121: }
8122: return $datatable;
8123: }
8124:
1.69 raeburn 8125: sub print_serverstatuses {
8126: my ($dom,$settings,$rowtotal) = @_;
8127: my $datatable;
8128: my @pages = &serverstatus_pages();
8129: my (%namedaccess,%machineaccess);
8130: foreach my $type (@pages) {
8131: $namedaccess{$type} = '';
8132: $machineaccess{$type}= '';
8133: }
8134: if (ref($settings) eq 'HASH') {
8135: foreach my $type (@pages) {
8136: if (exists($settings->{$type})) {
8137: if (ref($settings->{$type}) eq 'HASH') {
8138: foreach my $key (keys(%{$settings->{$type}})) {
8139: if ($key eq 'namedusers') {
8140: $namedaccess{$type} = $settings->{$type}->{$key};
8141: } elsif ($key eq 'machines') {
8142: $machineaccess{$type} = $settings->{$type}->{$key};
8143: }
8144: }
8145: }
8146: }
8147: }
8148: }
1.81 raeburn 8149: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8150: my $rownum = 0;
8151: my $css_class;
8152: foreach my $type (@pages) {
8153: $rownum ++;
8154: $css_class = $rownum%2?' class="LC_odd_row"':'';
8155: $datatable .= '<tr'.$css_class.'>'.
8156: '<td><span class="LC_nobreak">'.
8157: $titles->{$type}.'</span></td>'.
8158: '<td class="LC_left_item">'.
8159: '<input type="text" name="'.$type.'_namedusers" '.
8160: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8161: '<td class="LC_right_item">'.
8162: '<span class="LC_nobreak">'.
8163: '<input type="text" name="'.$type.'_machines" '.
8164: 'value="'.$machineaccess{$type}.'" size="10" />'.
8165: '</td></tr>'."\n";
8166: }
8167: $$rowtotal += $rownum;
8168: return $datatable;
8169: }
8170:
8171: sub serverstatus_pages {
8172: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 8173: 'checksums','clusterstatus','certstatus','metadata_keywords',
8174: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
8175: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8176: }
8177:
1.236 raeburn 8178: sub defaults_javascript {
8179: my ($settings) = @_;
1.294 raeburn 8180: 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.');
8181: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
8182: &js_escape(\$intauthcheck);
8183: &js_escape(\$intauthcost);
8184: my $intauthjs = <<"ENDSCRIPT";
8185:
8186: function warnIntAuth(field) {
8187: if (field.name == 'intauth_check') {
8188: if (field.value == '2') {
8189: alert('$intauthcheck');
8190: }
8191: }
8192: if (field.name == 'intauth_cost') {
8193: field.value.replace(/\s/g,'');
8194: if (field.value != '') {
8195: var regexdigit=/^\\d+\$/;
8196: if (!regexdigit.test(field.value)) {
8197: alert('$intauthcost');
8198: }
8199: }
8200: }
8201: return;
8202: }
8203:
8204: ENDSCRIPT
8205:
8206: if (ref($settings) ne 'HASH') {
8207: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8208: }
1.236 raeburn 8209: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8210: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8211: if ($maxnum eq '') {
8212: $maxnum = 0;
8213: }
8214: $maxnum ++;
1.249 raeburn 8215: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 8216: return <<"ENDSCRIPT";
8217: <script type="text/javascript">
8218: // <![CDATA[
8219: function reorderTypes(form,caller) {
8220: var changedVal;
8221: $jstext
8222: var newpos = 'addinststatus_pos';
8223: var current = new Array;
8224: var maxh = $maxnum;
8225: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8226: var oldVal;
8227: if (caller == newpos) {
8228: changedVal = newitemVal;
8229: } else {
8230: var curritem = 'inststatus_pos_'+caller;
8231: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8232: current[newitemVal] = newpos;
8233: }
8234: for (var i=0; i<inststatuses.length; i++) {
8235: if (inststatuses[i] != caller) {
8236: var elementName = 'inststatus_pos_'+inststatuses[i];
8237: if (form.elements[elementName]) {
8238: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8239: current[currVal] = elementName;
8240: }
8241: }
8242: }
8243: for (var j=0; j<maxh; j++) {
8244: if (current[j] == undefined) {
8245: oldVal = j;
8246: }
8247: }
8248: if (oldVal < changedVal) {
8249: for (var k=oldVal+1; k<=changedVal ; k++) {
8250: var elementName = current[k];
8251: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8252: }
8253: } else {
8254: for (var k=changedVal; k<oldVal; k++) {
8255: var elementName = current[k];
8256: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8257: }
8258: }
8259: return;
8260: }
8261:
1.294 raeburn 8262: $intauthjs
8263:
1.236 raeburn 8264: // ]]>
8265: </script>
8266:
8267: ENDSCRIPT
1.294 raeburn 8268: } else {
8269: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 8270: }
8271: }
8272:
1.49 raeburn 8273: sub coursecategories_javascript {
8274: my ($settings) = @_;
1.57 raeburn 8275: my ($output,$jstext,$cathash);
1.49 raeburn 8276: if (ref($settings) eq 'HASH') {
1.57 raeburn 8277: $cathash = $settings->{'cats'};
8278: }
8279: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8280: my (@cats,@jsarray,%idx);
1.57 raeburn 8281: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8282: if (@jsarray > 0) {
8283: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8284: for (my $i=0; $i<@jsarray; $i++) {
8285: if (ref($jsarray[$i]) eq 'ARRAY') {
8286: my $catstr = join('","',@{$jsarray[$i]});
8287: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8288: }
8289: }
8290: }
8291: } else {
8292: $jstext = ' var categories = Array(1);'."\n".
8293: ' categories[0] = Array("instcode_pos");'."\n";
8294: }
1.237 bisitz 8295: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8296: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 8297: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 8298: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8299: &js_escape(\$instcode_reserved);
8300: &js_escape(\$communities_reserved);
1.272 raeburn 8301: &js_escape(\$placement_reserved);
1.265 damieng 8302: &js_escape(\$choose_again);
1.49 raeburn 8303: $output = <<"ENDSCRIPT";
8304: <script type="text/javascript">
1.109 raeburn 8305: // <![CDATA[
1.49 raeburn 8306: function reorderCats(form,parent,item,idx) {
8307: var changedVal;
8308: $jstext
8309: var newpos = 'addcategory_pos';
8310: if (parent == '') {
8311: var has_instcode = 0;
8312: var maxtop = categories[idx].length;
8313: for (var j=0; j<maxtop; j++) {
8314: if (categories[idx][j] == 'instcode::0') {
8315: has_instcode == 1;
8316: }
8317: }
8318: if (has_instcode == 0) {
8319: categories[idx][maxtop] = 'instcode_pos';
8320: }
8321: } else {
8322: newpos += '_'+parent;
8323: }
8324: var maxh = 1 + categories[idx].length;
8325: var current = new Array;
8326: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8327: if (item == newpos) {
8328: changedVal = newitemVal;
8329: } else {
8330: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8331: current[newitemVal] = newpos;
8332: }
8333: for (var i=0; i<categories[idx].length; i++) {
8334: var elementName = categories[idx][i];
8335: if (elementName != item) {
8336: if (form.elements[elementName]) {
8337: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8338: current[currVal] = elementName;
8339: }
8340: }
8341: }
8342: var oldVal;
8343: for (var j=0; j<maxh; j++) {
8344: if (current[j] == undefined) {
8345: oldVal = j;
8346: }
8347: }
8348: if (oldVal < changedVal) {
8349: for (var k=oldVal+1; k<=changedVal ; k++) {
8350: var elementName = current[k];
8351: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8352: }
8353: } else {
8354: for (var k=changedVal; k<oldVal; k++) {
8355: var elementName = current[k];
8356: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8357: }
8358: }
8359: return;
8360: }
1.120 raeburn 8361:
8362: function categoryCheck(form) {
8363: if (form.elements['addcategory_name'].value == 'instcode') {
8364: alert('$instcode_reserved\\n$choose_again');
8365: return false;
8366: }
8367: if (form.elements['addcategory_name'].value == 'communities') {
8368: alert('$communities_reserved\\n$choose_again');
8369: return false;
8370: }
1.272 raeburn 8371: if (form.elements['addcategory_name'].value == 'placement') {
8372: alert('$placement_reserved\\n$choose_again');
8373: return false;
8374: }
1.120 raeburn 8375: return true;
8376: }
8377:
1.109 raeburn 8378: // ]]>
1.49 raeburn 8379: </script>
8380:
8381: ENDSCRIPT
8382: return $output;
8383: }
8384:
1.48 raeburn 8385: sub initialize_categories {
8386: my ($itemcount) = @_;
1.120 raeburn 8387: my ($datatable,$css_class,$chgstr);
8388: my %default_names = (
8389: instcode => 'Official courses (with institutional codes)',
8390: communities => 'Communities',
1.272 raeburn 8391: placement => 'Placement Tests',
1.120 raeburn 8392: );
8393: my $select0 = ' selected="selected"';
8394: my $select1 = '';
1.272 raeburn 8395: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8396: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8397: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 8398: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 8399: $select1 = $select0;
8400: $select0 = '';
8401: }
8402: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8403: .'<select name="'.$default.'_pos">'
8404: .'<option value="0"'.$select0.'>1</option>'
8405: .'<option value="1"'.$select1.'>2</option>'
8406: .'<option value="2">3</option></select> '
8407: .$default_names{$default}
8408: .'</span></td><td><span class="LC_nobreak">'
8409: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8410: .&mt('Display').'</label> <label>'
8411: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8412: .'</label></span></td></tr>';
1.120 raeburn 8413: $itemcount ++;
8414: }
1.48 raeburn 8415: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8416: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8417: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8418: .'<select name="addcategory_pos"'.$chgstr.'>'
8419: .'<option value="0">1</option>'
8420: .'<option value="1">2</option>'
8421: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 8422: .&mt('Add category').'</td><td>'.&mt('Name:')
8423: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
8424: return $datatable;
8425: }
8426:
8427: sub build_category_rows {
1.49 raeburn 8428: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8429: my ($text,$name,$item,$chgstr);
1.48 raeburn 8430: if (ref($cats) eq 'ARRAY') {
8431: my $maxdepth = scalar(@{$cats});
8432: if (ref($cats->[$depth]) eq 'HASH') {
8433: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8434: my $numchildren = @{$cats->[$depth]{$parent}};
8435: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 8436: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8437: my ($idxnum,$parent_name,$parent_item);
8438: my $higher = $depth - 1;
8439: if ($higher == 0) {
8440: $parent_name = &escape($parent).'::'.$higher;
8441: } else {
8442: if (ref($path) eq 'ARRAY') {
8443: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8444: }
8445: }
8446: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8447: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8448: if ($j < $numchildren) {
1.48 raeburn 8449: $name = $cats->[$depth]{$parent}[$j];
8450: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8451: $idxnum = $idx->{$item};
8452: } else {
8453: $name = $parent_name;
8454: $item = $parent_item;
1.48 raeburn 8455: }
1.49 raeburn 8456: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8457: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8458: for (my $i=0; $i<=$numchildren; $i++) {
8459: my $vpos = $i+1;
8460: my $selstr;
8461: if ($j == $i) {
8462: $selstr = ' selected="selected" ';
8463: }
8464: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8465: }
8466: $text .= '</select> ';
8467: if ($j < $numchildren) {
8468: my $deeper = $depth+1;
8469: $text .= $name.' '
8470: .'<label><input type="checkbox" name="deletecategory" value="'
8471: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8472: if(ref($path) eq 'ARRAY') {
8473: push(@{$path},$name);
1.49 raeburn 8474: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8475: pop(@{$path});
8476: }
8477: } else {
1.59 bisitz 8478: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 8479: if ($j == $numchildren) {
8480: $text .= $name;
8481: } else {
8482: $text .= $item;
8483: }
8484: $text .= '" value="" />';
8485: }
8486: $text .= '</td></tr>';
8487: }
8488: $text .= '</table></td>';
8489: } else {
8490: my $higher = $depth-1;
8491: if ($higher == 0) {
8492: $name = &escape($parent).'::'.$higher;
8493: } else {
8494: if (ref($path) eq 'ARRAY') {
8495: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8496: }
8497: }
8498: my $colspan;
8499: if ($parent ne 'instcode') {
8500: $colspan = $maxdepth - $depth - 1;
8501: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
8502: }
8503: }
8504: }
8505: }
8506: return $text;
8507: }
8508:
1.33 raeburn 8509: sub modifiable_userdata_row {
1.305 raeburn 8510: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8511: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 8512: my ($role,$rolename,$statustype);
8513: $role = $item;
1.224 raeburn 8514: if ($context eq 'cancreate') {
1.305 raeburn 8515: if ($item =~ /^(emailusername)_(.+)$/) {
8516: $role = $1;
8517: $statustype = $2;
1.228 raeburn 8518: if (ref($usertypes) eq 'HASH') {
8519: if ($usertypes->{$statustype}) {
8520: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8521: } else {
8522: $rolename = &mt('Data provided by user');
8523: }
8524: }
1.224 raeburn 8525: }
8526: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8527: if (ref($usertypes) eq 'HASH') {
8528: $rolename = $usertypes->{$role};
8529: } else {
8530: $rolename = $role;
8531: }
1.325 ! raeburn 8532: } elsif ($context eq 'lti') {
! 8533: $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 8534: } else {
1.63 raeburn 8535: if ($role eq 'cr') {
8536: $rolename = &mt('Custom role');
8537: } else {
8538: $rolename = &Apache::lonnet::plaintext($role);
8539: }
1.33 raeburn 8540: }
1.224 raeburn 8541: my (@fields,%fieldtitles);
8542: if (ref($fieldsref) eq 'ARRAY') {
8543: @fields = @{$fieldsref};
8544: } else {
8545: @fields = ('lastname','firstname','middlename','generation',
8546: 'permanentemail','id');
8547: }
8548: if ((ref($titlesref) eq 'HASH')) {
8549: %fieldtitles = %{$titlesref};
8550: } else {
8551: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8552: }
1.33 raeburn 8553: my $output;
1.305 raeburn 8554: my $css_class;
8555: if ($rowcount%2) {
8556: $css_class = 'LC_odd_row';
8557: }
8558: if ($customcss) {
8559: $css_class .= " $customcss";
8560: }
8561: $css_class =~ s/^\s+//;
8562: if ($css_class) {
8563: $css_class = ' class="'.$css_class.'"';
8564: }
8565: if ($rowstyle) {
8566: $css_class .= ' style="'.$rowstyle.'"';
8567: }
8568: if ($rowid) {
8569: $rowid = ' id="'.$rowid.'"';
8570: }
8571: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8572: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8573: '<td class="LC_left_item" colspan="2"><table>';
8574: my $rem;
8575: my %checks;
1.325 ! raeburn 8576: my %current;
1.33 raeburn 8577: if (ref($settings) eq 'HASH') {
1.325 ! raeburn 8578: my $hashref;
! 8579: if ($context eq 'lti') {
! 8580: if (ref($settings) eq 'HASH') {
! 8581: $hashref = $settings->{'instdata'};
! 8582: }
! 8583: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 8584: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 ! raeburn 8585: $hashref = $settings->{'lti_instdata'};
! 8586: }
! 8587: if ($role eq 'emailusername') {
! 8588: if ($statustype) {
! 8589: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
! 8590: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 8591: }
1.325 ! raeburn 8592: }
! 8593: }
! 8594: }
! 8595: if (ref($hashref) eq 'HASH') {
! 8596: foreach my $field (@fields) {
! 8597: if ($hashref->{$field}) {
! 8598: if ($role eq 'emailusername') {
! 8599: $checks{$field} = $hashref->{$field};
! 8600: } else {
! 8601: $checks{$field} = ' checked="checked" ';
1.33 raeburn 8602: }
8603: }
8604: }
8605: }
8606: }
1.305 raeburn 8607:
8608: my $total = scalar(@fields);
8609: for (my $i=0; $i<$total; $i++) {
8610: $rem = $i%($numinrow);
1.33 raeburn 8611: if ($rem == 0) {
8612: if ($i > 0) {
8613: $output .= '</tr>';
8614: }
8615: $output .= '<tr>';
8616: }
8617: my $check = ' ';
1.228 raeburn 8618: unless ($role eq 'emailusername') {
8619: if (exists($checks{$fields[$i]})) {
8620: $check = $checks{$fields[$i]}
1.325 ! raeburn 8621: } elsif ($context ne 'lti') {
1.228 raeburn 8622: if ($role eq 'st') {
8623: if (ref($settings) ne 'HASH') {
8624: $check = ' checked="checked" ';
8625: }
1.33 raeburn 8626: }
8627: }
8628: }
8629: $output .= '<td class="LC_left_item">'.
1.228 raeburn 8630: '<span class="LC_nobreak">';
1.325 ! raeburn 8631: my $prefix = 'canmodify';
1.228 raeburn 8632: if ($role eq 'emailusername') {
8633: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8634: $checks{$fields[$i]} = 'omit';
8635: }
8636: foreach my $option ('required','optional','omit') {
8637: my $checked='';
8638: if ($checks{$fields[$i]} eq $option) {
8639: $checked='checked="checked" ';
8640: }
8641: $output .= '<label>'.
1.325 ! raeburn 8642: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 8643: &mt($option).'</label>'.(' ' x2);
8644: }
8645: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8646: } else {
1.325 ! raeburn 8647: if ($context eq 'lti') {
! 8648: $prefix = 'lti';
! 8649: }
1.228 raeburn 8650: $output .= '<label>'.
1.325 ! raeburn 8651: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 8652: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8653: '</label>';
8654: }
8655: $output .= '</span></td>';
1.33 raeburn 8656: }
1.305 raeburn 8657: $rem = $total%$numinrow;
8658: my $colsleft;
8659: if ($rem) {
8660: $colsleft = $numinrow - $rem;
8661: }
8662: if ($colsleft > 1) {
1.33 raeburn 8663: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8664: ' </td>';
8665: } elsif ($colsleft == 1) {
8666: $output .= '<td class="LC_left_item"> </td>';
8667: }
8668: $output .= '</tr></table></td></tr>';
8669: return $output;
8670: }
1.28 raeburn 8671:
1.93 raeburn 8672: sub insttypes_row {
1.305 raeburn 8673: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8674: $customcss,$rowstyle) = @_;
1.93 raeburn 8675: my %lt = &Apache::lonlocal::texthash (
8676: cansearch => 'Users allowed to search',
8677: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8678: lockablenames => 'User preference to lock name',
1.305 raeburn 8679: selfassign => 'Self-reportable affiliations',
1.315 raeburn 8680: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8681: );
8682: my $showdom;
8683: if ($context eq 'cansearch') {
8684: $showdom = ' ('.$dom.')';
8685: }
1.165 raeburn 8686: my $class = 'LC_left_item';
8687: if ($context eq 'statustocreate') {
8688: $class = 'LC_right_item';
8689: }
1.305 raeburn 8690: my $css_class;
8691: if ($$rowtotal%2) {
8692: $css_class = 'LC_odd_row';
8693: }
8694: if ($customcss) {
8695: $css_class .= ' '.$customcss;
8696: }
8697: $css_class =~ s/^\s+//;
8698: if ($css_class) {
8699: $css_class = ' class="'.$css_class.'"';
8700: }
8701: if ($rowstyle) {
8702: $css_class .= ' style="'.$rowstyle.'"';
8703: }
8704: if ($onclick) {
8705: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 8706: }
8707: my $output = '<tr'.$css_class.'>'.
8708: '<td>'.$lt{$context}.$showdom.
8709: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8710: my $rem;
8711: if (ref($types) eq 'ARRAY') {
8712: for (my $i=0; $i<@{$types}; $i++) {
8713: if (defined($usertypes->{$types->[$i]})) {
8714: my $rem = $i%($numinrow);
8715: if ($rem == 0) {
8716: if ($i > 0) {
8717: $output .= '</tr>';
8718: }
8719: $output .= '<tr>';
1.23 raeburn 8720: }
1.26 raeburn 8721: my $check = ' ';
1.99 raeburn 8722: if (ref($settings) eq 'HASH') {
8723: if (ref($settings->{$context}) eq 'ARRAY') {
8724: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8725: $check = ' checked="checked" ';
8726: }
1.315 raeburn 8727: } elsif (ref($settings->{$context}) eq 'HASH') {
8728: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8729: $check = ' checked="checked" ';
8730: }
1.99 raeburn 8731: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8732: $check = ' checked="checked" ';
8733: }
1.23 raeburn 8734: }
1.26 raeburn 8735: $output .= '<td class="LC_left_item">'.
8736: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8737: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 8738: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 8739: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8740: }
8741: }
1.26 raeburn 8742: $rem = @{$types}%($numinrow);
1.23 raeburn 8743: }
8744: my $colsleft = $numinrow - $rem;
1.315 raeburn 8745: if ($context eq 'overrides') {
8746: if ($colsleft > 1) {
8747: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8748: } else {
8749: $output .= '<td class="LC_left_item">';
8750: }
8751: $output .= ' ';
1.23 raeburn 8752: } else {
1.315 raeburn 8753: if (($rem == 0) && (@{$types} > 0)) {
8754: $output .= '<tr>';
8755: }
8756: if ($colsleft > 1) {
8757: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8758: } else {
8759: $output .= '<td class="LC_left_item">';
8760: }
8761: my $defcheck = ' ';
8762: if (ref($settings) eq 'HASH') {
8763: if (ref($settings->{$context}) eq 'ARRAY') {
8764: if (grep(/^default$/,@{$settings->{$context}})) {
8765: $defcheck = ' checked="checked" ';
8766: }
8767: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8768: $defcheck = ' checked="checked" ';
8769: }
1.26 raeburn 8770: }
1.315 raeburn 8771: $output .= '<span class="LC_nobreak"><label>'.
8772: '<input type="checkbox" name="'.$context.'" '.
8773: 'value="default"'.$defcheck.$onclick.' />'.
8774: $othertitle.'</label></span>';
1.23 raeburn 8775: }
1.315 raeburn 8776: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8777: return $output;
1.23 raeburn 8778: }
8779:
8780: sub sorted_searchtitles {
8781: my %searchtitles = &Apache::lonlocal::texthash(
8782: 'uname' => 'username',
8783: 'lastname' => 'last name',
8784: 'lastfirst' => 'last name, first name',
8785: );
8786: my @titleorder = ('uname','lastname','lastfirst');
8787: return (\%searchtitles,\@titleorder);
8788: }
8789:
1.25 raeburn 8790: sub sorted_searchtypes {
8791: my %srchtypes_desc = (
8792: exact => 'is exact match',
8793: contains => 'contains ..',
8794: begins => 'begins with ..',
8795: );
8796: my @srchtypeorder = ('exact','begins','contains');
8797: return (\%srchtypes_desc,\@srchtypeorder);
8798: }
8799:
1.3 raeburn 8800: sub usertype_update_row {
8801: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8802: my $datatable;
8803: my $numinrow = 4;
8804: foreach my $type (@{$types}) {
8805: if (defined($usertypes->{$type})) {
8806: $$rownums ++;
8807: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8808: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8809: '</td><td class="LC_left_item"><table>';
8810: for (my $i=0; $i<@{$fields}; $i++) {
8811: my $rem = $i%($numinrow);
8812: if ($rem == 0) {
8813: if ($i > 0) {
8814: $datatable .= '</tr>';
8815: }
8816: $datatable .= '<tr>';
8817: }
8818: my $check = ' ';
1.39 raeburn 8819: if (ref($settings) eq 'HASH') {
8820: if (ref($settings->{'fields'}) eq 'HASH') {
8821: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8822: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8823: $check = ' checked="checked" ';
8824: }
1.3 raeburn 8825: }
8826: }
8827: }
8828:
8829: if ($i == @{$fields}-1) {
8830: my $colsleft = $numinrow - $rem;
8831: if ($colsleft > 1) {
8832: $datatable .= '<td colspan="'.$colsleft.'">';
8833: } else {
8834: $datatable .= '<td>';
8835: }
8836: } else {
8837: $datatable .= '<td>';
8838: }
1.8 raeburn 8839: $datatable .= '<span class="LC_nobreak"><label>'.
8840: '<input type="checkbox" name="updateable_'.$type.
8841: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8842: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8843: }
8844: $datatable .= '</tr></table></td></tr>';
8845: }
8846: }
8847: return $datatable;
1.1 raeburn 8848: }
8849:
8850: sub modify_login {
1.205 raeburn 8851: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 8852: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8853: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8854: %title = ( coursecatalog => 'Display course catalog',
8855: adminmail => 'Display administrator E-mail address',
1.188 raeburn 8856: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 8857: newuser => 'Link for visitors to create a user account',
8858: loginheader => 'Log-in box header');
8859: @offon = ('off','on');
1.112 raeburn 8860: if (ref($domconfig{login}) eq 'HASH') {
8861: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8862: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8863: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8864: }
8865: }
8866: }
1.9 raeburn 8867: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8868: \%domconfig,\%loginhash);
1.188 raeburn 8869: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8870: foreach my $item (@toggles) {
8871: $loginhash{login}{$item} = $env{'form.'.$item};
8872: }
1.41 raeburn 8873: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 8874: if (ref($colchanges{'login'}) eq 'HASH') {
8875: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8876: \%loginhash);
8877: }
1.110 raeburn 8878:
1.149 raeburn 8879: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 8880: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 8881: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 8882: if (keys(%servers) > 1) {
8883: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 8884: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8885: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8886: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8887: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8888: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8889: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8890: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8891: $changes{'loginvia'}{$lonhost} = 1;
8892: } else {
8893: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8894: $changes{'loginvia'}{$lonhost} = 1;
8895: }
8896: } else {
8897: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8898: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8899: $changes{'loginvia'}{$lonhost} = 1;
8900: }
8901: }
8902: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8903: foreach my $item (@loginvia_attribs) {
8904: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
8905: }
8906: } else {
8907: foreach my $item (@loginvia_attribs) {
8908: my $new = $env{'form.'.$lonhost.'_'.$item};
8909: if (($item eq 'serverpath') && ($new eq 'custom')) {
8910: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
8911: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8912: $new = '/';
8913: }
8914: }
8915: if (($item eq 'custompath') &&
8916: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8917: $new = '';
8918: }
8919: if ($new ne $curr_loginvia{$lonhost}{$item}) {
8920: $changes{'loginvia'}{$lonhost} = 1;
8921: }
8922: if ($item eq 'exempt') {
1.256 raeburn 8923: $new = &check_exempt_addresses($new);
1.128 raeburn 8924: }
8925: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8926: }
8927: }
1.112 raeburn 8928: } else {
1.128 raeburn 8929: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8930: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 8931: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 8932: foreach my $item (@loginvia_attribs) {
8933: my $new = $env{'form.'.$lonhost.'_'.$item};
8934: if (($item eq 'serverpath') && ($new eq 'custom')) {
8935: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8936: $new = '/';
8937: }
8938: }
8939: if (($item eq 'custompath') &&
8940: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8941: $new = '';
8942: }
8943: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8944: }
1.110 raeburn 8945: }
8946: }
8947: }
8948: }
1.119 raeburn 8949:
1.168 raeburn 8950: my $servadm = $r->dir_config('lonAdmEMail');
8951: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
8952: if (ref($domconfig{'login'}) eq 'HASH') {
8953: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
8954: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
8955: if ($lang eq 'nolang') {
8956: push(@currlangs,$lang);
8957: } elsif (defined($langchoices{$lang})) {
8958: push(@currlangs,$lang);
8959: } else {
8960: next;
8961: }
8962: }
8963: }
8964: }
8965: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
8966: if (@currlangs > 0) {
8967: foreach my $lang (@currlangs) {
8968: if (grep(/^\Q$lang\E$/,@delurls)) {
8969: $changes{'helpurl'}{$lang} = 1;
8970: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
8971: $changes{'helpurl'}{$lang} = 1;
8972: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
8973: push(@newlangs,$lang);
8974: } else {
8975: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8976: }
8977: }
8978: }
8979: unless (grep(/^nolang$/,@currlangs)) {
8980: if ($env{'form.loginhelpurl_nolang.filename'}) {
8981: $changes{'helpurl'}{'nolang'} = 1;
8982: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
8983: push(@newlangs,'nolang');
8984: }
8985: }
8986: if ($env{'form.loginhelpurl_add_lang'}) {
8987: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
8988: ($env{'form.loginhelpurl_add_file.filename'})) {
8989: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
8990: $addedfile = $env{'form.loginhelpurl_add_lang'};
8991: }
8992: }
8993: if ((@newlangs > 0) || ($addedfile)) {
8994: my $error;
8995: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8996: if ($configuserok eq 'ok') {
8997: if ($switchserver) {
8998: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
8999: } elsif ($author_ok eq 'ok') {
9000: my @allnew = @newlangs;
9001: if ($addedfile ne '') {
9002: push(@allnew,$addedfile);
9003: }
9004: foreach my $lang (@allnew) {
9005: my $formelem = 'loginhelpurl_'.$lang;
9006: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9007: $formelem = 'loginhelpurl_add_file';
9008: }
9009: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9010: "help/$lang",'','',$newfile{$lang});
9011: if ($result eq 'ok') {
9012: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9013: $changes{'helpurl'}{$lang} = 1;
9014: } else {
9015: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9016: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 9017: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 9018: (!grep(/^\Q$lang\E$/,@delurls))) {
9019: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9020: }
9021: }
9022: }
9023: } else {
9024: $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);
9025: }
9026: } else {
9027: $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);
9028: }
9029: if ($error) {
9030: &Apache::lonnet::logthis($error);
9031: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9032: }
9033: }
1.256 raeburn 9034:
9035: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9036: if (ref($domconfig{'login'}) eq 'HASH') {
9037: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9038: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9039: if ($domservers{$lonhost}) {
9040: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9041: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 9042: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 9043: }
9044: }
9045: }
9046: }
9047: }
9048: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9049: foreach my $lonhost (sort(keys(%domservers))) {
9050: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9051: $changes{'headtag'}{$lonhost} = 1;
9052: } else {
9053: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9054: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9055: }
9056: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9057: push(@newhosts,$lonhost);
9058: } elsif ($currheadtagurls{$lonhost}) {
9059: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9060: if ($currexempt{$lonhost}) {
1.289 raeburn 9061: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 9062: $changes{'headtag'}{$lonhost} = 1;
9063: }
9064: } elsif ($possexempt{$lonhost}) {
9065: $changes{'headtag'}{$lonhost} = 1;
9066: }
9067: if ($possexempt{$lonhost}) {
9068: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9069: }
9070: }
9071: }
9072: }
9073: if (@newhosts) {
9074: my $error;
9075: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9076: if ($configuserok eq 'ok') {
9077: if ($switchserver) {
9078: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9079: } elsif ($author_ok eq 'ok') {
9080: foreach my $lonhost (@newhosts) {
9081: my $formelem = 'loginheadtag_'.$lonhost;
9082: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9083: "login/headtag/$lonhost",'','',
9084: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9085: if ($result eq 'ok') {
9086: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9087: $changes{'headtag'}{$lonhost} = 1;
9088: if ($possexempt{$lonhost}) {
9089: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9090: }
9091: } else {
9092: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9093: $newheadtagurls{$lonhost},$result);
9094: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9095: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9096: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9097: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9098: }
9099: }
9100: }
9101: } else {
9102: $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);
9103: }
9104: } else {
9105: $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);
9106: }
9107: if ($error) {
9108: &Apache::lonnet::logthis($error);
9109: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9110: }
9111: }
1.169 raeburn 9112: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 9113:
9114: my $defaulthelpfile = '/adm/loginproblems.html';
9115: my $defaulttext = &mt('Default in use');
9116:
1.1 raeburn 9117: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9118: $dom);
9119: if ($putresult eq 'ok') {
1.188 raeburn 9120: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9121: my %defaultchecked = (
9122: 'coursecatalog' => 'on',
1.188 raeburn 9123: 'helpdesk' => 'on',
1.42 raeburn 9124: 'adminmail' => 'off',
1.43 raeburn 9125: 'newuser' => 'off',
1.42 raeburn 9126: );
1.55 raeburn 9127: if (ref($domconfig{'login'}) eq 'HASH') {
9128: foreach my $item (@toggles) {
9129: if ($defaultchecked{$item} eq 'on') {
9130: if (($domconfig{'login'}{$item} eq '0') &&
9131: ($env{'form.'.$item} eq '1')) {
9132: $changes{$item} = 1;
9133: } elsif (($domconfig{'login'}{$item} eq '' ||
9134: $domconfig{'login'}{$item} eq '1') &&
9135: ($env{'form.'.$item} eq '0')) {
9136: $changes{$item} = 1;
9137: }
9138: } elsif ($defaultchecked{$item} eq 'off') {
9139: if (($domconfig{'login'}{$item} eq '1') &&
9140: ($env{'form.'.$item} eq '0')) {
9141: $changes{$item} = 1;
9142: } elsif (($domconfig{'login'}{$item} eq '' ||
9143: $domconfig{'login'}{$item} eq '0') &&
9144: ($env{'form.'.$item} eq '1')) {
9145: $changes{$item} = 1;
9146: }
1.42 raeburn 9147: }
9148: }
1.41 raeburn 9149: }
1.6 raeburn 9150: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9151: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9152: if (ref($lastactref) eq 'HASH') {
9153: $lastactref->{'domainconfig'} = 1;
9154: }
1.1 raeburn 9155: $resulttext = &mt('Changes made:').'<ul>';
9156: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9157: if ($item eq 'loginvia') {
1.112 raeburn 9158: if (ref($changes{$item}) eq 'HASH') {
9159: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9160: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9161: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9162: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9163: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9164: $protocol = 'http' if ($protocol ne 'https');
9165: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9166:
9167: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9168: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9169: } else {
9170: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9171: }
9172: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9173: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9174: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9175: }
9176: $resulttext .= '</li>';
9177: } else {
9178: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9179: }
1.112 raeburn 9180: } else {
1.128 raeburn 9181: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9182: }
9183: }
1.128 raeburn 9184: $resulttext .= '</ul></li>';
1.112 raeburn 9185: }
1.168 raeburn 9186: } elsif ($item eq 'helpurl') {
9187: if (ref($changes{$item}) eq 'HASH') {
9188: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9189: if (grep(/^\Q$lang\E$/,@delurls)) {
9190: my ($chg,$link);
9191: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9192: if ($lang eq 'nolang') {
9193: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9194: } else {
9195: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9196: }
9197: $resulttext .= '<li>'.$chg.'</li>';
9198: } else {
9199: my $chg;
9200: if ($lang eq 'nolang') {
9201: $chg = &mt('custom log-in help file for no preferred language');
9202: } else {
9203: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9204: }
9205: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9206: $loginhash{'login'}{'helpurl'}{$lang}.
9207: '?inhibitmenu=yes',$chg,600,500).
9208: '</li>';
9209: }
9210: }
9211: }
1.256 raeburn 9212: } elsif ($item eq 'headtag') {
9213: if (ref($changes{$item}) eq 'HASH') {
9214: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9215: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9216: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9217: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9218: $resulttext .= '<li><a href="'.
9219: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9220: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9221: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9222: if ($possexempt{$lonhost}) {
9223: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9224: } else {
9225: $resulttext .= &mt('included for any client IP');
9226: }
9227: $resulttext .= '</li>';
9228: }
9229: }
9230: }
1.169 raeburn 9231: } elsif ($item eq 'captcha') {
9232: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 9233: my $chgtxt;
1.169 raeburn 9234: if ($loginhash{'login'}{$item} eq 'notused') {
9235: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9236: } else {
9237: my %captchas = &captcha_phrases();
9238: if ($captchas{$loginhash{'login'}{$item}}) {
9239: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9240: } else {
9241: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9242: }
9243: }
9244: $resulttext .= '<li>'.$chgtxt.'</li>';
9245: }
9246: } elsif ($item eq 'recaptchakeys') {
9247: if (ref($loginhash{'login'}) eq 'HASH') {
9248: my ($privkey,$pubkey);
9249: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9250: $pubkey = $loginhash{'login'}{$item}{'public'};
9251: $privkey = $loginhash{'login'}{$item}{'private'};
9252: }
9253: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9254: if (!$pubkey) {
9255: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9256: } else {
9257: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9258: }
9259: if (!$privkey) {
9260: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9261: } else {
1.251 raeburn 9262: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 9263: }
9264: $chgtxt .= '</ul>';
9265: $resulttext .= '<li>'.$chgtxt.'</li>';
9266: }
1.269 raeburn 9267: } elsif ($item eq 'recaptchaversion') {
9268: if (ref($loginhash{'login'}) eq 'HASH') {
9269: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 9270: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 9271: '</li>';
9272: }
9273: }
1.41 raeburn 9274: } else {
9275: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9276: }
1.1 raeburn 9277: }
1.6 raeburn 9278: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9279: } else {
9280: $resulttext = &mt('No changes made to log-in page settings');
9281: }
9282: } else {
1.11 albertel 9283: $resulttext = '<span class="LC_error">'.
9284: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9285: }
1.6 raeburn 9286: if ($errors) {
1.9 raeburn 9287: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9288: $errors.'</ul>';
9289: }
9290: return $resulttext;
9291: }
9292:
1.256 raeburn 9293: sub check_exempt_addresses {
9294: my ($iplist) = @_;
9295: $iplist =~ s/^\s+//;
9296: $iplist =~ s/\s+$//;
9297: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9298: my (@okips,$new);
9299: foreach my $ip (@poss_ips) {
9300: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9301: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9302: push(@okips,$ip);
9303: }
9304: }
9305: }
9306: if (@okips > 0) {
9307: $new = join(',',@okips);
9308: } else {
9309: $new = '';
9310: }
9311: return $new;
9312: }
9313:
1.6 raeburn 9314: sub color_font_choices {
9315: my %choices =
9316: &Apache::lonlocal::texthash (
9317: img => "Header",
9318: bgs => "Background colors",
9319: links => "Link colors",
1.55 raeburn 9320: images => "Images",
1.6 raeburn 9321: font => "Font color",
1.201 raeburn 9322: fontmenu => "Font menu",
1.76 raeburn 9323: pgbg => "Page",
1.6 raeburn 9324: tabbg => "Header",
9325: sidebg => "Border",
9326: link => "Link",
9327: alink => "Active link",
9328: vlink => "Visited link",
9329: );
9330: return %choices;
9331: }
9332:
9333: sub modify_rolecolors {
1.205 raeburn 9334: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9335: my ($resulttext,%rolehash);
9336: $rolehash{'rolecolors'} = {};
1.55 raeburn 9337: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9338: if ($domconfig{'rolecolors'} eq '') {
9339: $domconfig{'rolecolors'} = {};
9340: }
9341: }
1.9 raeburn 9342: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9343: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9344: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9345: $dom);
9346: if ($putresult eq 'ok') {
9347: if (keys(%changes) > 0) {
1.41 raeburn 9348: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9349: if (ref($lastactref) eq 'HASH') {
9350: $lastactref->{'domainconfig'} = 1;
9351: }
1.6 raeburn 9352: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9353: $rolehash{'rolecolors'});
9354: } else {
9355: $resulttext = &mt('No changes made to default color schemes');
9356: }
9357: } else {
1.11 albertel 9358: $resulttext = '<span class="LC_error">'.
9359: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9360: }
9361: if ($errors) {
9362: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9363: $errors.'</ul>';
9364: }
9365: return $resulttext;
9366: }
9367:
9368: sub modify_colors {
1.9 raeburn 9369: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9370: my (%changes,%choices);
1.51 raeburn 9371: my @bgs;
1.6 raeburn 9372: my @links = ('link','alink','vlink');
1.41 raeburn 9373: my @logintext;
1.6 raeburn 9374: my @images;
9375: my $servadm = $r->dir_config('lonAdmEMail');
9376: my $errors;
1.200 raeburn 9377: my %defaults;
1.6 raeburn 9378: foreach my $role (@{$roles}) {
9379: if ($role eq 'login') {
1.12 raeburn 9380: %choices = &login_choices();
1.41 raeburn 9381: @logintext = ('textcol','bgcol');
1.12 raeburn 9382: } else {
9383: %choices = &color_font_choices();
9384: }
9385: if ($role eq 'login') {
1.41 raeburn 9386: @images = ('img','logo','domlogo','login');
1.51 raeburn 9387: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9388: } else {
9389: @images = ('img');
1.200 raeburn 9390: @bgs = ('pgbg','tabbg','sidebg');
9391: }
9392: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9393: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9394: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9395: }
9396: if ($role eq 'login') {
9397: foreach my $item (@logintext) {
1.234 raeburn 9398: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9399: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9400: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9401: }
9402: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 9403: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9404: }
9405: }
9406: } else {
1.234 raeburn 9407: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9408: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9409: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9410: }
9411: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 9412: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9413: }
1.6 raeburn 9414: }
1.200 raeburn 9415: foreach my $item (@bgs) {
1.234 raeburn 9416: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9417: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9418: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9419: }
9420: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 9421: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9422: }
9423: }
9424: foreach my $item (@links) {
1.234 raeburn 9425: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9426: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9427: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9428: }
9429: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 9430: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9431: }
1.6 raeburn 9432: }
1.46 raeburn 9433: my ($configuserok,$author_ok,$switchserver) =
9434: &config_check($dom,$confname,$servadm);
1.9 raeburn 9435: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 9436: if (ref($domconfig->{$role}) ne 'HASH') {
9437: $domconfig->{$role} = {};
9438: }
1.8 raeburn 9439: foreach my $img (@images) {
1.70 raeburn 9440: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9441: if (defined($env{'form.login_showlogo_'.$img})) {
9442: $confhash->{$role}{'showlogo'}{$img} = 1;
9443: } else {
9444: $confhash->{$role}{'showlogo'}{$img} = 0;
9445: }
9446: }
1.18 albertel 9447: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9448: && !defined($domconfig->{$role}{$img})
9449: && !$env{'form.'.$role.'_del_'.$img}
9450: && $env{'form.'.$role.'_import_'.$img}) {
9451: # import the old configured image from the .tab setting
9452: # if they haven't provided a new one
9453: $domconfig->{$role}{$img} =
9454: $env{'form.'.$role.'_import_'.$img};
9455: }
1.6 raeburn 9456: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9457: my $error;
1.6 raeburn 9458: if ($configuserok eq 'ok') {
1.9 raeburn 9459: if ($switchserver) {
1.12 raeburn 9460: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9461: } else {
9462: if ($author_ok eq 'ok') {
9463: my ($result,$logourl) =
9464: &publishlogo($r,'upload',$role.'_'.$img,
9465: $dom,$confname,$img,$width,$height);
9466: if ($result eq 'ok') {
9467: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9468: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9469: } else {
1.12 raeburn 9470: $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 9471: }
9472: } else {
1.46 raeburn 9473: $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 9474: }
9475: }
9476: } else {
1.46 raeburn 9477: $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 9478: }
9479: if ($error) {
1.8 raeburn 9480: &Apache::lonnet::logthis($error);
1.11 albertel 9481: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9482: }
9483: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9484: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9485: my $error;
9486: if ($configuserok eq 'ok') {
9487: # is confname an author?
9488: if ($switchserver eq '') {
9489: if ($author_ok eq 'ok') {
9490: my ($result,$logourl) =
9491: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9492: $dom,$confname,$img,$width,$height);
9493: if ($result eq 'ok') {
9494: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9495: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9496: }
9497: }
9498: }
9499: }
1.6 raeburn 9500: }
9501: }
9502: }
9503: if (ref($domconfig) eq 'HASH') {
9504: if (ref($domconfig->{$role}) eq 'HASH') {
9505: foreach my $img (@images) {
9506: if ($domconfig->{$role}{$img} ne '') {
9507: if ($env{'form.'.$role.'_del_'.$img}) {
9508: $confhash->{$role}{$img} = '';
1.12 raeburn 9509: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9510: } else {
1.9 raeburn 9511: if ($confhash->{$role}{$img} eq '') {
9512: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
9513: }
1.6 raeburn 9514: }
9515: } else {
9516: if ($env{'form.'.$role.'_del_'.$img}) {
9517: $confhash->{$role}{$img} = '';
1.12 raeburn 9518: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9519: }
9520: }
1.70 raeburn 9521: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
9522: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
9523: if ($confhash->{$role}{'showlogo'}{$img} ne
9524: $domconfig->{$role}{'showlogo'}{$img}) {
9525: $changes{$role}{'showlogo'}{$img} = 1;
9526: }
9527: } else {
9528: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9529: $changes{$role}{'showlogo'}{$img} = 1;
9530: }
9531: }
9532: }
9533: }
1.6 raeburn 9534: if ($domconfig->{$role}{'font'} ne '') {
9535: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
9536: $changes{$role}{'font'} = 1;
9537: }
9538: } else {
9539: if ($confhash->{$role}{'font'}) {
9540: $changes{$role}{'font'} = 1;
9541: }
9542: }
1.107 raeburn 9543: if ($role ne 'login') {
9544: if ($domconfig->{$role}{'fontmenu'} ne '') {
9545: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
9546: $changes{$role}{'fontmenu'} = 1;
9547: }
9548: } else {
9549: if ($confhash->{$role}{'fontmenu'}) {
9550: $changes{$role}{'fontmenu'} = 1;
9551: }
1.97 tempelho 9552: }
9553: }
1.6 raeburn 9554: foreach my $item (@bgs) {
9555: if ($domconfig->{$role}{$item} ne '') {
9556: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9557: $changes{$role}{'bgs'}{$item} = 1;
9558: }
9559: } else {
9560: if ($confhash->{$role}{$item}) {
9561: $changes{$role}{'bgs'}{$item} = 1;
9562: }
9563: }
9564: }
9565: foreach my $item (@links) {
9566: if ($domconfig->{$role}{$item} ne '') {
9567: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9568: $changes{$role}{'links'}{$item} = 1;
9569: }
9570: } else {
9571: if ($confhash->{$role}{$item}) {
9572: $changes{$role}{'links'}{$item} = 1;
9573: }
9574: }
9575: }
1.41 raeburn 9576: foreach my $item (@logintext) {
9577: if ($domconfig->{$role}{$item} ne '') {
9578: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9579: $changes{$role}{'logintext'}{$item} = 1;
9580: }
9581: } else {
9582: if ($confhash->{$role}{$item}) {
9583: $changes{$role}{'logintext'}{$item} = 1;
9584: }
9585: }
9586: }
1.6 raeburn 9587: } else {
9588: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9589: \@logintext,$confhash,\%changes);
1.6 raeburn 9590: }
9591: } else {
9592: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9593: \@logintext,$confhash,\%changes);
1.6 raeburn 9594: }
9595: }
9596: return ($errors,%changes);
9597: }
9598:
1.46 raeburn 9599: sub config_check {
9600: my ($dom,$confname,$servadm) = @_;
9601: my ($configuserok,$author_ok,$switchserver,%currroles);
9602: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
9603: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
9604: $confname,$servadm);
9605: if ($configuserok eq 'ok') {
9606: $switchserver = &check_switchserver($dom,$confname);
9607: if ($switchserver eq '') {
9608: $author_ok = &check_authorstatus($dom,$confname,%currroles);
9609: }
9610: }
9611: return ($configuserok,$author_ok,$switchserver);
9612: }
9613:
1.6 raeburn 9614: sub default_change_checker {
1.41 raeburn 9615: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 9616: foreach my $item (@{$links}) {
9617: if ($confhash->{$role}{$item}) {
9618: $changes->{$role}{'links'}{$item} = 1;
9619: }
9620: }
9621: foreach my $item (@{$bgs}) {
9622: if ($confhash->{$role}{$item}) {
9623: $changes->{$role}{'bgs'}{$item} = 1;
9624: }
9625: }
1.41 raeburn 9626: foreach my $item (@{$logintext}) {
9627: if ($confhash->{$role}{$item}) {
9628: $changes->{$role}{'logintext'}{$item} = 1;
9629: }
9630: }
1.6 raeburn 9631: foreach my $img (@{$images}) {
9632: if ($env{'form.'.$role.'_del_'.$img}) {
9633: $confhash->{$role}{$img} = '';
1.12 raeburn 9634: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 9635: }
1.70 raeburn 9636: if ($role eq 'login') {
9637: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9638: $changes->{$role}{'showlogo'}{$img} = 1;
9639: }
9640: }
1.6 raeburn 9641: }
9642: if ($confhash->{$role}{'font'}) {
9643: $changes->{$role}{'font'} = 1;
9644: }
1.48 raeburn 9645: }
1.6 raeburn 9646:
9647: sub display_colorchgs {
9648: my ($dom,$changes,$roles,$confhash) = @_;
9649: my (%choices,$resulttext);
9650: if (!grep(/^login$/,@{$roles})) {
9651: $resulttext = &mt('Changes made:').'<br />';
9652: }
9653: foreach my $role (@{$roles}) {
9654: if ($role eq 'login') {
9655: %choices = &login_choices();
9656: } else {
9657: %choices = &color_font_choices();
9658: }
9659: if (ref($changes->{$role}) eq 'HASH') {
9660: if ($role ne 'login') {
9661: $resulttext .= '<h4>'.&mt($role).'</h4>';
9662: }
9663: foreach my $key (sort(keys(%{$changes->{$role}}))) {
9664: if ($role ne 'login') {
9665: $resulttext .= '<ul>';
9666: }
9667: if (ref($changes->{$role}{$key}) eq 'HASH') {
9668: if ($role ne 'login') {
9669: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9670: }
9671: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 9672: if (($role eq 'login') && ($key eq 'showlogo')) {
9673: if ($confhash->{$role}{$key}{$item}) {
9674: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9675: } else {
9676: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9677: }
9678: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 9679: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9680: } else {
1.12 raeburn 9681: my $newitem = $confhash->{$role}{$item};
9682: if ($key eq 'images') {
1.306 raeburn 9683: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 9684: }
9685: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 9686: }
9687: }
9688: if ($role ne 'login') {
9689: $resulttext .= '</ul></li>';
9690: }
9691: } else {
9692: if ($confhash->{$role}{$key} eq '') {
9693: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9694: } else {
9695: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9696: }
9697: }
9698: if ($role ne 'login') {
9699: $resulttext .= '</ul>';
9700: }
9701: }
9702: }
9703: }
1.3 raeburn 9704: return $resulttext;
1.1 raeburn 9705: }
9706:
1.9 raeburn 9707: sub thumb_dimensions {
9708: return ('200','50');
9709: }
9710:
1.16 raeburn 9711: sub check_dimensions {
9712: my ($inputfile) = @_;
9713: my ($fullwidth,$fullheight);
9714: if ($inputfile =~ m|^[/\w.\-]+$|) {
9715: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9716: my $imageinfo = <PIPE>;
9717: if (!close(PIPE)) {
9718: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9719: }
9720: chomp($imageinfo);
9721: my ($fullsize) =
1.21 raeburn 9722: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 9723: if ($fullsize) {
9724: ($fullwidth,$fullheight) = split(/x/,$fullsize);
9725: }
9726: }
9727: }
9728: return ($fullwidth,$fullheight);
9729: }
9730:
1.9 raeburn 9731: sub check_configuser {
9732: my ($uhome,$dom,$confname,$servadm) = @_;
9733: my ($configuserok,%currroles);
9734: if ($uhome eq 'no_host') {
9735: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
9736: my $configpass = &LONCAPA::Enrollment::create_password();
9737: $configuserok =
9738: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
9739: $configpass,'','','','','',undef,$servadm);
9740: } else {
9741: $configuserok = 'ok';
9742: %currroles =
9743: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9744: }
9745: return ($configuserok,%currroles);
9746: }
9747:
9748: sub check_authorstatus {
9749: my ($dom,$confname,%currroles) = @_;
9750: my $author_ok;
1.40 raeburn 9751: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 9752: my $start = time;
9753: my $end = 0;
9754: $author_ok =
9755: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 9756: 'au',$end,$start,'','','domconfig');
1.9 raeburn 9757: } else {
9758: $author_ok = 'ok';
9759: }
9760: return $author_ok;
9761: }
9762:
9763: sub publishlogo {
1.46 raeburn 9764: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 9765: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 9766: if ($action eq 'upload') {
9767: $fname=$env{'form.'.$formname.'.filename'};
9768: chop($env{'form.'.$formname});
9769: } else {
9770: ($fname) = ($formname =~ /([^\/]+)$/);
9771: }
1.46 raeburn 9772: if ($savefileas ne '') {
9773: $fname = $savefileas;
9774: }
1.9 raeburn 9775: $fname=&Apache::lonnet::clean_filename($fname);
9776: # See if there is anything left
9777: unless ($fname) { return ('error: no uploaded file'); }
9778: $fname="$subdir/$fname";
1.210 raeburn 9779: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 9780: my $filepath="$docroot/priv";
9781: my $relpath = "$dom/$confname";
1.9 raeburn 9782: my ($fnamepath,$file,$fetchthumb);
9783: $file=$fname;
9784: if ($fname=~m|/|) {
9785: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9786: }
1.164 raeburn 9787: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9788: my $count;
1.164 raeburn 9789: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9790: $filepath.="/$parts[$count]";
9791: if ((-e $filepath)!=1) {
9792: mkdir($filepath,02770);
9793: }
9794: }
9795: # Check for bad extension and disallow upload
9796: if ($file=~/\.(\w+)$/ &&
9797: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9798: $output =
1.207 bisitz 9799: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9800: } elsif ($file=~/\.(\w+)$/ &&
9801: !defined(&Apache::loncommon::fileembstyle($1))) {
9802: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9803: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 9804: $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 9805: } elsif (-d "$filepath/$file") {
1.195 bisitz 9806: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9807: } else {
9808: my $source = $filepath.'/'.$file;
9809: my $logfile;
1.316 raeburn 9810: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 9811: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9812: }
9813: print $logfile
9814: "\n================= Publish ".localtime()." ================\n".
9815: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9816: # Save the file
1.316 raeburn 9817: if (!open(FH,">",$source)) {
1.9 raeburn 9818: &Apache::lonnet::logthis('Failed to create '.$source);
9819: return (&mt('Failed to create file'));
9820: }
9821: if ($action eq 'upload') {
9822: if (!print FH ($env{'form.'.$formname})) {
9823: &Apache::lonnet::logthis('Failed to write to '.$source);
9824: return (&mt('Failed to write file'));
9825: }
9826: } else {
9827: my $original = &Apache::lonnet::filelocation('',$formname);
9828: if(!copy($original,$source)) {
9829: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9830: return (&mt('Failed to write file'));
9831: }
9832: }
9833: close(FH);
9834: chmod(0660, $source); # Permissions to rw-rw---.
9835:
9836: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9837: my $copyfile=$targetdir.'/'.$file;
9838:
9839: my @parts=split(/\//,$targetdir);
9840: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9841: for (my $count=5;$count<=$#parts;$count++) {
9842: $path.="/$parts[$count]";
9843: if (!-e $path) {
9844: print $logfile "\nCreating directory ".$path;
9845: mkdir($path,02770);
9846: }
9847: }
9848: my $versionresult;
9849: if (-e $copyfile) {
9850: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9851: } else {
9852: $versionresult = 'ok';
9853: }
9854: if ($versionresult eq 'ok') {
9855: if (copy($source,$copyfile)) {
9856: print $logfile "\nCopied original source to ".$copyfile."\n";
9857: $output = 'ok';
9858: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9859: push(@{$modified_urls},[$copyfile,$source]);
9860: my $metaoutput =
9861: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9862: unless ($registered_cleanup) {
9863: my $handlers = $r->get_handlers('PerlCleanupHandler');
9864: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9865: $registered_cleanup=1;
9866: }
1.9 raeburn 9867: } else {
9868: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9869: $output = &mt('Failed to copy file to RES space').", $!";
9870: }
9871: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9872: my $inputfile = $filepath.'/'.$file;
9873: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 9874: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9875: if ($fullwidth ne '' && $fullheight ne '') {
9876: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9877: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 9878: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
9879: system({$args[0]} @args);
1.16 raeburn 9880: chmod(0660, $filepath.'/tn-'.$file);
9881: if (-e $outfile) {
9882: my $copyfile=$targetdir.'/tn-'.$file;
9883: if (copy($outfile,$copyfile)) {
9884: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 9885: my $thumb_metaoutput =
9886: &write_metadata($dom,$confname,$formname,
9887: $targetdir,'tn-'.$file,$logfile);
9888: push(@{$modified_urls},[$copyfile,$outfile]);
9889: unless ($registered_cleanup) {
9890: my $handlers = $r->get_handlers('PerlCleanupHandler');
9891: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9892: $registered_cleanup=1;
9893: }
1.267 raeburn 9894: $madethumb = 1;
1.16 raeburn 9895: } else {
9896: print $logfile "\nUnable to write ".$copyfile.
9897: ':'.$!."\n";
9898: }
9899: }
1.9 raeburn 9900: }
9901: }
9902: }
9903: } else {
9904: $output = $versionresult;
9905: }
9906: }
1.267 raeburn 9907: return ($output,$logourl,$madethumb);
1.9 raeburn 9908: }
9909:
9910: sub logo_versioning {
9911: my ($targetdir,$file,$logfile) = @_;
9912: my $target = $targetdir.'/'.$file;
9913: my ($maxversion,$fn,$extn,$output);
9914: $maxversion = 0;
9915: if ($file =~ /^(.+)\.(\w+)$/) {
9916: $fn=$1;
9917: $extn=$2;
9918: }
9919: opendir(DIR,$targetdir);
9920: while (my $filename=readdir(DIR)) {
9921: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
9922: $maxversion=($1>$maxversion)?$1:$maxversion;
9923: }
9924: }
9925: $maxversion++;
9926: print $logfile "\nCreating old version ".$maxversion."\n";
9927: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
9928: if (copy($target,$copyfile)) {
9929: print $logfile "Copied old target to ".$copyfile."\n";
9930: $copyfile=$copyfile.'.meta';
9931: if (copy($target.'.meta',$copyfile)) {
9932: print $logfile "Copied old target metadata to ".$copyfile."\n";
9933: $output = 'ok';
9934: } else {
9935: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
9936: $output = &mt('Failed to copy old meta').", $!, ";
9937: }
9938: } else {
9939: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
9940: $output = &mt('Failed to copy old target').", $!, ";
9941: }
9942: return $output;
9943: }
9944:
9945: sub write_metadata {
9946: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
9947: my (%metadatafields,%metadatakeys,$output);
9948: $metadatafields{'title'}=$formname;
9949: $metadatafields{'creationdate'}=time;
9950: $metadatafields{'lastrevisiondate'}=time;
9951: $metadatafields{'copyright'}='public';
9952: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
9953: $env{'user.domain'};
9954: $metadatafields{'authorspace'}=$confname.':'.$dom;
9955: $metadatafields{'domain'}=$dom;
9956: {
9957: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
9958: my $mfh;
1.316 raeburn 9959: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 9960: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 9961: unless ($_=~/\./) {
9962: my $unikey=$_;
9963: $unikey=~/^([A-Za-z]+)/;
9964: my $tag=$1;
9965: $tag=~tr/A-Z/a-z/;
9966: print $mfh "\n\<$tag";
9967: foreach (split(/\,/,$metadatakeys{$unikey})) {
9968: my $value=$metadatafields{$unikey.'.'.$_};
9969: $value=~s/\"/\'\'/g;
9970: print $mfh ' '.$_.'="'.$value.'"';
9971: }
9972: print $mfh '>'.
9973: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
9974: .'</'.$tag.'>';
9975: }
9976: }
9977: $output = 'ok';
9978: print $logfile "\nWrote metadata";
9979: close($mfh);
9980: } else {
9981: print $logfile "\nFailed to open metadata file";
1.9 raeburn 9982: $output = &mt('Could not write metadata');
9983: }
9984: }
1.155 raeburn 9985: return $output;
9986: }
9987:
9988: sub notifysubscribed {
9989: foreach my $targetsource (@{$modified_urls}){
9990: next unless (ref($targetsource) eq 'ARRAY');
9991: my ($target,$source)=@{$targetsource};
9992: if ($source ne '') {
1.316 raeburn 9993: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 9994: print $logfh "\nCleanup phase: Notifications\n";
9995: my @subscribed=&subscribed_hosts($target);
9996: foreach my $subhost (@subscribed) {
9997: print $logfh "\nNotifying host ".$subhost.':';
9998: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
9999: print $logfh $reply;
10000: }
10001: my @subscribedmeta=&subscribed_hosts("$target.meta");
10002: foreach my $subhost (@subscribedmeta) {
10003: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10004: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10005: $subhost);
10006: print $logfh $reply;
10007: }
10008: print $logfh "\n============ Done ============\n";
1.160 raeburn 10009: close($logfh);
1.155 raeburn 10010: }
10011: }
10012: }
10013: return OK;
10014: }
10015:
10016: sub subscribed_hosts {
10017: my ($target) = @_;
10018: my @subscribed;
1.316 raeburn 10019: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10020: while (my $subline=<$fh>) {
10021: if ($subline =~ /^($match_lonid):/) {
10022: my $host = $1;
10023: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10024: unless (grep(/^\Q$host\E$/,@subscribed)) {
10025: push(@subscribed,$host);
10026: }
10027: }
10028: }
10029: }
10030: }
10031: return @subscribed;
1.9 raeburn 10032: }
10033:
10034: sub check_switchserver {
10035: my ($dom,$confname) = @_;
10036: my ($allowed,$switchserver);
10037: my $home = &Apache::lonnet::homeserver($confname,$dom);
10038: if ($home eq 'no_host') {
10039: $home = &Apache::lonnet::domain($dom,'primary');
10040: }
10041: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10042: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10043: if (!$allowed) {
1.180 raeburn 10044: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10045: }
10046: return $switchserver;
10047: }
10048:
1.1 raeburn 10049: sub modify_quotas {
1.216 raeburn 10050: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10051: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 10052: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 10053: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10054: $validationfieldsref);
1.86 raeburn 10055: if ($action eq 'quotas') {
10056: $context = 'tools';
1.163 raeburn 10057: } else {
1.86 raeburn 10058: $context = $action;
10059: }
10060: if ($context eq 'requestcourses') {
1.325 ! raeburn 10061: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 10062: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10063: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10064: %titles = &courserequest_titles();
10065: $toolregexp = join('|',@usertools);
10066: %conditions = &courserequest_conditions();
1.216 raeburn 10067: $confname = $dom.'-domainconfig';
10068: my $servadm = $r->dir_config('lonAdmEMail');
10069: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 10070: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10071: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 10072: } elsif ($context eq 'requestauthor') {
10073: @usertools = ('author');
10074: %titles = &authorrequest_titles();
1.86 raeburn 10075: } else {
1.162 raeburn 10076: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10077: %titles = &tool_titles();
1.86 raeburn 10078: }
1.212 raeburn 10079: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10080: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10081: foreach my $key (keys(%env)) {
1.101 raeburn 10082: if ($context eq 'requestcourses') {
10083: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10084: my $item = $1;
10085: my $type = $2;
10086: if ($type =~ /^limit_(.+)/) {
10087: $limithash{$item}{$1} = $env{$key};
10088: } else {
10089: $confhash{$item}{$type} = $env{$key};
10090: }
10091: }
1.163 raeburn 10092: } elsif ($context eq 'requestauthor') {
10093: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10094: $confhash{$1} = $env{$key};
10095: }
1.101 raeburn 10096: } else {
1.86 raeburn 10097: if ($key =~ /^form\.quota_(.+)$/) {
10098: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 10099: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10100: $confhash{'authorquota'}{$1} = $env{$key};
10101: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10102: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10103: }
1.72 raeburn 10104: }
10105: }
1.163 raeburn 10106: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 10107: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10108: @approvalnotify = sort(@approvalnotify);
10109: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 ! raeburn 10110: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 10111: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10112: foreach my $type (@hasuniquecode) {
10113: if (grep(/^\Q$type\E$/,@crstypes)) {
10114: $confhash{'uniquecode'}{$type} = 1;
10115: }
1.216 raeburn 10116: }
1.242 raeburn 10117: my (%newbook,%allpos);
1.216 raeburn 10118: if ($context eq 'requestcourses') {
1.242 raeburn 10119: foreach my $type ('textbooks','templates') {
10120: @{$allpos{$type}} = ();
10121: my $invalid;
10122: if ($type eq 'textbooks') {
10123: $invalid = &mt('Invalid LON-CAPA course for textbook');
10124: } else {
10125: $invalid = &mt('Invalid LON-CAPA course for template');
10126: }
10127: if ($env{'form.'.$type.'_addbook'}) {
10128: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10129: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10130: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10131: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10132: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10133: } else {
10134: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10135: my $position = $env{'form.'.$type.'_addbook_pos'};
10136: $position =~ s/\D+//g;
10137: if ($position ne '') {
10138: $allpos{$type}[$position] = $newbook{$type};
10139: }
1.216 raeburn 10140: }
1.242 raeburn 10141: } else {
10142: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 10143: }
10144: }
1.242 raeburn 10145: }
1.216 raeburn 10146: }
1.102 raeburn 10147: if (ref($domconfig{$action}) eq 'HASH') {
10148: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10149: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10150: $changes{'notify'}{'approval'} = 1;
10151: }
10152: } else {
1.144 raeburn 10153: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10154: $changes{'notify'}{'approval'} = 1;
10155: }
10156: }
1.218 raeburn 10157: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10158: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10159: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10160: unless ($confhash{'uniquecode'}{$crstype}) {
10161: $changes{'uniquecode'} = 1;
10162: }
10163: }
10164: unless ($changes{'uniquecode'}) {
10165: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10166: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10167: $changes{'uniquecode'} = 1;
10168: }
10169: }
10170: }
10171: } else {
10172: $changes{'uniquecode'} = 1;
10173: }
10174: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10175: $changes{'uniquecode'} = 1;
1.216 raeburn 10176: }
10177: if ($context eq 'requestcourses') {
1.242 raeburn 10178: foreach my $type ('textbooks','templates') {
10179: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10180: my %deletions;
10181: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10182: if (@todelete) {
10183: map { $deletions{$_} = 1; } @todelete;
10184: }
10185: my %imgdeletions;
10186: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10187: if (@todeleteimages) {
10188: map { $imgdeletions{$_} = 1; } @todeleteimages;
10189: }
10190: my $maxnum = $env{'form.'.$type.'_maxnum'};
10191: for (my $i=0; $i<=$maxnum; $i++) {
10192: my $itemid = $env{'form.'.$type.'_id_'.$i};
10193: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10194: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10195: if ($deletions{$key}) {
10196: if ($domconfig{$action}{$type}{$key}{'image'}) {
10197: #FIXME need to obsolete item in RES space
10198: }
10199: next;
10200: } else {
10201: my $newpos = $env{'form.'.$itemid};
10202: $newpos =~ s/\D+//g;
1.243 raeburn 10203: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 10204: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 10205: ($type eq 'templates'));
1.242 raeburn 10206: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10207: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10208: $changes{$type}{$key} = 1;
10209: }
10210: }
10211: $allpos{$type}[$newpos] = $key;
10212: }
10213: if ($imgdeletions{$key}) {
10214: $changes{$type}{$key} = 1;
1.216 raeburn 10215: #FIXME need to obsolete item in RES space
1.242 raeburn 10216: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10217: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 10218: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10219: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10220: } else {
10221: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10222: $cdom,$cnum,$type,$configuserok,
10223: $switchserver,$author_ok);
10224: if ($imgurl) {
10225: $confhash{$type}{$key}{'image'} = $imgurl;
10226: $changes{$type}{$key} = 1;
10227: }
10228: if ($error) {
10229: &Apache::lonnet::logthis($error);
10230: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10231: }
10232: }
1.242 raeburn 10233: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10234: $confhash{$type}{$key}{'image'} =
10235: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 10236: }
10237: }
10238: }
10239: }
10240: }
10241: }
1.102 raeburn 10242: } else {
1.144 raeburn 10243: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10244: $changes{'notify'}{'approval'} = 1;
10245: }
1.218 raeburn 10246: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 10247: $changes{'uniquecode'} = 1;
10248: }
10249: }
10250: if ($context eq 'requestcourses') {
1.242 raeburn 10251: foreach my $type ('textbooks','templates') {
10252: if ($newbook{$type}) {
10253: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 10254: foreach my $item ('subject','title','publisher','author') {
10255: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10256: ($type eq 'template'));
1.242 raeburn 10257: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10258: if ($env{'form.'.$type.'_addbook_'.$item}) {
10259: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10260: }
10261: }
10262: if ($type eq 'textbooks') {
10263: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10264: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 10265: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10266: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10267: } else {
10268: my ($imageurl,$error) =
10269: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10270: $configuserok,$switchserver,$author_ok);
10271: if ($imageurl) {
10272: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10273: }
10274: if ($error) {
10275: &Apache::lonnet::logthis($error);
10276: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10277: }
1.242 raeburn 10278: }
10279: }
1.216 raeburn 10280: }
10281: }
1.242 raeburn 10282: if (@{$allpos{$type}} > 0) {
10283: my $idx = 0;
10284: foreach my $item (@{$allpos{$type}}) {
10285: if ($item ne '') {
10286: $confhash{$type}{$item}{'order'} = $idx;
10287: if (ref($domconfig{$action}) eq 'HASH') {
10288: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10289: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10290: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10291: $changes{$type}{$item} = 1;
10292: }
1.216 raeburn 10293: }
10294: }
10295: }
1.242 raeburn 10296: $idx ++;
1.216 raeburn 10297: }
10298: }
10299: }
10300: }
1.235 raeburn 10301: if (ref($validationitemsref) eq 'ARRAY') {
10302: foreach my $item (@{$validationitemsref}) {
10303: if ($item eq 'fields') {
10304: my @changed;
10305: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10306: if (@{$confhash{'validation'}{$item}} > 0) {
10307: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10308: }
1.266 raeburn 10309: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10310: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10311: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10312: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10313: $domconfig{'requestcourses'}{'validation'}{$item});
10314: } else {
10315: @changed = @{$confhash{'validation'}{$item}};
10316: }
1.235 raeburn 10317: } else {
10318: @changed = @{$confhash{'validation'}{$item}};
10319: }
10320: } else {
10321: @changed = @{$confhash{'validation'}{$item}};
10322: }
10323: if (@changed) {
10324: if ($confhash{'validation'}{$item}) {
10325: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10326: } else {
10327: $changes{'validation'}{$item} = &mt('None');
10328: }
10329: }
10330: } else {
10331: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10332: if ($item eq 'markup') {
10333: if ($env{'form.requestcourses_validation_'.$item}) {
10334: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10335: }
10336: }
1.266 raeburn 10337: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10338: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10339: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10340: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10341: }
10342: } else {
10343: if ($confhash{'validation'}{$item} ne '') {
10344: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10345: }
1.235 raeburn 10346: }
10347: } else {
10348: if ($confhash{'validation'}{$item} ne '') {
10349: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10350: }
10351: }
10352: }
10353: }
10354: }
10355: if ($env{'form.validationdc'}) {
10356: my $newval = $env{'form.validationdc'};
1.285 raeburn 10357: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 10358: if (exists($domcoords{$newval})) {
10359: $confhash{'validation'}{'dc'} = $newval;
10360: }
10361: }
10362: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 10363: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10364: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10365: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10366: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10367: if ($confhash{'validation'}{'dc'} eq '') {
10368: $changes{'validation'}{'dc'} = &mt('None');
10369: } else {
10370: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10371: }
1.235 raeburn 10372: }
1.266 raeburn 10373: } elsif ($confhash{'validation'}{'dc'} ne '') {
10374: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 10375: }
10376: } elsif ($confhash{'validation'}{'dc'} ne '') {
10377: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10378: }
10379: } elsif ($confhash{'validation'}{'dc'} ne '') {
10380: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 10381: }
1.266 raeburn 10382: } else {
10383: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10384: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10385: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10386: $changes{'validation'}{'dc'} = &mt('None');
10387: }
10388: }
1.235 raeburn 10389: }
10390: }
1.102 raeburn 10391: }
10392: } else {
1.86 raeburn 10393: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 10394: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10395: }
1.72 raeburn 10396: foreach my $item (@usertools) {
10397: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10398: my $unset;
1.101 raeburn 10399: if ($context eq 'requestcourses') {
1.104 raeburn 10400: $unset = '0';
10401: if ($type eq '_LC_adv') {
10402: $unset = '';
10403: }
1.101 raeburn 10404: if ($confhash{$item}{$type} eq 'autolimit') {
10405: $confhash{$item}{$type} .= '=';
10406: unless ($limithash{$item}{$type} =~ /\D/) {
10407: $confhash{$item}{$type} .= $limithash{$item}{$type};
10408: }
10409: }
1.163 raeburn 10410: } elsif ($context eq 'requestauthor') {
10411: $unset = '0';
10412: if ($type eq '_LC_adv') {
10413: $unset = '';
10414: }
1.72 raeburn 10415: } else {
1.101 raeburn 10416: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10417: $confhash{$item}{$type} = 1;
10418: } else {
10419: $confhash{$item}{$type} = 0;
10420: }
1.72 raeburn 10421: }
1.86 raeburn 10422: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 10423: if ($action eq 'requestauthor') {
10424: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10425: $changes{$type} = 1;
10426: }
10427: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10428: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10429: $changes{$item}{$type} = 1;
10430: }
10431: } else {
10432: if ($context eq 'requestcourses') {
1.104 raeburn 10433: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 10434: $changes{$item}{$type} = 1;
10435: }
10436: } else {
10437: if (!$confhash{$item}{$type}) {
10438: $changes{$item}{$type} = 1;
10439: }
10440: }
10441: }
10442: } else {
10443: if ($context eq 'requestcourses') {
1.104 raeburn 10444: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10445: $changes{$item}{$type} = 1;
10446: }
1.163 raeburn 10447: } elsif ($context eq 'requestauthor') {
10448: if ($confhash{$type} ne $unset) {
10449: $changes{$type} = 1;
10450: }
1.72 raeburn 10451: } else {
10452: if (!$confhash{$item}{$type}) {
10453: $changes{$item}{$type} = 1;
10454: }
10455: }
10456: }
1.1 raeburn 10457: }
10458: }
1.163 raeburn 10459: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10460: if (ref($domconfig{'quotas'}) eq 'HASH') {
10461: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10462: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10463: if (exists($confhash{'defaultquota'}{$key})) {
10464: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10465: $changes{'defaultquota'}{$key} = 1;
10466: }
10467: } else {
10468: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10469: }
10470: }
1.86 raeburn 10471: } else {
10472: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10473: if (exists($confhash{'defaultquota'}{$key})) {
10474: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10475: $changes{'defaultquota'}{$key} = 1;
10476: }
10477: } else {
10478: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10479: }
1.1 raeburn 10480: }
10481: }
1.197 raeburn 10482: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10483: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10484: if (exists($confhash{'authorquota'}{$key})) {
10485: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10486: $changes{'authorquota'}{$key} = 1;
10487: }
10488: } else {
10489: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10490: }
10491: }
10492: }
1.1 raeburn 10493: }
1.86 raeburn 10494: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10495: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10496: if (ref($domconfig{'quotas'}) eq 'HASH') {
10497: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10498: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
10499: $changes{'defaultquota'}{$key} = 1;
10500: }
10501: } else {
10502: if (!exists($domconfig{'quotas'}{$key})) {
10503: $changes{'defaultquota'}{$key} = 1;
10504: }
1.72 raeburn 10505: }
10506: } else {
1.86 raeburn 10507: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 10508: }
1.1 raeburn 10509: }
10510: }
1.197 raeburn 10511: if (ref($confhash{'authorquota'}) eq 'HASH') {
10512: foreach my $key (keys(%{$confhash{'authorquota'}})) {
10513: if (ref($domconfig{'quotas'}) eq 'HASH') {
10514: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10515: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
10516: $changes{'authorquota'}{$key} = 1;
10517: }
10518: } else {
10519: $changes{'authorquota'}{$key} = 1;
10520: }
10521: } else {
10522: $changes{'authorquota'}{$key} = 1;
10523: }
10524: }
10525: }
1.1 raeburn 10526: }
1.72 raeburn 10527:
1.163 raeburn 10528: if ($context eq 'requestauthor') {
10529: $domdefaults{'requestauthor'} = \%confhash;
10530: } else {
10531: foreach my $key (keys(%confhash)) {
1.242 raeburn 10532: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 10533: $domdefaults{$key} = $confhash{$key};
10534: }
1.163 raeburn 10535: }
1.72 raeburn 10536: }
1.163 raeburn 10537:
1.1 raeburn 10538: my %quotahash = (
1.86 raeburn 10539: $action => { %confhash }
1.1 raeburn 10540: );
10541: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
10542: $dom);
10543: if ($putresult eq 'ok') {
10544: if (keys(%changes) > 0) {
1.72 raeburn 10545: my $cachetime = 24*60*60;
10546: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10547: if (ref($lastactref) eq 'HASH') {
10548: $lastactref->{'domdefaults'} = 1;
10549: }
1.1 raeburn 10550: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 10551: unless (($context eq 'requestcourses') ||
1.163 raeburn 10552: ($context eq 'requestauthor')) {
1.86 raeburn 10553: if (ref($changes{'defaultquota'}) eq 'HASH') {
10554: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
10555: foreach my $type (@{$types},'default') {
10556: if (defined($changes{'defaultquota'}{$type})) {
10557: my $typetitle = $usertypes->{$type};
10558: if ($type eq 'default') {
10559: $typetitle = $othertitle;
10560: }
1.213 raeburn 10561: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 10562: }
10563: }
1.86 raeburn 10564: $resulttext .= '</ul></li>';
1.72 raeburn 10565: }
1.197 raeburn 10566: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 10567: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 10568: foreach my $type (@{$types},'default') {
10569: if (defined($changes{'authorquota'}{$type})) {
10570: my $typetitle = $usertypes->{$type};
10571: if ($type eq 'default') {
10572: $typetitle = $othertitle;
10573: }
1.213 raeburn 10574: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 10575: }
10576: }
10577: $resulttext .= '</ul></li>';
10578: }
1.72 raeburn 10579: }
1.80 raeburn 10580: my %newenv;
1.72 raeburn 10581: foreach my $item (@usertools) {
1.163 raeburn 10582: my (%haschgs,%inconf);
10583: if ($context eq 'requestauthor') {
10584: %haschgs = %changes;
1.210 raeburn 10585: %inconf = %confhash;
1.163 raeburn 10586: } else {
10587: if (ref($changes{$item}) eq 'HASH') {
10588: %haschgs = %{$changes{$item}};
10589: }
10590: if (ref($confhash{$item}) eq 'HASH') {
10591: %inconf = %{$confhash{$item}};
10592: }
10593: }
10594: if (keys(%haschgs) > 0) {
1.80 raeburn 10595: my $newacc =
10596: &Apache::lonnet::usertools_access($env{'user.name'},
10597: $env{'user.domain'},
1.86 raeburn 10598: $item,'reload',$context);
1.210 raeburn 10599: if (($context eq 'requestcourses') ||
1.163 raeburn 10600: ($context eq 'requestauthor')) {
1.108 raeburn 10601: if ($env{'environment.canrequest.'.$item} ne $newacc) {
10602: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 10603: }
10604: } else {
10605: if ($env{'environment.availabletools.'.$item} ne $newacc) {
10606: $newenv{'environment.availabletools.'.$item} = $newacc;
10607: }
1.80 raeburn 10608: }
1.163 raeburn 10609: unless ($context eq 'requestauthor') {
10610: $resulttext .= '<li>'.$titles{$item}.'<ul>';
10611: }
1.72 raeburn 10612: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 10613: if ($haschgs{$type}) {
1.72 raeburn 10614: my $typetitle = $usertypes->{$type};
10615: if ($type eq 'default') {
10616: $typetitle = $othertitle;
10617: } elsif ($type eq '_LC_adv') {
10618: $typetitle = 'LON-CAPA Advanced Users';
10619: }
1.163 raeburn 10620: if ($inconf{$type}) {
1.101 raeburn 10621: if ($context eq 'requestcourses') {
10622: my $cond;
1.163 raeburn 10623: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 10624: if ($1 eq '') {
10625: $cond = &mt('(Automatic processing of any request).');
10626: } else {
10627: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
10628: }
10629: } else {
1.163 raeburn 10630: $cond = $conditions{$inconf{$type}};
1.101 raeburn 10631: }
10632: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 10633: } elsif ($context eq 'requestauthor') {
10634: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
10635: $titles{$inconf{$type}},$typetitle);
10636:
1.101 raeburn 10637: } else {
10638: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
10639: }
1.72 raeburn 10640: } else {
1.104 raeburn 10641: if ($type eq '_LC_adv') {
1.163 raeburn 10642: if ($inconf{$type} eq '0') {
1.104 raeburn 10643: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10644: } else {
10645: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
10646: }
10647: } else {
10648: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10649: }
1.72 raeburn 10650: }
10651: }
1.26 raeburn 10652: }
1.163 raeburn 10653: unless ($context eq 'requestauthor') {
10654: $resulttext .= '</ul></li>';
10655: }
1.26 raeburn 10656: }
1.1 raeburn 10657: }
1.163 raeburn 10658: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 10659: if (ref($changes{'notify'}) eq 'HASH') {
10660: if ($changes{'notify'}{'approval'}) {
10661: if (ref($confhash{'notify'}) eq 'HASH') {
10662: if ($confhash{'notify'}{'approval'}) {
10663: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
10664: } else {
1.163 raeburn 10665: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 10666: }
10667: }
10668: }
10669: }
10670: }
1.216 raeburn 10671: if ($action eq 'requestcourses') {
10672: my @offon = ('off','on');
10673: if ($changes{'uniquecode'}) {
1.218 raeburn 10674: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10675: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10676: $resulttext .= '<li>'.
10677: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10678: '</li>';
10679: } else {
10680: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10681: '</li>';
10682: }
1.216 raeburn 10683: }
1.242 raeburn 10684: foreach my $type ('textbooks','templates') {
10685: if (ref($changes{$type}) eq 'HASH') {
10686: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10687: foreach my $key (sort(keys(%{$changes{$type}}))) {
10688: my %coursehash = &Apache::lonnet::coursedescription($key);
10689: my $coursetitle = $coursehash{'description'};
10690: my $position = $confhash{$type}{$key}{'order'} + 1;
10691: $resulttext .= '<li>';
1.243 raeburn 10692: foreach my $item ('subject','title','publisher','author') {
10693: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10694: ($type eq 'templates'));
1.242 raeburn 10695: my $name = $item.':';
10696: $name =~ s/^(\w)/\U$1/;
10697: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10698: }
10699: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10700: if ($type eq 'textbooks') {
10701: if ($confhash{$type}{$key}{'image'}) {
10702: $resulttext .= ' '.&mt('Image: [_1]',
10703: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10704: ' alt="Textbook cover" />').'<br />';
10705: }
10706: }
10707: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 10708: }
1.242 raeburn 10709: $resulttext .= '</ul></li>';
1.216 raeburn 10710: }
10711: }
1.235 raeburn 10712: if (ref($changes{'validation'}) eq 'HASH') {
10713: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10714: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10715: foreach my $item (@{$validationitemsref}) {
10716: if (exists($changes{'validation'}{$item})) {
10717: if ($item eq 'markup') {
10718: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10719: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10720: } else {
10721: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10722: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10723: }
10724: }
10725: }
10726: if (exists($changes{'validation'}{'dc'})) {
10727: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
10728: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
10729: }
10730: }
10731: }
1.216 raeburn 10732: }
1.1 raeburn 10733: $resulttext .= '</ul>';
1.80 raeburn 10734: if (keys(%newenv)) {
10735: &Apache::lonnet::appenv(\%newenv);
10736: }
1.1 raeburn 10737: } else {
1.86 raeburn 10738: if ($context eq 'requestcourses') {
10739: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 10740: } elsif ($context eq 'requestauthor') {
10741: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 10742: } else {
1.90 weissno 10743: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 10744: }
1.1 raeburn 10745: }
10746: } else {
1.11 albertel 10747: $resulttext = '<span class="LC_error">'.
10748: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10749: }
1.216 raeburn 10750: if ($errors) {
10751: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10752: '<ul>'.$errors.'</ul></p>';
10753: }
1.3 raeburn 10754: return $resulttext;
1.1 raeburn 10755: }
10756:
1.216 raeburn 10757: sub process_textbook_image {
1.242 raeburn 10758: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 10759: my $filename = $env{'form.'.$caller.'.filename'};
10760: my ($error,$url);
10761: my ($width,$height) = (50,50);
10762: if ($configuserok eq 'ok') {
10763: if ($switchserver) {
10764: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10765: $switchserver);
10766: } elsif ($author_ok eq 'ok') {
10767: my ($result,$imageurl) =
10768: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 10769: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 10770: if ($result eq 'ok') {
10771: $url = $imageurl;
10772: } else {
10773: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10774: }
10775: } else {
10776: $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);
10777: }
10778: } else {
10779: $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);
10780: }
10781: return ($url,$error);
10782: }
10783:
1.267 raeburn 10784: sub modify_ltitools {
10785: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10786: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 10787: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 10788: my $confname = $dom.'-domainconfig';
10789: my $servadm = $r->dir_config('lonAdmEMail');
10790: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10791: my (%posslti,%possfield);
10792: my @courseroles = ('cc','in','ta','ep','st');
10793: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10794: map { $posslti{$_} = 1; } @ltiroles;
10795: my @allfields = ('fullname','firstname','lastname','email','user','roles');
10796: map { $possfield{$_} = 1; } @allfields;
10797: my %lt = <itools_names();
10798: if ($env{'form.ltitools_add'}) {
10799: my $title = $env{'form.ltitools_add_title'};
10800: $title =~ s/(`)/'/g;
10801: ($newid,my $error) = &get_ltitools_id($dom,$title);
10802: if ($newid) {
10803: my $position = $env{'form.ltitools_add_pos'};
10804: $position =~ s/\D+//g;
10805: if ($position ne '') {
10806: $allpos[$position] = $newid;
10807: }
10808: $changes{$newid} = 1;
1.322 raeburn 10809: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 10810: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 10811: if ($item eq 'lifetime') {
10812: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
10813: }
1.267 raeburn 10814: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 10815: if (($item eq 'key') || ($item eq 'secret')) {
10816: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10817: } else {
10818: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10819: }
1.267 raeburn 10820: }
10821: }
10822: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10823: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10824: }
10825: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10826: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10827: }
1.323 raeburn 10828: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
10829: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
10830: } else {
10831: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
10832: }
1.296 raeburn 10833: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 10834: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10835: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 10836: if (($item eq 'width') || ($item eq 'height')) {
10837: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10838: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10839: }
10840: } else {
10841: if ($env{'form.ltitools_add_'.$item} ne '') {
10842: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10843: }
1.267 raeburn 10844: }
10845: }
10846: if ($env{'form.ltitools_add_target'} eq 'window') {
10847: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 10848: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10849: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 10850: } else {
10851: $confhash{$newid}{'display'}{'target'} = 'iframe';
10852: }
10853: foreach my $item ('passback','roster') {
1.319 raeburn 10854: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 10855: $confhash{$newid}{$item} = 1;
1.319 raeburn 10856: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
10857: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
10858: $lifetime =~ s/^\s+|\s+$//g;
10859: if ($lifetime =~ /^\d+\.?\d*$/) {
10860: $confhash{$newid}{$item.'valid'} = $lifetime;
10861: }
10862: }
1.267 raeburn 10863: }
10864: }
10865: if ($env{'form.ltitools_add_image.filename'} ne '') {
10866: my ($imageurl,$error) =
1.307 raeburn 10867: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 10868: $configuserok,$switchserver,$author_ok);
10869: if ($imageurl) {
10870: $confhash{$newid}{'image'} = $imageurl;
10871: }
10872: if ($error) {
10873: &Apache::lonnet::logthis($error);
10874: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10875: }
10876: }
10877: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
10878: foreach my $field (@fields) {
10879: if ($possfield{$field}) {
10880: if ($field eq 'roles') {
10881: foreach my $role (@courseroles) {
10882: my $choice = $env{'form.ltitools_add_roles_'.$role};
10883: if (($choice ne '') && ($posslti{$choice})) {
10884: $confhash{$newid}{'roles'}{$role} = $choice;
10885: if ($role eq 'cc') {
10886: $confhash{$newid}{'roles'}{'co'} = $choice;
10887: }
10888: }
10889: }
10890: } else {
10891: $confhash{$newid}{'fields'}{$field} = 1;
10892: }
10893: }
10894: }
1.324 raeburn 10895: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
10896: if ($confhash{$newid}{'fields'}{'user'}) {
10897: if ($env{'form.ltitools_userincdom_add'}) {
10898: $confhash{$newid}{'incdom'} = 1;
10899: }
10900: }
10901: }
1.273 raeburn 10902: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
10903: foreach my $item (@courseconfig) {
10904: $confhash{$newid}{'crsconf'}{$item} = 1;
10905: }
1.267 raeburn 10906: if ($env{'form.ltitools_add_custom'}) {
10907: my $name = $env{'form.ltitools_add_custom_name'};
10908: my $value = $env{'form.ltitools_add_custom_value'};
10909: $value =~ s/(`)/'/g;
10910: $name =~ s/(`)/'/g;
10911: $confhash{$newid}{'custom'}{$name} = $value;
10912: }
10913: } else {
10914: my $error = &mt('Failed to acquire unique ID for new external tool');
10915: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10916: }
10917: }
10918: if (ref($domconfig{$action}) eq 'HASH') {
10919: my %deletions;
10920: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
10921: if (@todelete) {
10922: map { $deletions{$_} = 1; } @todelete;
10923: }
10924: my %customadds;
10925: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
10926: if (@newcustom) {
10927: map { $customadds{$_} = 1; } @newcustom;
10928: }
10929: my %imgdeletions;
10930: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
10931: if (@todeleteimages) {
10932: map { $imgdeletions{$_} = 1; } @todeleteimages;
10933: }
10934: my $maxnum = $env{'form.ltitools_maxnum'};
10935: for (my $i=0; $i<=$maxnum; $i++) {
10936: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 10937: $itemid =~ s/\D+//g;
1.267 raeburn 10938: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10939: if ($deletions{$itemid}) {
10940: if ($domconfig{$action}{$itemid}{'image'}) {
10941: #FIXME need to obsolete item in RES space
10942: }
10943: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
10944: next;
10945: } else {
10946: my $newpos = $env{'form.ltitools_'.$itemid};
10947: $newpos =~ s/\D+//g;
1.322 raeburn 10948: foreach my $item ('title','url','lifetime') {
1.267 raeburn 10949: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10950: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
10951: $changes{$itemid} = 1;
10952: }
10953: }
1.297 raeburn 10954: foreach my $item ('key','secret') {
10955: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10956: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
10957: $changes{$itemid} = 1;
10958: }
10959: }
1.267 raeburn 10960: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
10961: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
10962: }
10963: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
10964: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
10965: }
1.323 raeburn 10966: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
10967: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
10968: } else {
10969: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
10970: }
10971: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
10972: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
10973: $changes{$itemid} = 1;
10974: }
10975: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
10976: $changes{$itemid} = 1;
10977: }
1.267 raeburn 10978: foreach my $size ('width','height') {
10979: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
10980: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
10981: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
10982: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
10983: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10984: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
10985: $changes{$itemid} = 1;
10986: }
10987: } else {
10988: $changes{$itemid} = 1;
10989: }
1.296 raeburn 10990: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10991: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
10992: $changes{$itemid} = 1;
10993: }
10994: }
10995: }
10996: foreach my $item ('linktext','explanation') {
10997: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
10998: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
10999: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
11000: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11001: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11002: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
11003: $changes{$itemid} = 1;
11004: }
11005: } else {
11006: $changes{$itemid} = 1;
11007: }
11008: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11009: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
11010: $changes{$itemid} = 1;
11011: }
1.267 raeburn 11012: }
11013: }
11014: if ($env{'form.ltitools_target_'.$i} eq 'window') {
11015: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 11016: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
11017: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 11018: } else {
11019: $confhash{$itemid}{'display'}{'target'} = 'iframe';
11020: }
11021: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11022: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
11023: $changes{$itemid} = 1;
11024: }
11025: } else {
11026: $changes{$itemid} = 1;
11027: }
11028: foreach my $extra ('passback','roster') {
11029: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
11030: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 11031: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
11032: my $lifetime = $env{'form.ltitools_'.$extra.'valid_add'};
11033: $lifetime =~ s/^\s+|\s+$//g;
11034: if ($lifetime =~ /^\d+\.?\d*$/) {
11035: $confhash{$itemid}{$extra.'valid'} = $lifetime;
11036: }
11037: }
1.267 raeburn 11038: }
11039: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
11040: $changes{$itemid} = 1;
11041: }
1.319 raeburn 11042: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
11043: $changes{$itemid} = 1;
11044: }
1.267 raeburn 11045: }
1.273 raeburn 11046: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 11047: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 11048: if (grep(/^\Q$item\E$/,@courseconfig)) {
11049: $confhash{$itemid}{'crsconf'}{$item} = 1;
11050: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
11051: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
11052: $changes{$itemid} = 1;
11053: }
11054: } else {
11055: $changes{$itemid} = 1;
11056: }
11057: }
11058: }
1.267 raeburn 11059: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
11060: foreach my $field (@fields) {
11061: if ($possfield{$field}) {
11062: if ($field eq 'roles') {
11063: foreach my $role (@courseroles) {
11064: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
11065: if (($choice ne '') && ($posslti{$choice})) {
11066: $confhash{$itemid}{'roles'}{$role} = $choice;
11067: if ($role eq 'cc') {
11068: $confhash{$itemid}{'roles'}{'co'} = $choice;
11069: }
11070: }
11071: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
11072: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
11073: $changes{$itemid} = 1;
11074: }
11075: } elsif ($confhash{$itemid}{'roles'}{$role}) {
11076: $changes{$itemid} = 1;
11077: }
11078: }
11079: } else {
11080: $confhash{$itemid}{'fields'}{$field} = 1;
11081: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
11082: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
11083: $changes{$itemid} = 1;
11084: }
11085: } else {
11086: $changes{$itemid} = 1;
11087: }
11088: }
11089: }
11090: }
1.324 raeburn 11091: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11092: if ($confhash{$itemid}{'fields'}{'user'}) {
11093: if ($env{'form.ltitools_userincdom_'.$i}) {
11094: $confhash{$itemid}{'incdom'} = 1;
11095: }
11096: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
11097: $changes{$itemid} = 1;
11098: }
11099: }
11100: }
1.267 raeburn 11101: $allpos[$newpos] = $itemid;
11102: }
11103: if ($imgdeletions{$itemid}) {
11104: $changes{$itemid} = 1;
11105: #FIXME need to obsolete item in RES space
11106: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
11107: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
11108: $itemid,$configuserok,$switchserver,
11109: $author_ok);
11110: if ($imgurl) {
11111: $confhash{$itemid}{'image'} = $imgurl;
11112: $changes{$itemid} = 1;
11113: }
11114: if ($error) {
11115: &Apache::lonnet::logthis($error);
11116: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11117: }
11118: } elsif ($domconfig{$action}{$itemid}{'image'}) {
11119: $confhash{$itemid}{'image'} =
11120: $domconfig{$action}{$itemid}{'image'};
11121: }
11122: if ($customadds{$i}) {
11123: my $name = $env{'form.ltitools_custom_name_'.$i};
11124: $name =~ s/(`)/'/g;
11125: $name =~ s/^\s+//;
11126: $name =~ s/\s+$//;
11127: my $value = $env{'form.ltitools_custom_value_'.$i};
11128: $value =~ s/(`)/'/g;
11129: $value =~ s/^\s+//;
11130: $value =~ s/\s+$//;
11131: if ($name ne '') {
11132: $confhash{$itemid}{'custom'}{$name} = $value;
11133: $changes{$itemid} = 1;
11134: }
11135: }
11136: my %customdels;
11137: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
11138: if (@customdeletions) {
11139: $changes{$itemid} = 1;
11140: }
11141: map { $customdels{$_} = 1; } @customdeletions;
11142: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
11143: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
11144: unless ($customdels{$key}) {
11145: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
11146: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
11147: }
11148: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
11149: $changes{$itemid} = 1;
11150: }
11151: }
11152: }
11153: }
11154: unless ($changes{$itemid}) {
11155: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
11156: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
11157: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
11158: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
11159: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
11160: $changes{$itemid} = 1;
11161: last;
11162: }
11163: }
11164: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
11165: $changes{$itemid} = 1;
11166: }
11167: }
11168: last if ($changes{$itemid});
11169: }
11170: }
11171: }
11172: }
11173: }
11174: if (@allpos > 0) {
11175: my $idx = 0;
11176: foreach my $itemid (@allpos) {
11177: if ($itemid ne '') {
11178: $confhash{$itemid}{'order'} = $idx;
11179: if (ref($domconfig{$action}) eq 'HASH') {
11180: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11181: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11182: $changes{$itemid} = 1;
11183: }
11184: }
11185: }
11186: $idx ++;
11187: }
11188: }
11189: }
11190: my %ltitoolshash = (
11191: $action => { %confhash }
11192: );
11193: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
11194: $dom);
11195: if ($putresult eq 'ok') {
1.297 raeburn 11196: my %ltienchash = (
11197: $action => { %encconfig }
11198: );
11199: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 11200: if (keys(%changes) > 0) {
11201: my $cachetime = 24*60*60;
1.297 raeburn 11202: my %ltiall = %confhash;
11203: foreach my $id (keys(%ltiall)) {
11204: if (ref($encconfig{$id}) eq 'HASH') {
11205: foreach my $item ('key','secret') {
11206: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11207: }
11208: }
11209: }
11210: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 11211: if (ref($lastactref) eq 'HASH') {
11212: $lastactref->{'ltitools'} = 1;
11213: }
11214: $resulttext = &mt('Changes made:').'<ul>';
11215: my %bynum;
11216: foreach my $itemid (sort(keys(%changes))) {
11217: my $position = $confhash{$itemid}{'order'};
11218: $bynum{$position} = $itemid;
11219: }
11220: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11221: my $itemid = $bynum{$pos};
11222: if (ref($confhash{$itemid}) ne 'HASH') {
11223: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11224: } else {
11225: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
11226: if ($confhash{$itemid}{'image'}) {
11227: $resulttext .= ' '.
11228: '<img src="'.$confhash{$itemid}{'image'}.'"'.
11229: ' alt="'.&mt('Tool Provider icon').'" />';
11230: }
11231: $resulttext .= '</li><ul>';
11232: my $position = $pos + 1;
11233: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 11234: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 11235: if ($confhash{$itemid}{$item} ne '') {
11236: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11237: }
11238: }
1.297 raeburn 11239: if ($encconfig{$itemid}{'key'} ne '') {
11240: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11241: }
11242: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 11243: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 11244: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 11245: $resulttext .= ('*'x$num).'</li>';
11246: }
1.273 raeburn 11247: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 11248: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 11249: my $numconfig = 0;
11250: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
11251: foreach my $item (@possconfig) {
11252: if ($confhash{$itemid}{'crsconf'}{$item}) {
11253: $numconfig ++;
1.296 raeburn 11254: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 11255: }
11256: }
11257: }
11258: if (!$numconfig) {
11259: $resulttext .= &mt('None');
11260: }
11261: $resulttext .= '</li>';
1.267 raeburn 11262: foreach my $item ('passback','roster') {
11263: $resulttext .= '<li>'.$lt{$item}.' ';
11264: if ($confhash{$itemid}{$item}) {
11265: $resulttext .= &mt('Yes');
1.319 raeburn 11266: if ($confhash{$itemid}{$item.'valid'}) {
11267: if ($item eq 'passback') {
11268: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
11269: $confhash{$itemid}{$item.'valid'});
11270: } else {
11271: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
11272: $confhash{$itemid}{$item.'valid'});
11273: }
11274: }
1.267 raeburn 11275: } else {
11276: $resulttext .= &mt('No');
11277: }
11278: $resulttext .= '</li>';
11279: }
11280: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11281: my $displaylist;
11282: if ($confhash{$itemid}{'display'}{'target'}) {
11283: $displaylist = &mt('Display target').': '.
11284: $confhash{$itemid}{'display'}{'target'}.',';
11285: }
11286: foreach my $size ('width','height') {
11287: if ($confhash{$itemid}{'display'}{$size}) {
11288: $displaylist .= (' 'x2).$lt{$size}.': '.
11289: $confhash{$itemid}{'display'}{$size}.',';
11290: }
11291: }
11292: if ($displaylist) {
11293: $displaylist =~ s/,$//;
11294: $resulttext .= '<li>'.$displaylist.'</li>';
11295: }
1.296 raeburn 11296: foreach my $item ('linktext','explanation') {
11297: if ($confhash{$itemid}{'display'}{$item}) {
11298: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11299: }
11300: }
11301: }
1.267 raeburn 11302: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11303: my $fieldlist;
11304: foreach my $field (@allfields) {
11305: if ($confhash{$itemid}{'fields'}{$field}) {
11306: $fieldlist .= (' 'x2).$lt{$field}.',';
11307: }
11308: }
11309: if ($fieldlist) {
11310: $fieldlist =~ s/,$//;
1.324 raeburn 11311: if ($confhash{$itemid}{'fields'}{'user'}) {
11312: if ($confhash{$itemid}{'incdom'}) {
11313: $fieldlist .= ' ('.&mt('username:domain').')';
11314: } else {
11315: $fieldlist .= ' ('.&mt('username').')';
11316: }
11317: }
1.267 raeburn 11318: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11319: }
11320: }
11321: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11322: my $rolemaps;
11323: foreach my $role (@courseroles) {
11324: if ($confhash{$itemid}{'roles'}{$role}) {
11325: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11326: $confhash{$itemid}{'roles'}{$role}.',';
11327: }
11328: }
11329: if ($rolemaps) {
11330: $rolemaps =~ s/,$//;
11331: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11332: }
11333: }
11334: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11335: my $customlist;
11336: if (keys(%{$confhash{$itemid}{'custom'}})) {
11337: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11338: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11339: }
11340: }
11341: if ($customlist) {
1.317 raeburn 11342: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 11343: }
11344: }
11345: $resulttext .= '</ul></li>';
11346: }
11347: }
11348: $resulttext .= '</ul>';
11349: } else {
11350: $resulttext = &mt('No changes made.');
11351: }
11352: } else {
11353: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11354: }
11355: if ($errors) {
11356: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11357: $errors.'</ul>';
11358: }
11359: return $resulttext;
11360: }
11361:
11362: sub process_ltitools_image {
11363: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11364: my $filename = $env{'form.'.$caller.'.filename'};
11365: my ($error,$url);
11366: my ($width,$height) = (21,21);
11367: if ($configuserok eq 'ok') {
11368: if ($switchserver) {
11369: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11370: $switchserver);
11371: } elsif ($author_ok eq 'ok') {
11372: my ($result,$imageurl,$madethumb) =
11373: &publishlogo($r,'upload',$caller,$dom,$confname,
11374: "ltitools/$itemid/icon",$width,$height);
11375: if ($result eq 'ok') {
11376: if ($madethumb) {
11377: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11378: my $imagethumb = "$path/tn-".$imagefile;
11379: $url = $imagethumb;
11380: } else {
11381: $url = $imageurl;
11382: }
11383: } else {
11384: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11385: }
11386: } else {
11387: $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);
11388: }
11389: } else {
11390: $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);
11391: }
11392: return ($url,$error);
11393: }
11394:
11395: sub get_ltitools_id {
11396: my ($cdom,$title) = @_;
11397: # get lock on ltitools db
11398: my $lockhash = {
11399: lock => $env{'user.name'}.
11400: ':'.$env{'user.domain'},
11401: };
11402: my $tries = 0;
11403: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11404: my ($id,$error);
11405:
11406: while (($gotlock ne 'ok') && ($tries<10)) {
11407: $tries ++;
11408: sleep (0.1);
11409: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11410: }
11411: if ($gotlock eq 'ok') {
11412: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11413: if ($currids{'lock'}) {
11414: delete($currids{'lock'});
11415: if (keys(%currids)) {
11416: my @curr = sort { $a <=> $b } keys(%currids);
11417: if ($curr[-1] =~ /^\d+$/) {
11418: $id = 1 + $curr[-1];
11419: }
11420: } else {
11421: $id = 1;
11422: }
11423: if ($id) {
11424: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11425: $error = 'nostore';
11426: }
11427: } else {
11428: $error = 'nonumber';
11429: }
11430: }
11431: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11432: } else {
11433: $error = 'nolock';
11434: }
11435: return ($id,$error);
11436: }
11437:
1.320 raeburn 11438: sub modify_lti {
11439: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11440: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11441: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
11442: my (%posslti,%posslticrs,%posscrstype);
11443: my @courseroles = ('cc','in','ta','ep','st');
11444: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
11445: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
11446: my @coursetypes = ('official','unofficial','community','textbook','placement');
11447: my %coursetypetitles = &Apache::lonlocal::texthash (
11448: official => 'Official',
11449: unofficial => 'Unofficial',
11450: community => 'Community',
11451: textbook => 'Textbook',
11452: placement => 'Placement Test',
11453: );
1.325 ! raeburn 11454: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 11455: my %lt = <i_names();
11456: map { $posslti{$_} = 1; } @ltiroles;
11457: map { $posslticrs{$_} = 1; } @lticourseroles;
11458: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 ! raeburn 11459:
! 11460: #FIXME
1.320 raeburn 11461:
11462: my (@items,%deletions,%itemids);
11463: if ($env{'form.lti_add'}) {
11464: my $consumer = $env{'form.lti_consumer_add'};
11465: $consumer =~ s/(`)/'/g;
11466: ($newid,my $error) = &get_lti_id($dom,$consumer);
11467: if ($newid) {
11468: $itemids{'add'} = $newid;
11469: push(@items,'add');
11470: $changes{$newid} = 1;
11471: } else {
11472: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
11473: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11474: }
11475: }
11476: if (ref($domconfig{$action}) eq 'HASH') {
11477: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
11478: if (@todelete) {
11479: map { $deletions{$_} = 1; } @todelete;
11480: }
11481: my $maxnum = $env{'form.lti_maxnum'};
11482: for (my $i=0; $i<=$maxnum; $i++) {
11483: my $itemid = $env{'form.lti_id_'.$i};
11484: $itemid =~ s/\D+//g;
11485: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11486: if ($deletions{$itemid}) {
11487: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
11488: } else {
11489: push(@items,$i);
11490: $itemids{$i} = $itemid;
11491: }
11492: }
11493: }
11494: }
11495: foreach my $idx (@items) {
11496: my $itemid = $itemids{$idx};
11497: next unless ($itemid);
11498: my $position = $env{'form.lti_pos_'.$idx};
11499: $position =~ s/\D+//g;
11500: if ($position ne '') {
11501: $allpos[$position] = $itemid;
11502: }
11503: foreach my $item ('consumer','key','secret','lifetime') {
11504: my $formitem = 'form.lti_'.$item.'_'.$idx;
11505: $env{$formitem} =~ s/(`)/'/g;
11506: if ($item eq 'lifetime') {
11507: $env{$formitem} =~ s/[^\d.]//g;
11508: }
11509: if ($env{$formitem} ne '') {
11510: if (($item eq 'key') || ($item eq 'secret')) {
11511: $encconfig{$itemid}{$item} = $env{$formitem};
11512: } else {
11513: $confhash{$itemid}{$item} = $env{$formitem};
11514: unless (($idx eq 'add') || ($changes{$itemid})) {
11515: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11516: $changes{$itemid} = 1;
11517: }
11518: }
11519: }
11520: }
11521: }
11522: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
11523: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
11524: }
11525: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
11526: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
11527: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
11528: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
11529: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
11530: my $mapuser = $env{'form.lti_customuser_'.$idx};
11531: $mapuser =~ s/(`)/'/g;
11532: $mapuser =~ s/^\s+|\s+$//g;
11533: $confhash{$itemid}{'mapuser'} = $mapuser;
11534: }
11535: foreach my $ltirole (@lticourseroles) {
11536: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
11537: if (grep(/^\Q$possrole\E$/,@courseroles)) {
11538: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
11539: }
11540: }
11541: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
11542: my @makeuser;
11543: foreach my $ltirole (sort(@possmakeuser)) {
11544: if ($posslti{$ltirole}) {
11545: push(@makeuser,$ltirole);
11546: }
11547: }
11548: $confhash{$itemid}{'makeuser'} = \@makeuser;
1.325 ! raeburn 11549: if (@makeuser) {
! 11550: my $lcauth = $env{'form.lti_lcauth_'.$idx};
! 11551: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
! 11552: $confhash{$itemid}{'lcauth'} = $lcauth;
! 11553: if ($lcauth ne 'internal') {
! 11554: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
! 11555: $lcauthparm =~ s/^(\s+|\s+)$//g;
! 11556: $lcauthparm =~ s/`//g;
! 11557: if ($lcauthparm ne '') {
! 11558: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
! 11559: }
! 11560: }
! 11561: } else {
! 11562: $confhash{$itemid}{'lcauth'} = 'lti';
! 11563: }
! 11564: }
! 11565: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
! 11566: if (@possinstdata) {
! 11567: foreach my $field (@possinstdata) {
! 11568: if (exists($fieldtitles{$field})) {
! 11569: push(@{$confhash{$itemid}{'instdata'}});
! 11570: }
! 11571: }
! 11572: }
1.320 raeburn 11573: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
11574: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
11575: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
11576: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
11577: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
11578: $mapcrs =~ s/(`)/'/g;
11579: $mapcrs =~ s/^\s+|\s+$//g;
11580: $confhash{$itemid}{'mapcrs'} = $mapcrs;
11581: }
11582: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
11583: my @crstypes;
11584: foreach my $type (sort(@posstypes)) {
11585: if ($posscrstype{$type}) {
11586: push(@crstypes,$type);
11587: }
11588: }
11589: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
11590: if ($env{'form.lti_makecrs_'.$idx}) {
11591: $confhash{$itemid}{'makecrs'} = 1;
11592: }
11593: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
11594: my @selfenroll;
11595: foreach my $type (sort(@possenroll)) {
11596: if ($posslticrs{$type}) {
11597: push(@selfenroll,$type);
11598: }
11599: }
11600: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
11601: if ($env{'form.lti_crssec_'.$idx}) {
11602: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
11603: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
11604: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
11605: my $section = $env{'form.lti_customsection_'.$idx};
11606: $section =~ s/(`)/'/g;
11607: $section =~ s/^\s+|\s+$//g;
11608: if ($section ne '') {
11609: $confhash{$itemid}{'section'} = $section;
11610: }
11611: }
11612: }
11613: foreach my $field ('passback','roster') {
1.321 raeburn 11614: if ($env{'form.lti_'.$field.'_'.$idx}) {
1.320 raeburn 11615: $confhash{$itemid}{$field} = 1;
11616: }
11617: }
11618: unless (($idx eq 'add') || ($changes{$itemid})) {
1.325 ! raeburn 11619: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm') {
1.320 raeburn 11620: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
11621: $changes{$itemid} = 1;
11622: }
11623: }
1.325 ! raeburn 11624: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata') {
1.320 raeburn 11625: unless ($changes{$itemid}) {
11626: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
11627: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11628: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
11629: $confhash{$itemid}{$field});
11630: if (@diffs) {
11631: $changes{$itemid} = 1;
11632: }
11633: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
11634: $changes{$itemid} = 1;
11635: }
11636: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11637: if (@{$confhash{$itemid}{$field}} > 0) {
11638: $changes{$itemid} = 1;
11639: }
11640: }
11641: }
11642: }
11643: unless ($changes{$itemid}) {
11644: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
11645: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11646: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
11647: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
11648: $confhash{$itemid}{'maproles'}{$ltirole}) {
11649: $changes{$itemid} = 1;
11650: last;
11651: }
11652: }
11653: unless ($changes{$itemid}) {
11654: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
11655: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
11656: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
11657: $changes{$itemid} = 1;
11658: last;
11659: }
11660: }
11661: }
11662: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
11663: $changes{$itemid} = 1;
11664: }
11665: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11666: unless ($changes{$itemid}) {
11667: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
11668: $changes{$itemid} = 1;
11669: }
11670: }
11671: }
11672: }
11673: }
11674: }
11675: if (@allpos > 0) {
11676: my $idx = 0;
11677: foreach my $itemid (@allpos) {
11678: if ($itemid ne '') {
11679: $confhash{$itemid}{'order'} = $idx;
11680: if (ref($domconfig{$action}) eq 'HASH') {
11681: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11682: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11683: $changes{$itemid} = 1;
11684: }
11685: }
11686: }
11687: $idx ++;
11688: }
11689: }
11690: }
11691: my %ltihash = (
11692: $action => { %confhash }
11693: );
11694: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
11695: $dom);
11696: if ($putresult eq 'ok') {
11697: my %ltienchash = (
11698: $action => { %encconfig }
11699: );
11700: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
11701: if (keys(%changes) > 0) {
11702: my $cachetime = 24*60*60;
11703: my %ltiall = %confhash;
11704: foreach my $id (keys(%ltiall)) {
11705: if (ref($encconfig{$id}) eq 'HASH') {
11706: foreach my $item ('key','secret') {
11707: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11708: }
11709: }
11710: }
11711: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
11712: if (ref($lastactref) eq 'HASH') {
11713: $lastactref->{'lti'} = 1;
11714: }
11715: $resulttext = &mt('Changes made:').'<ul>';
11716: my %bynum;
11717: foreach my $itemid (sort(keys(%changes))) {
11718: my $position = $confhash{$itemid}{'order'};
11719: $bynum{$position} = $itemid;
11720: }
11721: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11722: my $itemid = $bynum{$pos};
11723: if (ref($confhash{$itemid}) ne 'HASH') {
11724: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11725: } else {
11726: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
11727: my $position = $pos + 1;
11728: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11729: foreach my $item ('version','lifetime') {
11730: if ($confhash{$itemid}{$item} ne '') {
11731: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11732: }
11733: }
11734: if ($encconfig{$itemid}{'key'} ne '') {
11735: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11736: }
11737: if ($encconfig{$itemid}{'secret'} ne '') {
11738: $resulttext .= '<li>'.$lt{'secret'}.': ';
11739: my $num = length($encconfig{$itemid}{'secret'});
11740: $resulttext .= ('*'x$num).'</li>';
11741: }
11742: if ($confhash{$itemid}{'mapuser'}) {
11743: my $shownmapuser;
11744: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
11745: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
11746: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
11747: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
11748: } else {
11749: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
11750: }
11751: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
11752: }
11753: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11754: my $rolemaps;
11755: foreach my $role (@ltiroles) {
11756: if ($confhash{$itemid}{'maproles'}{$role}) {
11757: $rolemaps .= (' 'x2).$role.'='.
11758: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
11759: 'Course').',';
11760: }
11761: }
11762: if ($rolemaps) {
11763: $rolemaps =~ s/,$//;
11764: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11765: }
11766: }
11767: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
11768: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
11769: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
1.325 ! raeburn 11770: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
! 11771: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
! 11772: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
! 11773: } else {
! 11774: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
! 11775: $confhash{$itemid}{'lcauth'});
! 11776: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
! 11777: $resulttext .= '; '.&mt('a randomly generated password will be created');
! 11778: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
! 11779: if ($confhash{$itemid}{'lcauthparm'} ne '') {
! 11780: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
! 11781: }
! 11782: } else {
! 11783: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
! 11784: }
! 11785: }
! 11786: $resulttext .= '</li>';
1.320 raeburn 11787: } else {
11788: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
11789: }
11790: }
1.325 ! raeburn 11791: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
! 11792: if (@{$confhash{$itemid}{'instdata'}} > 0) {
! 11793: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
! 11794: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
! 11795: } else {
! 11796: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
! 11797: }
! 11798: }
1.320 raeburn 11799: if ($confhash{$itemid}{'mapcrs'}) {
11800: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
11801: }
11802: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
11803: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
11804: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
11805: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
11806: '</li>';
11807: } else {
11808: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
11809: }
11810: }
11811: if ($confhash{$itemid}{'makecrs'}) {
11812: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
11813: } else {
11814: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
11815: }
11816: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
11817: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
11818: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
11819: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
11820: '</li>';
11821: } else {
11822: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
11823: }
11824: }
11825: if ($confhash{$itemid}{'section'}) {
11826: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
11827: $resulttext .= '<li>'.&mt('User section from standard field:').
11828: ' (course_section_sourcedid)'.'</li>';
11829: } else {
11830: $resulttext .= '<li>'.&mt('User section from:').' '.
11831: $confhash{$itemid}{'section'}.'</li>';
11832: }
11833: } else {
11834: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
11835: }
11836: foreach my $item ('passback','roster') {
11837: $resulttext .= '<li>'.$lt{$item}.' ';
11838: if ($confhash{$itemid}{$item}) {
11839: $resulttext .= &mt('Yes');
11840: } else {
11841: $resulttext .= &mt('No');
11842: }
11843: $resulttext .= '</li>';
11844: }
11845: $resulttext .= '</ul></li>';
11846: }
11847: }
11848: $resulttext .= '</ul>';
11849: } else {
11850: $resulttext = &mt('No changes made.');
11851: }
11852: } else {
11853: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11854: }
11855: if ($errors) {
11856: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11857: $errors.'</ul>';
11858: }
11859: return $resulttext;
11860: }
11861:
11862: sub get_lti_id {
11863: my ($domain,$consumer) = @_;
11864: # get lock on lti db
11865: my $lockhash = {
11866: lock => $env{'user.name'}.
11867: ':'.$env{'user.domain'},
11868: };
11869: my $tries = 0;
11870: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11871: my ($id,$error);
11872:
11873: while (($gotlock ne 'ok') && ($tries<10)) {
11874: $tries ++;
11875: sleep (0.1);
11876: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11877: }
11878: if ($gotlock eq 'ok') {
11879: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
11880: if ($currids{'lock'}) {
11881: delete($currids{'lock'});
11882: if (keys(%currids)) {
11883: my @curr = sort { $a <=> $b } keys(%currids);
11884: if ($curr[-1] =~ /^\d+$/) {
11885: $id = 1 + $curr[-1];
11886: }
11887: } else {
11888: $id = 1;
11889: }
11890: if ($id) {
11891: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
11892: $error = 'nostore';
11893: }
11894: } else {
11895: $error = 'nonumber';
11896: }
11897: }
11898: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
11899: } else {
11900: $error = 'nolock';
11901: }
11902: return ($id,$error);
11903: }
11904:
1.3 raeburn 11905: sub modify_autoenroll {
1.205 raeburn 11906: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 11907: my ($resulttext,%changes);
11908: my %currautoenroll;
11909: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
11910: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
11911: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
11912: }
11913: }
11914: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
11915: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 11916: sender => 'Sender for notification messages',
1.274 raeburn 11917: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
11918: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 11919: my @offon = ('off','on');
1.17 raeburn 11920: my $sender_uname = $env{'form.sender_uname'};
11921: my $sender_domain = $env{'form.sender_domain'};
11922: if ($sender_domain eq '') {
11923: $sender_uname = '';
11924: } elsif ($sender_uname eq '') {
11925: $sender_domain = '';
11926: }
1.129 raeburn 11927: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 11928: my $failsafe = $env{'form.autoenroll_failsafe'};
11929: $failsafe =~ s{^\s+|\s+$}{}g;
11930: if ($failsafe =~ /\D/) {
11931: undef($failsafe);
11932: }
1.1 raeburn 11933: my %autoenrollhash = (
1.129 raeburn 11934: autoenroll => { 'run' => $env{'form.autoenroll_run'},
11935: 'sender_uname' => $sender_uname,
11936: 'sender_domain' => $sender_domain,
11937: 'co-owners' => $coowners,
1.274 raeburn 11938: 'autofailsafe' => $failsafe,
1.1 raeburn 11939: }
11940: );
1.4 raeburn 11941: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
11942: $dom);
1.1 raeburn 11943: if ($putresult eq 'ok') {
11944: if (exists($currautoenroll{'run'})) {
11945: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
11946: $changes{'run'} = 1;
11947: }
11948: } elsif ($autorun) {
11949: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 11950: $changes{'run'} = 1;
1.1 raeburn 11951: }
11952: }
1.17 raeburn 11953: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 11954: $changes{'sender'} = 1;
11955: }
1.17 raeburn 11956: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 11957: $changes{'sender'} = 1;
11958: }
1.129 raeburn 11959: if ($currautoenroll{'co-owners'} ne '') {
11960: if ($currautoenroll{'co-owners'} ne $coowners) {
11961: $changes{'coowners'} = 1;
11962: }
11963: } elsif ($coowners) {
11964: $changes{'coowners'} = 1;
1.274 raeburn 11965: }
11966: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
11967: $changes{'autofailsafe'} = 1;
11968: }
1.1 raeburn 11969: if (keys(%changes) > 0) {
11970: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 11971: if ($changes{'run'}) {
1.1 raeburn 11972: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
11973: }
11974: if ($changes{'sender'}) {
1.17 raeburn 11975: if ($sender_uname eq '' || $sender_domain eq '') {
11976: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
11977: } else {
11978: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
11979: }
1.1 raeburn 11980: }
1.129 raeburn 11981: if ($changes{'coowners'}) {
11982: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
11983: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11984: if (ref($lastactref) eq 'HASH') {
11985: $lastactref->{'domainconfig'} = 1;
11986: }
1.129 raeburn 11987: }
1.274 raeburn 11988: if ($changes{'autofailsafe'}) {
11989: if ($failsafe ne '') {
1.299 raeburn 11990: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 11991: } else {
1.299 raeburn 11992: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 11993: }
11994: &Apache::lonnet::get_domain_defaults($dom,1);
11995: if (ref($lastactref) eq 'HASH') {
11996: $lastactref->{'domdefaults'} = 1;
11997: }
11998: }
1.1 raeburn 11999: $resulttext .= '</ul>';
12000: } else {
12001: $resulttext = &mt('No changes made to auto-enrollment settings');
12002: }
12003: } else {
1.11 albertel 12004: $resulttext = '<span class="LC_error">'.
12005: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12006: }
1.3 raeburn 12007: return $resulttext;
1.1 raeburn 12008: }
12009:
12010: sub modify_autoupdate {
1.3 raeburn 12011: my ($dom,%domconfig) = @_;
1.1 raeburn 12012: my ($resulttext,%currautoupdate,%fields,%changes);
12013: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
12014: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
12015: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
12016: }
12017: }
12018: my @offon = ('off','on');
12019: my %title = &Apache::lonlocal::texthash (
12020: run => 'Auto-update:',
12021: classlists => 'Updates to user information in classlists?'
12022: );
1.44 raeburn 12023: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12024: my %fieldtitles = &Apache::lonlocal::texthash (
12025: id => 'Student/Employee ID',
1.20 raeburn 12026: permanentemail => 'E-mail address',
1.1 raeburn 12027: lastname => 'Last Name',
12028: firstname => 'First Name',
12029: middlename => 'Middle Name',
1.132 raeburn 12030: generation => 'Generation',
1.1 raeburn 12031: );
1.142 raeburn 12032: $othertitle = &mt('All users');
1.1 raeburn 12033: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 12034: $othertitle = &mt('Other users');
1.1 raeburn 12035: }
12036: foreach my $key (keys(%env)) {
12037: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 12038: my ($usertype,$item) = ($1,$2);
12039: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
12040: if ($usertype eq 'default') {
12041: push(@{$fields{$1}},$2);
12042: } elsif (ref($types) eq 'ARRAY') {
12043: if (grep(/^\Q$usertype\E$/,@{$types})) {
12044: push(@{$fields{$1}},$2);
12045: }
12046: }
12047: }
1.1 raeburn 12048: }
12049: }
1.131 raeburn 12050: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
12051: @lockablenames = sort(@lockablenames);
12052: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
12053: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12054: if (@changed) {
12055: $changes{'lockablenames'} = 1;
12056: }
12057: } else {
12058: if (@lockablenames) {
12059: $changes{'lockablenames'} = 1;
12060: }
12061: }
1.1 raeburn 12062: my %updatehash = (
12063: autoupdate => { run => $env{'form.autoupdate_run'},
12064: classlists => $env{'form.classlists'},
12065: fields => {%fields},
1.131 raeburn 12066: lockablenames => \@lockablenames,
1.1 raeburn 12067: }
12068: );
12069: foreach my $key (keys(%currautoupdate)) {
12070: if (($key eq 'run') || ($key eq 'classlists')) {
12071: if (exists($updatehash{autoupdate}{$key})) {
12072: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
12073: $changes{$key} = 1;
12074: }
12075: }
12076: } elsif ($key eq 'fields') {
12077: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 12078: foreach my $item (@{$types},'default') {
1.1 raeburn 12079: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
12080: my $change = 0;
12081: foreach my $type (@{$currautoupdate{$key}{$item}}) {
12082: if (!exists($fields{$item})) {
12083: $change = 1;
1.132 raeburn 12084: last;
1.1 raeburn 12085: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 12086: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 12087: $change = 1;
1.132 raeburn 12088: last;
1.1 raeburn 12089: }
12090: }
12091: }
12092: if ($change) {
12093: push(@{$changes{$key}},$item);
12094: }
1.26 raeburn 12095: }
1.1 raeburn 12096: }
12097: }
1.131 raeburn 12098: } elsif ($key eq 'lockablenames') {
12099: if (ref($currautoupdate{$key}) eq 'ARRAY') {
12100: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12101: if (@changed) {
12102: $changes{'lockablenames'} = 1;
12103: }
12104: } else {
12105: if (@lockablenames) {
12106: $changes{'lockablenames'} = 1;
12107: }
12108: }
12109: }
12110: }
12111: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
12112: if (@lockablenames) {
12113: $changes{'lockablenames'} = 1;
1.1 raeburn 12114: }
12115: }
1.26 raeburn 12116: foreach my $item (@{$types},'default') {
12117: if (defined($fields{$item})) {
12118: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 12119: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
12120: my $change = 0;
12121: if (ref($fields{$item}) eq 'ARRAY') {
12122: foreach my $type (@{$fields{$item}}) {
12123: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
12124: $change = 1;
12125: last;
12126: }
12127: }
12128: }
12129: if ($change) {
12130: push(@{$changes{'fields'}},$item);
12131: }
12132: } else {
1.26 raeburn 12133: push(@{$changes{'fields'}},$item);
12134: }
12135: } else {
12136: push(@{$changes{'fields'}},$item);
1.1 raeburn 12137: }
12138: }
12139: }
12140: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
12141: $dom);
12142: if ($putresult eq 'ok') {
12143: if (keys(%changes) > 0) {
12144: $resulttext = &mt('Changes made:').'<ul>';
12145: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 12146: if ($key eq 'lockablenames') {
12147: $resulttext .= '<li>';
12148: if (@lockablenames) {
12149: $usertypes->{'default'} = $othertitle;
12150: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
12151: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
12152: } else {
12153: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
12154: }
12155: $resulttext .= '</li>';
12156: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 12157: foreach my $item (@{$changes{$key}}) {
12158: my @newvalues;
12159: foreach my $type (@{$fields{$item}}) {
12160: push(@newvalues,$fieldtitles{$type});
12161: }
1.3 raeburn 12162: my $newvaluestr;
12163: if (@newvalues > 0) {
12164: $newvaluestr = join(', ',@newvalues);
12165: } else {
12166: $newvaluestr = &mt('none');
1.6 raeburn 12167: }
1.1 raeburn 12168: if ($item eq 'default') {
1.26 raeburn 12169: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 12170: } else {
1.26 raeburn 12171: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 12172: }
12173: }
12174: } else {
12175: my $newvalue;
12176: if ($key eq 'run') {
12177: $newvalue = $offon[$env{'form.autoupdate_run'}];
12178: } else {
12179: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 12180: }
1.1 raeburn 12181: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
12182: }
12183: }
12184: $resulttext .= '</ul>';
12185: } else {
1.3 raeburn 12186: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 12187: }
12188: } else {
1.11 albertel 12189: $resulttext = '<span class="LC_error">'.
12190: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12191: }
1.3 raeburn 12192: return $resulttext;
1.1 raeburn 12193: }
12194:
1.125 raeburn 12195: sub modify_autocreate {
12196: my ($dom,%domconfig) = @_;
12197: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
12198: if (ref($domconfig{'autocreate'}) eq 'HASH') {
12199: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
12200: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
12201: }
12202: }
12203: my %title= ( xml => 'Auto-creation of courses in XML course description files',
12204: req => 'Auto-creation of validated requests for official courses',
12205: xmldc => 'Identity of course creator of courses from XML files',
12206: );
12207: my @types = ('xml','req');
12208: foreach my $item (@types) {
12209: $newvals{$item} = $env{'form.autocreate_'.$item};
12210: $newvals{$item} =~ s/\D//g;
12211: $newvals{$item} = 0 if ($newvals{$item} eq '');
12212: }
12213: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 12214: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 12215: unless (exists($domcoords{$newvals{'xmldc'}})) {
12216: $newvals{'xmldc'} = '';
12217: }
12218: %autocreatehash = (
12219: autocreate => { xml => $newvals{'xml'},
12220: req => $newvals{'req'},
12221: }
12222: );
12223: if ($newvals{'xmldc'} ne '') {
12224: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
12225: }
12226: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
12227: $dom);
12228: if ($putresult eq 'ok') {
12229: my @items = @types;
12230: if ($newvals{'xml'}) {
12231: push(@items,'xmldc');
12232: }
12233: foreach my $item (@items) {
12234: if (exists($currautocreate{$item})) {
12235: if ($currautocreate{$item} ne $newvals{$item}) {
12236: $changes{$item} = 1;
12237: }
12238: } elsif ($newvals{$item}) {
12239: $changes{$item} = 1;
12240: }
12241: }
12242: if (keys(%changes) > 0) {
12243: my @offon = ('off','on');
12244: $resulttext = &mt('Changes made:').'<ul>';
12245: foreach my $item (@types) {
12246: if ($changes{$item}) {
12247: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 12248: $resulttext .= '<li>'.
12249: &mt("$title{$item} set to [_1]$newtxt [_2]",
12250: '<b>','</b>').
12251: '</li>';
1.125 raeburn 12252: }
12253: }
12254: if ($changes{'xmldc'}) {
12255: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
12256: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 12257: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 12258: }
12259: $resulttext .= '</ul>';
12260: } else {
12261: $resulttext = &mt('No changes made to auto-creation settings');
12262: }
12263: } else {
12264: $resulttext = '<span class="LC_error">'.
12265: &mt('An error occurred: [_1]',$putresult).'</span>';
12266: }
12267: return $resulttext;
12268: }
12269:
1.23 raeburn 12270: sub modify_directorysrch {
1.295 raeburn 12271: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 12272: my ($resulttext,%changes);
12273: my %currdirsrch;
12274: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
12275: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
12276: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
12277: }
12278: }
1.277 raeburn 12279: my %title = ( available => 'Institutional directory search available',
12280: localonly => 'Other domains can search institution',
12281: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 12282: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 12283: searchby => 'Search types',
12284: searchtypes => 'Search latitude');
12285: my @offon = ('off','on');
1.24 raeburn 12286: my @otherdoms = ('Yes','No');
1.23 raeburn 12287:
1.25 raeburn 12288: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 12289: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
12290: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
12291:
1.44 raeburn 12292: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 12293: if (keys(%{$usertypes}) == 0) {
12294: @cansearch = ('default');
12295: } else {
12296: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
12297: foreach my $type (@{$currdirsrch{'cansearch'}}) {
12298: if (!grep(/^\Q$type\E$/,@cansearch)) {
12299: push(@{$changes{'cansearch'}},$type);
12300: }
1.23 raeburn 12301: }
1.26 raeburn 12302: foreach my $type (@cansearch) {
12303: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
12304: push(@{$changes{'cansearch'}},$type);
12305: }
1.23 raeburn 12306: }
1.26 raeburn 12307: } else {
12308: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 12309: }
12310: }
12311:
12312: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
12313: foreach my $by (@{$currdirsrch{'searchby'}}) {
12314: if (!grep(/^\Q$by\E$/,@searchby)) {
12315: push(@{$changes{'searchby'}},$by);
12316: }
12317: }
12318: foreach my $by (@searchby) {
12319: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
12320: push(@{$changes{'searchby'}},$by);
12321: }
12322: }
12323: } else {
12324: push(@{$changes{'searchby'}},@searchby);
12325: }
1.25 raeburn 12326:
12327: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
12328: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
12329: if (!grep(/^\Q$type\E$/,@searchtypes)) {
12330: push(@{$changes{'searchtypes'}},$type);
12331: }
12332: }
12333: foreach my $type (@searchtypes) {
12334: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
12335: push(@{$changes{'searchtypes'}},$type);
12336: }
12337: }
12338: } else {
12339: if (exists($currdirsrch{'searchtypes'})) {
12340: foreach my $type (@searchtypes) {
12341: if ($type ne $currdirsrch{'searchtypes'}) {
12342: push(@{$changes{'searchtypes'}},$type);
12343: }
12344: }
12345: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
12346: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12347: }
12348: } else {
12349: push(@{$changes{'searchtypes'}},@searchtypes);
12350: }
12351: }
12352:
1.23 raeburn 12353: my %dirsrch_hash = (
12354: directorysrch => { available => $env{'form.dirsrch_available'},
12355: cansearch => \@cansearch,
1.277 raeburn 12356: localonly => $env{'form.dirsrch_instlocalonly'},
12357: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12358: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 12359: searchby => \@searchby,
1.25 raeburn 12360: searchtypes => \@searchtypes,
1.23 raeburn 12361: }
12362: );
12363: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12364: $dom);
12365: if ($putresult eq 'ok') {
12366: if (exists($currdirsrch{'available'})) {
12367: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12368: $changes{'available'} = 1;
12369: }
12370: } else {
12371: if ($env{'form.dirsrch_available'} eq '1') {
12372: $changes{'available'} = 1;
12373: }
12374: }
1.277 raeburn 12375: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 12376: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12377: $changes{'lcavailable'} = 1;
12378: }
1.277 raeburn 12379: } else {
12380: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12381: $changes{'lcavailable'} = 1;
12382: }
12383: }
1.24 raeburn 12384: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 12385: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
12386: $changes{'localonly'} = 1;
12387: }
1.24 raeburn 12388: } else {
1.277 raeburn 12389: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 12390: $changes{'localonly'} = 1;
12391: }
12392: }
1.277 raeburn 12393: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 12394: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12395: $changes{'lclocalonly'} = 1;
12396: }
1.277 raeburn 12397: } else {
12398: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12399: $changes{'lclocalonly'} = 1;
12400: }
12401: }
1.23 raeburn 12402: if (keys(%changes) > 0) {
12403: $resulttext = &mt('Changes made:').'<ul>';
12404: if ($changes{'available'}) {
12405: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12406: }
1.277 raeburn 12407: if ($changes{'lcavailable'}) {
12408: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12409: }
1.24 raeburn 12410: if ($changes{'localonly'}) {
1.277 raeburn 12411: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 12412: }
1.277 raeburn 12413: if ($changes{'lclocalonly'}) {
12414: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 12415: }
1.23 raeburn 12416: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12417: my $chgtext;
1.26 raeburn 12418: if (ref($usertypes) eq 'HASH') {
12419: if (keys(%{$usertypes}) > 0) {
12420: foreach my $type (@{$types}) {
12421: if (grep(/^\Q$type\E$/,@cansearch)) {
12422: $chgtext .= $usertypes->{$type}.'; ';
12423: }
12424: }
12425: if (grep(/^default$/,@cansearch)) {
12426: $chgtext .= $othertitle;
12427: } else {
12428: $chgtext =~ s/\; $//;
12429: }
1.210 raeburn 12430: $resulttext .=
1.178 raeburn 12431: '<li>'.
12432: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12433: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12434: '</li>';
1.23 raeburn 12435: }
12436: }
12437: }
12438: if (ref($changes{'searchby'}) eq 'ARRAY') {
12439: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12440: my $chgtext;
12441: foreach my $type (@{$titleorder}) {
12442: if (grep(/^\Q$type\E$/,@searchby)) {
12443: if (defined($searchtitles->{$type})) {
12444: $chgtext .= $searchtitles->{$type}.'; ';
12445: }
12446: }
12447: }
12448: $chgtext =~ s/\; $//;
12449: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12450: }
1.25 raeburn 12451: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
12452: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
12453: my $chgtext;
12454: foreach my $type (@{$srchtypeorder}) {
12455: if (grep(/^\Q$type\E$/,@searchtypes)) {
12456: if (defined($srchtypes_desc->{$type})) {
12457: $chgtext .= $srchtypes_desc->{$type}.'; ';
12458: }
12459: }
12460: }
12461: $chgtext =~ s/\; $//;
1.178 raeburn 12462: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 12463: }
12464: $resulttext .= '</ul>';
1.295 raeburn 12465: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
12466: if (ref($lastactref) eq 'HASH') {
12467: $lastactref->{'directorysrch'} = 1;
12468: }
1.23 raeburn 12469: } else {
1.277 raeburn 12470: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 12471: }
12472: } else {
12473: $resulttext = '<span class="LC_error">'.
1.27 raeburn 12474: &mt('An error occurred: [_1]',$putresult).'</span>';
12475: }
12476: return $resulttext;
12477: }
12478:
1.28 raeburn 12479: sub modify_contacts {
1.205 raeburn 12480: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 12481: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
12482: if (ref($domconfig{'contacts'}) eq 'HASH') {
12483: foreach my $key (keys(%{$domconfig{'contacts'}})) {
12484: $currsetting{$key} = $domconfig{'contacts'}{$key};
12485: }
12486: }
1.286 raeburn 12487: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 12488: my @contacts = ('supportemail','adminemail');
1.286 raeburn 12489: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
12490: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 12491: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 12492: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 12493: foreach my $type (@mailings) {
12494: @{$newsetting{$type}} =
12495: &Apache::loncommon::get_env_multiple('form.'.$type);
12496: foreach my $item (@contacts) {
12497: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
12498: $contacts_hash{contacts}{$type}{$item} = 1;
12499: } else {
12500: $contacts_hash{contacts}{$type}{$item} = 0;
12501: }
1.289 raeburn 12502: }
1.28 raeburn 12503: $others{$type} = $env{'form.'.$type.'_others'};
12504: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 12505: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12506: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12507: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 12508: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12509: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12510: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12511: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12512: }
1.134 raeburn 12513: }
1.28 raeburn 12514: }
12515: foreach my $item (@contacts) {
12516: $to{$item} = $env{'form.'.$item};
12517: $contacts_hash{'contacts'}{$item} = $to{$item};
12518: }
1.203 raeburn 12519: foreach my $item (@toggles) {
12520: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12521: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12522: }
12523: }
1.286 raeburn 12524: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12525: foreach my $field (@{$fields}) {
12526: if (ref($possoptions->{$field}) eq 'ARRAY') {
12527: my $value = $env{'form.helpform_'.$field};
12528: $value =~ s/^\s+|\s+$//g;
12529: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 12530: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 12531: if ($field eq 'screenshot') {
12532: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12533: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 12534: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 12535: }
12536: }
12537: }
12538: }
12539: }
12540: }
1.315 raeburn 12541: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12542: my (@statuses,%usertypeshash,@overrides);
12543: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12544: @statuses = @{$types};
12545: if (ref($usertypes) eq 'HASH') {
12546: %usertypeshash = %{$usertypes};
12547: }
12548: }
12549: if (@statuses) {
12550: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12551: foreach my $type (@possoverrides) {
12552: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12553: push(@overrides,$type);
12554: }
12555: }
12556: if (@overrides) {
12557: foreach my $type (@overrides) {
12558: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12559: foreach my $item (@contacts) {
12560: if (grep(/^\Q$item\E$/,@standard)) {
12561: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12562: $newsetting{'override_'.$type}{$item} = 1;
12563: } else {
12564: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12565: $newsetting{'override_'.$type}{$item} = 0;
12566: }
12567: }
12568: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12569: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12570: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12571: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12572: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12573: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12574: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12575: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12576: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12577: }
12578: }
12579: }
12580: }
1.28 raeburn 12581: if (keys(%currsetting) > 0) {
12582: foreach my $item (@contacts) {
12583: if ($to{$item} ne $currsetting{$item}) {
12584: $changes{$item} = 1;
12585: }
12586: }
12587: foreach my $type (@mailings) {
12588: foreach my $item (@contacts) {
12589: if (ref($currsetting{$type}) eq 'HASH') {
12590: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12591: push(@{$changes{$type}},$item);
12592: }
12593: } else {
12594: push(@{$changes{$type}},@{$newsetting{$type}});
12595: }
12596: }
12597: if ($others{$type} ne $currsetting{$type}{'others'}) {
12598: push(@{$changes{$type}},'others');
12599: }
1.289 raeburn 12600: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12601: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12602: push(@{$changes{$type}},'bcc');
12603: }
1.286 raeburn 12604: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12605: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12606: push(@{$changes{$type}},'include');
12607: }
12608: }
12609: }
12610: if (ref($fields) eq 'ARRAY') {
12611: if (ref($currsetting{'helpform'}) eq 'HASH') {
12612: foreach my $field (@{$fields}) {
12613: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12614: push(@{$changes{'helpform'}},$field);
12615: }
12616: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12617: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12618: push(@{$changes{'helpform'}},'maxsize');
12619: }
12620: }
12621: }
12622: } else {
12623: foreach my $field (@{$fields}) {
12624: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12625: push(@{$changes{'helpform'}},$field);
12626: }
12627: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12628: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12629: push(@{$changes{'helpform'}},'maxsize');
12630: }
12631: }
12632: }
1.134 raeburn 12633: }
1.28 raeburn 12634: }
1.315 raeburn 12635: if (@statuses) {
12636: if (ref($currsetting{'overrides'}) eq 'HASH') {
12637: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12638: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12639: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12640: foreach my $item (@contacts,'bcc','others','include') {
12641: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12642: push(@{$changes{'overrides'}},$key);
12643: last;
12644: }
12645: }
12646: } else {
12647: push(@{$changes{'overrides'}},$key);
12648: }
12649: }
12650: }
12651: foreach my $key (@overrides) {
12652: unless (exists($currsetting{'overrides'}{$key})) {
12653: push(@{$changes{'overrides'}},$key);
12654: }
12655: }
12656: } else {
12657: foreach my $key (@overrides) {
12658: push(@{$changes{'overrides'}},$key);
12659: }
12660: }
12661: }
1.28 raeburn 12662: } else {
12663: my %default;
12664: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12665: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12666: $default{'errormail'} = 'adminemail';
12667: $default{'packagesmail'} = 'adminemail';
12668: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 12669: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12670: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12671: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 12672: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 12673: foreach my $item (@contacts) {
12674: if ($to{$item} ne $default{$item}) {
1.286 raeburn 12675: $changes{$item} = 1;
1.203 raeburn 12676: }
1.28 raeburn 12677: }
12678: foreach my $type (@mailings) {
12679: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12680: push(@{$changes{$type}},@{$newsetting{$type}});
12681: }
12682: if ($others{$type} ne '') {
12683: push(@{$changes{$type}},'others');
1.134 raeburn 12684: }
1.286 raeburn 12685: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12686: if ($bcc{$type} ne '') {
12687: push(@{$changes{$type}},'bcc');
12688: }
1.286 raeburn 12689: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12690: push(@{$changes{$type}},'include');
12691: }
1.134 raeburn 12692: }
1.28 raeburn 12693: }
1.286 raeburn 12694: if (ref($fields) eq 'ARRAY') {
12695: foreach my $field (@{$fields}) {
12696: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12697: push(@{$changes{'helpform'}},$field);
12698: }
12699: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12700: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12701: push(@{$changes{'helpform'}},'maxsize');
12702: }
12703: }
12704: }
1.289 raeburn 12705: }
1.28 raeburn 12706: }
1.203 raeburn 12707: foreach my $item (@toggles) {
12708: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12709: $changes{$item} = 1;
12710: } elsif ((!$env{'form.'.$item}) &&
12711: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12712: $changes{$item} = 1;
12713: }
12714: }
1.28 raeburn 12715: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12716: $dom);
12717: if ($putresult eq 'ok') {
12718: if (keys(%changes) > 0) {
1.205 raeburn 12719: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12720: if (ref($lastactref) eq 'HASH') {
12721: $lastactref->{'domainconfig'} = 1;
12722: }
1.28 raeburn 12723: my ($titles,$short_titles) = &contact_titles();
12724: $resulttext = &mt('Changes made:').'<ul>';
12725: foreach my $item (@contacts) {
12726: if ($changes{$item}) {
12727: $resulttext .= '<li>'.$titles->{$item}.
12728: &mt(' set to: ').
12729: '<span class="LC_cusr_emph">'.
12730: $to{$item}.'</span></li>';
12731: }
12732: }
12733: foreach my $type (@mailings) {
12734: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 12735: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 12736: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 12737: } else {
12738: $resulttext .= '<li>'.$titles->{$type}.': ';
12739: }
1.28 raeburn 12740: my @text;
12741: foreach my $item (@{$newsetting{$type}}) {
12742: push(@text,$short_titles->{$item});
12743: }
12744: if ($others{$type} ne '') {
12745: push(@text,$others{$type});
12746: }
1.286 raeburn 12747: if (@text) {
12748: $resulttext .= '<span class="LC_cusr_emph">'.
12749: join(', ',@text).'</span>';
12750: }
12751: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12752: if ($bcc{$type} ne '') {
1.286 raeburn 12753: my $bcctext;
12754: if (@text) {
1.289 raeburn 12755: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 12756: } else {
12757: $bcctext = '(Bcc)';
12758: }
12759: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12760: } elsif (!@text) {
12761: $resulttext .= &mt('No one');
12762: }
1.289 raeburn 12763: if ($includestr{$type} ne '') {
1.286 raeburn 12764: if ($includeloc{$type} eq 'b') {
12765: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12766: } elsif ($includeloc{$type} eq 's') {
12767: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12768: }
1.134 raeburn 12769: }
1.286 raeburn 12770: } elsif (!@text) {
12771: $resulttext .= &mt('No recipients');
1.134 raeburn 12772: }
12773: $resulttext .= '</li>';
1.28 raeburn 12774: }
12775: }
1.315 raeburn 12776: if (ref($changes{'overrides'}) eq 'ARRAY') {
12777: my @deletions;
12778: foreach my $type (@{$changes{'overrides'}}) {
12779: if ($usertypeshash{$type}) {
12780: if (grep(/^\Q$type\E/,@overrides)) {
12781: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12782: $usertypeshash{$type}).'<ul><li>';
12783: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12784: my @text;
12785: foreach my $item (@contacts) {
12786: if ($newsetting{'override_'.$type}{$item}) {
12787: push(@text,$short_titles->{$item});
12788: }
12789: }
12790: if ($newsetting{'override_'.$type}{'others'} ne '') {
12791: push(@text,$newsetting{'override_'.$type}{'others'});
12792: }
12793:
12794: if (@text) {
12795: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12796: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12797: }
12798: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12799: my $bcctext;
12800: if (@text) {
12801: $bcctext = ' '.&mt('with Bcc to');
12802: } else {
12803: $bcctext = '(Bcc)';
12804: }
12805: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12806: } elsif (!@text) {
12807: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12808: }
12809: $resulttext .= '</li>';
12810: if ($newsetting{'override_'.$type}{'include'} ne '') {
12811: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12812: if ($loc eq 'b') {
12813: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12814: } elsif ($loc eq 's') {
12815: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12816: }
12817: }
12818: }
12819: $resulttext .= '</li></ul></li>';
12820: } else {
12821: push(@deletions,$usertypeshash{$type});
12822: }
12823: }
12824: }
12825: if (@deletions) {
12826: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12827: join(', ',@deletions)).'</li>';
12828: }
12829: }
1.203 raeburn 12830: my @offon = ('off','on');
12831: if ($changes{'reporterrors'}) {
12832: $resulttext .= '<li>'.
12833: &mt('E-mail error reports to [_1] set to "'.
12834: $offon[$env{'form.reporterrors'}].'".',
12835: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12836: &mt('LON-CAPA core group - MSU'),600,500)).
12837: '</li>';
12838: }
12839: if ($changes{'reportupdates'}) {
12840: $resulttext .= '<li>'.
12841: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12842: $offon[$env{'form.reportupdates'}].'".',
12843: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12844: &mt('LON-CAPA core group - MSU'),600,500)).
12845: '</li>';
12846: }
1.286 raeburn 12847: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12848: my (@optional,@required,@unused,$maxsizechg);
12849: foreach my $field (@{$changes{'helpform'}}) {
12850: if ($field eq 'maxsize') {
12851: $maxsizechg = 1;
12852: next;
12853: }
12854: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 12855: push(@optional,$field);
1.286 raeburn 12856: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12857: push(@unused,$field);
12858: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 12859: push(@required,$field);
1.286 raeburn 12860: }
12861: }
12862: if (@optional) {
12863: $resulttext .= '<li>'.
12864: &mt('Help form fields changed to "Optional": [_1].',
12865: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12866: '</li>';
12867: }
12868: if (@required) {
12869: $resulttext .= '<li>'.
12870: &mt('Help form fields changed to "Required": [_1].',
12871: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12872: '</li>';
12873: }
12874: if (@unused) {
12875: $resulttext .= '<li>'.
12876: &mt('Help form fields changed to "Not shown": [_1].',
12877: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12878: '</li>';
12879: }
12880: if ($maxsizechg) {
12881: $resulttext .= '<li>'.
12882: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12883: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12884: '</li>';
12885: }
12886: }
1.28 raeburn 12887: $resulttext .= '</ul>';
12888: } else {
1.288 raeburn 12889: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 12890: }
12891: } else {
12892: $resulttext = '<span class="LC_error">'.
12893: &mt('An error occurred: [_1].',$putresult).'</span>';
12894: }
12895: return $resulttext;
12896: }
12897:
12898: sub modify_usercreation {
1.27 raeburn 12899: my ($dom,%domconfig) = @_;
1.224 raeburn 12900: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 12901: my $warningmsg;
1.27 raeburn 12902: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12903: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 12904: if ($key eq 'cancreate') {
12905: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
12906: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 12907: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
12908: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12909: } else {
1.224 raeburn 12910: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12911: }
12912: }
12913: }
12914: } elsif ($key eq 'email_rule') {
12915: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
12916: } else {
12917: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
12918: }
1.27 raeburn 12919: }
12920: }
12921: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 12922: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 12923: my @contexts = ('author','course','requestcrs');
1.34 raeburn 12924: foreach my $item(@contexts) {
1.224 raeburn 12925: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 12926: }
1.34 raeburn 12927: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12928: foreach my $item (@contexts) {
1.224 raeburn 12929: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
12930: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 12931: }
1.27 raeburn 12932: }
1.34 raeburn 12933: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
12934: foreach my $item (@contexts) {
1.43 raeburn 12935: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 12936: if ($cancreate{$item} ne 'any') {
12937: push(@{$changes{'cancreate'}},$item);
12938: }
12939: } else {
12940: if ($cancreate{$item} ne 'none') {
12941: push(@{$changes{'cancreate'}},$item);
12942: }
1.27 raeburn 12943: }
12944: }
12945: } else {
1.43 raeburn 12946: foreach my $item (@contexts) {
1.34 raeburn 12947: push(@{$changes{'cancreate'}},$item);
12948: }
1.27 raeburn 12949: }
1.34 raeburn 12950:
1.27 raeburn 12951: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
12952: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
12953: if (!grep(/^\Q$type\E$/,@username_rule)) {
12954: push(@{$changes{'username_rule'}},$type);
12955: }
12956: }
12957: foreach my $type (@username_rule) {
12958: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
12959: push(@{$changes{'username_rule'}},$type);
12960: }
12961: }
12962: } else {
12963: push(@{$changes{'username_rule'}},@username_rule);
12964: }
12965:
1.32 raeburn 12966: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
12967: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
12968: if (!grep(/^\Q$type\E$/,@id_rule)) {
12969: push(@{$changes{'id_rule'}},$type);
12970: }
12971: }
12972: foreach my $type (@id_rule) {
12973: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
12974: push(@{$changes{'id_rule'}},$type);
12975: }
12976: }
12977: } else {
12978: push(@{$changes{'id_rule'}},@id_rule);
12979: }
12980:
1.43 raeburn 12981: my @authen_contexts = ('author','course','domain');
1.325 ! raeburn 12982: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 12983: my %authhash;
1.43 raeburn 12984: foreach my $item (@authen_contexts) {
1.28 raeburn 12985: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
12986: foreach my $auth (@authtypes) {
12987: if (grep(/^\Q$auth\E$/,@authallowed)) {
12988: $authhash{$item}{$auth} = 1;
12989: } else {
12990: $authhash{$item}{$auth} = 0;
12991: }
12992: }
12993: }
12994: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 12995: foreach my $item (@authen_contexts) {
1.28 raeburn 12996: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
12997: foreach my $auth (@authtypes) {
12998: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
12999: push(@{$changes{'authtypes'}},$item);
13000: last;
13001: }
13002: }
13003: }
13004: }
13005: } else {
1.43 raeburn 13006: foreach my $item (@authen_contexts) {
1.28 raeburn 13007: push(@{$changes{'authtypes'}},$item);
13008: }
13009: }
13010:
1.224 raeburn 13011: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13012: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13013: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13014: $save_usercreate{'id_rule'} = \@id_rule;
13015: $save_usercreate{'username_rule'} = \@username_rule,
13016: $save_usercreate{'authtypes'} = \%authhash;
13017:
1.27 raeburn 13018: my %usercreation_hash = (
1.224 raeburn 13019: usercreation => \%save_usercreate,
13020: );
1.27 raeburn 13021:
13022: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13023: $dom);
1.50 raeburn 13024:
1.224 raeburn 13025: if ($putresult eq 'ok') {
13026: if (keys(%changes) > 0) {
13027: $resulttext = &mt('Changes made:').'<ul>';
13028: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13029: my %lt = &usercreation_types();
13030: foreach my $type (@{$changes{'cancreate'}}) {
13031: my $chgtext = $lt{$type}.', ';
13032: if ($cancreate{$type} eq 'none') {
13033: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13034: } elsif ($cancreate{$type} eq 'any') {
13035: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13036: } elsif ($cancreate{$type} eq 'official') {
13037: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13038: } elsif ($cancreate{$type} eq 'unofficial') {
13039: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13040: }
13041: $resulttext .= '<li>'.$chgtext.'</li>';
13042: }
13043: }
13044: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13045: my ($rules,$ruleorder) =
13046: &Apache::lonnet::inst_userrules($dom,'username');
13047: my $chgtext = '<ul>';
13048: foreach my $type (@username_rule) {
13049: if (ref($rules->{$type}) eq 'HASH') {
13050: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13051: }
13052: }
13053: $chgtext .= '</ul>';
13054: if (@username_rule > 0) {
13055: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13056: } else {
13057: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13058: }
13059: }
13060: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13061: my ($idrules,$idruleorder) =
13062: &Apache::lonnet::inst_userrules($dom,'id');
13063: my $chgtext = '<ul>';
13064: foreach my $type (@id_rule) {
13065: if (ref($idrules->{$type}) eq 'HASH') {
13066: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13067: }
13068: }
13069: $chgtext .= '</ul>';
13070: if (@id_rule > 0) {
13071: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13072: } else {
13073: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13074: }
13075: }
13076: my %authname = &authtype_names();
13077: my %context_title = &context_names();
13078: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13079: my $chgtext = '<ul>';
13080: foreach my $type (@{$changes{'authtypes'}}) {
13081: my @allowed;
13082: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13083: foreach my $auth (@authtypes) {
13084: if ($authhash{$type}{$auth}) {
13085: push(@allowed,$authname{$auth});
13086: }
13087: }
13088: if (@allowed > 0) {
13089: $chgtext .= join(', ',@allowed).'</li>';
13090: } else {
13091: $chgtext .= &mt('none').'</li>';
13092: }
13093: }
13094: $chgtext .= '</ul>';
13095: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13096: $resulttext .= '</li>';
13097: }
13098: $resulttext .= '</ul>';
13099: } else {
13100: $resulttext = &mt('No changes made to user creation settings');
13101: }
13102: } else {
13103: $resulttext = '<span class="LC_error">'.
13104: &mt('An error occurred: [_1]',$putresult).'</span>';
13105: }
13106: if ($warningmsg ne '') {
13107: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13108: }
13109: return $resulttext;
13110: }
13111:
13112: sub modify_selfcreation {
1.305 raeburn 13113: my ($dom,$lastactref,%domconfig) = @_;
13114: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13115: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13116: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 13117: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13118: if (ref($typesref) eq 'ARRAY') {
13119: @types = @{$typesref};
13120: }
13121: if (ref($usertypesref) eq 'HASH') {
13122: %usertypes = %{$usertypesref};
1.228 raeburn 13123: }
1.303 raeburn 13124: $usertypes{'default'} = $othertitle;
1.224 raeburn 13125: #
13126: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13127: #
13128: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13129: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13130: if ($key eq 'cancreate') {
13131: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13132: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13133: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 13134: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13135: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13136: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13137: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 13138: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 13139: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13140: } else {
13141: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13142: }
13143: }
13144: }
13145: } elsif ($key eq 'email_rule') {
13146: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13147: } else {
13148: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13149: }
13150: }
13151: }
13152: #
13153: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13154: #
13155: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13156: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13157: if ($key eq 'selfcreate') {
13158: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13159: } else {
13160: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13161: }
13162: }
13163: }
1.305 raeburn 13164: #
13165: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13166: #
13167: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13168: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13169: if ($key eq 'inststatusguest') {
13170: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13171: } else {
13172: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13173: }
13174: }
13175: }
1.224 raeburn 13176:
13177: my @contexts = ('selfcreate');
13178: @{$cancreate{'selfcreate'}} = ();
13179: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 13180: if (@types) {
13181: @{$cancreate{'statustocreate'}} = ();
13182: }
1.236 raeburn 13183: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 13184: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 13185: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 13186: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 13187: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13188: my %selfcreatetypes = (
13189: sso => 'users authenticated by institutional single sign on',
13190: login => 'users authenticated by institutional log-in',
1.303 raeburn 13191: email => 'users verified by e-mail',
1.50 raeburn 13192: );
1.224 raeburn 13193: #
13194: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13195: # is permitted.
13196: #
1.305 raeburn 13197: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 13198:
1.305 raeburn 13199: my (@statuses,%email_rule);
1.228 raeburn 13200: foreach my $item ('login','sso','email') {
1.224 raeburn 13201: if ($item eq 'email') {
1.236 raeburn 13202: if ($env{'form.cancreate_email'}) {
1.305 raeburn 13203: if (@types) {
13204: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13205: foreach my $status (@poss_statuses) {
13206: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13207: push(@statuses,$status);
13208: }
13209: }
13210: $save_inststatus{'inststatusguest'} = \@statuses;
13211: } else {
13212: push(@statuses,'default');
13213: }
13214: if (@statuses) {
13215: my %curr_rule;
13216: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13217: foreach my $type (@statuses) {
13218: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 13219: }
1.305 raeburn 13220: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13221: foreach my $type (@statuses) {
13222: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13223: }
13224: }
13225: push(@{$cancreate{'selfcreate'}},'email');
13226: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13227: my %curremaildom;
13228: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13229: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13230: }
13231: foreach my $type (@statuses) {
13232: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13233: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13234: }
13235: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13236: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13237: }
13238: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13239: #
13240: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13241: #
13242: my $chosen = $1;
13243: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13244: my $emaildom;
13245: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13246: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13247: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13248: if (ref($curremaildom{$type}) eq 'HASH') {
13249: if (exists($curremaildom{$type}{$chosen})) {
13250: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13251: push(@{$changes{'cancreate'}},'emaildomain');
13252: }
13253: } elsif ($emaildom ne '') {
13254: push(@{$changes{'cancreate'}},'emaildomain');
13255: }
13256: } elsif ($emaildom ne '') {
13257: push(@{$changes{'cancreate'}},'emaildomain');
13258: }
13259: }
13260: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13261: } elsif ($chosen eq 'custom') {
13262: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13263: $email_rule{$type} = [];
13264: if (ref($emailrules) eq 'HASH') {
13265: foreach my $rule (@possemail_rules) {
13266: if (exists($emailrules->{$rule})) {
13267: push(@{$email_rule{$type}},$rule);
13268: }
13269: }
13270: }
13271: if (@{$email_rule{$type}}) {
13272: $cancreate{'emailoptions'}{$type} = 'custom';
13273: if (ref($curr_rule{$type}) eq 'ARRAY') {
13274: if (@{$curr_rule{$type}} > 0) {
13275: foreach my $rule (@{$curr_rule{$type}}) {
13276: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13277: push(@{$changes{'email_rule'}},$type);
13278: }
13279: }
13280: }
13281: foreach my $type (@{$email_rule{$type}}) {
13282: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13283: push(@{$changes{'email_rule'}},$type);
13284: }
13285: }
13286: } else {
13287: push(@{$changes{'email_rule'}},$type);
13288: }
13289: }
13290: } else {
13291: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13292: }
13293: }
13294: }
13295: if (@types) {
13296: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13297: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13298: if (@changed) {
13299: push(@{$changes{'inststatus'}},'inststatusguest');
13300: }
13301: } else {
13302: push(@{$changes{'inststatus'}},'inststatusguest');
13303: }
13304: }
13305: } else {
13306: delete($env{'form.cancreate_email'});
13307: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13308: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13309: push(@{$changes{'inststatus'}},'inststatusguest');
13310: }
13311: }
13312: }
13313: } else {
13314: $save_inststatus{'inststatusguest'} = [];
13315: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13316: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13317: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 13318: }
13319: }
1.224 raeburn 13320: }
13321: } else {
13322: if ($env{'form.cancreate_'.$item}) {
13323: push(@{$cancreate{'selfcreate'}},$item);
13324: }
13325: }
13326: }
1.305 raeburn 13327: my (%userinfo,%savecaptcha);
1.224 raeburn 13328: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13329: #
1.228 raeburn 13330: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13331: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 13332: #
1.236 raeburn 13333:
1.244 raeburn 13334: if ($env{'form.cancreate_email'}) {
1.228 raeburn 13335: push(@contexts,'emailusername');
1.305 raeburn 13336: if (@statuses) {
13337: foreach my $type (@statuses) {
1.228 raeburn 13338: if (ref($infofields) eq 'ARRAY') {
13339: foreach my $field (@{$infofields}) {
13340: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13341: $cancreate{'emailusername'}{$type}{$field} = $1;
13342: }
13343: }
1.224 raeburn 13344: }
13345: }
13346: }
13347: #
13348: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 13349: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 13350: #
13351:
13352: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13353: @approvalnotify = sort(@approvalnotify);
13354: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13355: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13356: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13357: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13358: push(@{$changes{'cancreate'}},'notify');
13359: }
13360: } else {
13361: if ($cancreate{'notify'}{'approval'}) {
13362: push(@{$changes{'cancreate'}},'notify');
13363: }
13364: }
13365: } elsif ($cancreate{'notify'}{'approval'}) {
13366: push(@{$changes{'cancreate'}},'notify');
13367: }
13368:
13369: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13370: }
13371: #
1.236 raeburn 13372: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 13373: # institutional log-in.
13374: #
13375: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13376: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13377: ($domdefaults{'auth_def'} eq 'localauth'))) {
13378: $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.').' '.
13379: &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.');
13380: }
13381: }
13382: my @fields = ('lastname','firstname','middlename','generation',
13383: 'permanentemail','id');
1.240 raeburn 13384: my @shibfields = (@fields,'inststatus');
1.224 raeburn 13385: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13386: #
13387: # Where usernames may created for institutional log-in and/or institutional single sign on:
13388: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13389: # may self-create accounts
13390: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13391: # which the user may supply, if institutional data is unavailable.
13392: #
13393: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 13394: if (@types) {
1.305 raeburn 13395: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13396: push(@contexts,'statustocreate');
1.303 raeburn 13397: foreach my $type (@types) {
1.224 raeburn 13398: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13399: foreach my $field (@fields) {
13400: if (grep(/^\Q$field\E$/,@modifiable)) {
13401: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13402: } else {
13403: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13404: }
13405: }
13406: }
13407: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 13408: foreach my $type (@types) {
1.224 raeburn 13409: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13410: foreach my $field (@fields) {
13411: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13412: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13413: push(@{$changes{'selfcreate'}},$type);
13414: last;
13415: }
13416: }
13417: }
13418: }
13419: } else {
1.303 raeburn 13420: foreach my $type (@types) {
1.224 raeburn 13421: push(@{$changes{'selfcreate'}},$type);
13422: }
13423: }
13424: }
1.240 raeburn 13425: foreach my $field (@shibfields) {
13426: if ($env{'form.shibenv_'.$field} ne '') {
13427: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13428: }
13429: }
13430: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13431: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13432: foreach my $field (@shibfields) {
13433: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13434: push(@{$changes{'cancreate'}},'shibenv');
13435: }
13436: }
13437: } else {
13438: foreach my $field (@shibfields) {
13439: if ($env{'form.shibenv_'.$field}) {
13440: push(@{$changes{'cancreate'}},'shibenv');
13441: last;
13442: }
13443: }
13444: }
13445: }
1.224 raeburn 13446: }
13447: foreach my $item (@contexts) {
13448: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13449: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13450: if (ref($cancreate{$item}) eq 'ARRAY') {
13451: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13452: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13453: push(@{$changes{'cancreate'}},$item);
13454: }
13455: }
13456: }
13457: }
13458: if (ref($cancreate{$item}) eq 'ARRAY') {
13459: foreach my $type (@{$cancreate{$item}}) {
13460: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13461: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13462: push(@{$changes{'cancreate'}},$item);
13463: }
13464: }
13465: }
13466: }
13467: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13468: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 13469: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13470: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13471: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13472: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13473: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13474: push(@{$changes{'cancreate'}},$item);
13475: }
13476: }
13477: }
1.305 raeburn 13478: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13479: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13480: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13481: push(@{$changes{'cancreate'}},$item);
13482: }
1.224 raeburn 13483: }
13484: }
13485: }
1.305 raeburn 13486: foreach my $type (keys(%{$cancreate{$item}})) {
13487: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13488: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13489: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13490: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13491: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13492: push(@{$changes{'cancreate'}},$item);
13493: }
13494: }
13495: } else {
13496: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13497: push(@{$changes{'cancreate'}},$item);
13498: }
13499: }
13500: }
1.305 raeburn 13501: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13502: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13503: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13504: push(@{$changes{'cancreate'}},$item);
13505: }
1.224 raeburn 13506: }
13507: }
13508: }
13509: }
13510: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13511: if (ref($cancreate{$item}) eq 'ARRAY') {
13512: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13513: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13514: push(@{$changes{'cancreate'}},$item);
13515: }
13516: }
1.305 raeburn 13517: }
13518: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13519: if (ref($cancreate{$item}) eq 'HASH') {
13520: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13521: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 13522: }
13523: }
13524: } elsif ($item eq 'emailusername') {
1.228 raeburn 13525: if (ref($cancreate{$item}) eq 'HASH') {
13526: foreach my $type (keys(%{$cancreate{$item}})) {
13527: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13528: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13529: if ($cancreate{$item}{$type}{$field}) {
13530: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13531: push(@{$changes{'cancreate'}},$item);
13532: }
13533: last;
13534: }
13535: }
13536: }
13537: }
1.224 raeburn 13538: }
13539: }
13540: }
13541: #
13542: # Populate %save_usercreate hash with updates to self-creation configuration.
13543: #
13544: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13545: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 13546: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 13547: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13548: if (ref($cancreate{'notify'}) eq 'HASH') {
13549: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13550: }
1.236 raeburn 13551: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13552: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13553: }
1.303 raeburn 13554: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13555: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13556: }
1.305 raeburn 13557: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13558: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13559: }
1.303 raeburn 13560: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13561: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13562: }
1.224 raeburn 13563: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13564: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13565: }
1.240 raeburn 13566: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13567: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13568: }
1.224 raeburn 13569: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 13570: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 13571:
13572: my %userconfig_hash = (
13573: usercreation => \%save_usercreate,
13574: usermodification => \%save_usermodify,
1.305 raeburn 13575: inststatus => \%save_inststatus,
1.224 raeburn 13576: );
1.305 raeburn 13577:
1.224 raeburn 13578: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13579: $dom);
13580: #
1.305 raeburn 13581: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 13582: #
1.27 raeburn 13583: if ($putresult eq 'ok') {
13584: if (keys(%changes) > 0) {
13585: $resulttext = &mt('Changes made:').'<ul>';
13586: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 13587: my %lt = &selfcreation_types();
1.34 raeburn 13588: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 13589: my $chgtext = '';
1.45 raeburn 13590: if ($type eq 'selfcreate') {
1.50 raeburn 13591: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 13592: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13593: } else {
1.224 raeburn 13594: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13595: '<ul>';
1.50 raeburn 13596: foreach my $case (@{$cancreate{$type}}) {
13597: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13598: }
13599: $chgtext .= '</ul>';
1.100 raeburn 13600: if (ref($cancreate{$type}) eq 'ARRAY') {
13601: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13602: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13603: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 13604: $chgtext .= '<span class="LC_warning">'.
13605: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13606: '</span><br />';
13607: }
13608: }
13609: }
13610: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 13611: if (!@statuses) {
13612: $chgtext .= '<span class="LC_warning">'.
13613: &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.").
13614: '</span><br />';
1.303 raeburn 13615:
1.100 raeburn 13616: }
13617: }
13618: }
1.43 raeburn 13619: }
1.240 raeburn 13620: } elsif ($type eq 'shibenv') {
13621: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 13622: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 13623: } else {
13624: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13625: '<ul>';
13626: foreach my $field (@shibfields) {
13627: next if ($cancreate{$type}{$field} eq '');
13628: if ($field eq 'inststatus') {
13629: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13630: } else {
13631: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13632: }
13633: }
13634: $chgtext .= '</ul>';
1.303 raeburn 13635: }
1.93 raeburn 13636: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13637: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13638: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13639: if (@{$cancreate{'selfcreate'}} > 0) {
13640: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13641: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13642: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 13643: $chgtext .= '<br />'.
13644: '<span class="LC_warning">'.
13645: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13646: '</span>';
13647: }
1.303 raeburn 13648: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13649: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13650: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13651: } else {
13652: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13653: }
13654: $chgtext .= '<ul>';
13655: foreach my $case (@{$cancreate{$type}}) {
13656: if ($case eq 'default') {
13657: $chgtext .= '<li>'.$othertitle.'</li>';
13658: } else {
1.303 raeburn 13659: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13660: }
13661: }
1.100 raeburn 13662: $chgtext .= '</ul>';
13663: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 13664: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 13665: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13666: '</span>';
1.100 raeburn 13667: }
13668: }
13669: } else {
13670: if (@{$cancreate{$type}} == 0) {
13671: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13672: } else {
13673: $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 13674: }
13675: }
1.303 raeburn 13676: $chgtext .= '<br />';
1.93 raeburn 13677: }
1.236 raeburn 13678: } elsif ($type eq 'selfcreateprocessing') {
13679: my %choices = &Apache::lonlocal::texthash (
13680: automatic => 'Automatic approval',
13681: approval => 'Queued for approval',
13682: );
1.305 raeburn 13683: if (@types) {
13684: if (@statuses) {
1.303 raeburn 13685: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 13686: '<ul>';
1.305 raeburn 13687: foreach my $status (@statuses) {
13688: if ($status eq 'default') {
13689: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13690: } else {
1.305 raeburn 13691: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13692: }
13693: }
13694: $chgtext .= '</ul>';
13695: }
13696: } else {
13697: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13698: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13699: }
13700: } elsif ($type eq 'emailverified') {
13701: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 13702: all => 'Same as e-mail',
13703: first => 'Omit @domain',
13704: free => 'Free to choose',
1.303 raeburn 13705: );
1.305 raeburn 13706: if (@types) {
13707: if (@statuses) {
1.303 raeburn 13708: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13709: '<ul>';
1.305 raeburn 13710: foreach my $status (@statuses) {
1.303 raeburn 13711: if ($type eq 'default') {
1.305 raeburn 13712: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13713: } else {
1.305 raeburn 13714: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13715: }
13716: }
13717: $chgtext .= '</ul>';
13718: }
13719: } else {
1.305 raeburn 13720: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 13721: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 13722: }
1.305 raeburn 13723: } elsif ($type eq 'emailoptions') {
13724: my %options = &Apache::lonlocal::texthash (
13725: any => 'Any e-mail',
13726: inst => 'Institutional only',
13727: noninst => 'Non-institutional only',
13728: custom => 'Custom restrictions',
13729: );
13730: if (@types) {
13731: if (@statuses) {
13732: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13733: '<ul>';
13734: foreach my $status (@statuses) {
13735: if ($type eq 'default') {
13736: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13737: } else {
13738: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 13739: }
13740: }
1.305 raeburn 13741: $chgtext .= '</ul>';
13742: }
13743: } else {
13744: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13745: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13746: } else {
13747: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13748: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 13749: }
1.305 raeburn 13750: }
13751: } elsif ($type eq 'emaildomain') {
13752: my $output;
13753: if (@statuses) {
13754: foreach my $type (@statuses) {
13755: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13756: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13757: if ($type eq 'default') {
13758: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13759: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13760: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13761: } else {
13762: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13763: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13764: }
1.303 raeburn 13765: } else {
1.305 raeburn 13766: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13767: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13768: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13769: } else {
13770: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13771: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13772: }
1.303 raeburn 13773: }
1.305 raeburn 13774: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13775: if ($type eq 'default') {
13776: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13777: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13778: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13779: } else {
13780: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13781: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13782: }
1.303 raeburn 13783: } else {
1.305 raeburn 13784: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13785: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13786: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13787: } else {
13788: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13789: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13790: }
1.303 raeburn 13791: }
13792: }
13793: }
13794: }
1.305 raeburn 13795: }
13796: if ($output ne '') {
13797: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
13798: '<ul>'.$output.'</ul>';
1.236 raeburn 13799: }
1.165 raeburn 13800: } elsif ($type eq 'captcha') {
1.224 raeburn 13801: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 13802: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
13803: } else {
13804: my %captchas = &captcha_phrases();
1.224 raeburn 13805: if ($captchas{$savecaptcha{$type}}) {
13806: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 13807: } else {
1.210 raeburn 13808: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 13809: }
13810: }
13811: } elsif ($type eq 'recaptchakeys') {
13812: my ($privkey,$pubkey);
1.224 raeburn 13813: if (ref($savecaptcha{$type}) eq 'HASH') {
13814: $pubkey = $savecaptcha{$type}{'public'};
13815: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 13816: }
13817: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
13818: if (!$pubkey) {
13819: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
13820: } else {
13821: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13822: }
13823: if (!$privkey) {
13824: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
13825: } else {
13826: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
13827: }
13828: $chgtext .= '</ul>';
1.269 raeburn 13829: } elsif ($type eq 'recaptchaversion') {
13830: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 13831: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 13832: }
1.224 raeburn 13833: } elsif ($type eq 'emailusername') {
13834: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 13835: if (@statuses) {
13836: foreach my $type (@statuses) {
1.228 raeburn 13837: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
13838: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 13839: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 13840: '<ul>';
13841: foreach my $field (@{$infofields}) {
13842: if ($cancreate{'emailusername'}{$type}{$field}) {
13843: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
13844: }
13845: }
1.245 raeburn 13846: $chgtext .= '</ul>';
13847: } else {
1.303 raeburn 13848: $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 13849: }
13850: } else {
1.303 raeburn 13851: $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 13852: }
13853: }
13854: }
13855: }
13856: } elsif ($type eq 'notify') {
1.303 raeburn 13857: my $numapprove = 0;
1.224 raeburn 13858: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13859: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
13860: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 13861: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
13862: $numapprove ++;
1.224 raeburn 13863: }
13864: }
1.43 raeburn 13865: }
1.303 raeburn 13866: unless ($numapprove) {
13867: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
13868: }
1.34 raeburn 13869: }
1.224 raeburn 13870: if ($chgtext) {
13871: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 13872: }
13873: }
13874: }
1.305 raeburn 13875: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 13876: my ($emailrules,$emailruleorder) =
13877: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 13878: foreach my $type (@{$changes{'email_rule'}}) {
13879: if (ref($email_rule{$type}) eq 'ARRAY') {
13880: my $chgtext = '<ul>';
13881: foreach my $rule (@{$email_rule{$type}}) {
13882: if (ref($emailrules->{$rule}) eq 'HASH') {
13883: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
13884: }
13885: }
13886: $chgtext .= '</ul>';
1.310 raeburn 13887: my $typename;
1.305 raeburn 13888: if (@types) {
13889: if ($type eq 'default') {
13890: $typename = $othertitle;
13891: } else {
13892: $typename = $usertypes{$type};
13893: }
13894: $chgtext .= &mt('(Affiliation: [_1])',$typename);
13895: }
13896: if (@{$email_rule{$type}} > 0) {
13897: $resulttext .= '<li>'.
13898: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
13899: $usertypes{$type}).
13900: $chgtext.
13901: '</li>';
13902: } else {
13903: $resulttext .= '<li>'.
1.310 raeburn 13904: &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 13905: '</li>'.
1.310 raeburn 13906: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 13907: }
1.43 raeburn 13908: }
13909: }
1.305 raeburn 13910: }
13911: if (ref($changes{'inststatus'}) eq 'ARRAY') {
13912: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
13913: if (@{$save_inststatus{'inststatusguest'}} > 0) {
13914: my $chgtext = '<ul>';
13915: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
13916: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
13917: }
13918: $chgtext .= '</ul>';
13919: $resulttext .= '<li>'.
13920: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
13921: $chgtext.
13922: '</li>';
13923: } else {
13924: $resulttext .= '<li>'.
13925: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
13926: '</li>';
13927: }
1.43 raeburn 13928: }
13929: }
1.224 raeburn 13930: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
13931: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
13932: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13933: foreach my $type (@{$changes{'selfcreate'}}) {
13934: my $typename = $type;
1.303 raeburn 13935: if (keys(%usertypes) > 0) {
13936: if ($usertypes{$type} ne '') {
13937: $typename = $usertypes{$type};
1.224 raeburn 13938: }
13939: }
13940: my @modifiable;
13941: $resulttext .= '<li>'.
13942: &mt('Self-creation of account by users with status: [_1]',
13943: '<span class="LC_cusr_emph">'.$typename.'</span>').
13944: ' - '.&mt('modifiable fields (if institutional data blank): ');
13945: foreach my $field (@fields) {
13946: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
13947: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 13948: }
13949: }
1.224 raeburn 13950: if (@modifiable > 0) {
13951: $resulttext .= join(', ',@modifiable);
1.43 raeburn 13952: } else {
1.224 raeburn 13953: $resulttext .= &mt('none');
1.43 raeburn 13954: }
1.224 raeburn 13955: $resulttext .= '</li>';
1.28 raeburn 13956: }
1.224 raeburn 13957: $resulttext .= '</ul></li>';
1.28 raeburn 13958: }
1.27 raeburn 13959: $resulttext .= '</ul>';
1.305 raeburn 13960: my $cachetime = 24*60*60;
13961: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
13962: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13963: if (ref($lastactref) eq 'HASH') {
13964: $lastactref->{'domdefaults'} = 1;
13965: }
1.27 raeburn 13966: } else {
1.224 raeburn 13967: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 13968: }
13969: } else {
13970: $resulttext = '<span class="LC_error">'.
1.23 raeburn 13971: &mt('An error occurred: [_1]',$putresult).'</span>';
13972: }
1.43 raeburn 13973: if ($warningmsg ne '') {
13974: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13975: }
1.23 raeburn 13976: return $resulttext;
13977: }
13978:
1.165 raeburn 13979: sub process_captcha {
13980: my ($container,$changes,$newsettings,$current) = @_;
13981: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
13982: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
13983: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
13984: $newsettings->{'captcha'} = 'original';
13985: }
13986: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 13987: if ($container eq 'cancreate') {
1.169 raeburn 13988: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13989: push(@{$changes->{'cancreate'}},'captcha');
13990: } elsif (!defined($changes->{'cancreate'})) {
13991: $changes->{'cancreate'} = ['captcha'];
13992: }
13993: } else {
13994: $changes->{'captcha'} = 1;
1.165 raeburn 13995: }
13996: }
1.269 raeburn 13997: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 13998: if ($newsettings->{'captcha'} eq 'recaptcha') {
13999: $newpub = $env{'form.'.$container.'_recaptchapub'};
14000: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 14001: $newpub =~ s/[^\w\-]//g;
14002: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 14003: $newsettings->{'recaptchakeys'} = {
14004: public => $newpub,
14005: private => $newpriv,
14006: };
1.269 raeburn 14007: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14008: $newversion =~ s/\D//g;
14009: if ($newversion ne '2') {
14010: $newversion = 1;
14011: }
14012: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 14013: }
14014: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
14015: $currpub = $current->{'recaptchakeys'}{'public'};
14016: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 14017: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14018: $newsettings->{'recaptchakeys'} = {
14019: public => '',
14020: private => '',
14021: }
14022: }
1.165 raeburn 14023: }
1.269 raeburn 14024: if ($current->{'captcha'} eq 'recaptcha') {
14025: $currversion = $current->{'recaptchaversion'};
14026: if ($currversion ne '2') {
14027: $currversion = 1;
14028: }
14029: }
14030: if ($currversion ne $newversion) {
14031: if ($container eq 'cancreate') {
14032: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14033: push(@{$changes->{'cancreate'}},'recaptchaversion');
14034: } elsif (!defined($changes->{'cancreate'})) {
14035: $changes->{'cancreate'} = ['recaptchaversion'];
14036: }
14037: } else {
14038: $changes->{'recaptchaversion'} = 1;
14039: }
14040: }
1.165 raeburn 14041: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 14042: if ($container eq 'cancreate') {
14043: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14044: push(@{$changes->{'cancreate'}},'recaptchakeys');
14045: } elsif (!defined($changes->{'cancreate'})) {
14046: $changes->{'cancreate'} = ['recaptchakeys'];
14047: }
14048: } else {
1.210 raeburn 14049: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 14050: }
14051: }
14052: return;
14053: }
14054:
1.33 raeburn 14055: sub modify_usermodification {
14056: my ($dom,%domconfig) = @_;
1.224 raeburn 14057: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14058: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14059: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 14060: if ($key eq 'selfcreate') {
14061: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14062: } else {
14063: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14064: }
1.33 raeburn 14065: }
14066: }
1.224 raeburn 14067: my @contexts = ('author','course');
1.33 raeburn 14068: my %context_title = (
14069: author => 'In author context',
14070: course => 'In course context',
14071: );
14072: my @fields = ('lastname','firstname','middlename','generation',
14073: 'permanentemail','id');
14074: my %roles = (
14075: author => ['ca','aa'],
14076: course => ['st','ep','ta','in','cr'],
14077: );
14078: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14079: foreach my $context (@contexts) {
14080: foreach my $role (@{$roles{$context}}) {
14081: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14082: foreach my $item (@fields) {
14083: if (grep(/^\Q$item\E$/,@modifiable)) {
14084: $modifyhash{$context}{$role}{$item} = 1;
14085: } else {
14086: $modifyhash{$context}{$role}{$item} = 0;
14087: }
14088: }
14089: }
14090: if (ref($curr_usermodification{$context}) eq 'HASH') {
14091: foreach my $role (@{$roles{$context}}) {
14092: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14093: foreach my $field (@fields) {
14094: if ($modifyhash{$context}{$role}{$field} ne
14095: $curr_usermodification{$context}{$role}{$field}) {
14096: push(@{$changes{$context}},$role);
14097: last;
14098: }
14099: }
14100: }
14101: }
14102: } else {
14103: foreach my $context (@contexts) {
14104: foreach my $role (@{$roles{$context}}) {
14105: push(@{$changes{$context}},$role);
14106: }
14107: }
14108: }
14109: }
14110: my %usermodification_hash = (
14111: usermodification => \%modifyhash,
14112: );
14113: my $putresult = &Apache::lonnet::put_dom('configuration',
14114: \%usermodification_hash,$dom);
14115: if ($putresult eq 'ok') {
14116: if (keys(%changes) > 0) {
14117: $resulttext = &mt('Changes made: ').'<ul>';
14118: foreach my $context (@contexts) {
14119: if (ref($changes{$context}) eq 'ARRAY') {
14120: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14121: if (ref($changes{$context}) eq 'ARRAY') {
14122: foreach my $role (@{$changes{$context}}) {
14123: my $rolename;
1.224 raeburn 14124: if ($role eq 'cr') {
14125: $rolename = &mt('Custom');
1.33 raeburn 14126: } else {
1.224 raeburn 14127: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14128: }
14129: my @modifiable;
1.224 raeburn 14130: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14131: foreach my $field (@fields) {
14132: if ($modifyhash{$context}{$role}{$field}) {
14133: push(@modifiable,$fieldtitles{$field});
14134: }
14135: }
14136: if (@modifiable > 0) {
14137: $resulttext .= join(', ',@modifiable);
14138: } else {
14139: $resulttext .= &mt('none');
14140: }
14141: $resulttext .= '</li>';
14142: }
14143: $resulttext .= '</ul></li>';
14144: }
14145: }
14146: }
14147: $resulttext .= '</ul>';
14148: } else {
14149: $resulttext = &mt('No changes made to user modification settings');
14150: }
14151: } else {
14152: $resulttext = '<span class="LC_error">'.
14153: &mt('An error occurred: [_1]',$putresult).'</span>';
14154: }
14155: return $resulttext;
14156: }
14157:
1.43 raeburn 14158: sub modify_defaults {
1.212 raeburn 14159: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14160: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 14161: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 14162: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
14163: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.325 ! raeburn 14164: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 14165: foreach my $item (@items) {
14166: $newvalues{$item} = $env{'form.'.$item};
14167: if ($item eq 'auth_def') {
14168: if ($newvalues{$item} ne '') {
14169: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14170: push(@errors,$item);
14171: }
14172: }
14173: } elsif ($item eq 'lang_def') {
14174: if ($newvalues{$item} ne '') {
14175: if ($newvalues{$item} =~ /^(\w+)/) {
14176: my $langcode = $1;
1.103 raeburn 14177: if ($langcode ne 'x_chef') {
14178: if (code2language($langcode) eq '') {
14179: push(@errors,$item);
14180: }
1.43 raeburn 14181: }
14182: } else {
14183: push(@errors,$item);
14184: }
14185: }
1.54 raeburn 14186: } elsif ($item eq 'timezone_def') {
14187: if ($newvalues{$item} ne '') {
1.62 raeburn 14188: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14189: push(@errors,$item);
14190: }
14191: }
1.68 raeburn 14192: } elsif ($item eq 'datelocale_def') {
14193: if ($newvalues{$item} ne '') {
14194: my @datelocale_ids = DateTime::Locale->ids();
14195: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14196: push(@errors,$item);
14197: }
14198: }
1.141 raeburn 14199: } elsif ($item eq 'portal_def') {
14200: if ($newvalues{$item} ne '') {
14201: 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])\/?$/) {
14202: push(@errors,$item);
14203: }
14204: }
1.294 raeburn 14205: } elsif ($item eq 'intauth_cost') {
14206: if ($newvalues{$item} ne '') {
14207: if ($newvalues{$item} =~ /\D/) {
14208: push(@errors,$item);
14209: }
14210: }
14211: } elsif ($item eq 'intauth_check') {
14212: if ($newvalues{$item} ne '') {
14213: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14214: push(@errors,$item);
14215: }
14216: }
14217: } elsif ($item eq 'intauth_switch') {
14218: if ($newvalues{$item} ne '') {
14219: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14220: push(@errors,$item);
14221: }
14222: }
1.43 raeburn 14223: }
14224: if (grep(/^\Q$item\E$/,@errors)) {
14225: $newvalues{$item} = $domdefaults{$item};
14226: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14227: $changes{$item} = 1;
14228: }
1.72 raeburn 14229: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14230: }
14231: my %defaults_hash = (
1.72 raeburn 14232: defaults => \%newvalues,
14233: );
1.43 raeburn 14234: my $title = &defaults_titles();
1.236 raeburn 14235:
14236: my $currinststatus;
14237: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14238: $currinststatus = $domconfig{'inststatus'};
14239: } else {
14240: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14241: $currinststatus = {
14242: inststatustypes => $usertypes,
14243: inststatusorder => $types,
14244: inststatusguest => [],
14245: };
14246: }
14247: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14248: my @allpos;
14249: my %alltypes;
1.305 raeburn 14250: my @inststatusguest;
14251: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14252: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14253: unless (grep(/^\Q$type\E$/,@todelete)) {
14254: push(@inststatusguest,$type);
14255: }
14256: }
14257: }
14258: my ($currtitles,$currorder);
1.236 raeburn 14259: if (ref($currinststatus) eq 'HASH') {
14260: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14261: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14262: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14263: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14264: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14265: }
14266: }
14267: unless (grep(/^\Q$type\E$/,@todelete)) {
14268: my $position = $env{'form.inststatus_pos_'.$type};
14269: $position =~ s/\D+//g;
14270: $allpos[$position] = $type;
14271: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14272: $alltypes{$type} =~ s/`//g;
14273: }
14274: }
14275: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14276: $currtitles =~ s/,$//;
14277: }
14278: }
14279: if ($env{'form.addinststatus'}) {
14280: my $newtype = $env{'form.addinststatus'};
14281: $newtype =~ s/\W//g;
14282: unless (exists($alltypes{$newtype})) {
14283: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14284: $alltypes{$newtype} =~ s/`//g;
14285: my $position = $env{'form.addinststatus_pos'};
14286: $position =~ s/\D+//g;
14287: if ($position ne '') {
14288: $allpos[$position] = $newtype;
14289: }
14290: }
14291: }
1.305 raeburn 14292: my @orderedstatus;
1.236 raeburn 14293: foreach my $type (@allpos) {
14294: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14295: push(@orderedstatus,$type);
14296: }
14297: }
14298: foreach my $type (keys(%alltypes)) {
14299: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14300: delete($alltypes{$type});
14301: }
14302: }
14303: $defaults_hash{'inststatus'} = {
14304: inststatustypes => \%alltypes,
14305: inststatusorder => \@orderedstatus,
1.305 raeburn 14306: inststatusguest => \@inststatusguest,
1.236 raeburn 14307: };
14308: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14309: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14310: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14311: }
14312: }
14313: if ($currorder ne join(',',@orderedstatus)) {
14314: $changes{'inststatus'}{'inststatusorder'} = 1;
14315: }
14316: my $newtitles;
14317: foreach my $item (@orderedstatus) {
14318: $newtitles .= $alltypes{$item}.',';
14319: }
14320: $newtitles =~ s/,$//;
14321: if ($currtitles ne $newtitles) {
14322: $changes{'inststatus'}{'inststatustypes'} = 1;
14323: }
1.43 raeburn 14324: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14325: $dom);
14326: if ($putresult eq 'ok') {
14327: if (keys(%changes) > 0) {
14328: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 14329: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14330: 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";
14331: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 14332: if ($item eq 'inststatus') {
14333: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 14334: if (@orderedstatus) {
1.236 raeburn 14335: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14336: foreach my $type (@orderedstatus) {
14337: $resulttext .= $alltypes{$type}.', ';
14338: }
14339: $resulttext =~ s/, $//;
14340: $resulttext .= '</li>';
1.305 raeburn 14341: } else {
14342: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 14343: }
14344: }
14345: } else {
14346: my $value = $env{'form.'.$item};
14347: if ($value eq '') {
14348: $value = &mt('none');
14349: } elsif ($item eq 'auth_def') {
14350: my %authnames = &authtype_names();
14351: my %shortauth = (
14352: internal => 'int',
14353: krb4 => 'krb4',
14354: krb5 => 'krb5',
14355: localauth => 'loc',
1.325 ! raeburn 14356: lti => 'lti',
1.236 raeburn 14357: );
14358: $value = $authnames{$shortauth{$value}};
1.294 raeburn 14359: } elsif ($item eq 'intauth_switch') {
14360: my %optiondesc = &Apache::lonlocal::texthash (
14361: 0 => 'No',
14362: 1 => 'Yes',
14363: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14364: );
14365: if ($value =~ /^(0|1|2)$/) {
14366: $value = $optiondesc{$value};
14367: } else {
14368: $value = &mt('none -- defaults to No');
14369: }
14370: } elsif ($item eq 'intauth_check') {
14371: my %optiondesc = &Apache::lonlocal::texthash (
14372: 0 => 'No',
14373: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14374: 2 => 'Yes, disallow login if stored cost is less than domain default',
14375: );
14376: if ($value =~ /^(0|1|2)$/) {
14377: $value = $optiondesc{$value};
14378: } else {
14379: $value = &mt('none -- defaults to No');
14380: }
1.236 raeburn 14381: }
14382: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14383: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14384: }
14385: }
14386: $resulttext .= '</ul>';
14387: $mailmsgtext .= "\n";
14388: my $cachetime = 24*60*60;
1.72 raeburn 14389: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14390: if (ref($lastactref) eq 'HASH') {
14391: $lastactref->{'domdefaults'} = 1;
14392: }
1.68 raeburn 14393: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 14394: my $notify = 1;
14395: if (ref($domconfig{'contacts'}) eq 'HASH') {
14396: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14397: $notify = 0;
14398: }
14399: }
14400: if ($notify) {
14401: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14402: "LON-CAPA Domain Settings Change - $dom",
14403: $mailmsgtext);
14404: }
1.54 raeburn 14405: }
1.43 raeburn 14406: } else {
1.54 raeburn 14407: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14408: }
14409: } else {
14410: $resulttext = '<span class="LC_error">'.
14411: &mt('An error occurred: [_1]',$putresult).'</span>';
14412: }
14413: if (@errors > 0) {
14414: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14415: foreach my $item (@errors) {
14416: $resulttext .= ' "'.$title->{$item}.'",';
14417: }
14418: $resulttext =~ s/,$//;
14419: }
14420: return $resulttext;
14421: }
14422:
1.46 raeburn 14423: sub modify_scantron {
1.205 raeburn 14424: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14425: my ($resulttext,%confhash,%changes,$errors);
14426: my $custom = 'custom.tab';
14427: my $default = 'default.tab';
14428: my $servadm = $r->dir_config('lonAdmEMail');
14429: my ($configuserok,$author_ok,$switchserver) =
14430: &config_check($dom,$confname,$servadm);
14431: if ($env{'form.scantronformat.filename'} ne '') {
14432: my $error;
14433: if ($configuserok eq 'ok') {
14434: if ($switchserver) {
1.130 raeburn 14435: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14436: } else {
14437: if ($author_ok eq 'ok') {
14438: my ($result,$scantronurl) =
14439: &publishlogo($r,'upload','scantronformat',$dom,
14440: $confname,'scantron','','',$custom);
14441: if ($result eq 'ok') {
14442: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14443: $changes{'scantronformat'} = 1;
1.46 raeburn 14444: } else {
14445: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14446: }
14447: } else {
14448: $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);
14449: }
14450: }
14451: } else {
14452: $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);
14453: }
14454: if ($error) {
14455: &Apache::lonnet::logthis($error);
14456: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14457: }
14458: }
1.48 raeburn 14459: if (ref($domconfig{'scantron'}) eq 'HASH') {
14460: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14461: if ($env{'form.scantronformat_del'}) {
14462: $confhash{'scantron'}{'scantronformat'} = '';
14463: $changes{'scantronformat'} = 1;
1.46 raeburn 14464: }
14465: }
14466: }
14467: if (keys(%confhash) > 0) {
14468: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14469: $dom);
14470: if ($putresult eq 'ok') {
14471: if (keys(%changes) > 0) {
1.48 raeburn 14472: if (ref($confhash{'scantron'}) eq 'HASH') {
14473: $resulttext = &mt('Changes made:').'<ul>';
14474: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 14475: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 14476: } else {
1.130 raeburn 14477: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 14478: }
1.48 raeburn 14479: $resulttext .= '</ul>';
14480: } else {
1.130 raeburn 14481: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14482: }
14483: $resulttext .= '</ul>';
14484: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14485: if (ref($lastactref) eq 'HASH') {
14486: $lastactref->{'domainconfig'} = 1;
14487: }
1.46 raeburn 14488: } else {
1.130 raeburn 14489: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14490: }
14491: } else {
14492: $resulttext = '<span class="LC_error">'.
14493: &mt('An error occurred: [_1]',$putresult).'</span>';
14494: }
14495: } else {
1.130 raeburn 14496: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14497: }
14498: if ($errors) {
14499: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14500: $errors.'</ul>';
14501: }
14502: return $resulttext;
14503: }
14504:
1.48 raeburn 14505: sub modify_coursecategories {
1.239 raeburn 14506: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14507: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14508: $cathash);
1.48 raeburn 14509: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 14510: my @catitems = ('unauth','auth');
14511: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14512: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14513: $cathash = $domconfig{'coursecategories'}{'cats'};
14514: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14515: $changes{'togglecats'} = 1;
14516: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14517: }
14518: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14519: $changes{'categorize'} = 1;
14520: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14521: }
1.120 raeburn 14522: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14523: $changes{'togglecatscomm'} = 1;
14524: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14525: }
14526: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14527: $changes{'categorizecomm'} = 1;
14528: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 14529:
14530: }
14531: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
14532: $changes{'togglecatsplace'} = 1;
14533: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
14534: }
14535: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
14536: $changes{'categorizeplace'} = 1;
14537: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 14538: }
1.238 raeburn 14539: foreach my $item (@catitems) {
14540: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14541: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14542: $changes{$item} = 1;
14543: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14544: }
14545: }
14546: }
1.57 raeburn 14547: } else {
14548: $changes{'togglecats'} = 1;
14549: $changes{'categorize'} = 1;
1.124 raeburn 14550: $changes{'togglecatscomm'} = 1;
14551: $changes{'categorizecomm'} = 1;
1.272 raeburn 14552: $changes{'togglecatsplace'} = 1;
14553: $changes{'categorizeplace'} = 1;
1.87 raeburn 14554: $domconfig{'coursecategories'} = {
14555: togglecats => $env{'form.togglecats'},
14556: categorize => $env{'form.categorize'},
1.124 raeburn 14557: togglecatscomm => $env{'form.togglecatscomm'},
14558: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 14559: togglecatsplace => $env{'form.togglecatsplace'},
14560: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 14561: };
1.238 raeburn 14562: foreach my $item (@catitems) {
14563: if ($env{'form.coursecat_'.$item} ne 'std') {
14564: $changes{$item} = 1;
14565: }
14566: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14567: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14568: }
14569: }
1.57 raeburn 14570: }
14571: if (ref($cathash) eq 'HASH') {
14572: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14573: push (@deletecategory,'instcode::0');
14574: }
1.120 raeburn 14575: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14576: push(@deletecategory,'communities::0');
14577: }
1.272 raeburn 14578: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
14579: push(@deletecategory,'placement::0');
14580: }
1.48 raeburn 14581: }
1.57 raeburn 14582: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14583: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14584: if (@deletecategory > 0) {
14585: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14586: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14587: foreach my $item (@deletecategory) {
1.57 raeburn 14588: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14589: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14590: $deletions{$item} = 1;
1.57 raeburn 14591: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14592: }
14593: }
14594: }
1.57 raeburn 14595: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14596: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14597: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14598: $reorderings{$item} = 1;
1.57 raeburn 14599: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14600: }
14601: if ($env{'form.addcategory_name_'.$item} ne '') {
14602: my $newcat = $env{'form.addcategory_name_'.$item};
14603: my $newdepth = $depth+1;
14604: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14605: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14606: $adds{$newitem} = 1;
14607: }
14608: if ($env{'form.subcat_'.$item} ne '') {
14609: my $newcat = $env{'form.subcat_'.$item};
14610: my $newdepth = $depth+1;
14611: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14612: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14613: $adds{$newitem} = 1;
14614: }
14615: }
14616: }
14617: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14618: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14619: my $newitem = 'instcode::0';
1.57 raeburn 14620: if ($cathash->{$newitem} eq '') {
14621: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14622: $adds{$newitem} = 1;
14623: }
14624: } else {
14625: my $newitem = 'instcode::0';
1.57 raeburn 14626: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14627: $adds{$newitem} = 1;
14628: }
14629: }
1.120 raeburn 14630: if ($env{'form.communities'} eq '1') {
14631: if (ref($cathash) eq 'HASH') {
14632: my $newitem = 'communities::0';
14633: if ($cathash->{$newitem} eq '') {
14634: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14635: $adds{$newitem} = 1;
14636: }
14637: } else {
14638: my $newitem = 'communities::0';
14639: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14640: $adds{$newitem} = 1;
14641: }
14642: }
1.272 raeburn 14643: if ($env{'form.placement'} eq '1') {
14644: if (ref($cathash) eq 'HASH') {
14645: my $newitem = 'placement::0';
14646: if ($cathash->{$newitem} eq '') {
14647: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14648: $adds{$newitem} = 1;
14649: }
14650: } else {
14651: my $newitem = 'placement::0';
14652: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14653: $adds{$newitem} = 1;
14654: }
14655: }
1.48 raeburn 14656: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14657: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 14658: ($env{'form.addcategory_name'} ne 'communities') &&
14659: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 14660: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14661: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14662: $adds{$newitem} = 1;
14663: }
1.48 raeburn 14664: }
1.57 raeburn 14665: my $putresult;
1.48 raeburn 14666: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14667: if (keys(%deletions) > 0) {
14668: foreach my $key (keys(%deletions)) {
14669: if ($predelallitems{$key} ne '') {
14670: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14671: }
14672: }
14673: }
14674: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14675: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14676: if (ref($chkcats[0]) eq 'ARRAY') {
14677: my $depth = 0;
14678: my $chg = 0;
14679: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14680: my $name = $chkcats[0][$i];
14681: my $item;
14682: if ($name eq '') {
14683: $chg ++;
14684: } else {
14685: $item = &escape($name).'::0';
14686: if ($chg) {
1.57 raeburn 14687: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14688: }
14689: $depth ++;
1.57 raeburn 14690: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14691: $depth --;
14692: }
14693: }
14694: }
1.57 raeburn 14695: }
14696: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14697: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14698: if ($putresult eq 'ok') {
1.57 raeburn 14699: my %title = (
1.120 raeburn 14700: togglecats => 'Show/Hide a course in catalog',
14701: categorize => 'Assign a category to a course',
14702: togglecatscomm => 'Show/Hide a community in catalog',
14703: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14704: );
14705: my %level = (
1.120 raeburn 14706: dom => 'set in Domain ("Modify Course/Community")',
14707: crs => 'set in Course ("Course Configuration")',
14708: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 14709: none => 'No catalog',
14710: std => 'Standard catalog',
14711: domonly => 'Domain-only catalog',
14712: codesrch => 'Code search form',
1.57 raeburn 14713: );
1.48 raeburn 14714: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14715: if ($changes{'togglecats'}) {
14716: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14717: }
14718: if ($changes{'categorize'}) {
14719: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14720: }
1.120 raeburn 14721: if ($changes{'togglecatscomm'}) {
14722: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14723: }
14724: if ($changes{'categorizecomm'}) {
14725: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14726: }
1.238 raeburn 14727: if ($changes{'unauth'}) {
14728: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14729: }
14730: if ($changes{'auth'}) {
14731: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14732: }
1.57 raeburn 14733: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14734: my $cathash;
14735: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14736: $cathash = $domconfig{'coursecategories'}{'cats'};
14737: } else {
14738: $cathash = {};
14739: }
14740: my (@cats,@trails,%allitems);
14741: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
14742: if (keys(%deletions) > 0) {
14743: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
14744: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
14745: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
14746: }
14747: $resulttext .= '</ul></li>';
14748: }
14749: if (keys(%reorderings) > 0) {
14750: my %sort_by_trail;
14751: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
14752: foreach my $key (keys(%reorderings)) {
14753: if ($allitems{$key} ne '') {
14754: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14755: }
1.48 raeburn 14756: }
1.57 raeburn 14757: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14758: $resulttext .= '<li>'.$trails[$trail].'</li>';
14759: }
14760: $resulttext .= '</ul></li>';
1.48 raeburn 14761: }
1.57 raeburn 14762: if (keys(%adds) > 0) {
14763: my %sort_by_trail;
14764: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
14765: foreach my $key (keys(%adds)) {
14766: if ($allitems{$key} ne '') {
14767: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14768: }
14769: }
14770: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14771: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 14772: }
1.57 raeburn 14773: $resulttext .= '</ul></li>';
1.48 raeburn 14774: }
14775: }
14776: $resulttext .= '</ul>';
1.239 raeburn 14777: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 14778: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14779: if ($changes{'auth'}) {
14780: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
14781: }
14782: if ($changes{'unauth'}) {
14783: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
14784: }
14785: my $cachetime = 24*60*60;
14786: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 14787: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 14788: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 14789: }
14790: }
1.48 raeburn 14791: } else {
14792: $resulttext = '<span class="LC_error">'.
1.57 raeburn 14793: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 14794: }
14795: } else {
1.120 raeburn 14796: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 14797: }
14798: return $resulttext;
14799: }
14800:
1.69 raeburn 14801: sub modify_serverstatuses {
14802: my ($dom,%domconfig) = @_;
14803: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
14804: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
14805: %currserverstatus = %{$domconfig{'serverstatuses'}};
14806: }
14807: my @pages = &serverstatus_pages();
14808: foreach my $type (@pages) {
14809: $newserverstatus{$type}{'namedusers'} = '';
14810: $newserverstatus{$type}{'machines'} = '';
14811: if (defined($env{'form.'.$type.'_namedusers'})) {
14812: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
14813: my @okusers;
14814: foreach my $user (@users) {
14815: my ($uname,$udom) = split(/:/,$user);
14816: if (($udom =~ /^$match_domain$/) &&
14817: (&Apache::lonnet::domain($udom)) &&
14818: ($uname =~ /^$match_username$/)) {
14819: if (!grep(/^\Q$user\E/,@okusers)) {
14820: push(@okusers,$user);
14821: }
14822: }
14823: }
14824: if (@okusers > 0) {
14825: @okusers = sort(@okusers);
14826: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
14827: }
14828: }
14829: if (defined($env{'form.'.$type.'_machines'})) {
14830: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
14831: my @okmachines;
14832: foreach my $ip (@machines) {
14833: my @parts = split(/\./,$ip);
14834: next if (@parts < 4);
14835: my $badip = 0;
14836: for (my $i=0; $i<4; $i++) {
14837: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
14838: $badip = 1;
14839: last;
14840: }
14841: }
14842: if (!$badip) {
14843: push(@okmachines,$ip);
14844: }
14845: }
14846: @okmachines = sort(@okmachines);
14847: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
14848: }
14849: }
14850: my %serverstatushash = (
14851: serverstatuses => \%newserverstatus,
14852: );
14853: foreach my $type (@pages) {
1.83 raeburn 14854: foreach my $setting ('namedusers','machines') {
1.84 raeburn 14855: my (@current,@new);
1.83 raeburn 14856: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 14857: if ($currserverstatus{$type}{$setting} ne '') {
14858: @current = split(/,/,$currserverstatus{$type}{$setting});
14859: }
14860: }
14861: if ($newserverstatus{$type}{$setting} ne '') {
14862: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 14863: }
14864: if (@current > 0) {
14865: if (@new > 0) {
14866: foreach my $item (@current) {
14867: if (!grep(/^\Q$item\E$/,@new)) {
14868: $changes{$type}{$setting} = 1;
1.82 raeburn 14869: last;
14870: }
14871: }
1.84 raeburn 14872: foreach my $item (@new) {
14873: if (!grep(/^\Q$item\E$/,@current)) {
14874: $changes{$type}{$setting} = 1;
14875: last;
1.82 raeburn 14876: }
14877: }
14878: } else {
1.83 raeburn 14879: $changes{$type}{$setting} = 1;
1.69 raeburn 14880: }
1.83 raeburn 14881: } elsif (@new > 0) {
14882: $changes{$type}{$setting} = 1;
1.69 raeburn 14883: }
14884: }
14885: }
14886: if (keys(%changes) > 0) {
1.81 raeburn 14887: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 14888: my $putresult = &Apache::lonnet::put_dom('configuration',
14889: \%serverstatushash,$dom);
14890: if ($putresult eq 'ok') {
14891: $resulttext .= &mt('Changes made:').'<ul>';
14892: foreach my $type (@pages) {
1.84 raeburn 14893: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 14894: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 14895: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 14896: if ($newserverstatus{$type}{'namedusers'} eq '') {
14897: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
14898: } else {
14899: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
14900: }
1.84 raeburn 14901: }
14902: if ($changes{$type}{'machines'}) {
1.69 raeburn 14903: if ($newserverstatus{$type}{'machines'} eq '') {
14904: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
14905: } else {
14906: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
14907: }
14908:
14909: }
14910: $resulttext .= '</ul></li>';
14911: }
14912: }
14913: $resulttext .= '</ul>';
14914: } else {
14915: $resulttext = '<span class="LC_error">'.
14916: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
14917:
14918: }
14919: } else {
14920: $resulttext = &mt('No changes made to access to server status pages');
14921: }
14922: return $resulttext;
14923: }
14924:
1.118 jms 14925: sub modify_helpsettings {
1.285 raeburn 14926: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 14927: my ($resulttext,$errors,%changes,%helphash);
14928: my %defaultchecked = ('submitbugs' => 'on');
14929: my @offon = ('off','on');
1.118 jms 14930: my @toggles = ('submitbugs');
1.285 raeburn 14931: my %current = ('submitbugs' => '',
14932: 'adhoc' => {},
14933: );
1.118 jms 14934: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 14935: %current = %{$domconfig{'helpsettings'}};
14936: }
1.285 raeburn 14937: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 14938: foreach my $item (@toggles) {
14939: if ($defaultchecked{$item} eq 'on') {
14940: if ($current{$item} eq '') {
14941: if ($env{'form.'.$item} eq '0') {
14942: $changes{$item} = 1;
14943: }
14944: } elsif ($current{$item} ne $env{'form.'.$item}) {
14945: $changes{$item} = 1;
14946: }
14947: } elsif ($defaultchecked{$item} eq 'off') {
14948: if ($current{$item} eq '') {
14949: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 14950: $changes{$item} = 1;
14951: }
1.282 raeburn 14952: } elsif ($current{$item} ne $env{'form.'.$item}) {
14953: $changes{$item} = 1;
14954: }
14955: }
14956: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
14957: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
14958: }
14959: }
1.285 raeburn 14960: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 14961: my $confname = $dom.'-domainconfig';
14962: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 14963: my (@allpos,%newsettings,%changedprivs,$newrole);
14964: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 14965: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 14966: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 14967: my %lt = &Apache::lonlocal::texthash(
14968: s => 'system',
14969: d => 'domain',
14970: order => 'Display order',
14971: access => 'Role usage',
1.291 raeburn 14972: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 14973: dh => 'All with domain helpdesk role',
14974: da => 'All with domain helpdesk assistant role',
1.285 raeburn 14975: none => 'None',
14976: status => 'Determined based on institutional status',
14977: inc => 'Include all, but exclude specific personnel',
14978: exc => 'Exclude all, but include specific personnel',
14979: );
14980: for (my $num=0; $num<=$maxnum; $num++) {
14981: my ($prefix,$identifier,$rolename,%curr);
14982: if ($num == $maxnum) {
14983: next unless ($env{'form.newcusthelp'} == $maxnum);
14984: $identifier = 'custhelp'.$num;
14985: $prefix = 'helproles_'.$num;
14986: $rolename = $env{'form.custhelpname'.$num};
14987: $rolename=~s/[^A-Za-z0-9]//gs;
14988: next if ($rolename eq '');
14989: next if (exists($existing{'rolesdef_'.$rolename}));
14990: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
14991: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
14992: $newprivs{'c'},$confname,$dom);
14993: if ($result ne 'ok') {
14994: $errors .= '<li><span class="LC_error">'.
14995: &mt('An error occurred storing the new custom role: [_1]',
14996: $result).'</span></li>';
14997: next;
14998: } else {
14999: $changedprivs{$rolename} = \%newprivs;
15000: $newrole = $rolename;
15001: }
15002: } else {
15003: $prefix = 'helproles_'.$num;
15004: $rolename = $env{'form.'.$prefix};
15005: next if ($rolename eq '');
15006: next unless (exists($existing{'rolesdef_'.$rolename}));
15007: $identifier = 'custhelp'.$num;
15008: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15009: my %currprivs;
1.289 raeburn 15010: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 15011: split(/\_/,$existing{'rolesdef_'.$rolename});
15012: foreach my $level ('c','d','s') {
15013: if ($newprivs{$level} ne $currprivs{$level}) {
15014: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15015: $newprivs{'c'},$confname,$dom);
15016: if ($result ne 'ok') {
15017: $errors .= '<li><span class="LC_error">'.
15018: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15019: $rolename,$result).'</span></li>';
15020: } else {
15021: $changedprivs{$rolename} = \%newprivs;
15022: }
15023: last;
15024: }
15025: }
15026: if (ref($current{'adhoc'}) eq 'HASH') {
15027: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15028: %curr = %{$current{'adhoc'}{$rolename}};
15029: }
15030: }
15031: }
15032: my $newpos = $env{'form.'.$prefix.'_pos'};
15033: $newpos =~ s/\D+//g;
15034: $allpos[$newpos] = $rolename;
15035: my $newdesc = $env{'form.'.$prefix.'_desc'};
15036: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15037: if ($curr{'desc'}) {
15038: if ($curr{'desc'} ne $newdesc) {
15039: $changes{'customrole'}{$rolename}{'desc'} = 1;
15040: $newsettings{$rolename}{'desc'} = $newdesc;
15041: }
15042: } elsif ($newdesc ne '') {
15043: $changes{'customrole'}{$rolename}{'desc'} = 1;
15044: $newsettings{$rolename}{'desc'} = $newdesc;
15045: }
15046: my $access = $env{'form.'.$prefix.'_access'};
15047: if (grep(/^\Q$access\E$/,@accesstypes)) {
15048: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15049: if ($access eq 'status') {
15050: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15051: if (scalar(@statuses) == 0) {
1.289 raeburn 15052: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 15053: } else {
15054: my (@shownstatus,$numtypes);
15055: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15056: if (ref($types) eq 'ARRAY') {
15057: $numtypes = scalar(@{$types});
15058: foreach my $type (sort(@statuses)) {
15059: if ($type eq 'default') {
15060: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15061: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15062: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15063: push(@shownstatus,$usertypes->{$type});
15064: }
15065: }
15066: }
15067: if (grep(/^default$/,@statuses)) {
15068: push(@shownstatus,$othertitle);
15069: }
15070: if (scalar(@shownstatus) == 1+$numtypes) {
15071: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15072: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15073: } else {
15074: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15075: if (ref($curr{'status'}) eq 'ARRAY') {
15076: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15077: if (@diffs) {
15078: $changes{'customrole'}{$rolename}{$access} = 1;
15079: }
15080: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15081: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 15082: }
1.166 raeburn 15083: }
15084: }
1.285 raeburn 15085: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15086: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15087: my @newspecstaff;
15088: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15089: foreach my $person (sort(@personnel)) {
15090: if ($domhelpdesk{$person}) {
15091: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15092: }
15093: }
15094: if (ref($curr{$access}) eq 'ARRAY') {
15095: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15096: if (@diffs) {
15097: $changes{'customrole'}{$rolename}{$access} = 1;
15098: }
15099: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15100: $changes{'customrole'}{$rolename}{$access} = 1;
15101: }
15102: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15103: my ($uname,$udom) = split(/:/,$person);
15104: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15105: }
15106: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 15107: }
1.285 raeburn 15108: } else {
15109: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15110: }
15111: unless ($curr{'access'} eq $access) {
15112: $changes{'customrole'}{$rolename}{'access'} = 1;
15113: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 15114: }
15115: }
1.285 raeburn 15116: if (@allpos > 0) {
15117: my $idx = 0;
15118: foreach my $rolename (@allpos) {
15119: if ($rolename ne '') {
15120: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15121: if (ref($current{'adhoc'}) eq 'HASH') {
15122: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15123: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15124: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 15125: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 15126: }
15127: }
1.282 raeburn 15128: }
1.285 raeburn 15129: $idx ++;
1.166 raeburn 15130: }
15131: }
1.118 jms 15132: }
1.123 jms 15133: my $putresult;
15134: if (keys(%changes) > 0) {
1.166 raeburn 15135: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 15136: if ($putresult eq 'ok') {
1.285 raeburn 15137: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15138: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15139: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15140: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15141: }
15142: }
15143: my $cachetime = 24*60*60;
15144: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15145: if (ref($lastactref) eq 'HASH') {
15146: $lastactref->{'domdefaults'} = 1;
15147: }
15148: } else {
15149: $errors .= '<li><span class="LC_error">'.
15150: &mt('An error occurred storing the settings: [_1]',
15151: $putresult).'</span></li>';
15152: }
15153: }
15154: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15155: $resulttext = &mt('Changes made:').'<ul>';
15156: my (%shownprivs,@levelorder);
15157: @levelorder = ('c','d','s');
15158: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 15159: foreach my $item (sort(keys(%changes))) {
15160: if ($item eq 'submitbugs') {
15161: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15162: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15163: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 15164: } elsif ($item eq 'customrole') {
15165: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 15166: my @keyorder = ('order','desc','access','status','exc','inc');
15167: my %keytext = &Apache::lonlocal::texthash(
15168: order => 'Order',
15169: desc => 'Role description',
15170: access => 'Role usage',
1.300 droeschl 15171: status => 'Allowed institutional types',
1.285 raeburn 15172: exc => 'Allowed personnel',
15173: inc => 'Disallowed personnel',
15174: );
1.282 raeburn 15175: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 15176: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15177: if ($role eq $newrole) {
15178: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15179: $role).'<ul>';
15180: } else {
15181: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15182: $role).'<ul>';
15183: }
15184: foreach my $key (@keyorder) {
15185: if ($changes{'customrole'}{$role}{$key}) {
15186: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15187: $keytext{$key},$newsettings{$role}{$key}).
15188: '</li>';
15189: }
15190: }
15191: if (ref($changedprivs{$role}) eq 'HASH') {
15192: $shownprivs{$role} = 1;
15193: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15194: foreach my $level (@levelorder) {
15195: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15196: next if ($item eq '');
15197: my ($priv) = split(/\&/,$item,2);
15198: if (&Apache::lonnet::plaintext($priv)) {
15199: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15200: unless ($level eq 'c') {
15201: $resulttext .= ' ('.$lt{$level}.')';
15202: }
15203: $resulttext .= '</li>';
15204: }
15205: }
15206: }
15207: $resulttext .= '</ul>';
15208: }
15209: $resulttext .= '</ul></li>';
15210: }
15211: }
15212: }
15213: }
15214: }
15215: }
15216: if (keys(%changedprivs)) {
15217: foreach my $role (sort(keys(%changedprivs))) {
15218: unless ($shownprivs{$role}) {
15219: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15220: $role).'<ul>'.
15221: '<li>'.&mt('Privileges set to :').'<ul>';
15222: foreach my $level (@levelorder) {
15223: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15224: next if ($item eq '');
15225: my ($priv) = split(/\&/,$item,2);
15226: if (&Apache::lonnet::plaintext($priv)) {
15227: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15228: unless ($level eq 'c') {
15229: $resulttext .= ' ('.$lt{$level}.')';
15230: }
15231: $resulttext .= '</li>';
15232: }
1.282 raeburn 15233: }
15234: }
1.285 raeburn 15235: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 15236: }
15237: }
15238: }
1.285 raeburn 15239: $resulttext .= '</ul>';
15240: } else {
15241: $resulttext = &mt('No changes made to help settings');
1.118 jms 15242: }
15243: if ($errors) {
1.168 raeburn 15244: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 15245: $errors.'</ul>';
1.118 jms 15246: }
15247: return $resulttext;
15248: }
15249:
1.121 raeburn 15250: sub modify_coursedefaults {
1.212 raeburn 15251: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15252: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 15253: my %defaultchecked = (
15254: 'canuse_pdfforms' => 'off',
15255: 'uselcmath' => 'on',
15256: 'usejsme' => 'on'
15257: );
15258: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 15259: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 15260: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
15261: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
15262: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 15263: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 15264: my %staticdefaults = (
15265: anonsurvey_threshold => 10,
15266: uploadquota => 500,
1.257 raeburn 15267: postsubmit => 60,
1.276 raeburn 15268: mysqltables => 172800,
1.198 raeburn 15269: );
1.314 raeburn 15270: my %texoptions = (
15271: MathJax => 'MathJax',
15272: mimetex => &mt('Convert to Images'),
15273: tth => &mt('TeX to HTML'),
15274: );
1.121 raeburn 15275: $defaultshash{'coursedefaults'} = {};
15276:
15277: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15278: if ($domconfig{'coursedefaults'} eq '') {
15279: $domconfig{'coursedefaults'} = {};
15280: }
15281: }
15282:
15283: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15284: foreach my $item (@toggles) {
15285: if ($defaultchecked{$item} eq 'on') {
15286: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15287: ($env{'form.'.$item} eq '0')) {
15288: $changes{$item} = 1;
1.192 raeburn 15289: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15290: $changes{$item} = 1;
15291: }
15292: } elsif ($defaultchecked{$item} eq 'off') {
15293: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15294: ($env{'form.'.$item} eq '1')) {
15295: $changes{$item} = 1;
15296: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15297: $changes{$item} = 1;
15298: }
15299: }
15300: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15301: }
1.198 raeburn 15302: foreach my $item (@numbers) {
15303: my ($currdef,$newdef);
1.208 raeburn 15304: $newdef = $env{'form.'.$item};
1.198 raeburn 15305: if ($item eq 'anonsurvey_threshold') {
15306: $currdef = $domconfig{'coursedefaults'}{$item};
15307: $newdef =~ s/\D//g;
15308: if ($newdef eq '' || $newdef < 1) {
15309: $newdef = 1;
15310: }
15311: $defaultshash{'coursedefaults'}{$item} = $newdef;
15312: } else {
1.276 raeburn 15313: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15314: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15315: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 15316: }
15317: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 15318: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 15319: }
15320: if ($currdef ne $newdef) {
15321: my $staticdef;
15322: if ($item eq 'anonsurvey_threshold') {
15323: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15324: $changes{$item} = 1;
15325: }
1.276 raeburn 15326: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 15327: my $setting = $1;
1.276 raeburn 15328: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15329: $changes{$setting} = 1;
1.198 raeburn 15330: }
15331: }
1.139 raeburn 15332: }
15333: }
1.314 raeburn 15334: my $texengine;
15335: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15336: $texengine = $env{'form.texengine'};
15337: if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {
15338: unless ($texengine eq 'MathJax') {
15339: $changes{'texengine'} = 1;
15340: }
15341: } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {
15342: $changes{'texengine'} = 1;
15343: }
15344: }
15345: if ($texengine ne '') {
15346: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15347: }
1.264 raeburn 15348: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15349: my @currclonecode;
15350: if (ref($currclone) eq 'HASH') {
15351: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15352: @currclonecode = @{$currclone->{'instcode'}};
15353: }
15354: }
15355: my $newclone;
1.289 raeburn 15356: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 15357: $newclone = $env{'form.canclone'};
15358: }
15359: if ($newclone eq 'instcode') {
15360: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15361: my (%codedefaults,@code_order,@clonecode);
15362: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15363: \@code_order);
15364: foreach my $item (@code_order) {
15365: if (grep(/^\Q$item\E$/,@newcodes)) {
15366: push(@clonecode,$item);
15367: }
15368: }
15369: if (@clonecode) {
15370: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15371: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15372: if (@diffs) {
15373: $changes{'canclone'} = 1;
15374: }
15375: } else {
15376: $newclone eq '';
15377: }
15378: } elsif ($newclone ne '') {
1.289 raeburn 15379: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15380: }
1.264 raeburn 15381: if ($newclone ne $currclone) {
15382: $changes{'canclone'} = 1;
15383: }
1.257 raeburn 15384: my %credits;
15385: foreach my $type (@types) {
15386: unless ($type eq 'community') {
15387: $credits{$type} = $env{'form.'.$type.'_credits'};
15388: $credits{$type} =~ s/[^\d.]+//g;
15389: }
15390: }
15391: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15392: ($env{'form.coursecredits'} eq '1')) {
15393: $changes{'coursecredits'} = 1;
15394: foreach my $type (keys(%credits)) {
15395: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15396: }
15397: } else {
1.289 raeburn 15398: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 15399: foreach my $type (@types) {
15400: unless ($type eq 'community') {
1.289 raeburn 15401: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 15402: $changes{'coursecredits'} = 1;
15403: }
15404: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15405: }
15406: }
15407: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15408: foreach my $type (@types) {
15409: unless ($type eq 'community') {
15410: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15411: $changes{'coursecredits'} = 1;
15412: last;
15413: }
15414: }
15415: }
15416: }
15417: }
15418: if ($env{'form.postsubmit'} eq '1') {
15419: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15420: my %currtimeout;
15421: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15422: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15423: $changes{'postsubmit'} = 1;
15424: }
15425: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15426: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15427: }
15428: } else {
15429: $changes{'postsubmit'} = 1;
15430: }
15431: foreach my $type (@types) {
15432: my $timeout = $env{'form.'.$type.'_timeout'};
15433: $timeout =~ s/\D//g;
15434: if ($timeout == $staticdefaults{'postsubmit'}) {
15435: $timeout = '';
15436: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15437: $timeout = '0';
15438: }
15439: unless ($timeout eq '') {
15440: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15441: }
15442: if (exists($currtimeout{$type})) {
15443: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 15444: $changes{'postsubmit'} = 1;
1.257 raeburn 15445: }
15446: } elsif ($timeout ne '') {
15447: $changes{'postsubmit'} = 1;
15448: }
15449: }
15450: } else {
15451: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15452: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15453: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15454: $changes{'postsubmit'} = 1;
15455: }
15456: } else {
15457: $changes{'postsubmit'} = 1;
15458: }
1.192 raeburn 15459: }
1.121 raeburn 15460: }
15461: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15462: $dom);
15463: if ($putresult eq 'ok') {
15464: if (keys(%changes) > 0) {
1.213 raeburn 15465: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 15466: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 15467: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 15468: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15469: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 15470: if ($changes{$item}) {
15471: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15472: }
1.289 raeburn 15473: }
1.192 raeburn 15474: if ($changes{'coursecredits'}) {
15475: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 15476: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15477: $domdefaults{$type.'credits'} =
15478: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15479: }
15480: }
15481: }
15482: if ($changes{'postsubmit'}) {
15483: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15484: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15485: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15486: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15487: $domdefaults{$type.'postsubtimeout'} =
15488: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15489: }
15490: }
1.192 raeburn 15491: }
15492: }
1.198 raeburn 15493: if ($changes{'uploadquota'}) {
15494: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15495: foreach my $type (@types) {
15496: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15497: }
15498: }
15499: }
1.264 raeburn 15500: if ($changes{'canclone'}) {
15501: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15502: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15503: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15504: if (@clonecodes) {
15505: $domdefaults{'canclone'} = join('+',@clonecodes);
15506: }
15507: }
15508: } else {
15509: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15510: }
15511: }
1.121 raeburn 15512: my $cachetime = 24*60*60;
15513: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 15514: if (ref($lastactref) eq 'HASH') {
15515: $lastactref->{'domdefaults'} = 1;
15516: }
1.121 raeburn 15517: }
15518: $resulttext = &mt('Changes made:').'<ul>';
15519: foreach my $item (sort(keys(%changes))) {
15520: if ($item eq 'canuse_pdfforms') {
15521: if ($env{'form.'.$item} eq '1') {
15522: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
15523: } else {
15524: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
15525: }
1.257 raeburn 15526: } elsif ($item eq 'uselcmath') {
15527: if ($env{'form.'.$item} eq '1') {
15528: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
15529: } else {
15530: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15531: }
15532: } elsif ($item eq 'usejsme') {
15533: if ($env{'form.'.$item} eq '1') {
15534: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15535: } else {
1.289 raeburn 15536: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 15537: }
1.314 raeburn 15538: } elsif ($item eq 'texengine') {
15539: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15540: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15541: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15542: }
1.139 raeburn 15543: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 15544: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 15545: } elsif ($item eq 'uploadquota') {
15546: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15547: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15548: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15549: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 15550: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 15551: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 15552: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15553: '</ul>'.
15554: '</li>';
15555: } else {
15556: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15557: }
1.276 raeburn 15558: } elsif ($item eq 'mysqltables') {
15559: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15560: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15561: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15562: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15563: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15564: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
15565: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15566: '</ul>'.
15567: '</li>';
15568: } else {
15569: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15570: }
1.257 raeburn 15571: } elsif ($item eq 'postsubmit') {
15572: if ($domdefaults{'postsubmit'} eq 'off') {
15573: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15574: } else {
15575: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 15576: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 15577: $resulttext .= &mt('durations:').'<ul>';
15578: foreach my $type (@types) {
15579: $resulttext .= '<li>';
15580: my $timeout;
15581: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15582: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15583: }
15584: my $display;
15585: if ($timeout eq '0') {
15586: $display = &mt('unlimited');
15587: } elsif ($timeout eq '') {
15588: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15589: } else {
15590: $display = &mt('[quant,_1,second]',$timeout);
15591: }
15592: if ($type eq 'community') {
15593: $resulttext .= &mt('Communities');
15594: } elsif ($type eq 'official') {
15595: $resulttext .= &mt('Official courses');
15596: } elsif ($type eq 'unofficial') {
15597: $resulttext .= &mt('Unofficial courses');
15598: } elsif ($type eq 'textbook') {
15599: $resulttext .= &mt('Textbook courses');
1.271 raeburn 15600: } elsif ($type eq 'placement') {
15601: $resulttext .= &mt('Placement tests');
1.257 raeburn 15602: }
15603: $resulttext .= ' -- '.$display.'</li>';
15604: }
15605: $resulttext .= '</ul>';
15606: }
1.289 raeburn 15607: $resulttext .= '</li>';
1.257 raeburn 15608: }
1.192 raeburn 15609: } elsif ($item eq 'coursecredits') {
15610: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15611: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 15612: ($domdefaults{'unofficialcredits'} eq '') &&
15613: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 15614: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15615: } else {
15616: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15617: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15618: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 15619: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 15620: '</ul>'.
15621: '</li>';
15622: }
15623: } else {
15624: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15625: }
1.264 raeburn 15626: } elsif ($item eq 'canclone') {
15627: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15628: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15629: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15630: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15631: }
15632: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15633: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15634: } else {
1.289 raeburn 15635: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 15636: }
1.140 raeburn 15637: }
1.121 raeburn 15638: }
15639: $resulttext .= '</ul>';
15640: } else {
15641: $resulttext = &mt('No changes made to course defaults');
15642: }
15643: } else {
15644: $resulttext = '<span class="LC_error">'.
15645: &mt('An error occurred: [_1]',$putresult).'</span>';
15646: }
15647: return $resulttext;
15648: }
15649:
1.231 raeburn 15650: sub modify_selfenrollment {
15651: my ($dom,$lastactref,%domconfig) = @_;
15652: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 15653: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 15654: my %titles = &tool_titles();
1.232 raeburn 15655: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15656: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 15657: $ordered{'default'} = ['types','registered','approval','limit'];
15658:
15659: my (%roles,%shown,%toplevel);
15660: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15661:
15662: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15663: if ($domconfig{'selfenrollment'} eq '') {
15664: $domconfig{'selfenrollment'} = {};
15665: }
15666: }
15667: %toplevel = (
15668: admin => 'Configuration Rights',
15669: default => 'Default settings',
15670: validation => 'Validation of self-enrollment requests',
15671: );
1.233 raeburn 15672: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 15673:
15674: if (ref($ordered{'admin'}) eq 'ARRAY') {
15675: foreach my $item (@{$ordered{'admin'}}) {
15676: foreach my $type (@types) {
15677: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15678: $selfenrollhash{'admin'}{$type}{$item} = 1;
15679: } else {
15680: $selfenrollhash{'admin'}{$type}{$item} = 0;
15681: }
15682: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15683: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15684: if ($selfenrollhash{'admin'}{$type}{$item} ne
15685: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15686: push(@{$changes{'admin'}{$type}},$item);
15687: }
15688: } else {
15689: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15690: push(@{$changes{'admin'}{$type}},$item);
15691: }
15692: }
15693: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15694: push(@{$changes{'admin'}{$type}},$item);
15695: }
15696: }
15697: }
15698: }
15699:
15700: foreach my $item (@{$ordered{'default'}}) {
15701: foreach my $type (@types) {
15702: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15703: if ($item eq 'types') {
15704: unless (($value eq 'all') || ($value eq 'dom')) {
15705: $value = '';
15706: }
15707: } elsif ($item eq 'registered') {
15708: unless ($value eq '1') {
15709: $value = 0;
15710: }
15711: } elsif ($item eq 'approval') {
15712: unless ($value =~ /^[012]$/) {
15713: $value = 0;
15714: }
15715: } else {
15716: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15717: $value = 'none';
15718: }
15719: }
15720: $selfenrollhash{'default'}{$type}{$item} = $value;
15721: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15722: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15723: if ($selfenrollhash{'default'}{$type}{$item} ne
15724: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15725: push(@{$changes{'default'}{$type}},$item);
15726: }
15727: } else {
15728: push(@{$changes{'default'}{$type}},$item);
15729: }
15730: } else {
15731: push(@{$changes{'default'}{$type}},$item);
15732: }
15733: if ($item eq 'limit') {
15734: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15735: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15736: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15737: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15738: }
15739: } else {
15740: $selfenrollhash{'default'}{$type}{'cap'} = '';
15741: }
15742: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15743: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15744: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15745: push(@{$changes{'default'}{$type}},'cap');
15746: }
15747: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
15748: push(@{$changes{'default'}{$type}},'cap');
15749: }
15750: }
15751: }
15752: }
15753:
15754: foreach my $item (@{$itemsref}) {
15755: if ($item eq 'fields') {
15756: my @changed;
15757: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
15758: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
15759: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
15760: }
15761: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15762: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
15763: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
15764: $domconfig{'selfenrollment'}{'validation'}{$item});
15765: } else {
15766: @changed = @{$selfenrollhash{'validation'}{$item}};
15767: }
15768: } else {
15769: @changed = @{$selfenrollhash{'validation'}{$item}};
15770: }
15771: if (@changed) {
15772: if ($selfenrollhash{'validation'}{$item}) {
15773: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
15774: } else {
15775: $changes{'validation'}{$item} = &mt('None');
15776: }
15777: }
15778: } else {
15779: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
15780: if ($item eq 'markup') {
15781: if ($env{'form.selfenroll_validation_'.$item}) {
15782: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
15783: }
15784: }
15785: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15786: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
15787: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
15788: }
15789: }
15790: }
15791: }
15792:
15793: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
15794: $dom);
15795: if ($putresult eq 'ok') {
15796: if (keys(%changes) > 0) {
15797: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15798: $resulttext = &mt('Changes made:').'<ul>';
15799: foreach my $key ('admin','default','validation') {
15800: if (ref($changes{$key}) eq 'HASH') {
15801: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
15802: if ($key eq 'validation') {
15803: foreach my $item (@{$itemsref}) {
15804: if (exists($changes{$key}{$item})) {
15805: if ($item eq 'markup') {
15806: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15807: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
15808: } else {
15809: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15810: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
15811: }
15812: }
15813: }
15814: } else {
15815: foreach my $type (@types) {
15816: if ($type eq 'community') {
15817: $roles{'1'} = &mt('Community personnel');
15818: } else {
15819: $roles{'1'} = &mt('Course personnel');
15820: }
15821: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 15822: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15823: if ($key eq 'admin') {
15824: my @mgrdc = ();
15825: if (ref($ordered{$key}) eq 'ARRAY') {
15826: foreach my $item (@{$ordered{'admin'}}) {
15827: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15828: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
15829: push(@mgrdc,$item);
15830: }
15831: }
15832: }
15833: if (@mgrdc) {
15834: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
15835: } else {
15836: delete($domdefaults{$type.'selfenrolladmdc'});
15837: }
15838: }
15839: } else {
15840: if (ref($ordered{$key}) eq 'ARRAY') {
15841: foreach my $item (@{$ordered{$key}}) {
15842: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15843: $domdefaults{$type.'selfenroll'.$item} =
15844: $selfenrollhash{$key}{$type}{$item};
15845: }
15846: }
15847: }
15848: }
15849: }
1.231 raeburn 15850: $resulttext .= '<li>'.$titles{$type}.'<ul>';
15851: foreach my $item (@{$ordered{$key}}) {
15852: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15853: $resulttext .= '<li>';
15854: if ($key eq 'admin') {
15855: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
15856: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
15857: } else {
15858: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
15859: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
15860: }
15861: $resulttext .= '</li>';
15862: }
15863: }
15864: $resulttext .= '</ul></li>';
15865: }
15866: }
15867: $resulttext .= '</ul></li>';
15868: }
15869: }
1.305 raeburn 15870: }
15871: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
15872: my $cachetime = 24*60*60;
15873: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15874: if (ref($lastactref) eq 'HASH') {
15875: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 15876: }
1.231 raeburn 15877: }
15878: $resulttext .= '</ul>';
15879: } else {
15880: $resulttext = &mt('No changes made to self-enrollment settings');
15881: }
15882: } else {
15883: $resulttext = '<span class="LC_error">'.
15884: &mt('An error occurred: [_1]',$putresult).'</span>';
15885: }
15886: return $resulttext;
15887: }
15888:
1.137 raeburn 15889: sub modify_usersessions {
1.212 raeburn 15890: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 15891: my @hostingtypes = ('version','excludedomain','includedomain');
15892: my @offloadtypes = ('primary','default');
15893: my %types = (
15894: remote => \@hostingtypes,
15895: hosted => \@hostingtypes,
15896: spares => \@offloadtypes,
15897: );
15898: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 15899: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 15900: my (%by_ip,%by_location,@intdoms,@instdoms);
15901: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 15902: my @locations = sort(keys(%by_location));
1.137 raeburn 15903: my (%defaultshash,%changes);
15904: foreach my $prefix (@prefixes) {
15905: $defaultshash{'usersessions'}{$prefix} = {};
15906: }
1.212 raeburn 15907: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 15908: my $resulttext;
1.138 raeburn 15909: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 15910: foreach my $prefix (@prefixes) {
1.145 raeburn 15911: next if ($prefix eq 'spares');
15912: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 15913: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
15914: if ($type eq 'version') {
15915: my $value = $env{'form.'.$prefix.'_'.$type};
15916: my $okvalue;
15917: if ($value ne '') {
15918: if (grep(/^\Q$value\E$/,@lcversions)) {
15919: $okvalue = $value;
15920: }
15921: }
15922: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15923: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15924: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
15925: if ($inuse == 0) {
15926: $changes{$prefix}{$type} = 1;
15927: } else {
15928: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
15929: $changes{$prefix}{$type} = 1;
15930: }
15931: if ($okvalue ne '') {
15932: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15933: }
15934: }
15935: } else {
15936: if (($inuse == 1) && ($okvalue ne '')) {
15937: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15938: $changes{$prefix}{$type} = 1;
15939: }
15940: }
15941: } else {
15942: if (($inuse == 1) && ($okvalue ne '')) {
15943: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15944: $changes{$prefix}{$type} = 1;
15945: }
15946: }
15947: } else {
15948: if (($inuse == 1) && ($okvalue ne '')) {
15949: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15950: $changes{$prefix}{$type} = 1;
15951: }
15952: }
15953: } else {
15954: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
15955: my @okvals;
15956: foreach my $val (@vals) {
1.138 raeburn 15957: if ($val =~ /:/) {
15958: my @items = split(/:/,$val);
15959: foreach my $item (@items) {
15960: if (ref($by_location{$item}) eq 'ARRAY') {
15961: push(@okvals,$item);
15962: }
15963: }
15964: } else {
15965: if (ref($by_location{$val}) eq 'ARRAY') {
15966: push(@okvals,$val);
15967: }
1.137 raeburn 15968: }
15969: }
15970: @okvals = sort(@okvals);
15971: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15972: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15973: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
15974: if ($inuse == 0) {
15975: $changes{$prefix}{$type} = 1;
15976: } else {
15977: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15978: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
15979: if (@changed > 0) {
15980: $changes{$prefix}{$type} = 1;
15981: }
15982: }
15983: } else {
15984: if ($inuse == 1) {
15985: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15986: $changes{$prefix}{$type} = 1;
15987: }
15988: }
15989: } else {
15990: if ($inuse == 1) {
15991: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15992: $changes{$prefix}{$type} = 1;
15993: }
15994: }
15995: } else {
15996: if ($inuse == 1) {
15997: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15998: $changes{$prefix}{$type} = 1;
15999: }
16000: }
16001: }
16002: }
16003: }
1.145 raeburn 16004:
16005: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16006: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16007: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16008: my $savespares;
16009:
16010: foreach my $lonhost (sort(keys(%servers))) {
16011: my $serverhomeID =
16012: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16013: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16014: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16015: my %spareschg;
16016: foreach my $type (@{$types{'spares'}}) {
16017: my @okspares;
16018: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16019: foreach my $server (@checked) {
1.152 raeburn 16020: if (&Apache::lonnet::hostname($server) ne '') {
16021: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16022: unless (grep(/^\Q$server\E$/,@okspares)) {
16023: push(@okspares,$server);
16024: }
1.145 raeburn 16025: }
16026: }
16027: }
16028: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16029: my $newspare;
1.152 raeburn 16030: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16031: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16032: $newspare = $new;
16033: }
16034: }
1.152 raeburn 16035: my @spares;
16036: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16037: @spares = sort(@okspares,$newspare);
16038: } else {
16039: @spares = sort(@okspares);
16040: }
16041: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16042: if (ref($spareid{$lonhost}) eq 'HASH') {
16043: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16044: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16045: if (@diffs > 0) {
16046: $spareschg{$type} = 1;
16047: }
16048: }
16049: }
16050: }
16051: if (keys(%spareschg) > 0) {
16052: $changes{'spares'}{$lonhost} = \%spareschg;
16053: }
16054: }
1.261 raeburn 16055: $defaultshash{'usersessions'}{'offloadnow'} = {};
16056: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16057: my @okoffload;
16058: if (@offloadnow) {
16059: foreach my $server (@offloadnow) {
16060: if (&Apache::lonnet::hostname($server) ne '') {
16061: unless (grep(/^\Q$server\E$/,@okoffload)) {
16062: push(@okoffload,$server);
16063: }
16064: }
16065: }
16066: if (@okoffload) {
16067: foreach my $lonhost (@okoffload) {
16068: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16069: }
16070: }
16071: }
1.145 raeburn 16072: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16073: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16074: if (ref($changes{'spares'}) eq 'HASH') {
16075: if (keys(%{$changes{'spares'}}) > 0) {
16076: $savespares = 1;
16077: }
16078: }
16079: } else {
16080: $savespares = 1;
16081: }
1.261 raeburn 16082: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
16083: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
16084: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
16085: $changes{'offloadnow'} = 1;
16086: last;
16087: }
16088: }
16089: unless ($changes{'offloadnow'}) {
1.289 raeburn 16090: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 16091: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
16092: $changes{'offloadnow'} = 1;
16093: last;
16094: }
16095: }
16096: }
16097: } elsif (@okoffload) {
16098: $changes{'offloadnow'} = 1;
16099: }
16100: } elsif (@okoffload) {
16101: $changes{'offloadnow'} = 1;
1.145 raeburn 16102: }
1.147 raeburn 16103: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16104: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16105: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16106: $dom);
16107: if ($putresult eq 'ok') {
16108: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16109: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16110: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16111: }
16112: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16113: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16114: }
1.261 raeburn 16115: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16116: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16117: }
1.137 raeburn 16118: }
16119: my $cachetime = 24*60*60;
16120: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 16121: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 16122: if (ref($lastactref) eq 'HASH') {
16123: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 16124: $lastactref->{'usersessions'} = 1;
1.212 raeburn 16125: }
1.147 raeburn 16126: if (keys(%changes) > 0) {
16127: my %lt = &usersession_titles();
16128: $resulttext = &mt('Changes made:').'<ul>';
16129: foreach my $prefix (@prefixes) {
16130: if (ref($changes{$prefix}) eq 'HASH') {
16131: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16132: if ($prefix eq 'spares') {
16133: if (ref($changes{$prefix}) eq 'HASH') {
16134: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16135: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16136: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 16137: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16138: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16139: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16140: foreach my $type (@{$types{$prefix}}) {
16141: if ($changes{$prefix}{$lonhost}{$type}) {
16142: my $offloadto = &mt('None');
16143: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16144: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16145: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16146: }
1.145 raeburn 16147: }
1.147 raeburn 16148: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16149: }
1.137 raeburn 16150: }
16151: }
1.147 raeburn 16152: $resulttext .= '</li>';
1.137 raeburn 16153: }
16154: }
1.147 raeburn 16155: } else {
16156: foreach my $type (@{$types{$prefix}}) {
16157: if (defined($changes{$prefix}{$type})) {
16158: my $newvalue;
16159: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16160: if (ref($defaultshash{'usersessions'}{$prefix})) {
16161: if ($type eq 'version') {
16162: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
16163: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16164: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16165: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16166: }
1.145 raeburn 16167: }
16168: }
16169: }
1.147 raeburn 16170: if ($newvalue eq '') {
16171: if ($type eq 'version') {
16172: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
16173: } else {
16174: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16175: }
1.145 raeburn 16176: } else {
1.147 raeburn 16177: if ($type eq 'version') {
16178: $newvalue .= ' '.&mt('(or later)');
16179: }
16180: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 16181: }
1.137 raeburn 16182: }
16183: }
16184: }
1.147 raeburn 16185: $resulttext .= '</ul>';
1.137 raeburn 16186: }
16187: }
1.261 raeburn 16188: if ($changes{'offloadnow'}) {
16189: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16190: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
16191: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
16192: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
16193: $resulttext .= '<li>'.$lonhost.'</li>';
16194: }
16195: $resulttext .= '</ul>';
16196: } else {
16197: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
16198: }
16199: } else {
16200: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
16201: }
16202: }
1.147 raeburn 16203: $resulttext .= '</ul>';
16204: } else {
16205: $resulttext = $nochgmsg;
1.137 raeburn 16206: }
16207: } else {
16208: $resulttext = '<span class="LC_error">'.
16209: &mt('An error occurred: [_1]',$putresult).'</span>';
16210: }
16211: } else {
1.147 raeburn 16212: $resulttext = $nochgmsg;
1.137 raeburn 16213: }
16214: return $resulttext;
16215: }
16216:
1.275 raeburn 16217: sub modify_ssl {
16218: my ($dom,$lastactref,%domconfig) = @_;
16219: my (%by_ip,%by_location,@intdoms,@instdoms);
16220: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16221: my @locations = sort(keys(%by_location));
16222: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16223: my (%defaultshash,%changes);
16224: my $action = 'ssl';
1.293 raeburn 16225: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 16226: foreach my $prefix (@prefixes) {
16227: $defaultshash{$action}{$prefix} = {};
16228: }
16229: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16230: my $resulttext;
16231: my %iphost = &Apache::lonnet::get_iphost();
16232: my @reptypes = ('certreq','nocertreq');
16233: my @connecttypes = ('dom','intdom','other');
16234: my %types = (
1.293 raeburn 16235: connto => \@connecttypes,
16236: connfrom => \@connecttypes,
16237: replication => \@reptypes,
1.275 raeburn 16238: );
16239: foreach my $prefix (sort(keys(%types))) {
16240: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 16241: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16242: my $value = 'yes';
16243: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
16244: $value = $env{'form.'.$prefix.'_'.$type};
16245: }
16246: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16247: if ($domconfig{$action}{$prefix}{$type} ne '') {
16248: if ($value ne $domconfig{$action}{$prefix}{$type}) {
16249: $changes{$prefix}{$type} = 1;
16250: }
16251: $defaultshash{$action}{$prefix}{$type} = $value;
16252: } else {
16253: $defaultshash{$action}{$prefix}{$type} = $value;
16254: $changes{$prefix}{$type} = 1;
16255: }
16256: } else {
16257: $defaultshash{$action}{$prefix}{$type} = $value;
16258: $changes{$prefix}{$type} = 1;
16259: }
16260: if (($type eq 'dom') && (keys(%servers) == 1)) {
16261: delete($changes{$prefix}{$type});
16262: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
16263: delete($changes{$prefix}{$type});
16264: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
16265: delete($changes{$prefix}{$type});
16266: }
16267: } elsif ($prefix eq 'replication') {
16268: if (@locations > 0) {
16269: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16270: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16271: my @okvals;
16272: foreach my $val (@vals) {
16273: if ($val =~ /:/) {
16274: my @items = split(/:/,$val);
16275: foreach my $item (@items) {
16276: if (ref($by_location{$item}) eq 'ARRAY') {
16277: push(@okvals,$item);
16278: }
16279: }
16280: } else {
16281: if (ref($by_location{$val}) eq 'ARRAY') {
16282: push(@okvals,$val);
16283: }
16284: }
16285: }
16286: @okvals = sort(@okvals);
16287: if (ref($domconfig{$action}) eq 'HASH') {
16288: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16289: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
16290: if ($inuse == 0) {
16291: $changes{$prefix}{$type} = 1;
16292: } else {
16293: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16294: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
16295: if (@changed > 0) {
16296: $changes{$prefix}{$type} = 1;
16297: }
16298: }
16299: } else {
16300: if ($inuse == 1) {
16301: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16302: $changes{$prefix}{$type} = 1;
16303: }
16304: }
16305: } else {
16306: if ($inuse == 1) {
16307: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16308: $changes{$prefix}{$type} = 1;
16309: }
16310: }
16311: } else {
16312: if ($inuse == 1) {
16313: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16314: $changes{$prefix}{$type} = 1;
16315: }
16316: }
16317: }
16318: }
16319: }
16320: }
16321: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
16322: if (keys(%changes) > 0) {
16323: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16324: $dom);
16325: if ($putresult eq 'ok') {
16326: if (ref($defaultshash{$action}) eq 'HASH') {
16327: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
16328: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
16329: }
1.293 raeburn 16330: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
16331: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
16332: }
16333: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
16334: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 16335: }
16336: }
16337: my $cachetime = 24*60*60;
16338: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16339: if (ref($lastactref) eq 'HASH') {
16340: $lastactref->{'domdefaults'} = 1;
16341: }
16342: if (keys(%changes) > 0) {
16343: my %titles = &ssl_titles();
16344: $resulttext = &mt('Changes made:').'<ul>';
16345: foreach my $prefix (@prefixes) {
16346: if (ref($changes{$prefix}) eq 'HASH') {
16347: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
16348: foreach my $type (@{$types{$prefix}}) {
16349: if (defined($changes{$prefix}{$type})) {
16350: my $newvalue;
16351: if (ref($defaultshash{$action}) eq 'HASH') {
16352: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 16353: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16354: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
16355: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
16356: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
16357: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
16358: }
16359: }
16360: }
16361: if ($newvalue eq '') {
16362: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
16363: } else {
16364: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
16365: }
16366: }
16367: }
16368: }
16369: $resulttext .= '</ul>';
16370: }
16371: }
16372: } else {
16373: $resulttext = $nochgmsg;
16374: }
16375: } else {
16376: $resulttext = '<span class="LC_error">'.
16377: &mt('An error occurred: [_1]',$putresult).'</span>';
16378: }
16379: } else {
16380: $resulttext = $nochgmsg;
16381: }
16382: return $resulttext;
16383: }
16384:
1.279 raeburn 16385: sub modify_trust {
16386: my ($dom,$lastactref,%domconfig) = @_;
16387: my (%by_ip,%by_location,@intdoms,@instdoms);
16388: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16389: my @locations = sort(keys(%by_location));
16390: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
16391: my @types = ('exc','inc');
16392: my (%defaultshash,%changes);
16393: foreach my $prefix (@prefixes) {
16394: $defaultshash{'trust'}{$prefix} = {};
16395: }
16396: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16397: my $resulttext;
16398: foreach my $prefix (@prefixes) {
16399: foreach my $type (@types) {
16400: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16401: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16402: my @okvals;
16403: foreach my $val (@vals) {
16404: if ($val =~ /:/) {
16405: my @items = split(/:/,$val);
16406: foreach my $item (@items) {
16407: if (ref($by_location{$item}) eq 'ARRAY') {
16408: push(@okvals,$item);
16409: }
16410: }
16411: } else {
16412: if (ref($by_location{$val}) eq 'ARRAY') {
16413: push(@okvals,$val);
16414: }
16415: }
16416: }
16417: @okvals = sort(@okvals);
16418: if (ref($domconfig{'trust'}) eq 'HASH') {
16419: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
16420: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16421: if ($inuse == 0) {
16422: $changes{$prefix}{$type} = 1;
16423: } else {
16424: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16425: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
16426: if (@changed > 0) {
16427: $changes{$prefix}{$type} = 1;
16428: }
16429: }
16430: } else {
16431: if ($inuse == 1) {
16432: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16433: $changes{$prefix}{$type} = 1;
16434: }
16435: }
16436: } else {
16437: if ($inuse == 1) {
16438: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16439: $changes{$prefix}{$type} = 1;
16440: }
16441: }
16442: } else {
16443: if ($inuse == 1) {
16444: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16445: $changes{$prefix}{$type} = 1;
16446: }
16447: }
16448: }
16449: }
16450: my $nochgmsg = &mt('No changes made to trust settings.');
16451: if (keys(%changes) > 0) {
16452: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16453: $dom);
16454: if ($putresult eq 'ok') {
16455: if (ref($defaultshash{'trust'}) eq 'HASH') {
16456: foreach my $prefix (@prefixes) {
16457: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
16458: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
16459: }
16460: }
16461: }
16462: my $cachetime = 24*60*60;
16463: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16464: if (ref($lastactref) eq 'HASH') {
16465: $lastactref->{'domdefaults'} = 1;
16466: }
16467: if (keys(%changes) > 0) {
16468: my %lt = &trust_titles();
16469: $resulttext = &mt('Changes made:').'<ul>';
16470: foreach my $prefix (@prefixes) {
16471: if (ref($changes{$prefix}) eq 'HASH') {
16472: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16473: foreach my $type (@types) {
16474: if (defined($changes{$prefix}{$type})) {
16475: my $newvalue;
16476: if (ref($defaultshash{'trust'}) eq 'HASH') {
16477: if (ref($defaultshash{'trust'}{$prefix})) {
16478: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16479: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
16480: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
16481: }
16482: }
16483: }
16484: }
16485: if ($newvalue eq '') {
16486: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16487: } else {
16488: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
16489: }
16490: }
16491: }
16492: $resulttext .= '</ul>';
16493: }
16494: }
16495: $resulttext .= '</ul>';
16496: } else {
16497: $resulttext = $nochgmsg;
16498: }
16499: } else {
16500: $resulttext = '<span class="LC_error">'.
16501: &mt('An error occurred: [_1]',$putresult).'</span>';
16502: }
16503: } else {
16504: $resulttext = $nochgmsg;
16505: }
16506: return $resulttext;
16507: }
16508:
1.150 raeburn 16509: sub modify_loadbalancing {
16510: my ($dom,%domconfig) = @_;
16511: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16512: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16513: my ($othertitle,$usertypes,$types) =
16514: &Apache::loncommon::sorted_inst_types($dom);
16515: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 16516: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 16517: my @sparestypes = ('primary','default');
16518: my %typetitles = &sparestype_titles();
16519: my $resulttext;
1.171 raeburn 16520: my (%currbalancer,%currtargets,%currrules,%existing);
16521: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16522: %existing = %{$domconfig{'loadbalancing'}};
16523: }
16524: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
16525: \%currtargets,\%currrules);
16526: my ($saveloadbalancing,%defaultshash,%changes);
16527: my ($alltypes,$othertypes,$titles) =
16528: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16529: my %ruletitles = &offloadtype_text();
16530: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16531: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16532: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16533: if ($balancer eq '') {
16534: next;
16535: }
1.210 raeburn 16536: if (!exists($servers{$balancer})) {
1.171 raeburn 16537: if (exists($currbalancer{$balancer})) {
16538: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 16539: }
1.171 raeburn 16540: next;
16541: }
16542: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16543: push(@{$changes{'delete'}},$balancer);
16544: next;
16545: }
16546: if (!exists($currbalancer{$balancer})) {
16547: push(@{$changes{'add'}},$balancer);
16548: }
16549: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16550: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16551: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16552: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16553: $saveloadbalancing = 1;
16554: }
16555: foreach my $sparetype (@sparestypes) {
16556: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16557: my @offloadto;
16558: foreach my $target (@targets) {
16559: if (($servers{$target}) && ($target ne $balancer)) {
16560: if ($sparetype eq 'default') {
16561: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16562: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 16563: }
16564: }
1.171 raeburn 16565: unless(grep(/^\Q$target\E$/,@offloadto)) {
16566: push(@offloadto,$target);
16567: }
1.150 raeburn 16568: }
16569: }
1.284 raeburn 16570: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16571: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16572: push(@offloadto,$balancer);
16573: }
16574: }
16575: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 16576: }
1.171 raeburn 16577: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 16578: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16579: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16580: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 16581: if (@targetdiffs > 0) {
1.171 raeburn 16582: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16583: }
1.171 raeburn 16584: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16585: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16586: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16587: }
16588: }
16589: }
16590: } else {
1.171 raeburn 16591: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 16592: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16593: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16594: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16595: $changes{'curr'}{$balancer}{'targets'} = 1;
16596: }
1.150 raeburn 16597: }
16598: }
1.210 raeburn 16599: }
1.150 raeburn 16600: }
16601: my $ishomedom;
1.171 raeburn 16602: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16603: $ishomedom = 1;
1.150 raeburn 16604: }
16605: if (ref($alltypes) eq 'ARRAY') {
16606: foreach my $type (@{$alltypes}) {
16607: my $rule;
1.210 raeburn 16608: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 16609: (!$ishomedom)) {
1.171 raeburn 16610: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16611: }
16612: if ($rule eq 'specific') {
1.255 raeburn 16613: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 16614: if (exists($servers{$specifiedhost})) {
1.255 raeburn 16615: $rule = $specifiedhost;
16616: }
1.150 raeburn 16617: }
1.171 raeburn 16618: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16619: if (ref($currrules{$balancer}) eq 'HASH') {
16620: if ($rule ne $currrules{$balancer}{$type}) {
16621: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16622: }
16623: } elsif ($rule ne '') {
1.171 raeburn 16624: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16625: }
16626: }
16627: }
1.171 raeburn 16628: }
16629: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
16630: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
16631: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
16632: $defaultshash{'loadbalancing'} = {};
16633: }
16634: my $putresult = &Apache::lonnet::put_dom('configuration',
16635: \%defaultshash,$dom);
16636: if ($putresult eq 'ok') {
16637: if (keys(%changes) > 0) {
1.252 raeburn 16638: my %toupdate;
1.171 raeburn 16639: if (ref($changes{'delete'}) eq 'ARRAY') {
16640: foreach my $balancer (sort(@{$changes{'delete'}})) {
16641: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 16642: $toupdate{$balancer} = 1;
1.150 raeburn 16643: }
1.171 raeburn 16644: }
16645: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 16646: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 16647: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 16648: $toupdate{$balancer} = 1;
1.171 raeburn 16649: }
16650: }
16651: if (ref($changes{'curr'}) eq 'HASH') {
16652: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 16653: $toupdate{$balancer} = 1;
1.171 raeburn 16654: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
16655: if ($changes{'curr'}{$balancer}{'targets'}) {
16656: my %offloadstr;
16657: foreach my $sparetype (@sparestypes) {
16658: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16659: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16660: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16661: }
16662: }
1.150 raeburn 16663: }
1.171 raeburn 16664: if (keys(%offloadstr) == 0) {
16665: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 16666: } else {
1.171 raeburn 16667: my $showoffload;
16668: foreach my $sparetype (@sparestypes) {
16669: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
16670: if (defined($offloadstr{$sparetype})) {
16671: $showoffload .= $offloadstr{$sparetype};
16672: } else {
16673: $showoffload .= &mt('None');
16674: }
16675: $showoffload .= (' 'x3);
16676: }
16677: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 16678: }
16679: }
16680: }
1.171 raeburn 16681: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
16682: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
16683: foreach my $type (@{$alltypes}) {
16684: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
16685: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16686: my $balancetext;
16687: if ($rule eq '') {
16688: $balancetext = $ruletitles{'default'};
1.209 raeburn 16689: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 16690: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 16691: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 16692: foreach my $sparetype (@sparestypes) {
16693: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16694: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16695: }
16696: }
1.253 raeburn 16697: foreach my $item (@{$alltypes}) {
16698: next if ($item =~ /^_LC_ipchange/);
16699: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
16700: if ($hasrule eq 'homeserver') {
16701: map { $toupdate{$_} = 1; } (keys(%libraryservers));
16702: } else {
16703: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
16704: if ($servers{$hasrule}) {
16705: $toupdate{$hasrule} = 1;
16706: }
16707: }
16708: }
16709: }
1.254 raeburn 16710: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
16711: $balancetext = $ruletitles{$rule};
16712: } else {
16713: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16714: $balancetext = $ruletitles{'particular'}.' '.$receiver;
16715: if ($receiver) {
16716: $toupdate{$receiver};
16717: }
16718: }
16719: } else {
16720: $balancetext = $ruletitles{$rule};
1.252 raeburn 16721: }
1.171 raeburn 16722: } else {
16723: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
16724: }
1.210 raeburn 16725: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 16726: }
16727: }
16728: }
16729: }
1.252 raeburn 16730: if (keys(%toupdate)) {
16731: my %thismachine;
16732: my $updatedhere;
16733: my $cachetime = 60*60*24;
16734: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
16735: foreach my $lonhost (keys(%toupdate)) {
16736: if ($thismachine{$lonhost}) {
16737: unless ($updatedhere) {
16738: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
16739: $defaultshash{'loadbalancing'},
16740: $cachetime);
16741: $updatedhere = 1;
16742: }
16743: } else {
16744: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
16745: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
16746: }
16747: }
16748: }
1.150 raeburn 16749: }
1.171 raeburn 16750: }
16751: if ($resulttext ne '') {
16752: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 16753: } else {
16754: $resulttext = $nochgmsg;
16755: }
16756: } else {
1.171 raeburn 16757: $resulttext = $nochgmsg;
1.150 raeburn 16758: }
16759: } else {
1.171 raeburn 16760: $resulttext = '<span class="LC_error">'.
16761: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 16762: }
16763: } else {
1.171 raeburn 16764: $resulttext = $nochgmsg;
1.150 raeburn 16765: }
16766: return $resulttext;
16767: }
16768:
1.48 raeburn 16769: sub recurse_check {
16770: my ($chkcats,$categories,$depth,$name) = @_;
16771: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
16772: my $chg = 0;
16773: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
16774: my $category = $chkcats->[$depth]{$name}[$j];
16775: my $item;
16776: if ($category eq '') {
16777: $chg ++;
16778: } else {
16779: my $deeper = $depth + 1;
16780: $item = &escape($category).':'.&escape($name).':'.$depth;
16781: if ($chg) {
16782: $categories->{$item} -= $chg;
16783: }
16784: &recurse_check($chkcats,$categories,$deeper,$category);
16785: $deeper --;
16786: }
16787: }
16788: }
16789: return;
16790: }
16791:
16792: sub recurse_cat_deletes {
16793: my ($item,$coursecategories,$deletions) = @_;
16794: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16795: my $subdepth = $depth + 1;
16796: if (ref($coursecategories) eq 'HASH') {
16797: foreach my $subitem (keys(%{$coursecategories})) {
16798: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
16799: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
16800: delete($coursecategories->{$subitem});
16801: $deletions->{$subitem} = 1;
16802: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 16803: }
1.48 raeburn 16804: }
16805: }
16806: return;
16807: }
16808:
1.125 raeburn 16809: sub active_dc_picker {
1.191 raeburn 16810: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 16811: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 16812: my @domcoord = keys(%domcoords);
16813: if (keys(%currhash)) {
16814: foreach my $dc (keys(%currhash)) {
16815: unless (exists($domcoords{$dc})) {
16816: push(@domcoord,$dc);
16817: }
16818: }
16819: }
16820: @domcoord = sort(@domcoord);
1.210 raeburn 16821: my $numdcs = scalar(@domcoord);
1.191 raeburn 16822: my $rows = 0;
16823: my $table;
1.125 raeburn 16824: if ($numdcs > 1) {
1.191 raeburn 16825: $table = '<table>';
16826: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 16827: my $rem = $i%($numinrow);
16828: if ($rem == 0) {
16829: if ($i > 0) {
1.191 raeburn 16830: $table .= '</tr>';
1.125 raeburn 16831: }
1.191 raeburn 16832: $table .= '<tr>';
16833: $rows ++;
1.125 raeburn 16834: }
1.191 raeburn 16835: my $check = '';
16836: if ($inputtype eq 'radio') {
16837: if (keys(%currhash) == 0) {
16838: if (!$i) {
16839: $check = ' checked="checked"';
16840: }
16841: } elsif (exists($currhash{$domcoord[$i]})) {
16842: $check = ' checked="checked"';
16843: }
16844: } else {
16845: if (exists($currhash{$domcoord[$i]})) {
16846: $check = ' checked="checked"';
1.125 raeburn 16847: }
16848: }
1.191 raeburn 16849: if ($i == @domcoord - 1) {
1.125 raeburn 16850: my $colsleft = $numinrow - $rem;
16851: if ($colsleft > 1) {
1.191 raeburn 16852: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 16853: } else {
1.191 raeburn 16854: $table .= '<td class="LC_left_item">';
1.125 raeburn 16855: }
16856: } else {
1.191 raeburn 16857: $table .= '<td class="LC_left_item">';
16858: }
16859: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
16860: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
16861: $table .= '<span class="LC_nobreak"><label>'.
16862: '<input type="'.$inputtype.'" name="'.$name.'"'.
16863: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
16864: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 16865: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 16866: }
1.219 raeburn 16867: $table .= '</label></span></td>';
1.191 raeburn 16868: }
16869: $table .= '</tr></table>';
16870: } elsif ($numdcs == 1) {
1.219 raeburn 16871: my ($dcname,$dcdom) = split(':',$domcoord[0]);
16872: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 16873: if ($inputtype eq 'radio') {
1.247 raeburn 16874: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 16875: if ($user ne $dcname.':'.$dcdom) {
16876: $table .= ' ('.$dcname.':'.$dcdom.')';
16877: }
1.191 raeburn 16878: } else {
16879: my $check;
16880: if (exists($currhash{$domcoord[0]})) {
16881: $check = ' checked="checked"';
1.125 raeburn 16882: }
1.247 raeburn 16883: $table = '<span class="LC_nobreak"><label>'.
16884: '<input type="checkbox" name="'.$name.'" '.
16885: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 16886: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 16887: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 16888: }
1.220 raeburn 16889: $table .= '</label></span>';
1.191 raeburn 16890: $rows ++;
1.125 raeburn 16891: }
16892: }
1.191 raeburn 16893: return ($numdcs,$table,$rows);
1.125 raeburn 16894: }
16895:
1.137 raeburn 16896: sub usersession_titles {
16897: return &Apache::lonlocal::texthash(
16898: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
16899: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 16900: spares => 'Servers offloaded to, when busy',
1.137 raeburn 16901: version => 'LON-CAPA version requirement',
1.138 raeburn 16902: excludedomain => 'Allow all, but exclude specific domains',
16903: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 16904: primary => 'Primary (checked first)',
1.154 raeburn 16905: default => 'Default',
1.137 raeburn 16906: );
16907: }
16908:
1.152 raeburn 16909: sub id_for_thisdom {
16910: my (%servers) = @_;
16911: my %altids;
16912: foreach my $server (keys(%servers)) {
16913: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
16914: if ($serverhome ne $server) {
16915: $altids{$serverhome} = $server;
16916: }
16917: }
16918: return %altids;
16919: }
16920:
1.150 raeburn 16921: sub count_servers {
16922: my ($currbalancer,%servers) = @_;
16923: my (@spares,$numspares);
16924: foreach my $lonhost (sort(keys(%servers))) {
16925: next if ($currbalancer eq $lonhost);
16926: push(@spares,$lonhost);
16927: }
16928: if ($currbalancer) {
16929: $numspares = scalar(@spares);
16930: } else {
16931: $numspares = scalar(@spares) - 1;
16932: }
16933: return ($numspares,@spares);
16934: }
16935:
16936: sub lonbalance_targets_js {
1.171 raeburn 16937: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 16938: my $select = &mt('Select');
16939: my ($alltargets,$allishome,$allinsttypes,@alltypes);
16940: if (ref($servers) eq 'HASH') {
16941: $alltargets = join("','",sort(keys(%{$servers})));
16942: my @homedoms;
16943: foreach my $server (sort(keys(%{$servers}))) {
16944: if (&Apache::lonnet::host_domain($server) eq $dom) {
16945: push(@homedoms,'1');
16946: } else {
16947: push(@homedoms,'0');
16948: }
16949: }
16950: $allishome = join("','",@homedoms);
16951: }
16952: if (ref($types) eq 'ARRAY') {
16953: if (@{$types} > 0) {
16954: @alltypes = @{$types};
16955: }
16956: }
16957: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
16958: $allinsttypes = join("','",@alltypes);
1.171 raeburn 16959: my (%currbalancer,%currtargets,%currrules,%existing);
16960: if (ref($settings) eq 'HASH') {
16961: %existing = %{$settings};
16962: }
16963: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
16964: \%currtargets,\%currrules);
1.210 raeburn 16965: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 16966: return <<"END";
16967:
16968: <script type="text/javascript">
16969: // <![CDATA[
16970:
1.171 raeburn 16971: currBalancers = new Array('$balancers');
16972:
16973: function toggleTargets(balnum) {
16974: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
16975: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
16976: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
16977: var prevbalancer = prevhostitem.value;
16978: var baltotal = document.getElementById('loadbalancing_total').value;
16979: prevhostitem.value = balancer;
16980: if (prevbalancer != '') {
16981: var prevIdx = currBalancers.indexOf(prevbalancer);
16982: if (prevIdx != -1) {
16983: currBalancers.splice(prevIdx,1);
16984: }
16985: }
1.150 raeburn 16986: if (balancer == '') {
1.171 raeburn 16987: hideSpares(balnum);
1.150 raeburn 16988: } else {
1.171 raeburn 16989: var currIdx = currBalancers.indexOf(balancer);
16990: if (currIdx == -1) {
16991: currBalancers.push(balancer);
16992: }
1.150 raeburn 16993: var homedoms = new Array('$allishome');
1.171 raeburn 16994: var ishomedom = homedoms[lonhostitem.selectedIndex];
16995: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 16996: }
1.171 raeburn 16997: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 16998: return;
16999: }
17000:
1.171 raeburn 17001: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 17002: var alltargets = new Array('$alltargets');
17003: var insttypes = new Array('$allinsttypes');
1.151 raeburn 17004: var offloadtypes = new Array('primary','default');
17005:
1.171 raeburn 17006: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17007: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 17008:
1.151 raeburn 17009: for (var i=0; i<offloadtypes.length; i++) {
17010: var count = 0;
17011: for (var j=0; j<alltargets.length; j++) {
17012: if (alltargets[j] != balancer) {
1.171 raeburn 17013: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17014: item.value = alltargets[j];
17015: item.style.textAlign='left';
17016: item.style.textFace='normal';
17017: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17018: if (currBalancers.indexOf(alltargets[j]) == -1) {
17019: item.disabled = '';
17020: } else {
17021: item.disabled = 'disabled';
17022: item.checked = false;
17023: }
1.151 raeburn 17024: count ++;
17025: }
1.150 raeburn 17026: }
17027: }
1.151 raeburn 17028: for (var k=0; k<insttypes.length; k++) {
17029: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 17030: if (ishomedom == 1) {
1.171 raeburn 17031: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17032: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17033: } else {
1.171 raeburn 17034: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17035: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 17036: }
17037: } else {
1.171 raeburn 17038: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17039: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17040: }
1.151 raeburn 17041: if ((insttypes[k] != '_LC_external') &&
17042: ((insttypes[k] != '_LC_internetdom') ||
17043: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 17044: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17045: item.options.length = 0;
17046: item.options[0] = new Option("","",true,true);
1.210 raeburn 17047: var idx = 0;
1.151 raeburn 17048: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 17049: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17050: idx ++;
17051: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 17052: }
17053: }
17054: }
17055: }
17056: return;
17057: }
17058:
1.171 raeburn 17059: function hideSpares(balnum) {
1.150 raeburn 17060: var alltargets = new Array('$alltargets');
17061: var insttypes = new Array('$allinsttypes');
17062: var offloadtypes = new Array('primary','default');
17063:
1.171 raeburn 17064: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17065: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 17066:
17067: var total = alltargets.length - 1;
17068: for (var i=0; i<offloadtypes; i++) {
17069: for (var j=0; j<total; j++) {
1.171 raeburn 17070: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17071: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17072: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 17073: }
1.150 raeburn 17074: }
17075: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 17076: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17077: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 17078: if (insttypes[k] != '_LC_external') {
1.171 raeburn 17079: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17080: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 17081: }
17082: }
17083: return;
17084: }
17085:
1.171 raeburn 17086: function checkOffloads(item,balnum,type) {
1.150 raeburn 17087: var alltargets = new Array('$alltargets');
17088: var offloadtypes = new Array('primary','default');
17089: if (item.checked) {
17090: var total = alltargets.length - 1;
17091: var other;
17092: if (type == offloadtypes[0]) {
1.151 raeburn 17093: other = offloadtypes[1];
1.150 raeburn 17094: } else {
1.151 raeburn 17095: other = offloadtypes[0];
1.150 raeburn 17096: }
17097: for (var i=0; i<total; i++) {
1.171 raeburn 17098: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 17099: if (server == item.value) {
1.171 raeburn 17100: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17101: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 17102: }
17103: }
17104: }
17105: }
17106: return;
17107: }
17108:
1.171 raeburn 17109: function singleServerToggle(balnum,type) {
17110: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 17111: if (offloadtoSelIdx == 0) {
1.171 raeburn 17112: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17113: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17114:
17115: } else {
1.171 raeburn 17116: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17117: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 17118: }
17119: return;
17120: }
17121:
1.171 raeburn 17122: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 17123: if (type == '_LC_external') {
1.171 raeburn 17124: return;
1.150 raeburn 17125: }
1.171 raeburn 17126: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 17127: for (var i=0; i<typesRules.length; i++) {
17128: if (formname.elements[typesRules[i]].checked) {
17129: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 17130: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17131: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17132: } else {
1.171 raeburn 17133: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17134: }
17135: }
17136: }
17137: return;
17138: }
17139:
17140: function balancerDeleteChange(balnum) {
17141: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17142: var baltotal = document.getElementById('loadbalancing_total').value;
17143: var addtarget;
17144: var removetarget;
17145: var action = 'delete';
17146: if (document.getElementById('loadbalancing_delete_'+balnum)) {
17147: var lonhost = hostitem.value;
17148: var currIdx = currBalancers.indexOf(lonhost);
17149: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
17150: if (currIdx != -1) {
17151: currBalancers.splice(currIdx,1);
17152: }
17153: addtarget = lonhost;
17154: } else {
17155: if (currIdx == -1) {
17156: currBalancers.push(lonhost);
17157: }
17158: removetarget = lonhost;
17159: action = 'undelete';
17160: }
17161: balancerChange(balnum,baltotal,action,addtarget,removetarget);
17162: }
17163: return;
17164: }
17165:
17166: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
17167: if (baltotal > 1) {
17168: var offloadtypes = new Array('primary','default');
17169: var alltargets = new Array('$alltargets');
17170: var insttypes = new Array('$allinsttypes');
17171: for (var i=0; i<baltotal; i++) {
17172: if (i != balnum) {
17173: for (var j=0; j<offloadtypes.length; j++) {
17174: var total = alltargets.length - 1;
17175: for (var k=0; k<total; k++) {
17176: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
17177: var server = serveritem.value;
17178: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17179: if (server == addtarget) {
17180: serveritem.disabled = '';
17181: }
17182: }
17183: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17184: if (server == removetarget) {
17185: serveritem.disabled = 'disabled';
17186: serveritem.checked = false;
17187: }
17188: }
17189: }
17190: }
17191: for (var j=0; j<insttypes.length; j++) {
17192: if (insttypes[j] != '_LC_external') {
17193: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
17194: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
17195: var currSel = singleserver.selectedIndex;
17196: var currVal = singleserver.options[currSel].value;
17197: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17198: var numoptions = singleserver.options.length;
17199: var needsnew = 1;
17200: for (var k=0; k<numoptions; k++) {
17201: if (singleserver.options[k] == addtarget) {
17202: needsnew = 0;
17203: break;
17204: }
17205: }
17206: if (needsnew == 1) {
17207: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
17208: }
17209: }
17210: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17211: singleserver.options.length = 0;
17212: if ((currVal) && (currVal != removetarget)) {
17213: singleserver.options[0] = new Option("","",false,false);
17214: } else {
17215: singleserver.options[0] = new Option("","",true,true);
17216: }
17217: var idx = 0;
17218: for (var m=0; m<alltargets.length; m++) {
17219: if (currBalancers.indexOf(alltargets[m]) == -1) {
17220: idx ++;
17221: if (currVal == alltargets[m]) {
17222: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17223: } else {
17224: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17225: }
17226: }
17227: }
17228: }
17229: }
17230: }
17231: }
1.150 raeburn 17232: }
17233: }
17234: }
17235: return;
17236: }
17237:
1.152 raeburn 17238: // ]]>
17239: </script>
17240:
17241: END
17242: }
17243:
17244: sub new_spares_js {
17245: my @sparestypes = ('primary','default');
17246: my $types = join("','",@sparestypes);
17247: my $select = &mt('Select');
17248: return <<"END";
17249:
17250: <script type="text/javascript">
17251: // <![CDATA[
17252:
17253: function updateNewSpares(formname,lonhost) {
17254: var types = new Array('$types');
17255: var include = new Array();
17256: var exclude = new Array();
17257: for (var i=0; i<types.length; i++) {
17258: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17259: for (var j=0; j<spareboxes.length; j++) {
17260: if (formname.elements[spareboxes[j]].checked) {
17261: exclude.push(formname.elements[spareboxes[j]].value);
17262: } else {
17263: include.push(formname.elements[spareboxes[j]].value);
17264: }
17265: }
17266: }
17267: for (var i=0; i<types.length; i++) {
17268: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17269: var selIdx = newSpare.selectedIndex;
17270: var currnew = newSpare.options[selIdx].value;
17271: var okSpares = new Array();
17272: for (var j=0; j<newSpare.options.length; j++) {
17273: var possible = newSpare.options[j].value;
17274: if (possible != '') {
17275: if (exclude.indexOf(possible) == -1) {
17276: okSpares.push(possible);
17277: } else {
17278: if (currnew == possible) {
17279: selIdx = 0;
17280: }
17281: }
17282: }
17283: }
17284: for (var k=0; k<include.length; k++) {
17285: if (okSpares.indexOf(include[k]) == -1) {
17286: okSpares.push(include[k]);
17287: }
17288: }
17289: okSpares.sort();
17290: newSpare.options.length = 0;
17291: if (selIdx == 0) {
17292: newSpare.options[0] = new Option("$select","",true,true);
17293: } else {
17294: newSpare.options[0] = new Option("$select","",false,false);
17295: }
17296: for (var m=0; m<okSpares.length; m++) {
17297: var idx = m+1;
17298: var selThis = 0;
17299: if (selIdx != 0) {
17300: if (okSpares[m] == currnew) {
17301: selThis = 1;
17302: }
17303: }
17304: if (selThis == 1) {
17305: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17306: } else {
17307: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17308: }
17309: }
17310: }
17311: return;
17312: }
17313:
17314: function checkNewSpares(lonhost,type) {
17315: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17316: var chosen = newSpare.options[newSpare.selectedIndex].value;
17317: if (chosen != '') {
17318: var othertype;
17319: var othernewSpare;
17320: if (type == 'primary') {
17321: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17322: }
17323: if (type == 'default') {
17324: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17325: }
17326: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17327: othernewSpare.selectedIndex = 0;
17328: }
17329: }
17330: return;
17331: }
17332:
17333: // ]]>
17334: </script>
17335:
17336: END
17337:
17338: }
17339:
17340: sub common_domprefs_js {
17341: return <<"END";
17342:
17343: <script type="text/javascript">
17344: // <![CDATA[
17345:
1.150 raeburn 17346: function getIndicesByName(formname,item) {
1.152 raeburn 17347: var group = new Array();
1.150 raeburn 17348: for (var i=0;i<formname.elements.length;i++) {
17349: if (formname.elements[i].name == item) {
1.152 raeburn 17350: group.push(formname.elements[i].id);
1.150 raeburn 17351: }
17352: }
1.152 raeburn 17353: return group;
1.150 raeburn 17354: }
17355:
17356: // ]]>
17357: </script>
17358:
17359: END
1.152 raeburn 17360:
1.150 raeburn 17361: }
17362:
1.165 raeburn 17363: sub recaptcha_js {
17364: my %lt = &captcha_phrases();
17365: return <<"END";
17366:
17367: <script type="text/javascript">
17368: // <![CDATA[
17369:
17370: function updateCaptcha(caller,context) {
17371: var privitem;
17372: var pubitem;
17373: var privtext;
17374: var pubtext;
1.269 raeburn 17375: var versionitem;
17376: var versiontext;
1.165 raeburn 17377: if (document.getElementById(context+'_recaptchapub')) {
17378: pubitem = document.getElementById(context+'_recaptchapub');
17379: } else {
17380: return;
17381: }
17382: if (document.getElementById(context+'_recaptchapriv')) {
17383: privitem = document.getElementById(context+'_recaptchapriv');
17384: } else {
17385: return;
17386: }
17387: if (document.getElementById(context+'_recaptchapubtxt')) {
17388: pubtext = document.getElementById(context+'_recaptchapubtxt');
17389: } else {
17390: return;
17391: }
17392: if (document.getElementById(context+'_recaptchaprivtxt')) {
17393: privtext = document.getElementById(context+'_recaptchaprivtxt');
17394: } else {
17395: return;
17396: }
1.269 raeburn 17397: if (document.getElementById(context+'_recaptchaversion')) {
17398: versionitem = document.getElementById(context+'_recaptchaversion');
17399: } else {
17400: return;
17401: }
17402: if (document.getElementById(context+'_recaptchavertxt')) {
17403: versiontext = document.getElementById(context+'_recaptchavertxt');
17404: } else {
17405: return;
17406: }
1.165 raeburn 17407: if (caller.checked) {
17408: if (caller.value == 'recaptcha') {
17409: pubitem.type = 'text';
17410: privitem.type = 'text';
17411: pubitem.size = '40';
17412: privitem.size = '40';
17413: pubtext.innerHTML = "$lt{'pub'}";
17414: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 17415: versionitem.type = 'text';
17416: versionitem.size = '3';
1.289 raeburn 17417: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 17418: } else {
17419: pubitem.type = 'hidden';
17420: privitem.type = 'hidden';
1.269 raeburn 17421: versionitem.type = 'hidden';
1.165 raeburn 17422: pubtext.innerHTML = '';
17423: privtext.innerHTML = '';
1.269 raeburn 17424: versiontext.innerHTML = '';
1.165 raeburn 17425: }
17426: }
17427: return;
17428: }
17429:
17430: // ]]>
17431: </script>
17432:
17433: END
17434:
17435: }
17436:
1.236 raeburn 17437: sub toggle_display_js {
1.192 raeburn 17438: return <<"END";
17439:
17440: <script type="text/javascript">
17441: // <![CDATA[
17442:
1.236 raeburn 17443: function toggleDisplay(domForm,caller) {
17444: if (document.getElementById(caller)) {
17445: var divitem = document.getElementById(caller);
17446: var optionsElement = domForm.coursecredits;
1.264 raeburn 17447: var checkval = 1;
17448: var dispval = 'block';
1.303 raeburn 17449: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 17450: if (caller == 'emailoptions') {
17451: optionsElement = domForm.cancreate_email;
17452: }
1.257 raeburn 17453: if (caller == 'studentsubmission') {
17454: optionsElement = domForm.postsubmit;
17455: }
1.264 raeburn 17456: if (caller == 'cloneinstcode') {
17457: optionsElement = domForm.canclone;
17458: checkval = 'instcode';
17459: }
1.303 raeburn 17460: if (selfcreateRegExp.test(caller)) {
17461: optionsElement = domForm.elements[caller];
17462: checkval = 'other';
17463: dispval = 'inline'
17464: }
1.236 raeburn 17465: if (optionsElement.length) {
1.192 raeburn 17466: var currval;
1.236 raeburn 17467: for (var i=0; i<optionsElement.length; i++) {
17468: if (optionsElement[i].checked) {
17469: currval = optionsElement[i].value;
1.192 raeburn 17470: }
17471: }
1.264 raeburn 17472: if (currval == checkval) {
17473: divitem.style.display = dispval;
1.192 raeburn 17474: } else {
1.236 raeburn 17475: divitem.style.display = 'none';
1.192 raeburn 17476: }
17477: }
17478: }
17479: return;
17480: }
17481:
17482: // ]]>
17483: </script>
17484:
17485: END
17486:
17487: }
17488:
1.165 raeburn 17489: sub captcha_phrases {
17490: return &Apache::lonlocal::texthash (
17491: priv => 'Private key',
17492: pub => 'Public key',
17493: original => 'original (CAPTCHA)',
17494: recaptcha => 'successor (ReCAPTCHA)',
17495: notused => 'unused',
1.289 raeburn 17496: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 17497: );
17498: }
17499:
1.205 raeburn 17500: sub devalidate_remote_domconfs {
1.212 raeburn 17501: my ($dom,$cachekeys) = @_;
17502: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 17503: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17504: my %thismachine;
17505: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 17506: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 17507: if (keys(%servers)) {
1.205 raeburn 17508: foreach my $server (keys(%servers)) {
17509: next if ($thismachine{$server});
1.212 raeburn 17510: my @cached;
17511: foreach my $name (@posscached) {
17512: if ($cachekeys->{$name}) {
17513: push(@cached,&escape($name).':'.&escape($dom));
17514: }
17515: }
17516: if (@cached) {
17517: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17518: }
1.205 raeburn 17519: }
17520: }
17521: return;
17522: }
17523:
1.3 raeburn 17524: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>