Annotation of loncom/interface/domainprefs.pm, revision 1.347
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.347 ! raeburn 4: # $Id: domainprefs.pm,v 1.346 2019/01/27 14:39:48 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 107: (official, unofficial, community, textbook, placement, and lti).
1.271 raeburn 108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.1 raeburn 179:
1.155 raeburn 180: my $registered_cleanup;
181: my $modified_urls;
182:
1.1 raeburn 183: sub handler {
184: my $r=shift;
185: if ($r->header_only) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: return OK;
189: }
190:
1.91 raeburn 191: my $context = 'domain';
1.1 raeburn 192: my $dom = $env{'request.role.domain'};
1.5 albertel 193: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 194: if (&Apache::lonnet::allowed('mau',$dom)) {
195: &Apache::loncommon::content_type($r,'text/html');
196: $r->send_http_header;
197: } else {
198: $env{'user.error.msg'}=
199: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
200: return HTTP_NOT_ACCEPTABLE;
201: }
1.155 raeburn 202:
203: $registered_cleanup=0;
204: @{$modified_urls}=();
205:
1.1 raeburn 206: &Apache::lonhtmlcommon::clear_breadcrumbs();
207: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 208: ['phase','actions']);
1.30 raeburn 209: my $phase = 'pickactions';
1.3 raeburn 210: if ( exists($env{'form.phase'}) ) {
211: $phase = $env{'form.phase'};
212: }
1.150 raeburn 213: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 214: my %domconfig =
1.6 raeburn 215: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 216: 'quotas','autoenroll','autoupdate','autocreate',
217: 'directorysrch','usercreation','usermodification',
218: 'contacts','defaults','scantron','coursecategories',
219: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 220: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 221: 'requestauthor','selfenrollment','inststatus',
1.320 raeburn 222: 'ltitools','ssl','trust','lti'],$dom);
223: my %encconfig =
224: &Apache::lonnet::get_dom('encconfig',['ltitools','lti'],$dom);
1.297 raeburn 225: if (ref($domconfig{'ltitools'}) eq 'HASH') {
226: if (ref($encconfig{'ltitools'}) eq 'HASH') {
227: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 228: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
229: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297 raeburn 230: foreach my $item ('key','secret') {
231: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
232: }
233: }
234: }
235: }
236: }
1.320 raeburn 237: if (ref($domconfig{'lti'}) eq 'HASH') {
238: if (ref($encconfig{'lti'}) eq 'HASH') {
239: foreach my $id (keys(%{$domconfig{'lti'}})) {
240: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
241: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
242: foreach my $item ('key','secret') {
243: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
244: }
245: }
246: }
247: }
248: }
1.43 raeburn 249: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 250: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 251: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 252: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 253: 'serverstatuses','helpsettings','coursedefaults',
1.320 raeburn 254: 'ltitools','selfenrollment','usersessions','ssl','trust','lti');
1.171 raeburn 255: my %existing;
256: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
257: %existing = %{$domconfig{'loadbalancing'}};
258: }
259: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 260: push(@prefs_order,'loadbalancing');
261: }
1.30 raeburn 262: my %prefs = (
263: 'rolecolors' =>
264: { text => 'Default color schemes',
1.67 raeburn 265: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 266: header => [{col1 => 'Student Settings',
267: col2 => '',},
268: {col1 => 'Coordinator Settings',
269: col2 => '',},
270: {col1 => 'Author Settings',
271: col2 => '',},
272: {col1 => 'Administrator Settings',
273: col2 => '',}],
1.230 raeburn 274: print => \&print_rolecolors,
275: modify => \&modify_rolecolors,
1.30 raeburn 276: },
1.110 raeburn 277: 'login' =>
1.30 raeburn 278: { text => 'Log-in page options',
1.67 raeburn 279: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 280: header => [{col1 => 'Log-in Page Items',
281: col2 => '',},
282: {col1 => 'Log-in Help',
1.256 raeburn 283: col2 => 'Value'},
284: {col1 => 'Custom HTML in document head',
1.168 raeburn 285: col2 => 'Value'}],
1.230 raeburn 286: print => \&print_login,
287: modify => \&modify_login,
1.30 raeburn 288: },
1.43 raeburn 289: 'defaults' =>
1.236 raeburn 290: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 291: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 292: header => [{col1 => 'Setting',
1.236 raeburn 293: col2 => 'Value'},
1.294 raeburn 294: {col1 => 'Internal Authentication',
295: col2 => 'Value'},
1.236 raeburn 296: {col1 => 'Institutional user types',
1.305 raeburn 297: col2 => 'Name displayed'}],
1.230 raeburn 298: print => \&print_defaults,
299: modify => \&modify_defaults,
1.43 raeburn 300: },
1.30 raeburn 301: 'quotas' =>
1.197 raeburn 302: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 303: help => 'Domain_Configuration_Quotas',
1.77 raeburn 304: header => [{col1 => 'User affiliation',
1.72 raeburn 305: col2 => 'Available tools',
1.213 raeburn 306: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 307: print => \&print_quotas,
308: modify => \&modify_quotas,
1.30 raeburn 309: },
310: 'autoenroll' =>
311: { text => 'Auto-enrollment settings',
1.67 raeburn 312: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 313: header => [{col1 => 'Configuration setting',
314: col2 => 'Value(s)'}],
1.230 raeburn 315: print => \&print_autoenroll,
316: modify => \&modify_autoenroll,
1.30 raeburn 317: },
318: 'autoupdate' =>
319: { text => 'Auto-update settings',
1.67 raeburn 320: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 321: header => [{col1 => 'Setting',
322: col2 => 'Value',},
1.131 raeburn 323: {col1 => 'Setting',
324: col2 => 'Affiliation'},
1.43 raeburn 325: {col1 => 'User population',
1.227 bisitz 326: col2 => 'Updatable user data'}],
1.230 raeburn 327: print => \&print_autoupdate,
328: modify => \&modify_autoupdate,
1.30 raeburn 329: },
1.125 raeburn 330: 'autocreate' =>
331: { text => 'Auto-course creation settings',
332: help => 'Domain_Configuration_Auto_Creation',
333: header => [{col1 => 'Configuration Setting',
334: col2 => 'Value',}],
1.230 raeburn 335: print => \&print_autocreate,
336: modify => \&modify_autocreate,
1.125 raeburn 337: },
1.30 raeburn 338: 'directorysrch' =>
1.277 raeburn 339: { text => 'Directory searches',
1.67 raeburn 340: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 341: header => [{col1 => 'Institutional Directory Setting',
342: col2 => 'Value',},
343: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 344: col2 => 'Value',}],
1.230 raeburn 345: print => \&print_directorysrch,
346: modify => \&modify_directorysrch,
1.30 raeburn 347: },
348: 'contacts' =>
1.286 raeburn 349: { text => 'E-mail addresses and helpform',
1.67 raeburn 350: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 351: header => [{col1 => 'Default e-mail addresses',
352: col2 => 'Value',},
353: {col1 => 'Recipient(s) for notifications',
354: col2 => 'Value',},
1.340 raeburn 355: {col1 => 'Nightly status check e-mail',
356: col2 => 'Settings',},
1.286 raeburn 357: {col1 => 'Ask helpdesk form settings',
358: col2 => 'Value',},],
1.230 raeburn 359: print => \&print_contacts,
360: modify => \&modify_contacts,
1.30 raeburn 361: },
362: 'usercreation' =>
363: { text => 'User creation',
1.67 raeburn 364: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 365: header => [{col1 => 'Format rule type',
366: col2 => 'Format rules in force'},
1.34 raeburn 367: {col1 => 'User account creation',
368: col2 => 'Usernames which may be created',},
1.30 raeburn 369: {col1 => 'Context',
1.43 raeburn 370: col2 => 'Assignable authentication types'}],
1.230 raeburn 371: print => \&print_usercreation,
372: modify => \&modify_usercreation,
1.30 raeburn 373: },
1.224 raeburn 374: 'selfcreation' =>
375: { text => 'Users self-creating accounts',
376: help => 'Domain_Configuration_Self_Creation',
377: header => [{col1 => 'Self-creation with institutional username',
378: col2 => 'Enabled?'},
379: {col1 => 'Institutional user type (login/SSO self-creation)',
380: col2 => 'Information user can enter'},
1.303 raeburn 381: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 382: col2 => 'Settings'}],
1.230 raeburn 383: print => \&print_selfcreation,
384: modify => \&modify_selfcreation,
1.224 raeburn 385: },
1.69 raeburn 386: 'usermodification' =>
1.33 raeburn 387: { text => 'User modification',
1.67 raeburn 388: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 389: header => [{col1 => 'Target user has role',
1.227 bisitz 390: col2 => 'User information updatable in author context'},
1.33 raeburn 391: {col1 => 'Target user has role',
1.227 bisitz 392: col2 => 'User information updatable in course context'}],
1.230 raeburn 393: print => \&print_usermodification,
394: modify => \&modify_usermodification,
1.33 raeburn 395: },
1.69 raeburn 396: 'scantron' =>
1.346 raeburn 397: { text => 'Bubblesheet format',
1.67 raeburn 398: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 399: header => [ {col1 => 'Bubblesheet format file',
400: col2 => ''},
401: {col1 => 'Bubblesheet data upload formats',
402: col2 => 'Settings'}],
1.230 raeburn 403: print => \&print_scantron,
404: modify => \&modify_scantron,
1.46 raeburn 405: },
1.86 raeburn 406: 'requestcourses' =>
407: {text => 'Request creation of courses',
408: help => 'Domain_Configuration_Request_Courses',
409: header => [{col1 => 'User affiliation',
1.102 raeburn 410: col2 => 'Availability/Processing of requests',},
411: {col1 => 'Setting',
1.216 raeburn 412: col2 => 'Value'},
413: {col1 => 'Available textbooks',
1.235 raeburn 414: col2 => ''},
1.242 raeburn 415: {col1 => 'Available templates',
416: col2 => ''},
1.235 raeburn 417: {col1 => 'Validation (not official courses)',
418: col2 => 'Value'},],
1.230 raeburn 419: print => \&print_quotas,
420: modify => \&modify_quotas,
1.86 raeburn 421: },
1.163 raeburn 422: 'requestauthor' =>
1.223 bisitz 423: {text => 'Request Authoring Space',
1.163 raeburn 424: help => 'Domain_Configuration_Request_Author',
425: header => [{col1 => 'User affiliation',
426: col2 => 'Availability/Processing of requests',},
427: {col1 => 'Setting',
428: col2 => 'Value'}],
1.230 raeburn 429: print => \&print_quotas,
430: modify => \&modify_quotas,
1.163 raeburn 431: },
1.69 raeburn 432: 'coursecategories' =>
1.120 raeburn 433: { text => 'Cataloging of courses/communities',
1.67 raeburn 434: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 435: header => [{col1 => 'Catalog type/availability',
436: col2 => '',},
437: {col1 => 'Category settings for standard catalog',
1.57 raeburn 438: col2 => '',},
439: {col1 => 'Categories',
440: col2 => '',
441: }],
1.230 raeburn 442: print => \&print_coursecategories,
443: modify => \&modify_coursecategories,
1.69 raeburn 444: },
445: 'serverstatuses' =>
1.77 raeburn 446: {text => 'Access to server status pages',
1.69 raeburn 447: help => 'Domain_Configuration_Server_Status',
448: header => [{col1 => 'Status Page',
449: col2 => 'Other named users',
450: col3 => 'Specific IPs',
451: }],
1.230 raeburn 452: print => \&print_serverstatuses,
453: modify => \&modify_serverstatuses,
1.69 raeburn 454: },
1.118 jms 455: 'helpsettings' =>
1.282 raeburn 456: {text => 'Support settings',
1.118 jms 457: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 458: header => [{col1 => 'Help Page Settings (logged-in users)',
459: col2 => 'Value'},
460: {col1 => 'Helpdesk Roles',
461: col2 => 'Settings'},],
1.230 raeburn 462: print => \&print_helpsettings,
463: modify => \&modify_helpsettings,
1.118 jms 464: },
1.121 raeburn 465: 'coursedefaults' =>
466: {text => 'Course/Community defaults',
467: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 468: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
469: col2 => 'Value',},
470: {col1 => 'Defaults which can be overridden for each course by a DC',
471: col2 => 'Value',},],
1.230 raeburn 472: print => \&print_coursedefaults,
473: modify => \&modify_coursedefaults,
1.121 raeburn 474: },
1.231 raeburn 475: 'selfenrollment' =>
476: {text => 'Self-enrollment in Course/Community',
477: help => 'Domain_Configuration_Selfenrollment',
478: header => [{col1 => 'Configuration Rights',
479: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
480: {col1 => 'Defaults',
481: col2 => 'Value'},
482: {col1 => 'Self-enrollment validation (optional)',
483: col2 => 'Value'},],
484: print => \&print_selfenrollment,
485: modify => \&modify_selfenrollment,
486: },
1.120 raeburn 487: 'privacy' =>
488: {text => 'User Privacy',
489: help => 'Domain_Configuration_User_Privacy',
490: header => [{col1 => 'Setting',
491: col2 => 'Value',}],
1.230 raeburn 492: print => \&print_privacy,
493: modify => \&modify_privacy,
1.120 raeburn 494: },
1.141 raeburn 495: 'usersessions' =>
1.145 raeburn 496: {text => 'User session hosting/offloading',
1.137 raeburn 497: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 498: header => [{col1 => 'Domain server',
499: col2 => 'Servers to offload sessions to when busy'},
500: {col1 => 'Hosting of users from other domains',
1.137 raeburn 501: col2 => 'Rules'},
502: {col1 => "Hosting domain's own users elsewhere",
503: col2 => 'Rules'}],
1.230 raeburn 504: print => \&print_usersessions,
505: modify => \&modify_usersessions,
1.137 raeburn 506: },
1.279 raeburn 507: 'loadbalancing' =>
1.185 raeburn 508: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 509: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 510: header => [{col1 => 'Balancers',
1.150 raeburn 511: col2 => 'Default destinations',
1.183 bisitz 512: col3 => 'User affiliation',
1.150 raeburn 513: col4 => 'Overrides'},
514: ],
1.230 raeburn 515: print => \&print_loadbalancing,
516: modify => \&modify_loadbalancing,
1.150 raeburn 517: },
1.279 raeburn 518: 'ltitools' =>
1.267 raeburn 519: {text => 'External Tools (LTI)',
1.296 raeburn 520: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 521: header => [{col1 => 'Setting',
522: col2 => 'Value',}],
523: print => \&print_ltitools,
524: modify => \&modify_ltitools,
525: },
1.279 raeburn 526: 'ssl' =>
1.275 raeburn 527: {text => 'LON-CAPA Network (SSL)',
528: help => 'Domain_Configuration_Network_SSL',
529: header => [{col1 => 'Server',
530: col2 => 'Certificate Status'},
531: {col1 => 'Connections to other servers',
532: col2 => 'Rules'},
1.293 raeburn 533: {col1 => 'Connections from other servers',
534: col2 => 'Rules'},
1.275 raeburn 535: {col1 => "Replicating domain's published content",
536: col2 => 'Rules'}],
537: print => \&print_ssl,
538: modify => \&modify_ssl,
539: },
1.279 raeburn 540: 'trust' =>
541: {text => 'Trust Settings',
542: help => 'Domain_Configuration_Trust',
543: header => [{col1 => "Access to this domain's content by others",
544: col2 => 'Rules'},
545: {col1 => "Access to other domain's content by this domain",
546: col2 => 'Rules'},
547: {col1 => "Enrollment in this domain's courses by others",
548: col2 => 'Rules',},
549: {col1 => "Co-author roles in this domain for others",
550: col2 => 'Rules',},
551: {col1 => "Co-author roles for this domain's users elsewhere",
552: col2 => 'Rules',},
553: {col1 => "Domain roles in this domain assignable to others",
554: col2 => 'Rules'},
555: {col1 => "Course catalog for this domain displayed elsewhere",
556: col2 => 'Rules'},
557: {col1 => "Requests for creation of courses in this domain by others",
558: col2 => 'Rules'},
559: {col1 => "Users in other domains can send messages to this domain",
560: col2 => 'Rules'},],
561: print => \&print_trust,
562: modify => \&modify_trust,
563: },
1.320 raeburn 564: 'lti' =>
565: {text => 'LTI Provider',
566: help => 'Domain_Configuration_LTI_Provider',
567: header => [{col1 => 'Setting',
568: col2 => 'Value',}],
569: print => \&print_lti,
570: modify => \&modify_lti,
571: },
1.3 raeburn 572: );
1.110 raeburn 573: if (keys(%servers) > 1) {
574: $prefs{'login'} = { text => 'Log-in page options',
575: help => 'Domain_Configuration_Login_Page',
576: header => [{col1 => 'Log-in Service',
577: col2 => 'Server Setting',},
578: {col1 => 'Log-in Page Items',
1.168 raeburn 579: col2 => ''},
580: {col1 => 'Log-in Help',
1.256 raeburn 581: col2 => 'Value'},
582: {col1 => 'Custom HTML in document head',
1.168 raeburn 583: col2 => 'Value'}],
1.230 raeburn 584: print => \&print_login,
585: modify => \&modify_login,
1.110 raeburn 586: };
587: }
1.174 foxr 588:
1.6 raeburn 589: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 590: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 591: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 592: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 593: text=>"Settings to display/modify"});
1.9 raeburn 594: my $confname = $dom.'-domainconfig';
1.174 foxr 595:
1.3 raeburn 596: if ($phase eq 'process') {
1.212 raeburn 597: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
598: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 599: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 600: $r->rflush();
1.212 raeburn 601: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 602: }
1.30 raeburn 603: } elsif ($phase eq 'display') {
1.192 raeburn 604: my $js = &recaptcha_js().
1.236 raeburn 605: &toggle_display_js();
1.171 raeburn 606: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 607: my ($othertitle,$usertypes,$types) =
608: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 609: $js .= &lonbalance_targets_js($dom,$types,\%servers,
610: $domconfig{'loadbalancing'}).
1.170 raeburn 611: &new_spares_js().
612: &common_domprefs_js().
613: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 614: }
1.216 raeburn 615: if (grep(/^requestcourses$/,@actions)) {
616: my $javascript_validations;
617: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
618: $js .= <<END;
619: <script type="text/javascript">
620: $javascript_validations
621: </script>
622: $coursebrowserjs
623: END
624: }
1.305 raeburn 625: if (grep(/^selfcreation$/,@actions)) {
626: $js .= &selfcreate_javascript();
627: }
1.286 raeburn 628: if (grep(/^contacts$/,@actions)) {
629: $js .= &contacts_javascript();
630: }
1.346 raeburn 631: if (grep(/^scantron$/,@actions)) {
632: $js .= &scantron_javascript();
633: }
1.150 raeburn 634: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 635: } else {
1.180 raeburn 636: # check if domconfig user exists for the domain.
637: my $servadm = $r->dir_config('lonAdmEMail');
638: my ($configuserok,$author_ok,$switchserver) =
639: &config_check($dom,$confname,$servadm);
640: unless ($configuserok eq 'ok') {
1.181 raeburn 641: &Apache::lonconfigsettings::print_header($r,$phase,$context);
642: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 643: $confname).
1.181 raeburn 644: '<br />'
645: );
1.180 raeburn 646: if ($switchserver) {
1.181 raeburn 647: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
648: '<br />'.
649: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
650: '<br />'.
651: &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).
652: '<br />'.
653: &mt('To do that now, use the following link: [_1]',$switchserver)
654: );
655: } else {
656: $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.').
657: '<br />'.
658: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
659: );
1.180 raeburn 660: }
661: $r->print(&Apache::loncommon::end_page());
662: return OK;
663: }
1.21 raeburn 664: if (keys(%domconfig) == 0) {
665: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 666: my @ids=&Apache::lonnet::current_machine_ids();
667: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 668: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 669: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 670: my $custom_img_count = 0;
671: foreach my $img (@loginimages) {
672: if ($designhash{$dom.'.login.'.$img} ne '') {
673: $custom_img_count ++;
674: }
675: }
676: foreach my $role (@roles) {
677: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
678: $custom_img_count ++;
679: }
680: }
681: if ($custom_img_count > 0) {
1.94 raeburn 682: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 683: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 684: $r->print(
685: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
686: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
687: &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 />'.
688: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
689: if ($switch_server) {
1.30 raeburn 690: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 691: }
1.91 raeburn 692: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 693: return OK;
694: }
695: }
696: }
1.91 raeburn 697: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 698: }
699: return OK;
700: }
701:
702: sub process_changes {
1.205 raeburn 703: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 704: my %domconfig;
705: if (ref($values) eq 'HASH') {
706: %domconfig = %{$values};
707: }
1.3 raeburn 708: my $output;
709: if ($action eq 'login') {
1.205 raeburn 710: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 711: } elsif ($action eq 'rolecolors') {
1.9 raeburn 712: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 713: $lastactref,%domconfig);
1.3 raeburn 714: } elsif ($action eq 'quotas') {
1.216 raeburn 715: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 716: } elsif ($action eq 'autoenroll') {
1.205 raeburn 717: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 718: } elsif ($action eq 'autoupdate') {
719: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 720: } elsif ($action eq 'autocreate') {
721: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 722: } elsif ($action eq 'directorysrch') {
1.295 raeburn 723: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 724: } elsif ($action eq 'usercreation') {
1.28 raeburn 725: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 726: } elsif ($action eq 'selfcreation') {
1.305 raeburn 727: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 728: } elsif ($action eq 'usermodification') {
729: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 730: } elsif ($action eq 'contacts') {
1.205 raeburn 731: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 732: } elsif ($action eq 'defaults') {
1.212 raeburn 733: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 734: } elsif ($action eq 'scantron') {
1.205 raeburn 735: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 736: } elsif ($action eq 'coursecategories') {
1.239 raeburn 737: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 738: } elsif ($action eq 'serverstatuses') {
739: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 740: } elsif ($action eq 'requestcourses') {
1.216 raeburn 741: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 742: } elsif ($action eq 'requestauthor') {
1.216 raeburn 743: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 744: } elsif ($action eq 'helpsettings') {
1.285 raeburn 745: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 746: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 747: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 748: } elsif ($action eq 'selfenrollment') {
749: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 750: } elsif ($action eq 'usersessions') {
1.212 raeburn 751: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 752: } elsif ($action eq 'loadbalancing') {
753: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 754: } elsif ($action eq 'ltitools') {
755: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 756: } elsif ($action eq 'ssl') {
757: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 758: } elsif ($action eq 'trust') {
759: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 760: } elsif ($action eq 'lti') {
761: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 762: }
763: return $output;
764: }
765:
766: sub print_config_box {
1.9 raeburn 767: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 768: my $rowtotal = 0;
1.49 raeburn 769: my $output;
770: if ($action eq 'coursecategories') {
771: $output = &coursecategories_javascript($settings);
1.236 raeburn 772: } elsif ($action eq 'defaults') {
773: $output = &defaults_javascript($settings);
1.282 raeburn 774: } elsif ($action eq 'helpsettings') {
775: my (%privs,%levelscurrent);
776: my %full=();
777: my %levels=(
778: course => {},
779: domain => {},
780: system => {},
781: );
782: my $context = 'domain';
783: my $crstype = 'Course';
784: my $formname = 'display';
785: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
786: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
787: $output =
788: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
789: \@templateroles);
1.334 raeburn 790: } elsif ($action eq 'ltitools') {
791: $output .= <itools_javascript($settings);
792: } elsif ($action eq 'lti') {
793: $output .= <i_javascript($settings);
1.91 raeburn 794: }
1.236 raeburn 795: $output .=
1.30 raeburn 796: '<table class="LC_nested_outer">
1.3 raeburn 797: <tr>
1.306 raeburn 798: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 799: &mt($item->{text}).' '.
800: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
801: '</tr>';
1.30 raeburn 802: $rowtotal ++;
1.110 raeburn 803: my $numheaders = 1;
804: if (ref($item->{'header'}) eq 'ARRAY') {
805: $numheaders = scalar(@{$item->{'header'}});
806: }
807: if ($numheaders > 1) {
1.64 raeburn 808: my $colspan = '';
1.145 raeburn 809: my $rightcolspan = '';
1.238 raeburn 810: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 811: ($action eq 'directorysrch') ||
1.256 raeburn 812: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 813: $colspan = ' colspan="2"';
814: }
1.145 raeburn 815: if ($action eq 'usersessions') {
816: $rightcolspan = ' colspan="3"';
817: }
1.30 raeburn 818: $output .= '
1.3 raeburn 819: <tr>
820: <td>
821: <table class="LC_nested">
822: <tr class="LC_info_row">
1.59 bisitz 823: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 824: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 825: </tr>';
1.69 raeburn 826: $rowtotal ++;
1.230 raeburn 827: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 828: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 829: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 830: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
831: ($action eq 'contacts')) {
1.230 raeburn 832: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 833: } elsif ($action eq 'coursecategories') {
1.230 raeburn 834: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 835: } elsif ($action eq 'scantron') {
836: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 837: } elsif ($action eq 'login') {
1.256 raeburn 838: if ($numheaders == 4) {
1.168 raeburn 839: $colspan = ' colspan="2"';
840: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
841: } else {
842: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
843: }
1.230 raeburn 844: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 845: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 846: } elsif ($action eq 'rolecolors') {
1.30 raeburn 847: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 848: }
1.30 raeburn 849: $output .= '
1.6 raeburn 850: </table>
851: </td>
852: </tr>
853: <tr>
854: <td>
855: <table class="LC_nested">
856: <tr class="LC_info_row">
1.230 raeburn 857: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 858: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 859: </tr>';
860: $rowtotal ++;
1.230 raeburn 861: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
862: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 863: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.294 raeburn 864: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {
1.238 raeburn 865: if ($action eq 'coursecategories') {
866: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
867: $colspan = ' colspan="2"';
1.279 raeburn 868: } elsif ($action eq 'trust') {
869: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 870: } else {
871: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
872: }
1.279 raeburn 873: if ($action eq 'trust') {
874: $output .= '
875: </table>
876: </td>
877: </tr>';
878: my @trusthdrs = qw(2 3 4 5 6 7);
879: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
880: for (my $i=0; $i<@trusthdrs; $i++) {
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'}->[$trusthdrs[$i]]->{'col1'}).'</td>
887: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
888: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
889: </table>
890: </td>
891: </tr>';
892: }
893: $output .= '
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'}->[8]->{'col1'}).'</td>
899: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
900: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
901: } else {
902: $output .= '
1.63 raeburn 903: </table>
904: </td>
905: </tr>
906: <tr>
907: <td>
908: <table class="LC_nested">
909: <tr class="LC_info_row">
910: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 911: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 912: </tr>'."\n";
1.279 raeburn 913: if ($action eq 'coursecategories') {
914: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.340 raeburn 915: } elsif ($action eq 'contacts') {
916: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal).'
917: </tr>
918: </table>
919: </td>
920: </tr>
921: <tr>
922: <td>
923: <table class="LC_nested">
924: <tr class="LC_info_row">
925: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
926: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
927: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal).'
928: </table>
929: </td>
930: </tr>
931: <tr>';
1.279 raeburn 932: } else {
933: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
934: }
1.238 raeburn 935: }
1.63 raeburn 936: $rowtotal ++;
1.236 raeburn 937: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 938: ($action eq 'defaults') || ($action eq 'directorysrch') ||
939: ($action eq 'helpsettings')) {
1.230 raeburn 940: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 941: } elsif ($action eq 'scantron') {
942: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 943: } elsif ($action eq 'ssl') {
944: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
945: </table>
946: </td>
947: </tr>
948: <tr>
949: <td>
950: <table class="LC_nested">
951: <tr class="LC_info_row">
952: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
953: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
954: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
955: </table>
956: </td>
957: </tr>
958: <tr>
959: <td>
960: <table class="LC_nested">
961: <tr class="LC_info_row">
962: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
963: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
964: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 965: } elsif ($action eq 'login') {
1.256 raeburn 966: if ($numheaders == 4) {
1.168 raeburn 967: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
968: </table>
969: </td>
970: </tr>
971: <tr>
972: <td>
973: <table class="LC_nested">
974: <tr class="LC_info_row">
975: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 976: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 977: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
978: $rowtotal ++;
979: } else {
980: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
981: }
1.256 raeburn 982: $output .= '
983: </table>
984: </td>
985: </tr>
986: <tr>
987: <td>
988: <table class="LC_nested">
989: <tr class="LC_info_row">';
990: if ($numheaders == 4) {
991: $output .= '
992: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
993: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
994: </tr>';
995: } else {
996: $output .= '
997: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
998: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
999: </tr>';
1000: }
1001: $rowtotal ++;
1002: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1003: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1004: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1005: $rowtotal ++;
1006: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1007: </table>
1008: </td>
1009: </tr>
1010: <tr>
1011: <td>
1012: <table class="LC_nested">
1013: <tr class="LC_info_row">
1014: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1015: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1016: &textbookcourses_javascript($settings).
1017: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1018: </table>
1019: </td>
1020: </tr>
1021: <tr>
1022: <td>
1023: <table class="LC_nested">
1024: <tr class="LC_info_row">
1025: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1026: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1027: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1028: </table>
1029: </td>
1030: </tr>
1031: <tr>
1032: <td>
1033: <table class="LC_nested">
1034: <tr class="LC_info_row">
1.306 raeburn 1035: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1036: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1037: </tr>'.
1038: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1039: } elsif ($action eq 'requestauthor') {
1040: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1041: $rowtotal ++;
1.122 jms 1042: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1043: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1044: </table>
1045: </td>
1046: </tr>
1047: <tr>
1048: <td>
1049: <table class="LC_nested">
1050: <tr class="LC_info_row">
1.306 raeburn 1051: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1052: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1053: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1054: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1055: </tr>'.
1.30 raeburn 1056: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1057: </table>
1058: </td>
1059: </tr>
1060: <tr>
1061: <td>
1062: <table class="LC_nested">
1063: <tr class="LC_info_row">
1.59 bisitz 1064: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1065: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1066: </tr>'.
1.30 raeburn 1067: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1068: $rowtotal += 2;
1.6 raeburn 1069: }
1.3 raeburn 1070: } else {
1.30 raeburn 1071: $output .= '
1.3 raeburn 1072: <tr>
1073: <td>
1074: <table class="LC_nested">
1.30 raeburn 1075: <tr class="LC_info_row">';
1.277 raeburn 1076: if ($action eq 'login') {
1.30 raeburn 1077: $output .= '
1.59 bisitz 1078: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1079: } elsif ($action eq 'serverstatuses') {
1080: $output .= '
1.306 raeburn 1081: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1082: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1083:
1.6 raeburn 1084: } else {
1.30 raeburn 1085: $output .= '
1.306 raeburn 1086: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1087: }
1.72 raeburn 1088: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1089: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1090: &mt($item->{'header'}->[0]->{'col2'});
1091: if ($action eq 'serverstatuses') {
1092: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1093: }
1.69 raeburn 1094: } else {
1.306 raeburn 1095: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1096: &mt($item->{'header'}->[0]->{'col2'});
1097: }
1098: $output .= '</td>';
1099: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1100: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1101: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1102: &mt($item->{'header'}->[0]->{'col3'});
1103: } else {
1.306 raeburn 1104: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1105: &mt($item->{'header'}->[0]->{'col3'});
1106: }
1.69 raeburn 1107: if ($action eq 'serverstatuses') {
1108: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1109: }
1110: $output .= '</td>';
1.6 raeburn 1111: }
1.150 raeburn 1112: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1113: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1114: &mt($item->{'header'}->[0]->{'col4'});
1115: }
1.69 raeburn 1116: $output .= '</tr>';
1.48 raeburn 1117: $rowtotal ++;
1.168 raeburn 1118: if ($action eq 'quotas') {
1.86 raeburn 1119: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1120: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1121: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.320 raeburn 1122: ($action eq 'ltitools') || ($action eq 'lti')) {
1.230 raeburn 1123: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1124: }
1.3 raeburn 1125: }
1.30 raeburn 1126: $output .= '
1.3 raeburn 1127: </table>
1128: </td>
1129: </tr>
1.30 raeburn 1130: </table><br />';
1131: return ($output,$rowtotal);
1.1 raeburn 1132: }
1133:
1.3 raeburn 1134: sub print_login {
1.168 raeburn 1135: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1136: my ($css_class,$datatable);
1.6 raeburn 1137: my %choices = &login_choices();
1.110 raeburn 1138:
1.168 raeburn 1139: if ($caller eq 'service') {
1.149 raeburn 1140: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1141: my $choice = $choices{'disallowlogin'};
1142: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1143: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1144: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1145: '<th>'.$choices{'server'}.'</th>'.
1146: '<th>'.$choices{'serverpath'}.'</th>'.
1147: '<th>'.$choices{'custompath'}.'</th>'.
1148: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1149: my %disallowed;
1150: if (ref($settings) eq 'HASH') {
1151: if (ref($settings->{'loginvia'}) eq 'HASH') {
1152: %disallowed = %{$settings->{'loginvia'}};
1153: }
1154: }
1155: foreach my $lonhost (sort(keys(%servers))) {
1156: my $direct = 'selected="selected"';
1.128 raeburn 1157: if (ref($disallowed{$lonhost}) eq 'HASH') {
1158: if ($disallowed{$lonhost}{'server'} ne '') {
1159: $direct = '';
1160: }
1.110 raeburn 1161: }
1.115 raeburn 1162: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1163: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1164: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1165: '</option>';
1.184 raeburn 1166: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1167: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1168: my $selected = '';
1.128 raeburn 1169: if (ref($disallowed{$lonhost}) eq 'HASH') {
1170: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1171: $selected = 'selected="selected"';
1172: }
1.110 raeburn 1173: }
1174: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1175: $servers{$hostid}.'</option>';
1176: }
1.128 raeburn 1177: $datatable .= '</select></td>'.
1178: '<td><select name="'.$lonhost.'_serverpath">';
1179: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1180: my $pathname = $path;
1181: if ($path eq 'custom') {
1182: $pathname = &mt('Custom Path').' ->';
1183: }
1184: my $selected = '';
1185: if (ref($disallowed{$lonhost}) eq 'HASH') {
1186: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1187: $selected = 'selected="selected"';
1188: }
1189: } elsif ($path eq '') {
1190: $selected = 'selected="selected"';
1191: }
1192: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1193: }
1194: $datatable .= '</select></td>';
1195: my ($custom,$exempt);
1196: if (ref($disallowed{$lonhost}) eq 'HASH') {
1197: $custom = $disallowed{$lonhost}{'custompath'};
1198: $exempt = $disallowed{$lonhost}{'exempt'};
1199: }
1200: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1201: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1202: '</tr>';
1.110 raeburn 1203: }
1204: $datatable .= '</table></td></tr>';
1205: return $datatable;
1.168 raeburn 1206: } elsif ($caller eq 'page') {
1207: my %defaultchecked = (
1208: 'coursecatalog' => 'on',
1.188 raeburn 1209: 'helpdesk' => 'on',
1.168 raeburn 1210: 'adminmail' => 'off',
1211: 'newuser' => 'off',
1212: );
1.188 raeburn 1213: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1214: my (%checkedon,%checkedoff);
1.42 raeburn 1215: foreach my $item (@toggles) {
1.168 raeburn 1216: if ($defaultchecked{$item} eq 'on') {
1217: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1218: $checkedoff{$item} = ' ';
1.168 raeburn 1219: } elsif ($defaultchecked{$item} eq 'off') {
1220: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1221: $checkedon{$item} = ' ';
1222: }
1.1 raeburn 1223: }
1.168 raeburn 1224: my @images = ('img','logo','domlogo','login');
1225: my @logintext = ('textcol','bgcol');
1226: my @bgs = ('pgbg','mainbg','sidebg');
1227: my @links = ('link','alink','vlink');
1228: my %designhash = &Apache::loncommon::get_domainconf($dom);
1229: my %defaultdesign = %Apache::loncommon::defaultdesign;
1230: my (%is_custom,%designs);
1231: my %defaults = (
1232: font => $defaultdesign{'login.font'},
1233: );
1.6 raeburn 1234: foreach my $item (@images) {
1.168 raeburn 1235: $defaults{$item} = $defaultdesign{'login.'.$item};
1236: $defaults{'showlogo'}{$item} = 1;
1237: }
1238: foreach my $item (@bgs) {
1239: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1240: }
1.41 raeburn 1241: foreach my $item (@logintext) {
1.168 raeburn 1242: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1243: }
1.168 raeburn 1244: foreach my $item (@links) {
1245: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1246: }
1.168 raeburn 1247: if (ref($settings) eq 'HASH') {
1248: foreach my $item (@toggles) {
1249: if ($settings->{$item} eq '1') {
1250: $checkedon{$item} = ' checked="checked" ';
1251: $checkedoff{$item} = ' ';
1252: } elsif ($settings->{$item} eq '0') {
1253: $checkedoff{$item} = ' checked="checked" ';
1254: $checkedon{$item} = ' ';
1255: }
1256: }
1257: foreach my $item (@images) {
1258: if (defined($settings->{$item})) {
1259: $designs{$item} = $settings->{$item};
1260: $is_custom{$item} = 1;
1261: }
1262: if (defined($settings->{'showlogo'}{$item})) {
1263: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1264: }
1265: }
1266: foreach my $item (@logintext) {
1267: if ($settings->{$item} ne '') {
1268: $designs{'logintext'}{$item} = $settings->{$item};
1269: $is_custom{$item} = 1;
1270: }
1271: }
1272: if ($settings->{'font'} ne '') {
1273: $designs{'font'} = $settings->{'font'};
1274: $is_custom{'font'} = 1;
1275: }
1276: foreach my $item (@bgs) {
1277: if ($settings->{$item} ne '') {
1278: $designs{'bgs'}{$item} = $settings->{$item};
1279: $is_custom{$item} = 1;
1280: }
1281: }
1282: foreach my $item (@links) {
1283: if ($settings->{$item} ne '') {
1284: $designs{'links'}{$item} = $settings->{$item};
1285: $is_custom{$item} = 1;
1286: }
1287: }
1288: } else {
1289: if ($designhash{$dom.'.login.font'} ne '') {
1290: $designs{'font'} = $designhash{$dom.'.login.font'};
1291: $is_custom{'font'} = 1;
1292: }
1293: foreach my $item (@images) {
1294: if ($designhash{$dom.'.login.'.$item} ne '') {
1295: $designs{$item} = $designhash{$dom.'.login.'.$item};
1296: $is_custom{$item} = 1;
1297: }
1298: }
1299: foreach my $item (@bgs) {
1300: if ($designhash{$dom.'.login.'.$item} ne '') {
1301: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1302: $is_custom{$item} = 1;
1303: }
1.6 raeburn 1304: }
1.168 raeburn 1305: foreach my $item (@links) {
1306: if ($designhash{$dom.'.login.'.$item} ne '') {
1307: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1308: $is_custom{$item} = 1;
1309: }
1.6 raeburn 1310: }
1311: }
1.168 raeburn 1312: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1313: logo => 'Institution Logo',
1314: domlogo => 'Domain Logo',
1315: login => 'Login box');
1316: my $itemcount = 1;
1317: foreach my $item (@toggles) {
1318: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1319: $datatable .=
1320: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1321: '</td><td>'.
1322: '<span class="LC_nobreak"><label><input type="radio" name="'.
1323: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1324: '</label> <label><input type="radio" name="'.$item.'"'.
1325: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1326: '</tr>';
1327: $itemcount ++;
1.6 raeburn 1328: }
1.168 raeburn 1329: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1330: $datatable .= '</tr></table></td></tr>';
1331: } elsif ($caller eq 'help') {
1332: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1333: my $switchserver = &check_switchserver($dom,$confname);
1334: my $itemcount = 1;
1335: $defaulturl = '/adm/loginproblems.html';
1336: $defaulttype = 'default';
1337: %lt = &Apache::lonlocal::texthash (
1338: del => 'Delete?',
1339: rep => 'Replace:',
1340: upl => 'Upload:',
1341: default => 'Default',
1342: custom => 'Custom',
1343: );
1344: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1345: my @currlangs;
1346: if (ref($settings) eq 'HASH') {
1347: if (ref($settings->{'helpurl'}) eq 'HASH') {
1348: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1349: next if ($settings->{'helpurl'}{$key} eq '');
1350: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1351: $type{$key} = 'custom';
1352: unless ($key eq 'nolang') {
1353: push(@currlangs,$key);
1354: }
1355: }
1356: } elsif ($settings->{'helpurl'} ne '') {
1357: $type{'nolang'} = 'custom';
1358: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1359: }
1360: }
1.168 raeburn 1361: foreach my $lang ('nolang',sort(@currlangs)) {
1362: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1363: $datatable .= '<tr'.$css_class.'>';
1364: if ($url{$lang} eq '') {
1365: $url{$lang} = $defaulturl;
1366: }
1367: if ($type{$lang} eq '') {
1368: $type{$lang} = $defaulttype;
1369: }
1370: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1371: if ($lang eq 'nolang') {
1372: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1373: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1374: } else {
1375: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1376: $langchoices{$lang},
1377: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1378: }
1379: $datatable .= '</span></td>'."\n".
1380: '<td class="LC_left_item">';
1381: if ($type{$lang} eq 'custom') {
1382: $datatable .= '<span class="LC_nobreak"><label>'.
1383: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1384: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1385: } else {
1386: $datatable .= $lt{'upl'};
1387: }
1388: $datatable .='<br />';
1389: if ($switchserver) {
1390: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1391: } else {
1392: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1393: }
1.168 raeburn 1394: $datatable .= '</td></tr>';
1395: $itemcount ++;
1.6 raeburn 1396: }
1.168 raeburn 1397: my @addlangs;
1398: foreach my $lang (sort(keys(%langchoices))) {
1399: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1400: push(@addlangs,$lang);
1401: }
1402: if (@addlangs > 0) {
1403: my %toadd;
1404: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1405: $toadd{''} = &mt('Select');
1406: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1407: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1408: &mt('Add log-in help page for a specific language:').' '.
1409: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1410: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1411: if ($switchserver) {
1412: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1413: } else {
1414: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1415: }
1.168 raeburn 1416: $datatable .= '</td></tr>';
1.169 raeburn 1417: $itemcount ++;
1.6 raeburn 1418: }
1.169 raeburn 1419: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1420: } elsif ($caller eq 'headtag') {
1421: my %domservers = &Apache::lonnet::get_servers($dom);
1422: my $choice = $choices{'headtag'};
1423: $css_class = ' class="LC_odd_row"';
1424: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1425: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1426: '<th>'.$choices{'current'}.'</th>'.
1427: '<th>'.$choices{'action'}.'</th>'.
1428: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1429: my (%currurls,%currexempt);
1430: if (ref($settings) eq 'HASH') {
1431: if (ref($settings->{'headtag'}) eq 'HASH') {
1432: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1433: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1434: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1435: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1436: }
1437: }
1438: }
1439: }
1440: my %lt = &Apache::lonlocal::texthash(
1441: del => 'Delete?',
1442: rep => 'Replace:',
1443: upl => 'Upload:',
1444: curr => 'View contents',
1445: none => 'None',
1446: );
1447: my $switchserver = &check_switchserver($dom,$confname);
1448: foreach my $lonhost (sort(keys(%domservers))) {
1449: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1450: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1451: if ($currurls{$lonhost}) {
1452: $datatable .= '<td class="LC_right_item"><a href="'.
1453: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1454: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1455: '">'.$lt{'curr'}.'</a></td>'.
1456: '<td><span class="LC_nobreak"><label>'.
1457: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1458: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1459: } else {
1460: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1461: }
1462: $datatable .='<br />';
1463: if ($switchserver) {
1464: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1465: } else {
1466: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1467: }
1.330 raeburn 1468: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1469: }
1470: $datatable .= '</table></td></tr>';
1.1 raeburn 1471: }
1.6 raeburn 1472: return $datatable;
1473: }
1474:
1475: sub login_choices {
1476: my %choices =
1477: &Apache::lonlocal::texthash (
1.116 bisitz 1478: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1479: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1480: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1481: disallowlogin => "Login page requests redirected",
1482: hostid => "Server",
1.128 raeburn 1483: server => "Redirect to:",
1484: serverpath => "Path",
1485: custompath => "Custom",
1486: exempt => "Exempt IP(s)",
1.110 raeburn 1487: directlogin => "No redirect",
1488: newuser => "Link to create a user account",
1489: img => "Header",
1490: logo => "Main Logo",
1491: domlogo => "Domain Logo",
1492: login => "Log-in Header",
1493: textcol => "Text color",
1494: bgcol => "Box color",
1495: bgs => "Background colors",
1496: links => "Link colors",
1497: font => "Font color",
1498: pgbg => "Header",
1499: mainbg => "Page",
1500: sidebg => "Login box",
1501: link => "Link",
1502: alink => "Active link",
1503: vlink => "Visited link",
1.256 raeburn 1504: headtag => "Custom markup",
1505: action => "Action",
1506: current => "Current",
1.6 raeburn 1507: );
1508: return %choices;
1509: }
1510:
1511: sub print_rolecolors {
1.30 raeburn 1512: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1513: my %choices = &color_font_choices();
1514: my @bgs = ('pgbg','tabbg','sidebg');
1515: my @links = ('link','alink','vlink');
1516: my @images = ('img');
1517: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1518: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1519: my %defaultdesign = %Apache::loncommon::defaultdesign;
1520: my (%is_custom,%designs);
1.200 raeburn 1521: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1522: if (ref($settings) eq 'HASH') {
1523: if (ref($settings->{$role}) eq 'HASH') {
1524: if ($settings->{$role}->{'img'} ne '') {
1525: $designs{'img'} = $settings->{$role}->{'img'};
1526: $is_custom{'img'} = 1;
1527: }
1528: if ($settings->{$role}->{'font'} ne '') {
1529: $designs{'font'} = $settings->{$role}->{'font'};
1530: $is_custom{'font'} = 1;
1531: }
1.97 tempelho 1532: if ($settings->{$role}->{'fontmenu'} ne '') {
1533: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1534: $is_custom{'fontmenu'} = 1;
1535: }
1.6 raeburn 1536: foreach my $item (@bgs) {
1537: if ($settings->{$role}->{$item} ne '') {
1538: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1539: $is_custom{$item} = 1;
1540: }
1541: }
1542: foreach my $item (@links) {
1543: if ($settings->{$role}->{$item} ne '') {
1544: $designs{'links'}{$item} = $settings->{$role}->{$item};
1545: $is_custom{$item} = 1;
1546: }
1547: }
1548: }
1549: } else {
1550: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1551: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1552: $is_custom{'img'} = 1;
1553: }
1.97 tempelho 1554: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1555: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1556: $is_custom{'fontmenu'} = 1;
1557: }
1.6 raeburn 1558: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1559: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1560: $is_custom{'font'} = 1;
1561: }
1562: foreach my $item (@bgs) {
1563: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1564: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1565: $is_custom{$item} = 1;
1566:
1567: }
1568: }
1569: foreach my $item (@links) {
1570: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1571: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1572: $is_custom{$item} = 1;
1573: }
1574: }
1575: }
1576: my $itemcount = 1;
1.30 raeburn 1577: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1578: $datatable .= '</tr></table></td></tr>';
1579: return $datatable;
1580: }
1581:
1.200 raeburn 1582: sub role_defaults {
1583: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1584: my %defaults;
1585: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1586: return %defaults;
1587: }
1588: my %defaultdesign = %Apache::loncommon::defaultdesign;
1589: if ($role eq 'login') {
1590: %defaults = (
1591: font => $defaultdesign{$role.'.font'},
1592: );
1593: if (ref($logintext) eq 'ARRAY') {
1594: foreach my $item (@{$logintext}) {
1595: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1596: }
1597: }
1598: foreach my $item (@{$images}) {
1599: $defaults{'showlogo'}{$item} = 1;
1600: }
1601: } else {
1602: %defaults = (
1603: img => $defaultdesign{$role.'.img'},
1604: font => $defaultdesign{$role.'.font'},
1605: fontmenu => $defaultdesign{$role.'.fontmenu'},
1606: );
1607: }
1608: foreach my $item (@{$bgs}) {
1609: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1610: }
1611: foreach my $item (@{$links}) {
1612: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1613: }
1614: foreach my $item (@{$images}) {
1615: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1616: }
1617: return %defaults;
1618: }
1619:
1.6 raeburn 1620: sub display_color_options {
1.9 raeburn 1621: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1622: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1623: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1624: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1625: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1626: '<td>'.$choices->{'font'}.'</td>';
1627: if (!$is_custom->{'font'}) {
1.329 raeburn 1628: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1629: } else {
1630: $datatable .= '<td> </td>';
1631: }
1.174 foxr 1632: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1633:
1.8 raeburn 1634: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1635: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1636: ' value="'.$current_color.'" /> '.
1.329 raeburn 1637: ' </span></td></tr>';
1.107 raeburn 1638: unless ($role eq 'login') {
1639: $datatable .= '<tr'.$css_class.'>'.
1640: '<td>'.$choices->{'fontmenu'}.'</td>';
1641: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 1642: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1643: } else {
1644: $datatable .= '<td> </td>';
1645: }
1.202 raeburn 1646: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1647: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1648: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1649: '<input class="colorchooser" type="text" size="10" name="'
1650: .$role.'_fontmenu"'.
1651: ' value="'.$current_color.'" /> '.
1.329 raeburn 1652: ' </span></td></tr>';
1.97 tempelho 1653: }
1.9 raeburn 1654: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1655: foreach my $img (@{$images}) {
1.18 albertel 1656: $itemcount ++;
1.6 raeburn 1657: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1658: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1659: '<td>'.$choices->{$img};
1.41 raeburn 1660: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1661: if ($role eq 'login') {
1662: if ($img eq 'login') {
1663: $login_hdr_pick =
1.135 bisitz 1664: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1665: $logincolors =
1666: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1667: $designs,$defaults);
1.70 raeburn 1668: } elsif ($img ne 'domlogo') {
1669: $datatable.= &logo_display_options($img,$defaults,$designs);
1670: }
1671: }
1672: $datatable .= '</td>';
1.6 raeburn 1673: if ($designs->{$img} ne '') {
1674: $imgfile = $designs->{$img};
1.18 albertel 1675: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1676: } else {
1677: $imgfile = $defaults->{$img};
1678: }
1679: if ($imgfile) {
1.9 raeburn 1680: my ($showfile,$fullsize);
1681: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1682: my $urldir = $1;
1683: my $filename = $2;
1684: my @info = &Apache::lonnet::stat_file($designs->{$img});
1685: if (@info) {
1686: my $thumbfile = 'tn-'.$filename;
1687: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1688: if (@thumb) {
1689: $showfile = $urldir.'/'.$thumbfile;
1690: } else {
1691: $showfile = $imgfile;
1692: }
1693: } else {
1694: $showfile = '';
1695: }
1696: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1697: $showfile = $imgfile;
1.6 raeburn 1698: my $imgdir = $1;
1699: my $filename = $2;
1.159 raeburn 1700: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1701: $showfile = "/$imgdir/tn-".$filename;
1702: } else {
1.159 raeburn 1703: my $input = $londocroot.$imgfile;
1704: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1705: if (!-e $output) {
1.9 raeburn 1706: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1707: my ($fullwidth,$fullheight) = &check_dimensions($input);
1708: if ($fullwidth ne '' && $fullheight ne '') {
1709: if ($fullwidth > $width && $fullheight > $height) {
1710: my $size = $width.'x'.$height;
1.316 raeburn 1711: my @args = ('convert','-sample',$size,$input,$output);
1712: system({$args[0]} @args);
1.159 raeburn 1713: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1714: }
1715: }
1.6 raeburn 1716: }
1717: }
1.16 raeburn 1718: }
1.6 raeburn 1719: if ($showfile) {
1.40 raeburn 1720: if ($showfile =~ m{^/(adm|res)/}) {
1721: if ($showfile =~ m{^/res/}) {
1722: my $local_showfile =
1723: &Apache::lonnet::filelocation('',$showfile);
1724: &Apache::lonnet::repcopy($local_showfile);
1725: }
1726: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1727: }
1728: if ($imgfile) {
1729: if ($imgfile =~ m{^/(adm|res)/}) {
1730: if ($imgfile =~ m{^/res/}) {
1731: my $local_imgfile =
1732: &Apache::lonnet::filelocation('',$imgfile);
1733: &Apache::lonnet::repcopy($local_imgfile);
1734: }
1735: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1736: } else {
1737: $fullsize = $imgfile;
1738: }
1739: }
1.41 raeburn 1740: $datatable .= '<td>';
1741: if ($img eq 'login') {
1.135 bisitz 1742: $datatable .= $login_hdr_pick;
1743: }
1.41 raeburn 1744: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1745: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1746: } else {
1.201 raeburn 1747: $datatable .= '<td> </td><td class="LC_left_item">'.
1748: &mt('Upload:').'<br />';
1.6 raeburn 1749: }
1750: } else {
1.201 raeburn 1751: $datatable .= '<td> </td><td class="LC_left_item">'.
1752: &mt('Upload:').'<br />';
1.6 raeburn 1753: }
1.9 raeburn 1754: if ($switchserver) {
1755: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1756: } else {
1.135 bisitz 1757: if ($img ne 'login') { # suppress file selection for Log-in header
1758: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1759: }
1.9 raeburn 1760: }
1761: $datatable .= '</td></tr>';
1.6 raeburn 1762: }
1763: $itemcount ++;
1764: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1765: $datatable .= '<tr'.$css_class.'>'.
1766: '<td>'.$choices->{'bgs'}.'</td>';
1767: my $bgs_def;
1768: foreach my $item (@{$bgs}) {
1769: if (!$is_custom->{$item}) {
1.329 raeburn 1770: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1771: }
1772: }
1773: if ($bgs_def) {
1.8 raeburn 1774: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1775: } else {
1776: $datatable .= '<td> </td>';
1777: }
1778: $datatable .= '<td class="LC_right_item">'.
1779: '<table border="0"><tr>';
1.174 foxr 1780:
1.6 raeburn 1781: foreach my $item (@{$bgs}) {
1.306 raeburn 1782: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1783: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1784: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1785: $datatable .= ' ';
1.6 raeburn 1786: }
1.174 foxr 1787: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1788: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1789: }
1790: $datatable .= '</tr></table></td></tr>';
1791: $itemcount ++;
1792: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1793: $datatable .= '<tr'.$css_class.'>'.
1794: '<td>'.$choices->{'links'}.'</td>';
1795: my $links_def;
1796: foreach my $item (@{$links}) {
1797: if (!$is_custom->{$item}) {
1.329 raeburn 1798: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1799: }
1800: }
1801: if ($links_def) {
1.8 raeburn 1802: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1803: } else {
1804: $datatable .= '<td> </td>';
1805: }
1806: $datatable .= '<td class="LC_right_item">'.
1807: '<table border="0"><tr>';
1808: foreach my $item (@{$links}) {
1.234 raeburn 1809: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1810: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1811: if ($designs->{'links'}{$item}) {
1.174 foxr 1812: $datatable.=' ';
1.6 raeburn 1813: }
1.174 foxr 1814: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1815: '" /></td>';
1816: }
1.30 raeburn 1817: $$rowtotal += $itemcount;
1.3 raeburn 1818: return $datatable;
1819: }
1820:
1.70 raeburn 1821: sub logo_display_options {
1822: my ($img,$defaults,$designs) = @_;
1823: my $checkedon;
1824: if (ref($defaults) eq 'HASH') {
1825: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1826: if ($defaults->{'showlogo'}{$img}) {
1827: $checkedon = 'checked="checked" ';
1828: }
1829: }
1830: }
1831: if (ref($designs) eq 'HASH') {
1832: if (ref($designs->{'showlogo'}) eq 'HASH') {
1833: if (defined($designs->{'showlogo'}{$img})) {
1834: if ($designs->{'showlogo'}{$img} == 0) {
1835: $checkedon = '';
1836: } elsif ($designs->{'showlogo'}{$img} == 1) {
1837: $checkedon = 'checked="checked" ';
1838: }
1839: }
1840: }
1841: }
1842: return '<br /><label> <input type="checkbox" name="'.
1843: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1844: &mt('show').'</label>'."\n";
1845: }
1846:
1.41 raeburn 1847: sub login_header_options {
1.135 bisitz 1848: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1849: my $output = '';
1.41 raeburn 1850: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1851: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1852: if (!$is_custom->{'textcol'}) {
1853: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1854: ' ';
1855: }
1856: if (!$is_custom->{'bgcol'}) {
1857: $output .= $choices->{'bgcol'}.': '.
1858: '<span id="css_'.$role.'_font" style="background-color: '.
1859: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1860: }
1861: $output .= '<br />';
1862: }
1863: $output .='<br />';
1864: return $output;
1865: }
1866:
1867: sub login_text_colors {
1.201 raeburn 1868: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1869: my $color_menu = '<table border="0"><tr>';
1870: foreach my $item (@{$logintext}) {
1.306 raeburn 1871: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1872: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1873: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1874: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1875: }
1876: $color_menu .= '</tr></table><br />';
1877: return $color_menu;
1878: }
1879:
1880: sub image_changes {
1881: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1882: my $output;
1.135 bisitz 1883: if ($img eq 'login') {
1.331 raeburn 1884: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1885: } elsif (!$is_custom) {
1.70 raeburn 1886: if ($img ne 'domlogo') {
1.331 raeburn 1887: $output = &mt('Default image:').'<br />';
1.41 raeburn 1888: } else {
1.331 raeburn 1889: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1890: }
1891: }
1.331 raeburn 1892: if ($img ne 'login') {
1.135 bisitz 1893: if ($img_import) {
1894: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1895: }
1896: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1897: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1898: if ($is_custom) {
1899: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1900: '<input type="checkbox" name="'.
1901: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1902: '</label> '.&mt('Replace:').'</span><br />';
1903: } else {
1.306 raeburn 1904: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1905: }
1.41 raeburn 1906: }
1907: return $output;
1908: }
1909:
1.3 raeburn 1910: sub print_quotas {
1.86 raeburn 1911: my ($dom,$settings,$rowtotal,$action) = @_;
1912: my $context;
1913: if ($action eq 'quotas') {
1914: $context = 'tools';
1915: } else {
1916: $context = $action;
1917: }
1.197 raeburn 1918: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1919: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1920: my $typecount = 0;
1.101 raeburn 1921: my ($css_class,%titles);
1.86 raeburn 1922: if ($context eq 'requestcourses') {
1.325 raeburn 1923: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 1924: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1925: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1926: %titles = &courserequest_titles();
1.163 raeburn 1927: } elsif ($context eq 'requestauthor') {
1928: @usertools = ('author');
1929: @options = ('norequest','approval','automatic');
1.210 raeburn 1930: %titles = &authorrequest_titles();
1.86 raeburn 1931: } else {
1.162 raeburn 1932: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1933: %titles = &tool_titles();
1.86 raeburn 1934: }
1.26 raeburn 1935: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1936: foreach my $type (@{$types}) {
1.197 raeburn 1937: my ($currdefquota,$currauthorquota);
1.163 raeburn 1938: unless (($context eq 'requestcourses') ||
1939: ($context eq 'requestauthor')) {
1.86 raeburn 1940: if (ref($settings) eq 'HASH') {
1941: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1942: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1943: } else {
1944: $currdefquota = $settings->{$type};
1945: }
1.197 raeburn 1946: if (ref($settings->{authorquota}) eq 'HASH') {
1947: $currauthorquota = $settings->{authorquota}->{$type};
1948: }
1.78 raeburn 1949: }
1.72 raeburn 1950: }
1.3 raeburn 1951: if (defined($usertypes->{$type})) {
1952: $typecount ++;
1953: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1954: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1955: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1956: '<td class="LC_left_item">';
1.101 raeburn 1957: if ($context eq 'requestcourses') {
1958: $datatable .= '<table><tr>';
1959: }
1960: my %cell;
1.72 raeburn 1961: foreach my $item (@usertools) {
1.101 raeburn 1962: if ($context eq 'requestcourses') {
1963: my ($curroption,$currlimit);
1964: if (ref($settings) eq 'HASH') {
1965: if (ref($settings->{$item}) eq 'HASH') {
1966: $curroption = $settings->{$item}->{$type};
1967: if ($curroption =~ /^autolimit=(\d*)$/) {
1968: $currlimit = $1;
1969: }
1970: }
1971: }
1972: if (!$curroption) {
1973: $curroption = 'norequest';
1974: }
1975: $datatable .= '<th>'.$titles{$item}.'</th>';
1976: foreach my $option (@options) {
1977: my $val = $option;
1978: if ($option eq 'norequest') {
1979: $val = 0;
1980: }
1981: if ($option eq 'validate') {
1982: my $canvalidate = 0;
1983: if (ref($validations{$item}) eq 'HASH') {
1984: if ($validations{$item}{$type}) {
1985: $canvalidate = 1;
1986: }
1987: }
1988: next if (!$canvalidate);
1989: }
1990: my $checked = '';
1991: if ($option eq $curroption) {
1992: $checked = ' checked="checked"';
1993: } elsif ($option eq 'autolimit') {
1994: if ($curroption =~ /^autolimit/) {
1995: $checked = ' checked="checked"';
1996: }
1997: }
1998: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1999: '<input type="radio" name="crsreq_'.$item.
2000: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2001: $titles{$option}.'</label>';
1.101 raeburn 2002: if ($option eq 'autolimit') {
1.127 raeburn 2003: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2004: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2005: 'value="'.$currlimit.'" />';
1.101 raeburn 2006: }
1.127 raeburn 2007: $cell{$item} .= '</span> ';
1.103 raeburn 2008: if ($option eq 'autolimit') {
1.127 raeburn 2009: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2010: }
1.101 raeburn 2011: }
1.163 raeburn 2012: } elsif ($context eq 'requestauthor') {
2013: my $curroption;
2014: if (ref($settings) eq 'HASH') {
2015: $curroption = $settings->{$type};
2016: }
2017: if (!$curroption) {
2018: $curroption = 'norequest';
2019: }
2020: foreach my $option (@options) {
2021: my $val = $option;
2022: if ($option eq 'norequest') {
2023: $val = 0;
2024: }
2025: my $checked = '';
2026: if ($option eq $curroption) {
2027: $checked = ' checked="checked"';
2028: }
2029: $datatable .= '<span class="LC_nobreak"><label>'.
2030: '<input type="radio" name="authorreq_'.$type.
2031: '" value="'.$val.'"'.$checked.' />'.
2032: $titles{$option}.'</label></span> ';
2033: }
1.101 raeburn 2034: } else {
2035: my $checked = 'checked="checked" ';
2036: if (ref($settings) eq 'HASH') {
2037: if (ref($settings->{$item}) eq 'HASH') {
2038: if ($settings->{$item}->{$type} == 0) {
2039: $checked = '';
2040: } elsif ($settings->{$item}->{$type} == 1) {
2041: $checked = 'checked="checked" ';
2042: }
1.78 raeburn 2043: }
1.72 raeburn 2044: }
1.101 raeburn 2045: $datatable .= '<span class="LC_nobreak"><label>'.
2046: '<input type="checkbox" name="'.$context.'_'.$item.
2047: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2048: '</label></span> ';
1.72 raeburn 2049: }
1.101 raeburn 2050: }
2051: if ($context eq 'requestcourses') {
2052: $datatable .= '</tr><tr>';
2053: foreach my $item (@usertools) {
1.106 raeburn 2054: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2055: }
2056: $datatable .= '</tr></table>';
1.72 raeburn 2057: }
1.86 raeburn 2058: $datatable .= '</td>';
1.163 raeburn 2059: unless (($context eq 'requestcourses') ||
2060: ($context eq 'requestauthor')) {
1.86 raeburn 2061: $datatable .=
1.197 raeburn 2062: '<td class="LC_right_item">'.
2063: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2064: '<input type="text" name="quota_'.$type.
1.72 raeburn 2065: '" value="'.$currdefquota.
1.197 raeburn 2066: '" size="5" /></span>'.(' ' x 2).
2067: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2068: '<input type="text" name="authorquota_'.$type.
2069: '" value="'.$currauthorquota.
2070: '" size="5" /></span></td>';
1.86 raeburn 2071: }
2072: $datatable .= '</tr>';
1.3 raeburn 2073: }
2074: }
2075: }
1.163 raeburn 2076: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2077: $defaultquota = '20';
1.197 raeburn 2078: $authorquota = '500';
1.86 raeburn 2079: if (ref($settings) eq 'HASH') {
2080: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2081: $defaultquota = $settings->{'defaultquota'}->{'default'};
2082: } elsif (defined($settings->{'default'})) {
2083: $defaultquota = $settings->{'default'};
2084: }
1.197 raeburn 2085: if (ref($settings->{'authorquota'}) eq 'HASH') {
2086: $authorquota = $settings->{'authorquota'}->{'default'};
2087: }
1.3 raeburn 2088: }
2089: }
2090: $typecount ++;
2091: $css_class = $typecount%2?' class="LC_odd_row"':'';
2092: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2093: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2094: '<td class="LC_left_item">';
1.101 raeburn 2095: if ($context eq 'requestcourses') {
2096: $datatable .= '<table><tr>';
2097: }
2098: my %defcell;
1.72 raeburn 2099: foreach my $item (@usertools) {
1.101 raeburn 2100: if ($context eq 'requestcourses') {
2101: my ($curroption,$currlimit);
2102: if (ref($settings) eq 'HASH') {
2103: if (ref($settings->{$item}) eq 'HASH') {
2104: $curroption = $settings->{$item}->{'default'};
2105: if ($curroption =~ /^autolimit=(\d*)$/) {
2106: $currlimit = $1;
2107: }
2108: }
2109: }
2110: if (!$curroption) {
2111: $curroption = 'norequest';
2112: }
2113: $datatable .= '<th>'.$titles{$item}.'</th>';
2114: foreach my $option (@options) {
2115: my $val = $option;
2116: if ($option eq 'norequest') {
2117: $val = 0;
2118: }
2119: if ($option eq 'validate') {
2120: my $canvalidate = 0;
2121: if (ref($validations{$item}) eq 'HASH') {
2122: if ($validations{$item}{'default'}) {
2123: $canvalidate = 1;
2124: }
2125: }
2126: next if (!$canvalidate);
2127: }
2128: my $checked = '';
2129: if ($option eq $curroption) {
2130: $checked = ' checked="checked"';
2131: } elsif ($option eq 'autolimit') {
2132: if ($curroption =~ /^autolimit/) {
2133: $checked = ' checked="checked"';
2134: }
2135: }
2136: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2137: '<input type="radio" name="crsreq_'.$item.
2138: '_default" value="'.$val.'"'.$checked.' />'.
2139: $titles{$option}.'</label>';
2140: if ($option eq 'autolimit') {
1.127 raeburn 2141: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2142: $item.'_limit_default" size="1" '.
2143: 'value="'.$currlimit.'" />';
2144: }
1.127 raeburn 2145: $defcell{$item} .= '</span> ';
1.104 raeburn 2146: if ($option eq 'autolimit') {
1.127 raeburn 2147: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2148: }
1.101 raeburn 2149: }
1.163 raeburn 2150: } elsif ($context eq 'requestauthor') {
2151: my $curroption;
2152: if (ref($settings) eq 'HASH') {
1.172 raeburn 2153: $curroption = $settings->{'default'};
1.163 raeburn 2154: }
2155: if (!$curroption) {
2156: $curroption = 'norequest';
2157: }
2158: foreach my $option (@options) {
2159: my $val = $option;
2160: if ($option eq 'norequest') {
2161: $val = 0;
2162: }
2163: my $checked = '';
2164: if ($option eq $curroption) {
2165: $checked = ' checked="checked"';
2166: }
2167: $datatable .= '<span class="LC_nobreak"><label>'.
2168: '<input type="radio" name="authorreq_default"'.
2169: ' value="'.$val.'"'.$checked.' />'.
2170: $titles{$option}.'</label></span> ';
2171: }
1.101 raeburn 2172: } else {
2173: my $checked = 'checked="checked" ';
2174: if (ref($settings) eq 'HASH') {
2175: if (ref($settings->{$item}) eq 'HASH') {
2176: if ($settings->{$item}->{'default'} == 0) {
2177: $checked = '';
2178: } elsif ($settings->{$item}->{'default'} == 1) {
2179: $checked = 'checked="checked" ';
2180: }
1.78 raeburn 2181: }
1.72 raeburn 2182: }
1.101 raeburn 2183: $datatable .= '<span class="LC_nobreak"><label>'.
2184: '<input type="checkbox" name="'.$context.'_'.$item.
2185: '" value="default" '.$checked.'/>'.$titles{$item}.
2186: '</label></span> ';
2187: }
2188: }
2189: if ($context eq 'requestcourses') {
2190: $datatable .= '</tr><tr>';
2191: foreach my $item (@usertools) {
1.106 raeburn 2192: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2193: }
1.101 raeburn 2194: $datatable .= '</tr></table>';
1.72 raeburn 2195: }
1.86 raeburn 2196: $datatable .= '</td>';
1.163 raeburn 2197: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2198: $datatable .= '<td class="LC_right_item">'.
2199: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2200: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2201: $defaultquota.'" size="5" /></span>'.(' ' x2).
2202: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2203: '<input type="text" name="authorquota" value="'.
2204: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2205: }
2206: $datatable .= '</tr>';
1.72 raeburn 2207: $typecount ++;
2208: $css_class = $typecount%2?' class="LC_odd_row"':'';
2209: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2210: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2211: if ($context eq 'requestcourses') {
1.109 raeburn 2212: $datatable .= &mt('(overrides affiliation, if set)').
2213: '</td>'.
2214: '<td class="LC_left_item">'.
2215: '<table><tr>';
1.101 raeburn 2216: } else {
1.109 raeburn 2217: $datatable .= &mt('(overrides affiliation, if checked)').
2218: '</td>'.
2219: '<td class="LC_left_item" colspan="2">'.
2220: '<br />';
1.101 raeburn 2221: }
2222: my %advcell;
1.72 raeburn 2223: foreach my $item (@usertools) {
1.101 raeburn 2224: if ($context eq 'requestcourses') {
2225: my ($curroption,$currlimit);
2226: if (ref($settings) eq 'HASH') {
2227: if (ref($settings->{$item}) eq 'HASH') {
2228: $curroption = $settings->{$item}->{'_LC_adv'};
2229: if ($curroption =~ /^autolimit=(\d*)$/) {
2230: $currlimit = $1;
2231: }
2232: }
2233: }
2234: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2235: my $checked = '';
2236: if ($curroption eq '') {
2237: $checked = ' checked="checked"';
2238: }
2239: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2240: '<input type="radio" name="crsreq_'.$item.
2241: '__LC_adv" value=""'.$checked.' />'.
2242: &mt('No override set').'</label></span> ';
1.101 raeburn 2243: foreach my $option (@options) {
2244: my $val = $option;
2245: if ($option eq 'norequest') {
2246: $val = 0;
2247: }
2248: if ($option eq 'validate') {
2249: my $canvalidate = 0;
2250: if (ref($validations{$item}) eq 'HASH') {
2251: if ($validations{$item}{'_LC_adv'}) {
2252: $canvalidate = 1;
2253: }
2254: }
2255: next if (!$canvalidate);
2256: }
2257: my $checked = '';
1.104 raeburn 2258: if ($val eq $curroption) {
1.101 raeburn 2259: $checked = ' checked="checked"';
2260: } elsif ($option eq 'autolimit') {
2261: if ($curroption =~ /^autolimit/) {
2262: $checked = ' checked="checked"';
2263: }
2264: }
2265: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2266: '<input type="radio" name="crsreq_'.$item.
2267: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2268: $titles{$option}.'</label>';
2269: if ($option eq 'autolimit') {
1.127 raeburn 2270: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2271: $item.'_limit__LC_adv" size="1" '.
2272: 'value="'.$currlimit.'" />';
2273: }
1.127 raeburn 2274: $advcell{$item} .= '</span> ';
1.104 raeburn 2275: if ($option eq 'autolimit') {
1.127 raeburn 2276: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2277: }
1.101 raeburn 2278: }
1.163 raeburn 2279: } elsif ($context eq 'requestauthor') {
2280: my $curroption;
2281: if (ref($settings) eq 'HASH') {
2282: $curroption = $settings->{'_LC_adv'};
2283: }
2284: my $checked = '';
2285: if ($curroption eq '') {
2286: $checked = ' checked="checked"';
2287: }
2288: $datatable .= '<span class="LC_nobreak"><label>'.
2289: '<input type="radio" name="authorreq__LC_adv"'.
2290: ' value=""'.$checked.' />'.
2291: &mt('No override set').'</label></span> ';
2292: foreach my $option (@options) {
2293: my $val = $option;
2294: if ($option eq 'norequest') {
2295: $val = 0;
2296: }
2297: my $checked = '';
2298: if ($val eq $curroption) {
2299: $checked = ' checked="checked"';
2300: }
2301: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2302: '<input type="radio" name="authorreq__LC_adv"'.
2303: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2304: $titles{$option}.'</label></span> ';
2305: }
1.101 raeburn 2306: } else {
2307: my $checked = 'checked="checked" ';
2308: if (ref($settings) eq 'HASH') {
2309: if (ref($settings->{$item}) eq 'HASH') {
2310: if ($settings->{$item}->{'_LC_adv'} == 0) {
2311: $checked = '';
2312: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2313: $checked = 'checked="checked" ';
2314: }
1.79 raeburn 2315: }
1.72 raeburn 2316: }
1.101 raeburn 2317: $datatable .= '<span class="LC_nobreak"><label>'.
2318: '<input type="checkbox" name="'.$context.'_'.$item.
2319: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2320: '</label></span> ';
2321: }
2322: }
2323: if ($context eq 'requestcourses') {
2324: $datatable .= '</tr><tr>';
2325: foreach my $item (@usertools) {
1.106 raeburn 2326: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2327: }
1.101 raeburn 2328: $datatable .= '</tr></table>';
1.72 raeburn 2329: }
1.98 raeburn 2330: $datatable .= '</td></tr>';
1.30 raeburn 2331: $$rowtotal += $typecount;
1.3 raeburn 2332: return $datatable;
2333: }
2334:
1.163 raeburn 2335: sub print_requestmail {
1.305 raeburn 2336: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2337: my ($now,$datatable,%currapp);
1.102 raeburn 2338: $now = time;
2339: if (ref($settings) eq 'HASH') {
2340: if (ref($settings->{'notify'}) eq 'HASH') {
2341: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2342: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2343: }
2344: }
2345: }
1.191 raeburn 2346: my $numinrow = 2;
1.224 raeburn 2347: my $css_class;
1.305 raeburn 2348: if ($$rowtotal%2) {
2349: $css_class = 'LC_odd_row';
2350: }
2351: if ($customcss) {
2352: $css_class .= " $customcss";
2353: }
2354: $css_class =~ s/^\s+//;
2355: if ($css_class) {
2356: $css_class = ' class="'.$css_class.'"';
2357: }
2358: if ($rowstyle) {
2359: $css_class .= ' style="'.$rowstyle.'"';
2360: }
1.163 raeburn 2361: my $text;
2362: if ($action eq 'requestcourses') {
2363: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2364: } elsif ($action eq 'requestauthor') {
2365: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2366: } else {
1.224 raeburn 2367: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2368: }
1.224 raeburn 2369: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2370: ' <td>'.$text.'</td>'.
1.102 raeburn 2371: ' <td class="LC_left_item">';
1.191 raeburn 2372: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2373: $action.'notifyapproval',%currapp);
1.191 raeburn 2374: if ($numdc > 0) {
2375: $datatable .= $table;
1.102 raeburn 2376: } else {
2377: $datatable .= &mt('There are no active Domain Coordinators');
2378: }
2379: $datatable .='</td></tr>';
2380: return $datatable;
2381: }
2382:
1.216 raeburn 2383: sub print_studentcode {
2384: my ($settings,$rowtotal) = @_;
2385: my $rownum = 0;
1.218 raeburn 2386: my ($output,%current);
1.325 raeburn 2387: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2388: if (ref($settings) eq 'HASH') {
2389: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2390: foreach my $type (@crstypes) {
2391: $current{$type} = $settings->{'uniquecode'}{$type};
2392: }
1.218 raeburn 2393: }
2394: }
2395: $output .= '<tr>'.
2396: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2397: '<td class="LC_left_item">';
2398: foreach my $type (@crstypes) {
2399: my $check = ' ';
2400: if ($current{$type}) {
2401: $check = ' checked="checked" ';
2402: }
2403: $output .= '<span class="LC_nobreak"><label>'.
2404: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2405: &mt($type).'</label></span>'.(' 'x2).' ';
2406: }
2407: $output .= '</td></tr>';
2408: $$rowtotal ++;
2409: return $output;
1.216 raeburn 2410: }
2411:
2412: sub print_textbookcourses {
1.242 raeburn 2413: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2414: my $rownum = 0;
2415: my $css_class;
2416: my $itemcount = 1;
2417: my $maxnum = 0;
2418: my $bookshash;
2419: if (ref($settings) eq 'HASH') {
1.242 raeburn 2420: $bookshash = $settings->{$type};
1.216 raeburn 2421: }
2422: my %ordered;
2423: if (ref($bookshash) eq 'HASH') {
2424: foreach my $item (keys(%{$bookshash})) {
2425: if (ref($bookshash->{$item}) eq 'HASH') {
2426: my $num = $bookshash->{$item}{'order'};
2427: $ordered{$num} = $item;
2428: }
2429: }
2430: }
2431: my $confname = $dom.'-domainconfig';
2432: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2433: my $maxnum = scalar(keys(%ordered));
2434: my $datatable;
1.216 raeburn 2435: if (keys(%ordered)) {
2436: my @items = sort { $a <=> $b } keys(%ordered);
2437: for (my $i=0; $i<@items; $i++) {
2438: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2439: my $key = $ordered{$items[$i]};
2440: my %coursehash=&Apache::lonnet::coursedescription($key);
2441: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2442: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2443: if (ref($bookshash->{$key}) eq 'HASH') {
2444: $subject = $bookshash->{$key}->{'subject'};
2445: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2446: if ($type eq 'textbooks') {
1.243 raeburn 2447: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2448: $author = $bookshash->{$key}->{'author'};
2449: $image = $bookshash->{$key}->{'image'};
2450: if ($image ne '') {
2451: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2452: my $imagethumb = "$path/tn-".$imagefile;
2453: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2454: }
1.216 raeburn 2455: }
2456: }
1.242 raeburn 2457: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2458: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2459: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2460: for (my $k=0; $k<=$maxnum; $k++) {
2461: my $vpos = $k+1;
2462: my $selstr;
2463: if ($k == $i) {
2464: $selstr = ' selected="selected" ';
2465: }
2466: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2467: }
2468: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2469: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2470: &mt('Delete?').'</label></span></td>'.
2471: '<td colspan="2">'.
1.242 raeburn 2472: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2473: (' 'x2).
1.242 raeburn 2474: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2475: if ($type eq 'textbooks') {
2476: $datatable .= (' 'x2).
1.243 raeburn 2477: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2478: (' 'x2).
1.242 raeburn 2479: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2480: (' 'x2).
2481: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2482: if ($image) {
1.267 raeburn 2483: $datatable .= $imgsrc.
1.242 raeburn 2484: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2485: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2486: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2487: }
2488: if ($switchserver) {
2489: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2490: } else {
2491: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2492: }
1.216 raeburn 2493: }
1.242 raeburn 2494: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2495: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2496: $coursetitle.'</span></td></tr>'."\n";
2497: $itemcount ++;
2498: }
2499: }
2500: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2501: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2502: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2503: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2504: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2505: for (my $k=0; $k<$maxnum+1; $k++) {
2506: my $vpos = $k+1;
2507: my $selstr;
2508: if ($k == $maxnum) {
2509: $selstr = ' selected="selected" ';
2510: }
2511: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2512: }
2513: $datatable .= '</select> '."\n".
1.334 raeburn 2514: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2515: '<td colspan="2">'.
1.242 raeburn 2516: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2517: (' 'x2).
1.242 raeburn 2518: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2519: (' 'x2);
2520: if ($type eq 'textbooks') {
1.243 raeburn 2521: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2522: (' 'x2).
2523: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2524: (' 'x2).
2525: '<span class="LC_nobreak">'.&mt('Image:').' ';
2526: if ($switchserver) {
2527: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2528: } else {
2529: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2530: }
1.334 raeburn 2531: $datatable .= '</span>'."\n";
1.216 raeburn 2532: }
1.334 raeburn 2533: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2534: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2535: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2536: &Apache::loncommon::selectcourse_link
1.334 raeburn 2537: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2538: '</span></td>'."\n".
2539: '</tr>'."\n";
2540: $itemcount ++;
2541: return $datatable;
2542: }
2543:
1.217 raeburn 2544: sub textbookcourses_javascript {
1.242 raeburn 2545: my ($settings) = @_;
2546: return unless(ref($settings) eq 'HASH');
2547: my (%ordered,%total,%jstext);
2548: foreach my $type ('textbooks','templates') {
2549: $total{$type} = 0;
2550: if (ref($settings->{$type}) eq 'HASH') {
2551: foreach my $item (keys(%{$settings->{$type}})) {
2552: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2553: my $num = $settings->{$type}->{$item}{'order'};
2554: $ordered{$type}{$num} = $item;
2555: }
2556: }
2557: $total{$type} = scalar(keys(%{$settings->{$type}}));
2558: }
2559: my @jsarray = ();
2560: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2561: push(@jsarray,$ordered{$type}{$item});
2562: }
2563: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2564: }
2565: return <<"ENDSCRIPT";
2566: <script type="text/javascript">
2567: // <![CDATA[
1.242 raeburn 2568: function reorderBooks(form,item,caller) {
1.217 raeburn 2569: var changedVal;
1.242 raeburn 2570: $jstext{'textbooks'};
2571: $jstext{'templates'};
2572: var newpos;
2573: var maxh;
2574: if (caller == 'textbooks') {
2575: newpos = 'textbooks_addbook_pos';
2576: maxh = 1 + $total{'textbooks'};
2577: } else {
2578: newpos = 'templates_addbook_pos';
2579: maxh = 1 + $total{'templates'};
2580: }
1.217 raeburn 2581: var current = new Array;
2582: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2583: if (item == newpos) {
2584: changedVal = newitemVal;
2585: } else {
2586: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2587: current[newitemVal] = newpos;
2588: }
1.242 raeburn 2589: if (caller == 'textbooks') {
2590: for (var i=0; i<textbooks.length; i++) {
2591: var elementName = 'textbooks_'+textbooks[i];
2592: if (elementName != item) {
2593: if (form.elements[elementName]) {
2594: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2595: current[currVal] = elementName;
2596: }
2597: }
2598: }
2599: }
2600: if (caller == 'templates') {
2601: for (var i=0; i<templates.length; i++) {
2602: var elementName = 'templates_'+templates[i];
2603: if (elementName != item) {
2604: if (form.elements[elementName]) {
2605: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2606: current[currVal] = elementName;
2607: }
1.217 raeburn 2608: }
2609: }
2610: }
2611: var oldVal;
2612: for (var j=0; j<maxh; j++) {
2613: if (current[j] == undefined) {
2614: oldVal = j;
2615: }
2616: }
2617: if (oldVal < changedVal) {
2618: for (var k=oldVal+1; k<=changedVal ; k++) {
2619: var elementName = current[k];
2620: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2621: }
2622: } else {
2623: for (var k=changedVal; k<oldVal; k++) {
2624: var elementName = current[k];
2625: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2626: }
2627: }
2628: return;
2629: }
2630:
2631: // ]]>
2632: </script>
2633:
2634: ENDSCRIPT
2635: }
2636:
1.267 raeburn 2637: sub ltitools_javascript {
2638: my ($settings) = @_;
1.319 raeburn 2639: my $togglejs = <itools_toggle_js();
2640: unless (ref($settings) eq 'HASH') {
2641: return $togglejs;
2642: }
1.267 raeburn 2643: my (%ordered,$total,%jstext);
2644: $total = 0;
2645: foreach my $item (keys(%{$settings})) {
2646: if (ref($settings->{$item}) eq 'HASH') {
2647: my $num = $settings->{$item}{'order'};
2648: $ordered{$num} = $item;
2649: }
2650: }
2651: $total = scalar(keys(%{$settings}));
2652: my @jsarray = ();
2653: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2654: push(@jsarray,$ordered{$item});
2655: }
2656: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2657: return <<"ENDSCRIPT";
2658: <script type="text/javascript">
2659: // <![CDATA[
1.319 raeburn 2660: function reorderLTITools(form,item) {
1.267 raeburn 2661: var changedVal;
2662: $jstext
2663: var newpos = 'ltitools_add_pos';
2664: var maxh = 1 + $total;
2665: var current = new Array;
2666: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2667: if (item == newpos) {
2668: changedVal = newitemVal;
2669: } else {
2670: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2671: current[newitemVal] = newpos;
2672: }
2673: for (var i=0; i<ltitools.length; i++) {
2674: var elementName = 'ltitools_'+ltitools[i];
2675: if (elementName != item) {
2676: if (form.elements[elementName]) {
2677: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2678: current[currVal] = elementName;
2679: }
2680: }
2681: }
2682: var oldVal;
2683: for (var j=0; j<maxh; j++) {
2684: if (current[j] == undefined) {
2685: oldVal = j;
2686: }
2687: }
2688: if (oldVal < changedVal) {
2689: for (var k=oldVal+1; k<=changedVal ; k++) {
2690: var elementName = current[k];
2691: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2692: }
2693: } else {
2694: for (var k=changedVal; k<oldVal; k++) {
2695: var elementName = current[k];
2696: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2697: }
2698: }
2699: return;
2700: }
2701:
2702: // ]]>
2703: </script>
2704:
1.319 raeburn 2705: $togglejs
2706:
2707: ENDSCRIPT
2708: }
2709:
2710: sub ltitools_toggle_js {
2711: return <<"ENDSCRIPT";
2712: <script type="text/javascript">
2713: // <![CDATA[
2714:
2715: function toggleLTITools(form,setting,item) {
2716: var radioname = '';
2717: var divid = '';
2718: if ((setting == 'passback') || (setting == 'roster')) {
2719: radioname = 'ltitools_'+setting+'_'+item;
2720: divid = 'ltitools_'+setting+'time_'+item;
2721: var num = form.elements[radioname].length;
2722: if (num) {
2723: var setvis = '';
2724: for (var i=0; i<num; i++) {
2725: if (form.elements[radioname][i].checked) {
2726: if (form.elements[radioname][i].value == '1') {
2727: if (document.getElementById(divid)) {
2728: document.getElementById(divid).style.display = 'inline-block';
2729: }
2730: setvis = 1;
2731: }
2732: break;
2733: }
2734: }
2735: }
2736: if (!setvis) {
2737: if (document.getElementById(divid)) {
2738: document.getElementById(divid).style.display = 'none';
2739: }
2740: }
2741: }
1.324 raeburn 2742: if (setting == 'user') {
2743: divid = 'ltitools_'+setting+'_div_'+item;
2744: var checkid = 'ltitools_'+setting+'_field_'+item;
2745: if (document.getElementById(divid)) {
2746: if (document.getElementById(checkid)) {
2747: if (document.getElementById(checkid).checked) {
2748: document.getElementById(divid).style.display = 'inline-block';
2749: } else {
2750: document.getElementById(divid).style.display = 'none';
2751: }
2752: }
2753: }
2754: }
1.319 raeburn 2755: return;
2756: }
2757: // ]]>
2758: </script>
2759:
1.267 raeburn 2760: ENDSCRIPT
2761: }
2762:
1.320 raeburn 2763: sub lti_javascript {
2764: my ($settings) = @_;
2765: my $togglejs = <i_toggle_js();
2766: unless (ref($settings) eq 'HASH') {
2767: return $togglejs;
2768: }
2769: my (%ordered,$total,%jstext);
2770: $total = 0;
2771: foreach my $item (keys(%{$settings})) {
2772: if (ref($settings->{$item}) eq 'HASH') {
2773: my $num = $settings->{$item}{'order'};
2774: $ordered{$num} = $item;
2775: }
2776: }
2777: $total = scalar(keys(%{$settings}));
2778: my @jsarray = ();
2779: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2780: push(@jsarray,$ordered{$item});
2781: }
2782: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
2783: return <<"ENDSCRIPT";
2784: <script type="text/javascript">
2785: // <![CDATA[
2786: function reorderLTI(form,item) {
2787: var changedVal;
2788: $jstext
2789: var newpos = 'lti_pos_add';
2790: var maxh = 1 + $total;
2791: var current = new Array;
2792: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2793: if (item == newpos) {
2794: changedVal = newitemVal;
2795: } else {
2796: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2797: current[newitemVal] = newpos;
2798: }
2799: for (var i=0; i<lti.length; i++) {
2800: var elementName = 'lti_pos_'+lti[i];
2801: if (elementName != item) {
2802: if (form.elements[elementName]) {
2803: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2804: current[currVal] = elementName;
2805: }
2806: }
2807: }
2808: var oldVal;
2809: for (var j=0; j<maxh; j++) {
2810: if (current[j] == undefined) {
2811: oldVal = j;
2812: }
2813: }
2814: if (oldVal < changedVal) {
2815: for (var k=oldVal+1; k<=changedVal ; k++) {
2816: var elementName = current[k];
2817: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2818: }
2819: } else {
2820: for (var k=changedVal; k<oldVal; k++) {
2821: var elementName = current[k];
2822: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2823: }
2824: }
2825: return;
2826: }
2827: // ]]>
2828: </script>
2829:
2830: $togglejs
2831:
2832: ENDSCRIPT
2833: }
2834:
2835: sub lti_toggle_js {
1.325 raeburn 2836: my %lcauthparmtext = &Apache::lonlocal::texthash (
2837: localauth => 'Local auth argument',
2838: krb => 'Kerberos domain',
2839: );
1.320 raeburn 2840: return <<"ENDSCRIPT";
2841: <script type="text/javascript">
2842: // <![CDATA[
2843:
2844: function toggleLTI(form,setting,item) {
1.345 raeburn 2845: if (setting == 'requser') {
2846: var fieldsets = document.getElementsByClassName('ltioption_'+item);
2847: if (fieldsets.length) {
2848: var radioname = 'lti_'+setting+'_'+item;
2849: var num = form.elements[radioname].length;
2850: if (num) {
2851: var setvis = '';
2852: for (var i=0; i<num; i++) {
2853: if (form.elements[radioname][i].checked) {
2854: if (form.elements[radioname][i].value == '1') {
2855: setvis = 1;
2856: break;
2857: }
2858: }
2859: }
2860: for (var j=0; j<fieldsets.length; j++) {
2861: if (setvis) {
2862: fieldsets[j].style.display = 'block';
2863: } else {
2864: fieldsets[j].style.display = 'none';
2865: }
2866: }
2867: }
2868: }
2869: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback')) {
1.320 raeburn 2870: var radioname = '';
2871: var divid = '';
2872: if (setting == 'user') {
2873: radioname = 'lti_mapuser_'+item;
2874: divid = 'lti_userfield_'+item;
1.343 raeburn 2875: } else if (setting == 'crs') {
1.320 raeburn 2876: radioname = 'lti_mapcrs_'+item;
2877: divid = 'lti_crsfield_'+item;
1.337 raeburn 2878: } else {
2879: radioname = 'lti_passbackformat_'+item;
2880: divid = 'lti_passback_'+item;
1.320 raeburn 2881: }
2882: var num = form.elements[radioname].length;
2883: if (num) {
2884: var setvis = '';
2885: for (var i=0; i<num; i++) {
2886: if (form.elements[radioname][i].checked) {
1.337 raeburn 2887: if (setting == 'passback') {
2888: if (form.elements[radioname][i].value == '1') {
2889: if (document.getElementById(divid)) {
2890: document.getElementById(divid).style.display = 'inline-block';
2891: }
2892: setvis = 1;
2893: break;
2894: }
2895: } else {
2896: if (form.elements[radioname][i].value == 'other') {
2897: if (document.getElementById(divid)) {
2898: document.getElementById(divid).style.display = 'inline-block';
2899: }
2900: setvis = 1;
2901: break;
1.320 raeburn 2902: }
2903: }
2904: }
2905: }
2906: if (!setvis) {
2907: if (document.getElementById(divid)) {
2908: document.getElementById(divid).style.display = 'none';
2909: }
2910: }
2911: }
2912: } else if ((setting == 'sec') || (setting == 'secsrc')) {
2913: var numsec = form.elements['lti_crssec_'+item].length;
2914: if (numsec) {
2915: var setvis = '';
2916: for (var i=0; i<numsec; i++) {
2917: if (form.elements['lti_crssec_'+item][i].checked) {
2918: if (form.elements['lti_crssec_'+item][i].value == '1') {
2919: if (document.getElementById('lti_crssecfield_'+item)) {
2920: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
2921: setvis = 1;
2922: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
2923: if (numsrcsec) {
2924: var setsrcvis = '';
2925: for (var j=0; j<numsrcsec; j++) {
2926: if (form.elements['lti_crssecsrc_'+item][j].checked) {
2927: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
2928: if (document.getElementById('lti_secsrcfield_'+item)) {
2929: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
2930: setsrcvis = 1;
2931: }
2932: }
2933: }
2934: }
2935: if (!setsrcvis) {
2936: if (document.getElementById('lti_secsrcfield_'+item)) {
2937: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2938: }
2939: }
2940: }
2941: }
2942: }
2943: }
2944: }
2945: if (!setvis) {
2946: if (document.getElementById('lti_crssecfield_'+item)) {
2947: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
2948: }
2949: if (document.getElementById('lti_secsrcfield_'+item)) {
2950: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2951: }
2952: }
2953: }
1.325 raeburn 2954: } else if (setting == 'lcauth') {
2955: var numauth = form.elements['lti_lcauth_'+item].length;
2956: if (numauth) {
2957: for (var i=0; i<numauth; i++) {
2958: if (form.elements['lti_lcauth_'+item][i].checked) {
2959: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
2960: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
2961: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
2962: } else {
2963: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
2964: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
2965: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
2966: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
2967: } else {
2968: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
2969: }
2970: }
2971: }
2972: }
2973: }
2974: }
2975: }
1.326 raeburn 2976: } else if (setting == 'lcmenu') {
2977: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
2978: var divid = 'lti_menufield_'+item;
2979: var setvis = '';
2980: for (var i=0; i<menus.length; i++) {
2981: var radioname = menus[i];
2982: var num = form.elements[radioname].length;
2983: if (num) {
2984: for (var j=0; j<num; j++) {
2985: if (form.elements[radioname][j].checked) {
2986: if (form.elements[radioname][j].value == '1') {
2987: if (document.getElementById(divid)) {
2988: document.getElementById(divid).style.display = 'inline-block';
2989: }
2990: setvis = 1;
2991: break;
2992: }
2993: }
2994: }
2995: }
2996: if (setvis == 1) {
2997: break;
2998: }
2999: }
3000: if (!setvis) {
3001: if (document.getElementById(divid)) {
3002: document.getElementById(divid).style.display = 'none';
3003: }
3004: }
1.320 raeburn 3005: }
3006: return;
3007: }
3008: // ]]>
3009: </script>
3010:
3011: ENDSCRIPT
3012: }
3013:
1.3 raeburn 3014: sub print_autoenroll {
1.30 raeburn 3015: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3016: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 3017: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3018: if (ref($settings) eq 'HASH') {
3019: if (exists($settings->{'run'})) {
3020: if ($settings->{'run'} eq '0') {
3021: $runoff = ' checked="checked" ';
3022: $runon = ' ';
3023: } else {
3024: $runon = ' checked="checked" ';
3025: $runoff = ' ';
3026: }
3027: } else {
3028: if ($autorun) {
3029: $runon = ' checked="checked" ';
3030: $runoff = ' ';
3031: } else {
3032: $runoff = ' checked="checked" ';
3033: $runon = ' ';
3034: }
3035: }
1.129 raeburn 3036: if (exists($settings->{'co-owners'})) {
3037: if ($settings->{'co-owners'} eq '0') {
3038: $coownersoff = ' checked="checked" ';
3039: $coownerson = ' ';
3040: } else {
3041: $coownerson = ' checked="checked" ';
3042: $coownersoff = ' ';
3043: }
3044: } else {
3045: $coownersoff = ' checked="checked" ';
3046: $coownerson = ' ';
3047: }
1.3 raeburn 3048: if (exists($settings->{'sender_domain'})) {
3049: $defdom = $settings->{'sender_domain'};
3050: }
1.274 raeburn 3051: if (exists($settings->{'autofailsafe'})) {
3052: $failsafe = $settings->{'autofailsafe'};
3053: }
1.14 raeburn 3054: } else {
3055: if ($autorun) {
3056: $runon = ' checked="checked" ';
3057: $runoff = ' ';
3058: } else {
3059: $runoff = ' checked="checked" ';
3060: $runon = ' ';
3061: }
1.3 raeburn 3062: }
3063: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3064: my $notif_sender;
3065: if (ref($settings) eq 'HASH') {
3066: $notif_sender = $settings->{'sender_uname'};
3067: }
1.3 raeburn 3068: my $datatable='<tr class="LC_odd_row">'.
3069: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3070: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3071: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3072: $runon.' value="1" />'.&mt('Yes').'</label> '.
3073: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3074: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3075: '</tr><tr>'.
3076: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3077: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3078: &mt('username').': '.
3079: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3080: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3081: ': '.$domform.'</span></td></tr>'.
3082: '<tr class="LC_odd_row">'.
3083: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3084: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3085: '<input type="radio" name="autoassign_coowners"'.
3086: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3087: '<label><input type="radio" name="autoassign_coowners"'.
3088: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3089: '</tr><tr>'.
3090: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3091: '<td class="LC_right_item"><span class="LC_nobreak">'.
3092: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3093: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3094: $$rowtotal += 4;
1.3 raeburn 3095: return $datatable;
3096: }
3097:
3098: sub print_autoupdate {
1.30 raeburn 3099: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 3100: my $datatable;
3101: if ($position eq 'top') {
3102: my $updateon = ' ';
3103: my $updateoff = ' checked="checked" ';
3104: my $classlistson = ' ';
3105: my $classlistsoff = ' checked="checked" ';
3106: if (ref($settings) eq 'HASH') {
3107: if ($settings->{'run'} eq '1') {
3108: $updateon = $updateoff;
3109: $updateoff = ' ';
3110: }
3111: if ($settings->{'classlists'} eq '1') {
3112: $classlistson = $classlistsoff;
3113: $classlistsoff = ' ';
3114: }
3115: }
3116: my %title = (
3117: run => 'Auto-update active?',
3118: classlists => 'Update information in classlists?',
3119: );
3120: $datatable = '<tr class="LC_odd_row">'.
3121: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 3122: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3123: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 3124: $updateon.' value="1" />'.&mt('Yes').'</label> '.
3125: '<label><input type="radio" name="autoupdate_run"'.
3126: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3127: '</tr><tr>'.
3128: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 3129: '<td class="LC_right_item"><span class="LC_nobreak">'.
3130: '<label><input type="radio" name="classlists"'.
3131: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3132: '<label><input type="radio" name="classlists"'.
3133: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3134: '</tr>';
1.30 raeburn 3135: $$rowtotal += 2;
1.131 raeburn 3136: } elsif ($position eq 'middle') {
3137: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3138: my $numinrow = 3;
3139: my $locknamesettings;
3140: $datatable .= &insttypes_row($settings,$types,$usertypes,
3141: $dom,$numinrow,$othertitle,
1.305 raeburn 3142: 'lockablenames',$rowtotal);
1.131 raeburn 3143: $$rowtotal ++;
1.3 raeburn 3144: } else {
1.44 raeburn 3145: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3146: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3147: 'permanentemail','id');
1.33 raeburn 3148: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3149: my $numrows = 0;
1.26 raeburn 3150: if (ref($types) eq 'ARRAY') {
3151: if (@{$types} > 0) {
3152: $datatable =
3153: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3154: \@fields,$types,\$numrows);
1.30 raeburn 3155: $$rowtotal += @{$types};
1.26 raeburn 3156: }
1.3 raeburn 3157: }
3158: $datatable .=
3159: &usertype_update_row($settings,{'default' => $othertitle},
3160: \%fieldtitles,\@fields,['default'],
3161: \$numrows);
1.30 raeburn 3162: $$rowtotal ++;
1.3 raeburn 3163: }
3164: return $datatable;
3165: }
3166:
1.125 raeburn 3167: sub print_autocreate {
3168: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3169: my (%createon,%createoff,%currhash);
1.125 raeburn 3170: my @types = ('xml','req');
3171: if (ref($settings) eq 'HASH') {
3172: foreach my $item (@types) {
3173: $createoff{$item} = ' checked="checked" ';
3174: $createon{$item} = ' ';
3175: if (exists($settings->{$item})) {
3176: if ($settings->{$item}) {
3177: $createon{$item} = ' checked="checked" ';
3178: $createoff{$item} = ' ';
3179: }
3180: }
3181: }
1.210 raeburn 3182: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3183: $currhash{$settings->{'xmldc'}} = 1;
3184: }
1.125 raeburn 3185: } else {
3186: foreach my $item (@types) {
3187: $createoff{$item} = ' checked="checked" ';
3188: $createon{$item} = ' ';
3189: }
3190: }
3191: $$rowtotal += 2;
1.191 raeburn 3192: my $numinrow = 2;
1.125 raeburn 3193: my $datatable='<tr class="LC_odd_row">'.
3194: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3195: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3196: '<input type="radio" name="autocreate_xml"'.
3197: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3198: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3199: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3200: '</td></tr><tr>'.
3201: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3202: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3203: '<input type="radio" name="autocreate_req"'.
3204: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3205: '<label><input type="radio" name="autocreate_req"'.
3206: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3207: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3208: 'autocreate_xmldc',%currhash);
1.247 raeburn 3209: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3210: if ($numdc > 1) {
1.247 raeburn 3211: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3212: '</td><td class="LC_left_item">';
1.125 raeburn 3213: } else {
1.247 raeburn 3214: $datatable .= &mt('Course creation processed as:').
3215: '</td><td class="LC_right_item">';
1.125 raeburn 3216: }
1.247 raeburn 3217: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3218: $$rowtotal += $rows;
1.125 raeburn 3219: return $datatable;
3220: }
3221:
1.23 raeburn 3222: sub print_directorysrch {
1.277 raeburn 3223: my ($position,$dom,$settings,$rowtotal) = @_;
3224: my $datatable;
3225: if ($position eq 'top') {
3226: my $instsrchon = ' ';
3227: my $instsrchoff = ' checked="checked" ';
3228: my ($exacton,$containson,$beginson);
3229: my $instlocalon = ' ';
3230: my $instlocaloff = ' checked="checked" ';
3231: if (ref($settings) eq 'HASH') {
3232: if ($settings->{'available'} eq '1') {
3233: $instsrchon = $instsrchoff;
3234: $instsrchoff = ' ';
3235: }
3236: if ($settings->{'localonly'} eq '1') {
3237: $instlocalon = $instlocaloff;
3238: $instlocaloff = ' ';
3239: }
3240: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3241: foreach my $type (@{$settings->{'searchtypes'}}) {
3242: if ($type eq 'exact') {
3243: $exacton = ' checked="checked" ';
3244: } elsif ($type eq 'contains') {
3245: $containson = ' checked="checked" ';
3246: } elsif ($type eq 'begins') {
3247: $beginson = ' checked="checked" ';
3248: }
3249: }
3250: } else {
3251: if ($settings->{'searchtypes'} eq 'exact') {
3252: $exacton = ' checked="checked" ';
3253: } elsif ($settings->{'searchtypes'} eq 'contains') {
3254: $containson = ' checked="checked" ';
3255: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3256: $exacton = ' checked="checked" ';
3257: $containson = ' checked="checked" ';
3258: }
3259: }
1.277 raeburn 3260: }
3261: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3262: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3263:
3264: my $numinrow = 4;
3265: my $cansrchrow = 0;
3266: $datatable='<tr class="LC_odd_row">'.
3267: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3268: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3269: '<input type="radio" name="dirsrch_available"'.
3270: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3271: '<label><input type="radio" name="dirsrch_available"'.
3272: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3273: '</tr><tr>'.
3274: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3275: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3276: '<input type="radio" name="dirsrch_instlocalonly"'.
3277: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3278: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3279: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3280: '</tr>';
3281: $$rowtotal += 2;
3282: if (ref($usertypes) eq 'HASH') {
3283: if (keys(%{$usertypes}) > 0) {
3284: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3285: $numinrow,$othertitle,'cansearch',
3286: $rowtotal);
1.277 raeburn 3287: $cansrchrow = 1;
1.25 raeburn 3288: }
1.23 raeburn 3289: }
1.277 raeburn 3290: if ($cansrchrow) {
3291: $$rowtotal ++;
3292: $datatable .= '<tr>';
3293: } else {
3294: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3295: }
1.277 raeburn 3296: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3297: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3298: foreach my $title (@{$titleorder}) {
3299: if (defined($searchtitles->{$title})) {
3300: my $check = ' ';
3301: if (ref($settings) eq 'HASH') {
3302: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3303: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3304: $check = ' checked="checked" ';
3305: }
1.39 raeburn 3306: }
1.25 raeburn 3307: }
1.277 raeburn 3308: $datatable .= '<td class="LC_left_item">'.
3309: '<span class="LC_nobreak"><label>'.
3310: '<input type="checkbox" name="searchby" '.
3311: 'value="'.$title.'"'.$check.'/>'.
3312: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3313: }
3314: }
1.277 raeburn 3315: $datatable .= '</tr></table></td></tr>';
3316: $$rowtotal ++;
3317: if ($cansrchrow) {
3318: $datatable .= '<tr class="LC_odd_row">';
3319: } else {
3320: $datatable .= '<tr>';
3321: }
3322: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3323: '<td class="LC_left_item" colspan="2">'.
3324: '<span class="LC_nobreak"><label>'.
3325: '<input type="checkbox" name="searchtypes" '.
3326: $exacton.' value="exact" />'.&mt('Exact match').
3327: '</label> '.
3328: '<label><input type="checkbox" name="searchtypes" '.
3329: $beginson.' value="begins" />'.&mt('Begins with').
3330: '</label> '.
3331: '<label><input type="checkbox" name="searchtypes" '.
3332: $containson.' value="contains" />'.&mt('Contains').
3333: '</label></span></td></tr>';
3334: $$rowtotal ++;
1.26 raeburn 3335: } else {
1.277 raeburn 3336: my $domsrchon = ' checked="checked" ';
3337: my $domsrchoff = ' ';
3338: my $domlocalon = ' ';
3339: my $domlocaloff = ' checked="checked" ';
3340: if (ref($settings) eq 'HASH') {
3341: if ($settings->{'lclocalonly'} eq '1') {
3342: $domlocalon = $domlocaloff;
3343: $domlocaloff = ' ';
3344: }
3345: if ($settings->{'lcavailable'} eq '0') {
3346: $domsrchoff = $domsrchon;
3347: $domsrchon = ' ';
3348: }
3349: }
3350: $datatable='<tr class="LC_odd_row">'.
3351: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3352: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3353: '<input type="radio" name="dirsrch_domavailable"'.
3354: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3355: '<label><input type="radio" name="dirsrch_domavailable"'.
3356: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3357: '</tr><tr>'.
3358: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3359: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3360: '<input type="radio" name="dirsrch_domlocalonly"'.
3361: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3362: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3363: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3364: '</tr>';
3365: $$rowtotal += 2;
1.26 raeburn 3366: }
1.25 raeburn 3367: return $datatable;
3368: }
3369:
1.28 raeburn 3370: sub print_contacts {
1.286 raeburn 3371: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3372: my $datatable;
3373: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3374: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 3375: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 3376: if ($position eq 'top') {
3377: if (ref($settings) eq 'HASH') {
3378: foreach my $item (@contacts) {
3379: if (exists($settings->{$item})) {
3380: $to{$item} = $settings->{$item};
3381: }
3382: }
3383: }
3384: } elsif ($position eq 'middle') {
3385: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3386: 'updatesmail','idconflictsmail');
1.288 raeburn 3387: foreach my $type (@mailings) {
3388: $otheremails{$type} = '';
3389: }
1.340 raeburn 3390: } elsif ($position eq 'lower') {
3391: if (ref($settings) eq 'HASH') {
3392: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3393: %lonstatus = %{$settings->{'lonstatus'}};
3394: }
3395: }
1.286 raeburn 3396: } else {
3397: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3398: foreach my $type (@mailings) {
3399: $otheremails{$type} = '';
3400: }
1.286 raeburn 3401: $bccemails{'helpdeskmail'} = '';
3402: $bccemails{'otherdomsmail'} = '';
3403: $includestr{'helpdeskmail'} = '';
3404: $includestr{'otherdomsmail'} = '';
3405: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3406: }
1.28 raeburn 3407: if (ref($settings) eq 'HASH') {
1.340 raeburn 3408: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3409: foreach my $type (@mailings) {
3410: if (exists($settings->{$type})) {
3411: if (ref($settings->{$type}) eq 'HASH') {
3412: foreach my $item (@contacts) {
3413: if ($settings->{$type}{$item}) {
3414: $checked{$type}{$item} = ' checked="checked" ';
3415: }
3416: }
3417: $otheremails{$type} = $settings->{$type}{'others'};
3418: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3419: $bccemails{$type} = $settings->{$type}{'bcc'};
3420: if ($settings->{$type}{'include'} ne '') {
3421: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3422: $includestr{$type} = &unescape($includestr{$type});
3423: }
3424: }
3425: }
3426: } elsif ($type eq 'lonstatusmail') {
3427: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3428: }
1.28 raeburn 3429: }
3430: }
1.286 raeburn 3431: if ($position eq 'bottom') {
3432: foreach my $type (@mailings) {
3433: $bccemails{$type} = $settings->{$type}{'bcc'};
3434: if ($settings->{$type}{'include'} ne '') {
3435: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3436: $includestr{$type} = &unescape($includestr{$type});
3437: }
3438: }
3439: if (ref($settings->{'helpform'}) eq 'HASH') {
3440: if (ref($fields) eq 'ARRAY') {
3441: foreach my $field (@{$fields}) {
3442: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3443: }
1.286 raeburn 3444: }
3445: if (exists($settings->{'helpform'}{'maxsize'})) {
3446: $maxsize = $settings->{'helpform'}{'maxsize'};
3447: } else {
1.289 raeburn 3448: $maxsize = '1.0';
1.286 raeburn 3449: }
3450: } else {
3451: if (ref($fields) eq 'ARRAY') {
3452: foreach my $field (@{$fields}) {
3453: $currfield{$field} = 'yes';
1.134 raeburn 3454: }
1.28 raeburn 3455: }
1.286 raeburn 3456: $maxsize = '1.0';
1.28 raeburn 3457: }
3458: }
3459: } else {
1.286 raeburn 3460: if ($position eq 'top') {
3461: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3462: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3463: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3464: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3465: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3466: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3467: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3468: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3469: } elsif ($position eq 'bottom') {
3470: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3471: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3472: if (ref($fields) eq 'ARRAY') {
3473: foreach my $field (@{$fields}) {
3474: $currfield{$field} = 'yes';
3475: }
3476: }
3477: $maxsize = '1.0';
3478: }
1.28 raeburn 3479: }
3480: my ($titles,$short_titles) = &contact_titles();
3481: my $rownum = 0;
3482: my $css_class;
1.286 raeburn 3483: if ($position eq 'top') {
3484: foreach my $item (@contacts) {
3485: $css_class = $rownum%2?' class="LC_odd_row"':'';
3486: $datatable .= '<tr'.$css_class.'>'.
3487: '<td><span class="LC_nobreak">'.$titles->{$item}.
3488: '</span></td><td class="LC_right_item">'.
3489: '<input type="text" name="'.$item.'" value="'.
3490: $to{$item}.'" /></td></tr>';
3491: $rownum ++;
3492: }
1.315 raeburn 3493: } elsif ($position eq 'bottom') {
3494: $css_class = $rownum%2?' class="LC_odd_row"':'';
3495: $datatable .= '<tr'.$css_class.'>'.
3496: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3497: &mt('(e-mail, subject, and description always shown)').
3498: '</td><td class="LC_left_item">';
3499: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3500: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3501: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3502: foreach my $field (@{$fields}) {
3503: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3504: if (($field eq 'screenshot') || ($field eq 'cc')) {
3505: $datatable .= ' '.&mt('(logged-in users)');
3506: }
3507: $datatable .='</td><td>';
3508: my $clickaction;
3509: if ($field eq 'screenshot') {
3510: $clickaction = ' onclick="screenshotSize(this);"';
3511: }
3512: if (ref($possoptions->{$field}) eq 'ARRAY') {
3513: foreach my $option (@{$possoptions->{$field}}) {
3514: my $checked;
3515: if ($currfield{$field} eq $option) {
3516: $checked = ' checked="checked"';
3517: }
3518: $datatable .= '<span class="LC_nobreak"><label>'.
3519: '<input type="radio" name="helpform_'.$field.'" '.
3520: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3521: '</label></span>'.(' 'x2);
3522: }
3523: }
3524: if ($field eq 'screenshot') {
3525: my $display;
3526: if ($currfield{$field} eq 'no') {
3527: $display = ' style="display:none"';
3528: }
1.334 raeburn 3529: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 3530: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3531: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3532: }
3533: $datatable .= '</td></tr>';
3534: }
3535: $datatable .= '</table>';
3536: }
3537: $datatable .= '</td></tr>'."\n";
3538: $rownum ++;
3539: }
1.340 raeburn 3540: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3541: foreach my $type (@mailings) {
3542: $css_class = $rownum%2?' class="LC_odd_row"':'';
3543: $datatable .= '<tr'.$css_class.'>'.
3544: '<td><span class="LC_nobreak">'.
3545: $titles->{$type}.': </span></td>'.
3546: '<td class="LC_left_item">';
3547: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3548: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3549: }
3550: $datatable .= '<span class="LC_nobreak">';
3551: foreach my $item (@contacts) {
3552: $datatable .= '<label>'.
3553: '<input type="checkbox" name="'.$type.'"'.
3554: $checked{$type}{$item}.
3555: ' value="'.$item.'" />'.$short_titles->{$item}.
3556: '</label> ';
3557: }
3558: $datatable .= '</span><br />'.&mt('Others').': '.
3559: '<input type="text" name="'.$type.'_others" '.
3560: 'value="'.$otheremails{$type}.'" />';
3561: my %locchecked;
3562: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3563: foreach my $loc ('s','b') {
3564: if ($includeloc{$type} eq $loc) {
3565: $locchecked{$loc} = ' checked="checked"';
3566: last;
3567: }
3568: }
3569: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3570: '<input type="text" name="'.$type.'_bcc" '.
3571: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3572: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3573: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3574: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 3575: '<span class="LC_nobreak">'.&mt('Location:').' '.
3576: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3577: (' 'x2).
3578: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3579: '</span></fieldset>';
3580: }
3581: $datatable .= '</td></tr>'."\n";
3582: $rownum ++;
3583: }
1.28 raeburn 3584: }
1.286 raeburn 3585: if ($position eq 'middle') {
3586: my %choices;
1.340 raeburn 3587: my $corelink = &core_link_msu();
3588: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 3589: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 3590: $corelink);
3591: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3592: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 3593: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 3594: 'reportupdates' => 'on',
3595: 'reportstatus' => 'on');
1.286 raeburn 3596: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3597: \%choices,$rownum);
3598: $datatable .= $reports;
1.340 raeburn 3599: } elsif ($position eq 'lower') {
3600: $css_class = $rownum%2?' class="LC_odd_row"':'';
3601: my ($threshold,$sysmail,%excluded,%weights);
3602: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3603: if ($lonstatus{'threshold'} =~ /^\d+$/) {
3604: $threshold = $lonstatus{'threshold'};
3605: } else {
3606: $threshold = $defaults->{'threshold'};
3607: }
3608: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
3609: $sysmail = $lonstatus{'sysmail'};
3610: } else {
3611: $sysmail = $defaults->{'sysmail'};
3612: }
3613: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 3614: foreach my $type ('E','W','N','U') {
1.340 raeburn 3615: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3616: $weights{$type} = $lonstatus{'weights'}{$type};
3617: } else {
3618: $weights{$type} = $defaults->{$type};
3619: }
3620: }
3621: } else {
1.341 raeburn 3622: foreach my $type ('E','W','N','U') {
1.340 raeburn 3623: $weights{$type} = $defaults->{$type};
3624: }
3625: }
3626: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3627: if (@{$lonstatus{'excluded'}} > 0) {
3628: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3629: }
3630: }
3631: $datatable .= '<tr'.$css_class.'>'.
3632: '<td class="LC_left_item"><span class="LC_nobreak">'.
3633: $titles->{'errorthreshold'}.
3634: '</span></td><td class="LC_left_item">'.
3635: '<input type="text" name="errorthreshold" value="'.
3636: $threshold.'" size="5" /></td></tr>';
3637: $rownum ++;
3638: $css_class = $rownum%2?' class="LC_odd_row"':'';
3639: $datatable .= '<tr'.$css_class.'>'.
3640: '<td class="LC_left_item">'.
3641: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3642: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 3643: foreach my $type ('E','W','N','U') {
1.340 raeburn 3644: $datatable .= '<td>'.$names->{$type}.'<br />'.
3645: '<input type="text" name="errorweights_'.$type.'" value="'.
3646: $weights{$type}.'" size="5" /></td>';
3647: }
3648: $datatable .= '</tr></table></tr>';
3649: $rownum ++;
3650: $css_class = $rownum%2?' class="LC_odd_row"':'';
3651: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3652: $titles->{'errorexcluded'}.'</td>'.
3653: '<td class="LC_left_item"><table>';
3654: my $numinrow = 4;
3655: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3656: for (my $i=0; $i<@ids; $i++) {
3657: my $rem = $i%($numinrow);
3658: if ($rem == 0) {
3659: if ($i > 0) {
3660: $datatable .= '</tr>';
3661: }
3662: $datatable .= '<tr>';
3663: }
3664: my $check;
3665: if ($excluded{$ids[$i]}) {
3666: $check = ' checked="checked" ';
3667: }
3668: $datatable .= '<td class="LC_left_item">'.
3669: '<span class="LC_nobreak"><label>'.
3670: '<input type="checkbox" name="errorexcluded" '.
3671: 'value="'.$ids[$i].'"'.$check.' />'.
3672: $ids[$i].'</label></span></td>';
3673: }
3674: my $colsleft = $numinrow - @ids%($numinrow);
3675: if ($colsleft > 1 ) {
3676: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3677: ' </td>';
3678: } elsif ($colsleft == 1) {
3679: $datatable .= '<td class="LC_left_item"> </td>';
3680: }
3681: $datatable .= '</tr></table></td></tr>';
3682: $rownum ++;
3683: $css_class = $rownum%2?' class="LC_odd_row"':'';
3684: $datatable .= '<tr'.$css_class.'>'.
3685: '<td class="LC_left_item"><span class="LC_nobreak">'.
3686: $titles->{'errorsysmail'}.
3687: '</span></td><td class="LC_left_item">'.
3688: '<input type="text" name="errorsysmail" value="'.
3689: $sysmail.'" size="5" /></td></tr>';
3690: $rownum ++;
1.286 raeburn 3691: } elsif ($position eq 'bottom') {
1.315 raeburn 3692: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3693: my (@posstypes,%usertypeshash);
3694: if (ref($types) eq 'ARRAY') {
3695: @posstypes = @{$types};
3696: }
3697: if (@posstypes) {
3698: if (ref($usertypes) eq 'HASH') {
3699: %usertypeshash = %{$usertypes};
3700: }
3701: my @overridden;
3702: my $numinrow = 4;
3703: if (ref($settings) eq 'HASH') {
3704: if (ref($settings->{'overrides'}) eq 'HASH') {
3705: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3706: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3707: push(@overridden,$key);
3708: foreach my $item (@contacts) {
3709: if ($settings->{'overrides'}{$key}{$item}) {
3710: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3711: }
3712: }
3713: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3714: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3715: $includeloc{'override_'.$key} = '';
3716: $includestr{'override_'.$key} = '';
3717: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3718: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3719: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3720: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3721: }
1.286 raeburn 3722: }
3723: }
3724: }
1.315 raeburn 3725: }
3726: my $customclass = 'LC_helpdesk_override';
3727: my $optionsprefix = 'LC_options_helpdesk_';
3728:
3729: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3730:
3731: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3732: $numinrow,$othertitle,'overrides',
3733: \$rownum,$onclicktypes,$customclass);
3734: $rownum ++;
3735: $usertypeshash{'default'} = $othertitle;
3736: foreach my $status (@posstypes) {
3737: my $css_class;
3738: if ($rownum%2) {
3739: $css_class = 'LC_odd_row ';
3740: }
3741: $css_class .= $customclass;
3742: my $rowid = $optionsprefix.$status;
3743: my $hidden = 1;
3744: my $currstyle = 'display:none';
3745: if (grep(/^\Q$status\E$/,@overridden)) {
3746: $currstyle = 'display:table-row';
3747: $hidden = 0;
3748: }
3749: my $key = 'override_'.$status;
3750: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3751: $includeloc{$key},$includestr{$key},$status,$rowid,
3752: $usertypeshash{$status},$css_class,$currstyle,
3753: \@contacts,$short_titles);
3754: unless ($hidden) {
3755: $rownum ++;
1.286 raeburn 3756: }
3757: }
1.134 raeburn 3758: }
1.28 raeburn 3759: }
1.30 raeburn 3760: $$rowtotal += $rownum;
1.28 raeburn 3761: return $datatable;
3762: }
3763:
1.340 raeburn 3764: sub core_link_msu {
3765: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3766: &mt('LON-CAPA core group - MSU'),600,500);
3767: }
3768:
1.315 raeburn 3769: sub overridden_helpdesk {
3770: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3771: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3772: my $class = 'LC_left_item';
3773: if ($css_class) {
3774: $css_class = ' class="'.$css_class.'"';
3775: }
3776: if ($rowid) {
3777: $rowid = ' id="'.$rowid.'"';
3778: }
3779: if ($rowstyle) {
3780: $rowstyle = ' style="'.$rowstyle.'"';
3781: }
3782: my ($output,$description);
3783: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3784: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3785: "<td>$description</td>\n".
3786: '<td class="'.$class.'" colspan="2">'.
3787: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3788: '<span class="LC_nobreak">';
3789: if (ref($contacts) eq 'ARRAY') {
3790: foreach my $item (@{$contacts}) {
3791: my $check;
3792: if (ref($checked) eq 'HASH') {
3793: $check = $checked->{$item};
3794: }
3795: my $title;
3796: if (ref($short_titles) eq 'HASH') {
3797: $title = $short_titles->{$item};
3798: }
3799: $output .= '<label>'.
3800: '<input type="checkbox" name="override_'.$type.'"'.$check.
3801: ' value="'.$item.'" />'.$title.'</label> ';
3802: }
3803: }
3804: $output .= '</span><br />'.&mt('Others').': '.
3805: '<input type="text" name="override_'.$type.'_others" '.
3806: 'value="'.$otheremails.'" />';
3807: my %locchecked;
3808: foreach my $loc ('s','b') {
3809: if ($includeloc eq $loc) {
3810: $locchecked{$loc} = ' checked="checked"';
3811: last;
3812: }
3813: }
3814: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3815: '<input type="text" name="override_'.$type.'_bcc" '.
3816: 'value="'.$bccemails.'" /></fieldset>'.
3817: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3818: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3819: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 3820: '<span class="LC_nobreak">'.&mt('Location:').' '.
3821: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3822: (' 'x2).
3823: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3824: '</span></fieldset>'.
3825: '</td></tr>'."\n";
3826: return $output;
3827: }
3828:
1.286 raeburn 3829: sub contacts_javascript {
3830: return <<"ENDSCRIPT";
3831:
3832: <script type="text/javascript">
3833: // <![CDATA[
3834:
3835: function screenshotSize(field) {
3836: if (document.getElementById('help_screenshotsize')) {
3837: if (field.value == 'no') {
1.289 raeburn 3838: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3839: } else {
3840: document.getElementById('help_screenshotsize').style.display="";
3841: }
3842: }
3843: return;
3844: }
3845:
1.315 raeburn 3846: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3847: if (form.elements[checkbox].length != undefined) {
3848: var count = 0;
3849: if (docount) {
3850: for (var i=0; i<form.elements[checkbox].length; i++) {
3851: if (form.elements[checkbox][i].checked) {
3852: count ++;
3853: }
3854: }
3855: }
3856: for (var i=0; i<form.elements[checkbox].length; i++) {
3857: var type = form.elements[checkbox][i].value;
3858: if (document.getElementById(prefix+type)) {
3859: if (form.elements[checkbox][i].checked) {
3860: document.getElementById(prefix+type).style.display = 'table-row';
3861: if (count % 2 == 1) {
3862: document.getElementById(prefix+type).className = target+' LC_odd_row';
3863: } else {
3864: document.getElementById(prefix+type).className = target;
3865: }
3866: count ++;
3867: } else {
3868: document.getElementById(prefix+type).style.display = 'none';
3869: }
3870: }
3871: }
3872: }
3873: return;
3874: }
3875:
3876:
1.286 raeburn 3877: // ]]>
3878: </script>
3879:
3880: ENDSCRIPT
3881: }
3882:
1.118 jms 3883: sub print_helpsettings {
1.282 raeburn 3884: my ($position,$dom,$settings,$rowtotal) = @_;
3885: my $confname = $dom.'-domainconfig';
1.285 raeburn 3886: my $formname = 'display';
1.168 raeburn 3887: my ($datatable,$itemcount);
1.282 raeburn 3888: if ($position eq 'top') {
3889: $itemcount = 1;
3890: my (%choices,%defaultchecked,@toggles);
3891: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3892: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3893: &mt('LON-CAPA bug tracker'),600,500));
3894: %defaultchecked = ('submitbugs' => 'on');
3895: @toggles = ('submitbugs');
3896: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3897: \%choices,$itemcount);
3898: $$rowtotal ++;
3899: } else {
3900: my $css_class;
3901: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3902: my (%customroles,%ordered,%current);
1.301 raeburn 3903: if (ref($settings) eq 'HASH') {
3904: if (ref($settings->{'adhoc'}) eq 'HASH') {
3905: %current = %{$settings->{'adhoc'}};
3906: }
1.285 raeburn 3907: }
3908: my $count = 0;
3909: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3910: if ($key=~/^rolesdef\_(\w+)$/) {
3911: my $rolename = $1;
1.285 raeburn 3912: my (%privs,$order);
1.282 raeburn 3913: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3914: $customroles{$rolename} = \%privs;
1.285 raeburn 3915: if (ref($current{$rolename}) eq 'HASH') {
3916: $order = $current{$rolename}{'order'};
3917: }
3918: if ($order eq '') {
3919: $order = $count;
3920: }
3921: $ordered{$order} = $rolename;
3922: $count++;
3923: }
3924: }
3925: my $maxnum = scalar(keys(%ordered));
3926: my @roles_by_num = ();
3927: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3928: push(@roles_by_num,$item);
3929: }
3930: my $context = 'domprefs';
3931: my $crstype = 'Course';
3932: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3933: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3934: my ($numstatustypes,@jsarray);
3935: if (ref($types) eq 'ARRAY') {
3936: if (@{$types} > 0) {
3937: $numstatustypes = scalar(@{$types});
3938: push(@accesstypes,'status');
3939: @jsarray = ('bystatus');
1.282 raeburn 3940: }
3941: }
1.290 raeburn 3942: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3943: if (keys(%domhelpdesk)) {
3944: push(@accesstypes,('inc','exc'));
3945: push(@jsarray,('notinc','notexc'));
3946: }
3947: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 3948: my $context = 'domprefs';
3949: my $crstype = 'Course';
1.285 raeburn 3950: my $prefix = 'helproles_';
3951: my $add_class = 'LC_hidden';
3952: foreach my $num (@roles_by_num) {
3953: my $role = $ordered{$num};
3954: my ($desc,$access,@statuses);
3955: if (ref($current{$role}) eq 'HASH') {
3956: $desc = $current{$role}{'desc'};
3957: $access = $current{$role}{'access'};
3958: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3959: @statuses = @{$current{$role}{'insttypes'}};
3960: }
3961: }
3962: if ($desc eq '') {
3963: $desc = $role;
3964: }
3965: my $identifier = 'custhelp'.$num;
1.282 raeburn 3966: my %full=();
3967: my %levels= (
3968: course => {},
3969: domain => {},
3970: system => {},
3971: );
3972: my %levelscurrent=(
3973: course => {},
3974: domain => {},
3975: system => {},
3976: );
3977: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3978: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3979: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3980: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 3981: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 3982: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3983: for (my $k=0; $k<=$maxnum; $k++) {
3984: my $vpos = $k+1;
3985: my $selstr;
3986: if ($k == $num) {
3987: $selstr = ' selected="selected" ';
3988: }
3989: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3990: }
3991: $datatable .= '</select>'.(' 'x2).
3992: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3993: '</td>'.
3994: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3995: &mt('Name shown to users:').
3996: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3997: '</fieldset>'.
3998: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3999: $othertitle,$usertypes,$types,\%domhelpdesk).
4000: '<fieldset>'.
4001: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4002: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4003: \%levelscurrent,$identifier,
4004: 'LC_hidden',$prefix.$num.'_privs').
4005: '</fieldset></td>';
1.282 raeburn 4006: $itemcount ++;
4007: }
4008: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4009: my $newcust = 'custhelp'.$count;
4010: my (%privs,%levelscurrent);
4011: my %full=();
4012: my %levels= (
4013: course => {},
4014: domain => {},
4015: system => {},
4016: );
4017: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4018: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4019: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4020: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4021: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4022: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4023: for (my $k=0; $k<$maxnum+1; $k++) {
4024: my $vpos = $k+1;
4025: my $selstr;
4026: if ($k == $maxnum) {
4027: $selstr = ' selected="selected" ';
4028: }
4029: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4030: }
4031: $datatable .= '</select> '."\n".
1.282 raeburn 4032: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4033: '</label></span></td>'.
1.285 raeburn 4034: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4035: '<span class="LC_nobreak">'.
4036: &mt('Internal name:').
4037: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4038: '</span>'.(' 'x4).
4039: '<span class="LC_nobreak">'.
4040: &mt('Name shown to users:').
4041: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4042: '</span></fieldset>'.
4043: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4044: $usertypes,$types,\%domhelpdesk).
4045: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4046: &Apache::lonuserutils::custom_role_header($context,$crstype,
4047: \@templateroles,$newcust).
4048: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4049: \%levelscurrent,$newcust).
1.334 raeburn 4050: '</fieldset>'.
4051: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4052: '</td></tr>';
1.282 raeburn 4053: $count ++;
4054: $$rowtotal += $count;
4055: }
1.166 raeburn 4056: return $datatable;
1.121 raeburn 4057: }
4058:
1.285 raeburn 4059: sub adhocbutton {
4060: my ($prefix,$num,$field,$visibility) = @_;
4061: my %lt = &Apache::lonlocal::texthash(
4062: show => 'Show details',
4063: hide => 'Hide details',
4064: );
4065: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4066: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4067: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4068: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4069: }
4070:
4071: sub helpsettings_javascript {
4072: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4073: return unless(ref($roles_by_num) eq 'ARRAY');
4074: my %html_js_lt = &Apache::lonlocal::texthash(
4075: show => 'Show details',
4076: hide => 'Hide details',
4077: );
4078: &html_escape(\%html_js_lt);
4079: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4080: return <<"ENDSCRIPT";
4081: <script type="text/javascript">
4082: // <![CDATA[
4083:
4084: function reorderHelpRoles(form,item) {
4085: var changedVal;
4086: $jstext
4087: var newpos = 'helproles_${total}_pos';
4088: var maxh = 1 + $total;
4089: var current = new Array();
4090: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4091: if (item == newpos) {
4092: changedVal = newitemVal;
4093: } else {
4094: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4095: current[newitemVal] = newpos;
4096: }
4097: for (var i=0; i<helproles.length; i++) {
4098: var elementName = 'helproles_'+helproles[i]+'_pos';
4099: if (elementName != item) {
4100: if (form.elements[elementName]) {
4101: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4102: current[currVal] = elementName;
4103: }
4104: }
4105: }
4106: var oldVal;
4107: for (var j=0; j<maxh; j++) {
4108: if (current[j] == undefined) {
4109: oldVal = j;
4110: }
4111: }
4112: if (oldVal < changedVal) {
4113: for (var k=oldVal+1; k<=changedVal ; k++) {
4114: var elementName = current[k];
4115: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4116: }
4117: } else {
4118: for (var k=changedVal; k<oldVal; k++) {
4119: var elementName = current[k];
4120: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4121: }
4122: }
4123: return;
4124: }
4125:
4126: function helpdeskAccess(num) {
4127: var curraccess = null;
4128: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4129: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4130: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4131: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4132: }
4133: }
4134: }
4135: var shown = Array();
4136: var hidden = Array();
4137: if (curraccess == 'none') {
4138: hidden = Array('$hiddenstr');
4139: } else {
4140: if (curraccess == 'status') {
4141: shown = Array('bystatus');
4142: hidden = Array('notinc','notexc');
4143: } else {
4144: if (curraccess == 'exc') {
4145: shown = Array('notexc');
4146: hidden = Array('notinc','bystatus');
4147: }
4148: if (curraccess == 'inc') {
4149: shown = Array('notinc');
4150: hidden = Array('notexc','bystatus');
4151: }
1.293 raeburn 4152: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4153: hidden = Array('notinc','notexc','bystatus');
4154: }
4155: }
4156: }
4157: if (hidden.length > 0) {
4158: for (var i=0; i<hidden.length; i++) {
4159: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4160: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4161: }
4162: }
4163: }
4164: if (shown.length > 0) {
4165: for (var i=0; i<shown.length; i++) {
4166: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4167: if (shown[i] == 'privs') {
4168: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4169: } else {
4170: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4171: }
4172: }
4173: }
4174: }
4175: return;
4176: }
4177:
4178: function toggleHelpdeskItem(num,field) {
4179: if (document.getElementById('helproles_'+num+'_'+field)) {
4180: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4181: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4182: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4183: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4184: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4185: }
4186: } else {
4187: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4188: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4189: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4190: }
4191: }
4192: }
4193: return;
4194: }
4195:
4196: // ]]>
4197: </script>
4198:
4199: ENDSCRIPT
4200: }
4201:
4202: sub helpdeskroles_access {
4203: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4204: $usertypes,$types,$domhelpdesk) = @_;
4205: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4206: my %lt = &Apache::lonlocal::texthash(
4207: 'rou' => 'Role usage',
4208: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4209: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4210: 'dh' => 'All with domain helpdesk role',
4211: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4212: 'none' => 'None',
4213: 'status' => 'Determined based on institutional status',
4214: 'inc' => 'Include all, but exclude specific personnel',
4215: 'exc' => 'Exclude all, but include specific personnel',
4216: );
4217: my %usecheck = (
4218: all => ' checked="checked"',
4219: );
4220: my %displaydiv = (
4221: status => 'none',
4222: inc => 'none',
4223: exc => 'none',
4224: priv => 'block',
4225: );
4226: my $output;
4227: if (ref($current) eq 'HASH') {
4228: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4229: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4230: $usecheck{$current->{access}} = $usecheck{'all'};
4231: delete($usecheck{'all'});
4232: if ($current->{access} =~ /^(status|inc|exc)$/) {
4233: my $access = $1;
4234: $displaydiv{$access} = 'inline';
4235: } elsif ($current->{access} eq 'none') {
4236: $displaydiv{'priv'} = 'none';
4237: }
4238: }
4239: }
4240: }
4241: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4242: '<p>'.$lt{'whi'}.'</p>';
4243: foreach my $access (@{$accesstypes}) {
4244: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4245: ' onclick="helpdeskAccess('."'$num'".');" />'.
4246: $lt{$access}.'</label>';
4247: if ($access eq 'status') {
4248: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4249: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4250: $othertitle,$usertypes,$types).
4251: '</div>';
4252: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4253: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4254: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4255: '</div>';
4256: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4257: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4258: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4259: '</div>';
4260: }
4261: $output .= '</p>';
4262: }
4263: $output .= '</fieldset>';
4264: return $output;
4265: }
4266:
1.121 raeburn 4267: sub radiobutton_prefs {
1.192 raeburn 4268: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4269: $additional,$align) = @_;
1.121 raeburn 4270: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4271: (ref($choices) eq 'HASH'));
4272:
1.170 raeburn 4273: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4274:
4275: foreach my $item (@{$toggles}) {
4276: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4277: $checkedon{$item} = ' checked="checked" ';
4278: $checkedoff{$item} = ' ';
1.121 raeburn 4279: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4280: $checkedoff{$item} = ' checked="checked" ';
4281: $checkedon{$item} = ' ';
4282: }
4283: }
4284: if (ref($settings) eq 'HASH') {
1.121 raeburn 4285: foreach my $item (@{$toggles}) {
1.118 jms 4286: if ($settings->{$item} eq '1') {
4287: $checkedon{$item} = ' checked="checked" ';
4288: $checkedoff{$item} = ' ';
4289: } elsif ($settings->{$item} eq '0') {
4290: $checkedoff{$item} = ' checked="checked" ';
4291: $checkedon{$item} = ' ';
4292: }
4293: }
1.121 raeburn 4294: }
1.192 raeburn 4295: if ($onclick) {
4296: $onclick = ' onclick="'.$onclick.'"';
4297: }
1.121 raeburn 4298: foreach my $item (@{$toggles}) {
1.118 jms 4299: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4300: $datatable .=
1.306 raeburn 4301: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4302: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4303: '</span></td>';
4304: if ($align eq 'left') {
4305: $datatable .= '<td class="LC_left_item">';
4306: } else {
4307: $datatable .= '<td class="LC_right_item">';
4308: }
1.289 raeburn 4309: $datatable .=
1.257 raeburn 4310: '<span class="LC_nobreak">'.
1.118 jms 4311: '<label><input type="radio" name="'.
1.192 raeburn 4312: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4313: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4314: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4315: '</span>'.$additional.
4316: '</td>'.
1.118 jms 4317: '</tr>';
4318: $itemcount ++;
1.121 raeburn 4319: }
4320: return ($datatable,$itemcount);
4321: }
4322:
1.267 raeburn 4323: sub print_ltitools {
4324: my ($dom,$settings,$rowtotal) = @_;
4325: my $rownum = 0;
4326: my $css_class;
4327: my $itemcount = 1;
4328: my $maxnum = 0;
4329: my %ordered;
4330: if (ref($settings) eq 'HASH') {
4331: foreach my $item (keys(%{$settings})) {
4332: if (ref($settings->{$item}) eq 'HASH') {
4333: my $num = $settings->{$item}{'order'};
4334: $ordered{$num} = $item;
4335: }
4336: }
4337: }
4338: my $confname = $dom.'-domainconfig';
4339: my $switchserver = &check_switchserver($dom,$confname);
4340: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4341: my $datatable;
1.267 raeburn 4342: my %lt = <itools_names();
4343: my @courseroles = ('cc','in','ta','ep','st');
4344: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4345: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4346: if (keys(%ordered)) {
4347: my @items = sort { $a <=> $b } keys(%ordered);
4348: for (my $i=0; $i<@items; $i++) {
4349: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4350: my $item = $ordered{$items[$i]};
1.323 raeburn 4351: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4352: if (ref($settings->{$item}) eq 'HASH') {
4353: $title = $settings->{$item}->{'title'};
4354: $url = $settings->{$item}->{'url'};
4355: $key = $settings->{$item}->{'key'};
4356: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4357: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4358: my $image = $settings->{$item}->{'image'};
4359: if ($image ne '') {
4360: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4361: }
1.323 raeburn 4362: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4363: $sigsel{'HMAC-256'} = ' selected="selected"';
4364: } else {
4365: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4366: }
1.267 raeburn 4367: }
1.319 raeburn 4368: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4369: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4370: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4371: for (my $k=0; $k<=$maxnum; $k++) {
4372: my $vpos = $k+1;
4373: my $selstr;
4374: if ($k == $i) {
4375: $selstr = ' selected="selected" ';
4376: }
4377: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4378: }
4379: $datatable .= '</select>'.(' 'x2).
4380: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4381: &mt('Delete?').'</label></span></td>'.
4382: '<td colspan="2">'.
4383: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4384: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4385: (' 'x2).
4386: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4387: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4388: (' 'x2).
4389: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4390: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4391: (' 'x2).
4392: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4393: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4394: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4395: '<br /><br />'.
1.323 raeburn 4396: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4397: ' value="'.$url.'" /></span>'.
4398: (' 'x2).
1.319 raeburn 4399: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4400: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4401: (' 'x2).
1.322 raeburn 4402: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4403: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4404: (' 'x2).
1.267 raeburn 4405: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4406: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4407: '<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>'.
4408: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4409: '</fieldset>'.
4410: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4411: '<span class="LC_nobreak">'.&mt('Display target:');
4412: my %currdisp;
4413: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4414: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4415: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4416: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4417: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4418: } else {
4419: $currdisp{'iframe'} = ' checked="checked"';
4420: }
4421: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4422: $currdisp{'width'} = $1;
4423: }
4424: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4425: $currdisp{'height'} = $1;
4426: }
1.296 raeburn 4427: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4428: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4429: } else {
4430: $currdisp{'iframe'} = ' checked="checked"';
4431: }
1.298 raeburn 4432: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4433: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4434: $lt{$disp}.'</label>'.(' 'x2);
4435: }
4436: $datatable .= (' 'x4);
4437: foreach my $dimen ('width','height') {
4438: $datatable .= '<label>'.$lt{$dimen}.' '.
4439: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4440: (' 'x2);
4441: }
1.334 raeburn 4442: $datatable .= '</span><br />'.
1.296 raeburn 4443: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4444: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4445: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4446: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4447: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4448: my %units = (
4449: 'passback' => 'days',
4450: 'roster' => 'seconds',
4451: );
1.267 raeburn 4452: foreach my $extra ('passback','roster') {
1.319 raeburn 4453: my $validsty = 'none';
4454: my $currvalid;
1.267 raeburn 4455: my $checkedon = '';
4456: my $checkedoff = ' checked="checked"';
4457: if ($settings->{$item}->{$extra}) {
4458: $checkedon = $checkedoff;
4459: $checkedoff = '';
1.319 raeburn 4460: $validsty = 'inline-block';
4461: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4462: $currvalid = $settings->{$item}->{$extra.'valid'};
4463: }
4464: }
4465: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4466: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4467: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4468: &mt('No').'</label>'.(' 'x2).
4469: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4470: &mt('Yes').'</label></span></div>'.
4471: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4472: '<span class="LC_nobreak">'.
4473: &mt("at least [_1] $units{$extra} after launch",
4474: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4475: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4476: }
1.319 raeburn 4477: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4478: if ($imgsrc) {
4479: $datatable .= $imgsrc.
4480: '<label><input type="checkbox" name="ltitools_image_del"'.
4481: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4482: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4483: } else {
4484: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4485: }
4486: if ($switchserver) {
4487: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4488: } else {
4489: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4490: }
4491: $datatable .= '</span></fieldset>';
1.324 raeburn 4492: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4493: if (ref($settings->{$item}) eq 'HASH') {
4494: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4495: %checkedfields = %{$settings->{$item}->{'fields'}};
4496: }
1.324 raeburn 4497: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4498: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4499: %rolemaps = %{$settings->{$item}->{'roles'}};
4500: $checkedfields{'roles'} = 1;
4501: }
4502: }
4503: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4504: '<span class="LC_nobreak">';
1.324 raeburn 4505: my $userfieldstyle = 'display:none;';
4506: my $seluserdom = '';
4507: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4508: foreach my $field (@fields) {
1.324 raeburn 4509: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4510: if ($checkedfields{$field}) {
4511: $checked = ' checked="checked"';
4512: }
1.324 raeburn 4513: if ($field eq 'user') {
4514: $id = ' id="ltitools_user_field_'.$i.'"';
4515: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4516: if ($checked) {
4517: $userfieldstyle = 'display:inline-block';
4518: if ($userincdom) {
4519: $seluserdom = $unseluserdom;
4520: $unseluserdom = '';
4521: }
4522: }
4523: } else {
4524: $spacer = (' ' x2);
4525: }
1.267 raeburn 4526: $datatable .= '<label>'.
1.324 raeburn 4527: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4528: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4529: }
1.324 raeburn 4530: $datatable .= '</span>';
4531: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4532: '<span class="LC_nobreak"> : '.
4533: '<select name="ltitools_userincdom_'.$i.'">'.
4534: '<option value="">'.&mt('Select').'</option>'.
4535: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4536: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4537: '</select></span></div>';
4538: $datatable .= '</fieldset>'.
1.267 raeburn 4539: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4540: foreach my $role (@courseroles) {
4541: my ($selected,$selectnone);
4542: if (!$rolemaps{$role}) {
4543: $selectnone = ' selected="selected"';
4544: }
1.306 raeburn 4545: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4546: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4547: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4548: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4549: foreach my $ltirole (@ltiroles) {
4550: unless ($selectnone) {
4551: if ($rolemaps{$role} eq $ltirole) {
4552: $selected = ' selected="selected"';
4553: } else {
4554: $selected = '';
4555: }
4556: }
4557: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4558: }
4559: $datatable .= '</select></td>';
4560: }
1.273 raeburn 4561: $datatable .= '</tr></table></fieldset>';
4562: my %courseconfig;
4563: if (ref($settings->{$item}) eq 'HASH') {
4564: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4565: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4566: }
4567: }
4568: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4569: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4570: my $checked;
4571: if ($courseconfig{$item}) {
4572: $checked = ' checked="checked"';
4573: }
4574: $datatable .= '<label>'.
4575: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4576: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4577: }
4578: $datatable .= '</span></fieldset>'.
1.267 raeburn 4579: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4580: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4581: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4582: my %custom = %{$settings->{$item}->{'custom'}};
4583: if (keys(%custom) > 0) {
4584: foreach my $key (sort(keys(%custom))) {
4585: $datatable .= '<tr><td><span class="LC_nobreak">'.
4586: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4587: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4588: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4589: ' value="'.$custom{$key}.'" /></td></tr>';
4590: }
4591: }
4592: }
4593: $datatable .= '<tr><td><span class="LC_nobreak">'.
4594: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4595: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4596: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4597: $datatable .= '</table></fieldset></td></tr>'."\n";
4598: $itemcount ++;
4599: }
4600: }
4601: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4602: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4603: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4604: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4605: '<select name="ltitools_add_pos"'.$chgstr.'>';
4606: for (my $k=0; $k<$maxnum+1; $k++) {
4607: my $vpos = $k+1;
4608: my $selstr;
4609: if ($k == $maxnum) {
4610: $selstr = ' selected="selected" ';
4611: }
4612: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4613: }
4614: $datatable .= '</select> '."\n".
1.334 raeburn 4615: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 4616: '<td colspan="2">'.
4617: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4618: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4619: (' 'x2).
4620: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4621: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4622: (' 'x2).
4623: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4624: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4625: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4626: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4627: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4628: '<br />'.
1.323 raeburn 4629: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4630: (' 'x2).
4631: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4632: (' 'x2).
1.322 raeburn 4633: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4634: (' 'x2).
1.267 raeburn 4635: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4636: '<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".
4637: '</fieldset>'.
4638: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4639: '<span class="LC_nobreak">'.&mt('Display target:');
4640: my %defaultdisp;
4641: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4642: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4643: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4644: $lt{$disp}.'</label>'.(' 'x2);
4645: }
4646: $datatable .= (' 'x4);
4647: foreach my $dimen ('width','height') {
4648: $datatable .= '<label>'.$lt{$dimen}.' '.
4649: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4650: (' 'x2);
4651: }
1.334 raeburn 4652: $datatable .= '</span><br />'.
1.296 raeburn 4653: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4654: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 4655: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 4656: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 4657: '</div><div style=""></div><br />';
1.319 raeburn 4658: my %units = (
4659: 'passback' => 'days',
4660: 'roster' => 'seconds',
4661: );
4662: my %defaulttimes = (
4663: 'passback' => '7',
1.322 raeburn 4664: 'roster' => '300',
1.319 raeburn 4665: );
1.267 raeburn 4666: foreach my $extra ('passback','roster') {
1.319 raeburn 4667: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4668: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4669: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4670: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4671: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4672: &mt('Yes').'</label></span></div>'.
4673: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4674: '<span class="LC_nobreak">'.
4675: &mt("at least [_1] $units{$extra} after launch",
4676: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4677: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4678: }
1.319 raeburn 4679: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4680: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4681: if ($switchserver) {
4682: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4683: } else {
4684: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4685: }
4686: $datatable .= '</span></fieldset>'.
4687: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4688: '<span class="LC_nobreak">';
4689: foreach my $field (@fields) {
1.324 raeburn 4690: my ($id,$onclick,$spacer);
4691: if ($field eq 'user') {
4692: $id = ' id="ltitools_user_field_add"';
4693: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4694: } else {
4695: $spacer = (' ' x2);
4696: }
1.267 raeburn 4697: $datatable .= '<label>'.
1.324 raeburn 4698: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4699: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4700: }
1.324 raeburn 4701: $datatable .= '</span>'.
4702: '<div style="display:none;" id="ltitools_user_div_add">'.
4703: '<span class="LC_nobreak"> : '.
4704: '<select name="ltitools_userincdom_add">'.
4705: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4706: '<option value="0">'.&mt('username').'</option>'.
4707: '<option value="1">'.&mt('username:domain').'</option>'.
4708: '</select></span></div></fieldset>';
4709: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 4710: foreach my $role (@courseroles) {
4711: my ($checked,$checkednone);
1.306 raeburn 4712: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4713: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4714: '<select name="ltitools_add_roles_'.$role.'">'.
4715: '<option value="" selected="selected">'.&mt('Select').'</option>';
4716: foreach my $ltirole (@ltiroles) {
4717: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4718: }
4719: $datatable .= '</select></td>';
4720: }
4721: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4722: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4723: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4724: $datatable .= '<label>'.
4725: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4726: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4727: }
4728: $datatable .= '</span></fieldset>'.
1.267 raeburn 4729: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4730: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4731: '<tr><td><span class="LC_nobreak">'.
4732: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4733: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4734: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 4735: '</table></fieldset>'."\n".
1.267 raeburn 4736: '</td>'."\n".
4737: '</tr>'."\n";
4738: $itemcount ++;
4739: return $datatable;
4740: }
4741:
4742: sub ltitools_names {
4743: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4744: 'title' => 'Title',
4745: 'version' => 'Version',
4746: 'msgtype' => 'Message Type',
1.323 raeburn 4747: 'sigmethod' => 'Signature Method',
1.296 raeburn 4748: 'url' => 'URL',
4749: 'key' => 'Key',
1.322 raeburn 4750: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4751: 'secret' => 'Secret',
4752: 'icon' => 'Icon',
1.324 raeburn 4753: 'user' => 'User',
1.296 raeburn 4754: 'fullname' => 'Full Name',
4755: 'firstname' => 'First Name',
4756: 'lastname' => 'Last Name',
4757: 'email' => 'E-mail',
4758: 'roles' => 'Role',
1.298 raeburn 4759: 'window' => 'Window',
4760: 'tab' => 'Tab',
1.296 raeburn 4761: 'iframe' => 'iFrame',
4762: 'height' => 'Height',
4763: 'width' => 'Width',
4764: 'linktext' => 'Default Link Text',
4765: 'explanation' => 'Default Explanation',
4766: 'passback' => 'Tool can return grades:',
4767: 'roster' => 'Tool can retrieve roster:',
4768: 'crstarget' => 'Display target',
4769: 'crslabel' => 'Course label',
4770: 'crstitle' => 'Course title',
4771: 'crslinktext' => 'Link Text',
4772: 'crsexplanation' => 'Explanation',
1.318 raeburn 4773: 'crsappend' => 'Provider URL',
1.267 raeburn 4774: );
4775: return %lt;
4776: }
4777:
1.320 raeburn 4778: sub print_lti {
4779: my ($dom,$settings,$rowtotal) = @_;
4780: my $itemcount = 1;
4781: my $maxnum = 0;
4782: my $css_class;
4783: my %ordered;
4784: if (ref($settings) eq 'HASH') {
4785: foreach my $item (keys(%{$settings})) {
4786: if (ref($settings->{$item}) eq 'HASH') {
4787: my $num = $settings->{$item}{'order'};
4788: $ordered{$num} = $item;
4789: }
4790: }
4791: }
4792: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4793: my $datatable;
1.320 raeburn 4794: my %lt = <i_names();
4795: if (keys(%ordered)) {
4796: my @items = sort { $a <=> $b } keys(%ordered);
4797: for (my $i=0; $i<@items; $i++) {
4798: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4799: my $item = $ordered{$items[$i]};
1.345 raeburn 4800: my ($key,$secret,$lifetime,$consumer,$requser,$current);
1.320 raeburn 4801: if (ref($settings->{$item}) eq 'HASH') {
4802: $key = $settings->{$item}->{'key'};
4803: $secret = $settings->{$item}->{'secret'};
4804: $lifetime = $settings->{$item}->{'lifetime'};
4805: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 4806: $requser = $settings->{$item}->{'requser'};
1.320 raeburn 4807: $current = $settings->{$item};
4808: }
1.345 raeburn 4809: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
4810: my %checkedrequser = (
4811: yes => ' checked="checked"',
4812: no => '',
4813: );
4814: if (!$requser) {
4815: $checkedrequser{'no'} = $checkedrequser{'yes'};
4816: $checkedrequser{'yes'} = '';
4817: }
1.320 raeburn 4818: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
4819: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4820: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
4821: for (my $k=0; $k<=$maxnum; $k++) {
4822: my $vpos = $k+1;
4823: my $selstr;
4824: if ($k == $i) {
4825: $selstr = ' selected="selected" ';
4826: }
4827: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4828: }
4829: $datatable .= '</select>'.(' 'x2).
4830: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
4831: &mt('Delete?').'</label></span></td>'.
4832: '<td colspan="2">'.
4833: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4834: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 4835: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 4836: (' 'x2).
4837: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
4838: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4839: (' 'x2).
4840: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 4841: 'value="'.$lifetime.'" size="3" /></span>'.
4842: (' 'x2).
4843: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
4844: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
4845: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 4846: '<br /><br />'.
4847: '<span class="LC_nobreak">'.$lt{'key'}.
4848: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
4849: (' 'x2).
4850: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4851: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
4852: '<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>'.
4853: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 4854: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 4855: $itemcount ++;
4856: }
4857: }
4858: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4859: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
4860: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4861: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
4862: '<select name="lti_pos_add"'.$chgstr.'>';
4863: for (my $k=0; $k<$maxnum+1; $k++) {
4864: my $vpos = $k+1;
4865: my $selstr;
4866: if ($k == $maxnum) {
4867: $selstr = ' selected="selected" ';
4868: }
4869: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4870: }
4871: $datatable .= '</select> '."\n".
1.334 raeburn 4872: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 4873: '<td colspan="2">'.
4874: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4875: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 4876: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 4877: (' 'x2).
4878: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
4879: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4880: (' 'x2).
1.345 raeburn 4881: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
4882: (' 'x2).
4883: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
4884: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
4885: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 4886: '<br /><br />'.
4887: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
4888: (' 'x2).
4889: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
4890: '<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 4891: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 4892: '</td>'."\n".
4893: '</tr>'."\n";
4894: $$rowtotal ++;
4895: return $datatable;;
4896: }
4897:
4898: sub lti_names {
4899: my %lt = &Apache::lonlocal::texthash(
4900: 'version' => 'LTI Version',
4901: 'url' => 'URL',
4902: 'key' => 'Key',
1.322 raeburn 4903: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 4904: 'consumer' => 'Consumer',
1.320 raeburn 4905: 'secret' => 'Secret',
1.345 raeburn 4906: 'requser' => "User's identity sent",
1.320 raeburn 4907: 'email' => 'Email address',
4908: 'sourcedid' => 'User ID',
4909: 'other' => 'Other',
4910: 'passback' => 'Can return grades to Consumer:',
4911: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 4912: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 4913: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 4914: );
4915: return %lt;
4916: }
4917:
4918: sub lti_options {
1.325 raeburn 4919: my ($num,$current,$itemcount,%lt) = @_;
1.320 raeburn 4920: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);
4921: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
4922: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
4923: $checked{'makecrs'}{'N'} = ' checked="checked"';
4924: $checked{'mapcrstype'} = {};
4925: $checked{'makeuser'} = {};
4926: $checked{'selfenroll'} = {};
4927: $checked{'crssec'} = {};
4928: $checked{'crssecsrc'} = {};
1.325 raeburn 4929: $checked{'lcauth'} = {};
1.326 raeburn 4930: $checked{'menuitem'} = {};
1.325 raeburn 4931: if ($num eq 'add') {
4932: $checked{'lcauth'}{'lti'} = ' checked="checked"';
4933: }
1.320 raeburn 4934: my $userfieldsty = 'none';
4935: my $crsfieldsty = 'none';
4936: my $crssecfieldsty = 'none';
4937: my $secsrcfieldsty = 'none';
1.337 raeburn 4938: my $passbacksty = 'none';
1.345 raeburn 4939: my $optionsty = 'block';
1.325 raeburn 4940: my $lcauthparm;
4941: my $lcauthparmstyle = 'display:none';
4942: my $lcauthparmtext;
1.326 raeburn 4943: my $menusty;
1.325 raeburn 4944: my $numinrow = 4;
1.326 raeburn 4945: my %menutitles = <imenu_titles();
1.320 raeburn 4946:
4947: if (ref($current) eq 'HASH') {
1.345 raeburn 4948: if (!$current->{'requser'}) {
4949: $optionsty = 'none';
4950: }
1.320 raeburn 4951: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
4952: $checked{'mapuser'}{'sourcedid'} = '';
4953: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
4954: $checked{'mapuser'}{'email'} = ' checked="checked"';
4955: } else {
4956: $checked{'mapuser'}{'other'} = ' checked="checked"';
4957: $userfield = $current->{'mapuser'};
4958: $userfieldsty = 'inline-block';
4959: }
4960: }
4961: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
4962: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
4963: if ($current->{'mapcrs'} eq 'context_id') {
4964: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
4965: } else {
4966: $checked{'mapcrs'}{'other'} = ' checked="checked"';
4967: $cidfield = $current->{'mapcrs'};
4968: $crsfieldsty = 'inline-block';
4969: }
4970: }
4971: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
4972: foreach my $type (@{$current->{'mapcrstype'}}) {
4973: $checked{'mapcrstype'}{$type} = ' checked="checked"';
4974: }
4975: }
1.345 raeburn 4976: if ($current->{'makecrs'}) {
1.320 raeburn 4977: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 4978: }
1.320 raeburn 4979: if (ref($current->{'makeuser'}) eq 'ARRAY') {
4980: foreach my $role (@{$current->{'makeuser'}}) {
4981: $checked{'makeuser'}{$role} = ' checked="checked"';
4982: }
4983: }
1.325 raeburn 4984: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
4985: $checked{'lcauth'}{$1} = ' checked="checked"';
4986: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
4987: $lcauthparm = $current->{'lcauthparm'};
4988: $lcauthparmstyle = 'display:table-row';
4989: if ($current->{'lcauth'} eq 'localauth') {
4990: $lcauthparmtext = &mt('Local auth argument');
4991: } else {
4992: $lcauthparmtext = &mt('Kerberos domain');
4993: }
4994: }
4995: }
1.320 raeburn 4996: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
4997: foreach my $role (@{$current->{'selfenroll'}}) {
4998: $checked{'selfenroll'}{$role} = ' checked="checked"';
4999: }
5000: }
5001: if (ref($current->{'maproles'}) eq 'HASH') {
5002: %rolemaps = %{$current->{'maproles'}};
5003: }
5004: if ($current->{'section'} ne '') {
5005: $checked{'crssec'}{'Y'} = ' checked="checked"';
5006: $crssecfieldsty = 'inline-block';
5007: if ($current->{'section'} eq 'course_section_sourcedid') {
5008: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5009: } else {
5010: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5011: $crssecsrc = $current->{'section'};
5012: $secsrcfieldsty = 'inline-block';
5013: }
5014: } else {
5015: $checked{'crssec'}{'N'} = ' checked="checked"';
5016: }
1.326 raeburn 5017: if ($current->{'topmenu'}) {
5018: $checked{'topmenu'}{'Y'} = ' checked="checked"';
5019: } else {
5020: $checked{'topmenu'}{'N'} = ' checked="checked"';
5021: }
5022: if ($current->{'inlinemenu'}) {
5023: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5024: } else {
5025: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5026: }
5027: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5028: $menusty = 'inline-block';
5029: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5030: foreach my $item (@{$current->{'lcmenu'}}) {
5031: if (exists($menutitles{$item})) {
5032: $checked{'menuitem'}{$item} = ' checked="checked"';
5033: }
5034: }
5035: }
5036: } else {
5037: $menusty = 'none';
5038: }
1.320 raeburn 5039: } else {
5040: $checked{'makecrs'}{'N'} = ' checked="checked"';
5041: $checked{'crssec'}{'N'} = ' checked="checked"';
1.326 raeburn 5042: $checked{'topmenu'}{'N'} = ' checked="checked"';
5043: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5044: $checked{'menuitem'}{'grades'} = ' checked="checked"';
5045: $menusty = 'inline-block';
1.320 raeburn 5046: }
1.325 raeburn 5047: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 5048: my %coursetypetitles = &Apache::lonlocal::texthash (
5049: official => 'Official',
5050: unofficial => 'Unofficial',
5051: community => 'Community',
5052: textbook => 'Textbook',
5053: placement => 'Placement Test',
1.325 raeburn 5054: lti => 'LTI Provider',
1.320 raeburn 5055: );
1.325 raeburn 5056: my @authtypes = ('internal','krb4','krb5','localauth');
5057: my %shortauth = (
5058: internal => 'int',
5059: krb4 => 'krb4',
5060: krb5 => 'krb5',
5061: localauth => 'loc'
5062: );
5063: my %authnames = &authtype_names();
1.320 raeburn 5064: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5065: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5066: my @courseroles = ('cc','in','ta','ep','st');
5067: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5068: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5069: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
5070: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 5071: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 5072: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.345 raeburn 5073: my $output = '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 5074: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5075: foreach my $option ('sourcedid','email','other') {
5076: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5077: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5078: ($option eq 'other' ? '' : (' 'x2) );
5079: }
5080: $output .= '</span></div>'.
5081: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5082: '<input type="text" name="lti_customuser_'.$num.'" '.
5083: 'value="'.$userfield.'" /></div></fieldset>'.
1.345 raeburn 5084: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
1.320 raeburn 5085: foreach my $ltirole (@lticourseroles) {
5086: my ($selected,$selectnone);
5087: if ($rolemaps{$ltirole} eq '') {
5088: $selectnone = ' selected="selected"';
5089: }
5090: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5091: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5092: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5093: foreach my $role (@courseroles) {
5094: unless ($selectnone) {
5095: if ($rolemaps{$ltirole} eq $role) {
5096: $selected = ' selected="selected"';
5097: } else {
5098: $selected = '';
5099: }
5100: }
5101: $output .= '<option value="'.$role.'"'.$selected.'>'.
5102: &Apache::lonnet::plaintext($role,'Course').
5103: '</option>';
5104: }
5105: $output .= '</select></td>';
5106: }
5107: $output .= '</tr></table></fieldset>'.
1.345 raeburn 5108: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 5109: foreach my $ltirole (@ltiroles) {
5110: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5111: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5112: }
5113: $output .= '</fieldset>'.
1.345 raeburn 5114: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 5115: '<table>'.
5116: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5117: '</table>'.
5118: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5119: '<td class="LC_left_item">';
5120: foreach my $auth ('lti',@authtypes) {
5121: my $authtext;
5122: if ($auth eq 'lti') {
5123: $authtext = &mt('None');
5124: } else {
5125: $authtext = $authnames{$shortauth{$auth}};
5126: }
5127: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5128: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5129: $authtext.'</label></span> ';
5130: }
5131: $output .= '</td></tr>'.
5132: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5133: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5134: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5135: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5136: '</table></fieldset>'.
1.345 raeburn 5137: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 5138: '<div class="LC_floatleft"><span class="LC_nobreak">'.
5139: &mt('Unique course identifier').': ';
5140: foreach my $option ('course_offering_sourcedid','context_id','other') {
5141: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5142: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5143: ($option eq 'other' ? '' : (' 'x2) );
5144: }
1.334 raeburn 5145: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 5146: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5147: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5148: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5149: foreach my $type (@coursetypes) {
5150: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5151: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5152: (' 'x2);
5153: }
5154: $output .= '</span></fieldset>'.
1.345 raeburn 5155: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 5156: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5157: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5158: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5159: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5160: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5161: '</fieldset>'.
1.345 raeburn 5162: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 5163: foreach my $lticrsrole (@lticourseroles) {
5164: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5165: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5166: }
5167: $output .= '</fieldset>'.
1.345 raeburn 5168: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 5169: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5170: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5171: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
5172: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 5173: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 5174: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5175: '<span class="LC_nobreak">'.&mt('From').':<label>'.
5176: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5177: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
5178: &mt('Standard field').'</label>'.(' 'x2).
5179: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
5180: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 5181: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 5182: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 5183: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
5184: my ($pb1p1chk,$pb1p0chk,$onclickpb);
5185: foreach my $extra ('roster','passback') {
1.320 raeburn 5186: my $checkedon = '';
5187: my $checkedoff = ' checked="checked"';
1.337 raeburn 5188: if ($extra eq 'passback') {
5189: $pb1p1chk = ' checked="checked"';
5190: $pb1p0chk = '';
5191: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
5192: } else {
5193: $onclickpb = '';
5194: }
1.320 raeburn 5195: if (ref($current) eq 'HASH') {
5196: if (($current->{$extra})) {
5197: $checkedon = $checkedoff;
5198: $checkedoff = '';
1.337 raeburn 5199: if ($extra eq 'passback') {
5200: $passbacksty = 'inline-block';
5201: }
5202: if ($current->{'passbackformat'} eq '1.0') {
5203: $pb1p0chk = ' checked="checked"';
5204: $pb1p1chk = '';
5205: }
1.320 raeburn 5206: }
5207: }
5208: $output .= $lt{$extra}.' '.
1.337 raeburn 5209: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 5210: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 5211: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 5212: &mt('Yes').'</label><br />';
5213: }
1.337 raeburn 5214: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
5215: '<span class="LC_nobreak">'.&mt('Grade format').
5216: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
5217: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
5218: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
5219: &mt('Outcomes Extension (1.0)').'</label></span></div></fieldset>'.
1.345 raeburn 5220: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
1.326 raeburn 5221: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5222: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5223: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5224: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334 raeburn 5225: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326 raeburn 5226: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5227: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5228: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5229: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5230: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334 raeburn 5231: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326 raeburn 5232: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5233: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5234: '<span class="LC_nobreak">'.&mt('Menu items').': ';
5235: foreach my $type ('fullname','coursetitle','role','logout','grades') {
5236: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5237: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5238: (' 'x2);
5239: }
1.334 raeburn 5240: $output .= '</span></div></fieldset>';
1.320 raeburn 5241: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5242: #
5243: # $output .= '</fieldset>'.
5244: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5245: return $output;
5246: }
5247:
1.326 raeburn 5248: sub ltimenu_titles {
5249: return &Apache::lonlocal::texthash(
5250: fullname => 'Full name',
5251: coursetitle => 'Course title',
5252: role => 'Role',
5253: logout => 'Logout',
5254: grades => 'Grades',
5255: );
5256: }
5257:
1.121 raeburn 5258: sub print_coursedefaults {
1.139 raeburn 5259: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 5260: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5261: my $itemcount = 1;
1.192 raeburn 5262: my %choices = &Apache::lonlocal::texthash (
5263: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 5264: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 5265: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5266: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 5267: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5268: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 5269: texengine => 'Default method to display mathematics',
1.257 raeburn 5270: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 5271: canclone => "People who may clone a course (besides course's owner and coordinators)",
5272: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 5273: );
1.198 raeburn 5274: my %staticdefaults = (
1.314 raeburn 5275: texengine => 'MathJax',
1.198 raeburn 5276: anonsurvey_threshold => 10,
5277: uploadquota => 500,
1.257 raeburn 5278: postsubmit => 60,
1.276 raeburn 5279: mysqltables => 172800,
1.198 raeburn 5280: );
1.139 raeburn 5281: if ($position eq 'top') {
1.257 raeburn 5282: %defaultchecked = (
5283: 'canuse_pdfforms' => 'off',
5284: 'uselcmath' => 'on',
5285: 'usejsme' => 'on',
1.289 raeburn 5286: 'canclone' => 'none',
1.257 raeburn 5287: );
5288: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.314 raeburn 5289: my $deftex = $staticdefaults{'texengine'};
5290: if (ref($settings) eq 'HASH') {
5291: if ($settings->{'texengine'}) {
5292: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5293: $deftex = $settings->{'texengine'};
5294: }
5295: }
5296: }
5297: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5298: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5299: '<span class="LC_nobreak">'.$choices{'texengine'}.
5300: '</span></td><td class="LC_right_item">'.
5301: '<select name="texengine">'."\n";
5302: my %texoptions = (
5303: MathJax => 'MathJax',
5304: mimetex => &mt('Convert to Images'),
5305: tth => &mt('TeX to HTML'),
5306: );
5307: foreach my $renderer ('MathJax','mimetex','tth') {
5308: my $selected = '';
5309: if ($renderer eq $deftex) {
5310: $selected = ' selected="selected"';
5311: }
5312: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5313: }
5314: $mathdisp .= '</select></td></tr>'."\n";
5315: $itemcount ++;
1.139 raeburn 5316: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 5317: \%choices,$itemcount);
1.314 raeburn 5318: $datatable = $mathdisp.$datatable;
1.264 raeburn 5319: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5320: $datatable .=
1.306 raeburn 5321: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 5322: '<span class="LC_nobreak">'.$choices{'canclone'}.
5323: '</span></td><td class="LC_left_item">';
5324: my $currcanclone = 'none';
5325: my $onclick;
5326: my @cloneoptions = ('none','domain');
5327: my %clonetitles = (
5328: none => 'No additional course requesters',
5329: domain => "Any course requester in course's domain",
5330: instcode => 'Course requests for official courses ...',
5331: );
5332: my (%codedefaults,@code_order,@posscodes);
5333: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5334: \@code_order) eq 'ok') {
5335: if (@code_order > 0) {
5336: push(@cloneoptions,'instcode');
5337: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5338: }
5339: }
5340: if (ref($settings) eq 'HASH') {
5341: if ($settings->{'canclone'}) {
5342: if (ref($settings->{'canclone'}) eq 'HASH') {
5343: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5344: if (@code_order > 0) {
5345: $currcanclone = 'instcode';
5346: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5347: }
5348: }
5349: } elsif ($settings->{'canclone'} eq 'domain') {
5350: $currcanclone = $settings->{'canclone'};
5351: }
5352: }
1.289 raeburn 5353: }
1.264 raeburn 5354: foreach my $option (@cloneoptions) {
5355: my ($checked,$additional);
5356: if ($currcanclone eq $option) {
5357: $checked = ' checked="checked"';
5358: }
5359: if ($option eq 'instcode') {
5360: if (@code_order) {
5361: my $show = 'none';
5362: if ($checked) {
5363: $show = 'block';
5364: }
1.317 raeburn 5365: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 5366: &mt('Institutional codes for new and cloned course have identical:').
5367: '<br />';
5368: foreach my $item (@code_order) {
5369: my $codechk;
5370: if ($checked) {
5371: if (grep(/^\Q$item\E$/,@posscodes)) {
5372: $codechk = ' checked="checked"';
5373: }
5374: }
5375: $additional .= '<label>'.
5376: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5377: $item.'</label>';
5378: }
5379: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5380: }
5381: }
5382: $datatable .=
5383: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5384: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5385: '</label> '.$additional.'</span><br />';
5386: }
5387: $datatable .= '</td>'.
5388: '</tr>';
5389: $itemcount ++;
1.139 raeburn 5390: } else {
5391: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 5392: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 5393: my $currusecredits = 0;
1.257 raeburn 5394: my $postsubmitclient = 1;
1.271 raeburn 5395: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 5396: if (ref($settings) eq 'HASH') {
5397: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 5398: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5399: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5400: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5401: }
5402: }
1.192 raeburn 5403: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 5404: foreach my $type (@types) {
5405: next if ($type eq 'community');
5406: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5407: if ($defcredits{$type} ne '') {
5408: $currusecredits = 1;
5409: }
5410: }
5411: }
5412: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5413: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5414: $postsubmitclient = 0;
5415: foreach my $type (@types) {
5416: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5417: }
5418: } else {
5419: foreach my $type (@types) {
5420: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5421: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 5422: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 5423: } else {
5424: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5425: }
5426: } else {
5427: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5428: }
5429: }
5430: }
5431: } else {
5432: foreach my $type (@types) {
5433: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 5434: }
5435: }
1.276 raeburn 5436: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5437: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5438: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5439: }
5440: } else {
5441: foreach my $type (@types) {
5442: $currmysql{$type} = $staticdefaults{'mysqltables'};
5443: }
5444: }
1.258 raeburn 5445: } else {
5446: foreach my $type (@types) {
5447: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5448: }
1.139 raeburn 5449: }
5450: if (!$currdefresponder) {
1.198 raeburn 5451: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5452: } elsif ($currdefresponder < 1) {
5453: $currdefresponder = 1;
5454: }
1.198 raeburn 5455: foreach my $type (@types) {
5456: if ($curruploadquota{$type} eq '') {
5457: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5458: }
5459: }
1.139 raeburn 5460: $datatable .=
1.192 raeburn 5461: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5462: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5463: '</span></td>'.
5464: '<td class="LC_right_item"><span class="LC_nobreak">'.
5465: '<input type="text" name="anonsurvey_threshold"'.
5466: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5467: '</td></tr>'."\n";
5468: $itemcount ++;
5469: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5470: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5471: $choices{'uploadquota'}.
5472: '</span></td>'.
1.306 raeburn 5473: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5474: '<table><tr>';
1.198 raeburn 5475: foreach my $type (@types) {
1.306 raeburn 5476: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5477: '<input type="text" name="uploadquota_'.$type.'"'.
5478: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5479: }
5480: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5481: $itemcount ++;
1.236 raeburn 5482: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5483: my $display = 'none';
1.192 raeburn 5484: if ($currusecredits) {
5485: $display = 'block';
5486: }
5487: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5488: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5489: foreach my $type (@types) {
5490: next if ($type eq 'community');
1.306 raeburn 5491: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5492: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5493: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5494: }
5495: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5496: %defaultchecked = ('coursecredits' => 'off');
5497: @toggles = ('coursecredits');
5498: my $current = {
5499: 'coursecredits' => $currusecredits,
5500: };
5501: (my $table,$itemcount) =
5502: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5503: \%choices,$itemcount,$onclick,$additional,'left');
5504: $datatable .= $table;
5505: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5506: my $display = 'none';
5507: if ($postsubmitclient) {
5508: $display = 'block';
5509: }
5510: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5511: &mt('Number of seconds submit is disabled').'<br />'.
5512: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5513: '<table><tr>';
1.257 raeburn 5514: foreach my $type (@types) {
1.306 raeburn 5515: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5516: '<input type="text" name="'.$type.'_timeout" value="'.
5517: $deftimeout{$type}.'" size="5" /></td>';
5518: }
5519: $additional .= '</tr></table></div>'."\n";
5520: %defaultchecked = ('postsubmit' => 'on');
5521: @toggles = ('postsubmit');
1.280 raeburn 5522: $current = {
5523: 'postsubmit' => $postsubmitclient,
5524: };
1.257 raeburn 5525: ($table,$itemcount) =
5526: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5527: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5528: $datatable .= $table;
1.276 raeburn 5529: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5530: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5531: $choices{'mysqltables'}.
5532: '</span></td>'.
1.306 raeburn 5533: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5534: '<table><tr>';
5535: foreach my $type (@types) {
1.306 raeburn 5536: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5537: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5538: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5539: }
5540: $datatable .= '</tr></table></td></tr>'."\n";
5541: $itemcount ++;
5542:
1.139 raeburn 5543: }
1.192 raeburn 5544: $$rowtotal += $itemcount;
1.121 raeburn 5545: return $datatable;
1.118 jms 5546: }
5547:
1.231 raeburn 5548: sub print_selfenrollment {
5549: my ($position,$dom,$settings,$rowtotal) = @_;
5550: my ($css_class,$datatable);
5551: my $itemcount = 1;
1.271 raeburn 5552: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5553: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5554: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5555: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5556: my @rows;
5557: my $key;
5558: if ($position eq 'top') {
5559: $key = 'admin';
5560: if (ref($rowsref) eq 'ARRAY') {
5561: @rows = @{$rowsref};
5562: }
5563: } elsif ($position eq 'middle') {
5564: $key = 'default';
5565: @rows = ('types','registered','approval','limit');
5566: }
5567: foreach my $row (@rows) {
5568: if (defined($titlesref->{$row})) {
5569: $itemcount ++;
5570: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5571: $datatable .= '<tr'.$css_class.'>'.
5572: '<td>'.$titlesref->{$row}.'</td>'.
5573: '<td class="LC_left_item">'.
5574: '<table><tr>';
5575: my (%current,%currentcap);
5576: if (ref($settings) eq 'HASH') {
5577: if (ref($settings->{$key}) eq 'HASH') {
5578: foreach my $type (@types) {
5579: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5580: $current{$type} = $settings->{$key}->{$type}->{$row};
5581: }
5582: if (($row eq 'limit') && ($key eq 'default')) {
5583: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5584: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5585: }
5586: }
5587: }
5588: }
5589: }
5590: my %roles = (
5591: '0' => &Apache::lonnet::plaintext('dc'),
5592: );
5593:
5594: foreach my $type (@types) {
5595: unless (($row eq 'registered') && ($key eq 'default')) {
5596: $datatable .= '<th>'.&mt($type).'</th>';
5597: }
5598: }
5599: unless (($row eq 'registered') && ($key eq 'default')) {
5600: $datatable .= '</tr><tr>';
5601: }
5602: foreach my $type (@types) {
5603: if ($type eq 'community') {
5604: $roles{'1'} = &mt('Community personnel');
5605: } else {
5606: $roles{'1'} = &mt('Course personnel');
5607: }
5608: $datatable .= '<td style="vertical-align: top">';
5609: if ($position eq 'top') {
5610: my %checked;
5611: if ($current{$type} eq '0') {
5612: $checked{'0'} = ' checked="checked"';
5613: } else {
5614: $checked{'1'} = ' checked="checked"';
5615: }
5616: foreach my $role ('1','0') {
5617: $datatable .= '<span class="LC_nobreak"><label>'.
5618: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5619: 'value="'.$role.'"'.$checked{$role}.' />'.
5620: $roles{$role}.'</label></span> ';
5621: }
5622: } else {
5623: if ($row eq 'types') {
5624: my %checked;
5625: if ($current{$type} =~ /^(all|dom)$/) {
5626: $checked{$1} = ' checked="checked"';
5627: } else {
5628: $checked{''} = ' checked="checked"';
5629: }
5630: foreach my $val ('','dom','all') {
5631: $datatable .= '<span class="LC_nobreak"><label>'.
5632: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5633: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5634: }
5635: } elsif ($row eq 'registered') {
5636: my %checked;
5637: if ($current{$type} eq '1') {
5638: $checked{'1'} = ' checked="checked"';
5639: } else {
5640: $checked{'0'} = ' checked="checked"';
5641: }
5642: foreach my $val ('0','1') {
5643: $datatable .= '<span class="LC_nobreak"><label>'.
5644: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5645: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5646: }
5647: } elsif ($row eq 'approval') {
5648: my %checked;
5649: if ($current{$type} =~ /^([12])$/) {
5650: $checked{$1} = ' checked="checked"';
5651: } else {
5652: $checked{'0'} = ' checked="checked"';
5653: }
5654: for my $val (0..2) {
5655: $datatable .= '<span class="LC_nobreak"><label>'.
5656: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5657: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5658: }
5659: } elsif ($row eq 'limit') {
5660: my %checked;
5661: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5662: $checked{$1} = ' checked="checked"';
5663: } else {
5664: $checked{'none'} = ' checked="checked"';
5665: }
5666: my $cap;
5667: if ($currentcap{$type} =~ /^\d+$/) {
5668: $cap = $currentcap{$type};
5669: }
5670: foreach my $val ('none','allstudents','selfenrolled') {
5671: $datatable .= '<span class="LC_nobreak"><label>'.
5672: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5673: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5674: }
5675: $datatable .= '<br />'.
5676: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5677: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5678: '</span>';
5679: }
5680: }
5681: $datatable .= '</td>';
5682: }
5683: $datatable .= '</tr>';
5684: }
5685: $datatable .= '</table></td></tr>';
5686: }
5687: } elsif ($position eq 'bottom') {
1.235 raeburn 5688: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5689: }
5690: $$rowtotal += $itemcount;
5691: return $datatable;
5692: }
5693:
5694: sub print_validation_rows {
5695: my ($caller,$dom,$settings,$rowtotal) = @_;
5696: my ($itemsref,$namesref,$fieldsref);
5697: if ($caller eq 'selfenroll') {
5698: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5699: } elsif ($caller eq 'requestcourses') {
5700: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5701: }
5702: my %currvalidation;
5703: if (ref($settings) eq 'HASH') {
5704: if (ref($settings->{'validation'}) eq 'HASH') {
5705: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5706: }
1.235 raeburn 5707: }
5708: my $datatable;
5709: my $itemcount = 0;
5710: foreach my $item (@{$itemsref}) {
5711: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5712: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5713: $namesref->{$item}.
5714: '</span></td>'.
5715: '<td class="LC_left_item">';
5716: if (($item eq 'url') || ($item eq 'button')) {
5717: $datatable .= '<span class="LC_nobreak">'.
5718: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5719: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5720: } elsif ($item eq 'fields') {
5721: my @currfields;
5722: if (ref($currvalidation{$item}) eq 'ARRAY') {
5723: @currfields = @{$currvalidation{$item}};
5724: }
5725: foreach my $field (@{$fieldsref}) {
5726: my $check = '';
5727: if (grep(/^\Q$field\E$/,@currfields)) {
5728: $check = ' checked="checked"';
5729: }
5730: $datatable .= '<span class="LC_nobreak"><label>'.
5731: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5732: ' value="'.$field.'"'.$check.' />'.$field.
5733: '</label></span> ';
5734: }
5735: } elsif ($item eq 'markup') {
1.334 raeburn 5736: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 5737: $currvalidation{$item}.
1.231 raeburn 5738: '</textarea>';
1.235 raeburn 5739: }
5740: $datatable .= '</td></tr>'."\n";
5741: if (ref($rowtotal)) {
1.231 raeburn 5742: $itemcount ++;
5743: }
5744: }
1.235 raeburn 5745: if ($caller eq 'requestcourses') {
5746: my %currhash;
1.248 raeburn 5747: if (ref($settings) eq 'HASH') {
5748: if (ref($settings->{'validation'}) eq 'HASH') {
5749: if ($settings->{'validation'}{'dc'} ne '') {
5750: $currhash{$settings->{'validation'}{'dc'}} = 1;
5751: }
1.235 raeburn 5752: }
5753: }
5754: my $numinrow = 2;
5755: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5756: 'validationdc',%currhash);
1.247 raeburn 5757: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 5758: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 5759: if ($numdc > 1) {
1.247 raeburn 5760: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5761: } else {
1.247 raeburn 5762: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5763: }
1.247 raeburn 5764: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5765: $itemcount ++;
5766: }
5767: if (ref($rowtotal)) {
5768: $$rowtotal += $itemcount;
5769: }
1.231 raeburn 5770: return $datatable;
5771: }
5772:
1.137 raeburn 5773: sub print_usersessions {
5774: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 5775: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 5776: my (%by_ip,%by_location,@intdoms,@instdoms);
5777: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 5778:
5779: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5780: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5781: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5782: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5783: if ($position eq 'top') {
1.152 raeburn 5784: if (keys(%serverhomes) > 1) {
1.145 raeburn 5785: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 5786: my $curroffloadnow;
5787: if (ref($settings) eq 'HASH') {
5788: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5789: $curroffloadnow = $settings->{'offloadnow'};
5790: }
5791: }
5792: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 5793: } else {
1.140 raeburn 5794: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 5795: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
5796: '</td></tr>';
1.140 raeburn 5797: }
1.137 raeburn 5798: } else {
1.279 raeburn 5799: my %titles = &usersession_titles();
5800: my ($prefix,@types);
5801: if ($position eq 'bottom') {
5802: $prefix = 'remote';
5803: @types = ('version','excludedomain','includedomain');
1.145 raeburn 5804: } else {
1.279 raeburn 5805: $prefix = 'hosted';
5806: @types = ('excludedomain','includedomain');
5807: }
5808: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5809: }
5810: $$rowtotal += $itemcount;
5811: return $datatable;
5812: }
5813:
5814: sub rules_by_location {
5815: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
5816: my ($datatable,$itemcount,$css_class);
5817: if (keys(%{$by_location}) == 0) {
5818: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5819: $datatable = '<tr'.$css_class.'><td colspan="2">'.
5820: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
5821: '</td></tr>';
5822: $itemcount = 1;
5823: } else {
5824: $itemcount = 0;
5825: my $numinrow = 5;
5826: my (%current,%checkedon,%checkedoff);
5827: my @locations = sort(keys(%{$by_location}));
5828: foreach my $type (@{$types}) {
5829: $checkedon{$type} = '';
5830: $checkedoff{$type} = ' checked="checked"';
5831: }
5832: if (ref($settings) eq 'HASH') {
5833: if (ref($settings->{$prefix}) eq 'HASH') {
5834: foreach my $key (keys(%{$settings->{$prefix}})) {
5835: $current{$key} = $settings->{$prefix}{$key};
5836: if ($key eq 'version') {
5837: if ($current{$key} ne '') {
1.145 raeburn 5838: $checkedon{$key} = ' checked="checked"';
5839: $checkedoff{$key} = '';
5840: }
1.279 raeburn 5841: } elsif (ref($current{$key}) eq 'ARRAY') {
5842: $checkedon{$key} = ' checked="checked"';
5843: $checkedoff{$key} = '';
1.137 raeburn 5844: }
5845: }
5846: }
1.279 raeburn 5847: }
5848: foreach my $type (@{$types}) {
5849: next if ($type ne 'version' && !@locations);
5850: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5851: $datatable .= '<tr'.$css_class.'>
5852: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
5853: <span class="LC_nobreak">
5854: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5855: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5856: if ($type eq 'version') {
5857: my @lcversions = &Apache::lonnet::all_loncaparevs();
5858: my $selector = '<select name="'.$prefix.'_version">';
5859: foreach my $version (@lcversions) {
5860: my $selected = '';
5861: if ($current{'version'} eq $version) {
5862: $selected = ' selected="selected"';
1.145 raeburn 5863: }
1.279 raeburn 5864: $selector .= ' <option value="'.$version.'"'.
5865: $selected.'>'.$version.'</option>';
5866: }
5867: $selector .= '</select> ';
5868: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5869: } else {
5870: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5871: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5872: ' />'.(' 'x2).
5873: '<input type="button" value="'.&mt('uncheck all').'" '.
5874: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5875: "\n".
5876: '</div><div><table>';
5877: my $rem;
5878: for (my $i=0; $i<@locations; $i++) {
5879: my ($showloc,$value,$checkedtype);
5880: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
5881: my $ip = $by_location->{$locations[$i]}->[0];
5882: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5883: $value = join(':',@{$by_ip->{$ip}});
5884: $showloc = join(', ',@{$by_ip->{$ip}});
5885: if (ref($current{$type}) eq 'ARRAY') {
5886: foreach my $loc (@{$by_ip->{$ip}}) {
5887: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5888: $checkedtype = ' checked="checked"';
5889: last;
1.145 raeburn 5890: }
1.138 raeburn 5891: }
5892: }
5893: }
1.137 raeburn 5894: }
1.279 raeburn 5895: $rem = $i%($numinrow);
5896: if ($rem == 0) {
5897: if ($i > 0) {
5898: $datatable .= '</tr>';
5899: }
5900: $datatable .= '<tr>';
5901: }
5902: $datatable .= '<td class="LC_left_item">'.
5903: '<span class="LC_nobreak"><label>'.
5904: '<input type="checkbox" name="'.$prefix.'_'.$type.
5905: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5906: '</label></span></td>';
5907: }
5908: $rem = @locations%($numinrow);
5909: my $colsleft = $numinrow - $rem;
5910: if ($colsleft > 1 ) {
5911: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5912: ' </td>';
5913: } elsif ($colsleft == 1) {
5914: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5915: }
1.279 raeburn 5916: $datatable .= '</tr></table>';
1.137 raeburn 5917: }
1.279 raeburn 5918: $datatable .= '</td></tr>';
5919: $itemcount ++;
1.137 raeburn 5920: }
5921: }
1.279 raeburn 5922: return ($datatable,$itemcount);
1.137 raeburn 5923: }
5924:
1.275 raeburn 5925: sub print_ssl {
5926: my ($position,$dom,$settings,$rowtotal) = @_;
5927: my ($css_class,$datatable);
5928: my $itemcount = 1;
5929: if ($position eq 'top') {
1.281 raeburn 5930: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5931: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5932: my $same_institution;
5933: if ($intdom ne '') {
5934: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
5935: if (ref($internet_names) eq 'ARRAY') {
5936: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5937: $same_institution = 1;
5938: }
5939: }
5940: }
1.275 raeburn 5941: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 5942: $datatable = '<tr'.$css_class.'><td colspan="2">';
5943: if ($same_institution) {
5944: my %domservers = &Apache::lonnet::get_servers($dom);
5945: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
5946: } else {
5947: $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.");
5948: }
5949: $datatable .= '</td></tr>';
1.275 raeburn 5950: $itemcount ++;
5951: } else {
5952: my %titles = &ssl_titles();
5953: my (%by_ip,%by_location,@intdoms,@instdoms);
5954: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5955: my @alldoms = &Apache::lonnet::all_domains();
5956: my %serverhomes = %Apache::lonnet::serverhomeIDs;
5957: my @domservers = &Apache::lonnet::get_servers($dom);
5958: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5959: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 5960: if (($position eq 'connto') || ($position eq 'connfrom')) {
5961: my $legacy;
5962: unless (ref($settings) eq 'HASH') {
5963: my $name;
5964: if ($position eq 'connto') {
5965: $name = 'loncAllowInsecure';
5966: } else {
5967: $name = 'londAllowInsecure';
5968: }
5969: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
5970: my @ids=&Apache::lonnet::current_machine_ids();
5971: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
5972: my %what = (
5973: $name => 1,
5974: );
5975: my ($result,$returnhash) =
5976: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
5977: if ($result eq 'ok') {
5978: if (ref($returnhash) eq 'HASH') {
5979: $legacy = $returnhash->{$name};
5980: }
5981: }
5982: } else {
5983: $legacy = $Apache::lonnet::perlvar{$name};
5984: }
5985: }
1.275 raeburn 5986: foreach my $type ('dom','intdom','other') {
5987: my %checked;
5988: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5989: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
5990: '<td class="LC_right_item">';
5991: my $skip;
5992: if ($type eq 'dom') {
5993: unless (keys(%servers) > 1) {
5994: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
5995: $skip = 1;
5996: }
5997: }
5998: if ($type eq 'intdom') {
5999: unless (@instdoms > 1) {
6000: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
6001: $skip = 1;
6002: }
6003: } elsif ($type eq 'other') {
6004: if (keys(%by_location) == 0) {
6005: $datatable .= &mt('Nothing to set here, as there are no other institutions');
6006: $skip = 1;
6007: }
6008: }
6009: unless ($skip) {
6010: $checked{'yes'} = ' checked="checked"';
6011: if (ref($settings) eq 'HASH') {
1.293 raeburn 6012: if (ref($settings->{$position}) eq 'HASH') {
6013: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 6014: $checked{$1} = $checked{'yes'};
6015: delete($checked{'yes'});
6016: }
6017: }
1.293 raeburn 6018: } else {
6019: if ($legacy == 0) {
6020: $checked{'req'} = $checked{'yes'};
6021: delete($checked{'yes'});
6022: }
1.275 raeburn 6023: }
6024: foreach my $option ('no','yes','req') {
6025: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 6026: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 6027: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
6028: '</label></span>'.(' 'x2);
6029: }
6030: }
6031: $datatable .= '</td></tr>';
6032: $itemcount ++;
6033: }
6034: } else {
6035: my $prefix = 'replication';
6036: my @types = ('certreq','nocertreq');
1.279 raeburn 6037: if (keys(%by_location) == 0) {
6038: $datatable .= '<tr'.$css_class.'><td>'.
6039: &mt('Nothing to set here, as there are no other institutions').
6040: '</td></tr>';
6041: $itemcount ++;
1.275 raeburn 6042: } else {
1.279 raeburn 6043: ($datatable,$itemcount) =
6044: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 6045: }
6046: }
6047: }
6048: $$rowtotal += $itemcount;
6049: return $datatable;
6050: }
6051:
6052: sub ssl_titles {
6053: return &Apache::lonlocal::texthash (
6054: dom => 'LON-CAPA servers/VMs from same domain',
6055: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
6056: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 6057: connto => 'Connections to other servers',
6058: connfrom => 'Connections from other servers',
1.275 raeburn 6059: replication => 'Replicating content to other institutions',
6060: certreq => 'Client certificate required, but specific domains exempt',
6061: nocertreq => 'No client certificate required, except for specific domains',
6062: no => 'SSL not used',
6063: yes => 'SSL Optional (used if available)',
6064: req => 'SSL Required',
6065: );
1.279 raeburn 6066: }
6067:
6068: sub print_trust {
6069: my ($prefix,$dom,$settings,$rowtotal) = @_;
6070: my ($css_class,$datatable,%checked,%choices);
6071: my (%by_ip,%by_location,@intdoms,@instdoms);
6072: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6073: my $itemcount = 1;
6074: my %titles = &trust_titles();
6075: my @types = ('exc','inc');
6076: if ($prefix eq 'top') {
6077: $prefix = 'content';
6078: } elsif ($prefix eq 'bottom') {
6079: $prefix = 'msg';
6080: }
6081: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
6082: $$rowtotal += $itemcount;
6083: return $datatable;
6084: }
6085:
6086: sub trust_titles {
6087: return &Apache::lonlocal::texthash(
6088: content => "Access to this domain's content by others",
6089: shared => "Access to other domain's content by this domain",
6090: enroll => "Enrollment in this domain's courses by others",
6091: othcoau => "Co-author roles in this domain for others",
6092: coaurem => "Co-author roles for this domain's users elsewhere",
6093: domroles => "Domain roles in this domain assignable to others",
6094: catalog => "Course Catalog for this domain displayed elsewhere",
6095: reqcrs => "Requests for creation of courses in this domain by others",
6096: msg => "Users in other domains can send messages to this domain",
6097: exc => "Allow all, but exclude specific domains",
6098: inc => "Deny all, but include specific domains",
6099: );
1.275 raeburn 6100: }
6101:
1.138 raeburn 6102: sub build_location_hashes {
1.275 raeburn 6103: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 6104: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 6105: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 6106: my %iphost = &Apache::lonnet::get_iphost();
6107: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
6108: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
6109: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
6110: foreach my $id (@{$iphost{$primary_ip}}) {
6111: my $intdom = &Apache::lonnet::internet_dom($id);
6112: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
6113: push(@{$intdoms},$intdom);
6114: }
6115: }
6116: }
6117: foreach my $ip (keys(%iphost)) {
6118: if (ref($iphost{$ip}) eq 'ARRAY') {
6119: foreach my $id (@{$iphost{$ip}}) {
6120: my $location = &Apache::lonnet::internet_dom($id);
6121: if ($location) {
1.275 raeburn 6122: if (grep(/^\Q$location\E$/,@{$intdoms})) {
6123: my $dom = &Apache::lonnet::host_domain($id);
6124: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
6125: push(@{$instdoms},$dom);
6126: }
6127: next;
6128: }
1.138 raeburn 6129: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6130: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
6131: push(@{$by_ip->{$ip}},$location);
6132: }
6133: } else {
6134: $by_ip->{$ip} = [$location];
6135: }
6136: }
6137: }
6138: }
6139: }
6140: foreach my $ip (sort(keys(%{$by_ip}))) {
6141: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6142: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
6143: my $first = $by_ip->{$ip}->[0];
6144: if (ref($by_location->{$first}) eq 'ARRAY') {
6145: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
6146: push(@{$by_location->{$first}},$ip);
6147: }
6148: } else {
6149: $by_location->{$first} = [$ip];
6150: }
6151: }
6152: }
6153: return;
6154: }
6155:
1.145 raeburn 6156: sub current_offloads_to {
6157: my ($dom,$settings,$servers) = @_;
6158: my (%spareid,%otherdomconfigs);
1.152 raeburn 6159: if (ref($servers) eq 'HASH') {
1.145 raeburn 6160: foreach my $lonhost (sort(keys(%{$servers}))) {
6161: my $gotspares;
1.152 raeburn 6162: if (ref($settings) eq 'HASH') {
6163: if (ref($settings->{'spares'}) eq 'HASH') {
6164: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
6165: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
6166: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
6167: $gotspares = 1;
6168: }
1.145 raeburn 6169: }
6170: }
6171: unless ($gotspares) {
6172: my $gotspares;
6173: my $serverhomeID =
6174: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
6175: my $serverhomedom =
6176: &Apache::lonnet::host_domain($serverhomeID);
6177: if ($serverhomedom ne $dom) {
6178: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
6179: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6180: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6181: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6182: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6183: $gotspares = 1;
6184: }
6185: }
6186: } else {
6187: $otherdomconfigs{$serverhomedom} =
6188: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
6189: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
6190: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6191: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6192: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
6193: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6194: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6195: $gotspares = 1;
6196: }
6197: }
6198: }
6199: }
6200: }
6201: }
6202: }
6203: unless ($gotspares) {
6204: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6205: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6206: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6207: } else {
6208: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6209: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6210: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6211: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6212: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6213: } else {
1.150 raeburn 6214: my %what = (
6215: spareid => 1,
6216: );
6217: my ($result,$returnhash) =
6218: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6219: if ($result eq 'ok') {
6220: if (ref($returnhash) eq 'HASH') {
6221: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6222: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6223: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6224: }
6225: }
1.145 raeburn 6226: }
6227: }
6228: }
6229: }
6230: }
6231: }
6232: return %spareid;
6233: }
6234:
6235: sub spares_row {
1.261 raeburn 6236: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 6237: my $css_class;
6238: my $numinrow = 4;
6239: my $itemcount = 1;
6240: my $datatable;
1.152 raeburn 6241: my %typetitles = &sparestype_titles();
6242: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6243: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6244: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6245: my ($othercontrol,$serverdom);
6246: if ($serverhome ne $server) {
6247: $serverdom = &Apache::lonnet::host_domain($serverhome);
6248: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6249: } else {
6250: $serverdom = &Apache::lonnet::host_domain($server);
6251: if ($serverdom ne $dom) {
6252: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6253: }
6254: }
6255: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 6256: my $checkednow;
6257: if (ref($curroffloadnow) eq 'HASH') {
6258: if ($curroffloadnow->{$server}) {
6259: $checkednow = ' checked="checked"';
6260: }
6261: }
1.145 raeburn 6262: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6263: $datatable .= '<tr'.$css_class.'>
6264: <td rowspan="2">
1.183 bisitz 6265: <span class="LC_nobreak">'.
6266: &mt('[_1] when busy, offloads to:'
1.261 raeburn 6267: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 6268: '<span class="LC_nobreak">'."\n".
1.261 raeburn 6269: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
6270: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 6271: "\n";
1.145 raeburn 6272: my (%current,%canselect);
1.152 raeburn 6273: my @choices =
6274: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6275: foreach my $type ('primary','default') {
6276: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6277: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6278: my @spares = @{$spareid->{$server}{$type}};
6279: if (@spares > 0) {
1.152 raeburn 6280: if ($othercontrol) {
6281: $current{$type} = join(', ',@spares);
6282: } else {
6283: $current{$type} .= '<table>';
6284: my $numspares = scalar(@spares);
6285: for (my $i=0; $i<@spares; $i++) {
6286: my $rem = $i%($numinrow);
6287: if ($rem == 0) {
6288: if ($i > 0) {
6289: $current{$type} .= '</tr>';
6290: }
6291: $current{$type} .= '<tr>';
1.145 raeburn 6292: }
1.152 raeburn 6293: $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'".');" /> '.
6294: $spareid->{$server}{$type}[$i].
6295: '</label></td>'."\n";
6296: }
6297: my $rem = @spares%($numinrow);
6298: my $colsleft = $numinrow - $rem;
6299: if ($colsleft > 1 ) {
6300: $current{$type} .= '<td colspan="'.$colsleft.
6301: '" class="LC_left_item">'.
6302: ' </td>';
6303: } elsif ($colsleft == 1) {
6304: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6305: }
1.152 raeburn 6306: $current{$type} .= '</tr></table>';
1.150 raeburn 6307: }
1.145 raeburn 6308: }
6309: }
6310: if ($current{$type} eq '') {
6311: $current{$type} = &mt('None specified');
6312: }
1.152 raeburn 6313: if ($othercontrol) {
6314: if ($type eq 'primary') {
6315: $canselect{$type} = $othercontrol;
6316: }
6317: } else {
6318: $canselect{$type} =
6319: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6320: '<select name="newspare_'.$type.'_'.$server.'" '.
6321: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6322: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6323: if (@choices > 0) {
6324: foreach my $lonhost (@choices) {
6325: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6326: }
6327: }
6328: $canselect{$type} .= '</select>'."\n";
6329: }
6330: } else {
6331: $current{$type} = &mt('Could not be determined');
6332: if ($type eq 'primary') {
6333: $canselect{$type} = $othercontrol;
6334: }
1.145 raeburn 6335: }
1.152 raeburn 6336: if ($type eq 'default') {
6337: $datatable .= '<tr'.$css_class.'>';
6338: }
6339: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6340: '<td>'.$current{$type}.'</td>'."\n".
6341: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6342: }
6343: $itemcount ++;
6344: }
6345: }
6346: $$rowtotal += $itemcount;
6347: return $datatable;
6348: }
6349:
1.152 raeburn 6350: sub possible_newspares {
6351: my ($server,$currspares,$serverhomes,$altids) = @_;
6352: my $serverhostname = &Apache::lonnet::hostname($server);
6353: my %excluded;
6354: if ($serverhostname ne '') {
6355: %excluded = (
6356: $serverhostname => 1,
6357: );
6358: }
6359: if (ref($currspares) eq 'HASH') {
6360: foreach my $type (keys(%{$currspares})) {
6361: if (ref($currspares->{$type}) eq 'ARRAY') {
6362: if (@{$currspares->{$type}} > 0) {
6363: foreach my $curr (@{$currspares->{$type}}) {
6364: my $hostname = &Apache::lonnet::hostname($curr);
6365: $excluded{$hostname} = 1;
6366: }
6367: }
6368: }
6369: }
6370: }
6371: my @choices;
6372: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6373: if (keys(%{$serverhomes}) > 1) {
6374: foreach my $name (sort(keys(%{$serverhomes}))) {
6375: unless ($excluded{$name}) {
6376: if (exists($altids->{$serverhomes->{$name}})) {
6377: push(@choices,$altids->{$serverhomes->{$name}});
6378: } else {
6379: push(@choices,$serverhomes->{$name});
1.145 raeburn 6380: }
6381: }
6382: }
6383: }
6384: }
1.152 raeburn 6385: return sort(@choices);
1.145 raeburn 6386: }
6387:
1.150 raeburn 6388: sub print_loadbalancing {
6389: my ($dom,$settings,$rowtotal) = @_;
6390: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6391: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6392: my $numinrow = 1;
6393: my $datatable;
6394: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 6395: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 6396: if (ref($settings) eq 'HASH') {
6397: %existing = %{$settings};
6398: }
6399: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6400: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 6401: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 6402: } else {
6403: return;
6404: }
6405: my ($othertitle,$usertypes,$types) =
6406: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 6407: my $rownum = 8;
1.150 raeburn 6408: if (ref($types) eq 'ARRAY') {
6409: $rownum += scalar(@{$types});
6410: }
1.171 raeburn 6411: my @css_class = ('LC_odd_row','LC_even_row');
6412: my $balnum = 0;
6413: my $islast;
6414: my (@toshow,$disabledtext);
6415: if (keys(%currbalancer) > 0) {
6416: @toshow = sort(keys(%currbalancer));
6417: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6418: push(@toshow,'');
6419: }
6420: } else {
6421: @toshow = ('');
6422: $disabledtext = &mt('No existing load balancer');
6423: }
6424: foreach my $lonhost (@toshow) {
6425: if ($balnum == scalar(@toshow)-1) {
6426: $islast = 1;
6427: } else {
6428: $islast = 0;
6429: }
6430: my $cssidx = $balnum%2;
6431: my $targets_div_style = 'display: none';
6432: my $disabled_div_style = 'display: block';
6433: my $homedom_div_style = 'display: none';
6434: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 6435: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6436: '<p>';
6437: if ($lonhost eq '') {
1.210 raeburn 6438: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 6439: if (keys(%currbalancer) > 0) {
6440: $datatable .= &mt('Add balancer:');
6441: } else {
6442: $datatable .= &mt('Enable balancer:');
6443: }
6444: $datatable .= ' '.
6445: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6446: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6447: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6448: '<option value="" selected="selected">'.&mt('None').
6449: '</option>'."\n";
6450: foreach my $server (sort(keys(%servers))) {
6451: next if ($currbalancer{$server});
6452: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6453: }
1.210 raeburn 6454: $datatable .=
1.171 raeburn 6455: '</select>'."\n".
6456: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6457: } else {
6458: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6459: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6460: &mt('Stop balancing').'</label>'.
6461: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6462: $targets_div_style = 'display: block';
6463: $disabled_div_style = 'display: none';
6464: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6465: $homedom_div_style = 'display: block';
6466: }
6467: }
1.306 raeburn 6468: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6469: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6470: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6471: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6472: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6473: my @sparestypes = ('primary','default');
6474: my %typetitles = &sparestype_titles();
1.284 raeburn 6475: my %hostherechecked = (
6476: no => ' checked="checked"',
6477: );
1.342 raeburn 6478: my %balcookiechecked = (
6479: no => ' checked="checked"',
6480: );
1.171 raeburn 6481: foreach my $sparetype (@sparestypes) {
6482: my $targettable;
6483: for (my $i=0; $i<$numspares; $i++) {
6484: my $checked;
6485: if (ref($currtargets{$lonhost}) eq 'HASH') {
6486: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6487: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6488: $checked = ' checked="checked"';
6489: }
6490: }
6491: }
6492: my ($chkboxval,$disabled);
6493: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6494: $chkboxval = $spares[$i];
6495: }
6496: if (exists($currbalancer{$spares[$i]})) {
6497: $disabled = ' disabled="disabled"';
6498: }
1.210 raeburn 6499: $targettable .=
1.253 raeburn 6500: '<td><span class="LC_nobreak"><label>'.
6501: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 6502: $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 6503: '</span></label></span></td>';
1.171 raeburn 6504: my $rem = $i%($numinrow);
6505: if ($rem == 0) {
6506: if (($i > 0) && ($i < $numspares-1)) {
6507: $targettable .= '</tr>';
6508: }
6509: if ($i < $numspares-1) {
6510: $targettable .= '<tr>';
1.150 raeburn 6511: }
6512: }
6513: }
1.171 raeburn 6514: if ($targettable ne '') {
6515: my $rem = $numspares%($numinrow);
6516: my $colsleft = $numinrow - $rem;
6517: if ($colsleft > 1 ) {
6518: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6519: ' </td>';
6520: } elsif ($colsleft == 1) {
6521: $targettable .= '<td class="LC_left_item"> </td>';
6522: }
6523: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6524: '<table><tr>'.$targettable.'</tr></table><br />';
6525: }
1.284 raeburn 6526: $hostherechecked{$sparetype} = '';
6527: if (ref($currtargets{$lonhost}) eq 'HASH') {
6528: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6529: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6530: $hostherechecked{$sparetype} = ' checked="checked"';
6531: $hostherechecked{'no'} = '';
6532: }
6533: }
6534: }
6535: }
1.342 raeburn 6536: if ($currcookies{$lonhost}) {
6537: %balcookiechecked = (
6538: yes => ' checked="checked"',
6539: );
6540: }
1.284 raeburn 6541: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6542: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6543: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6544: foreach my $sparetype (@sparestypes) {
6545: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6546: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6547: '</i></label><br />';
1.171 raeburn 6548: }
1.342 raeburn 6549: $datatable .= &mt('Use balancer cookie').'<br />'.
6550: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
6551: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
6552: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
6553: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
6554: '</div></td></tr>'.
1.171 raeburn 6555: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6556: $othertitle,$usertypes,$types,\%servers,
6557: \%currbalancer,$lonhost,
6558: $targets_div_style,$homedom_div_style,
6559: $css_class[$cssidx],$balnum,$islast);
6560: $$rowtotal += $rownum;
6561: $balnum ++;
6562: }
6563: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6564: return $datatable;
6565: }
6566:
6567: sub get_loadbalancers_config {
1.342 raeburn 6568: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 6569: return unless ((ref($servers) eq 'HASH') &&
6570: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 6571: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
6572: (ref($currcookies) eq 'HASH'));
1.171 raeburn 6573: if (keys(%{$existing}) > 0) {
6574: my $oldlonhost;
6575: foreach my $key (sort(keys(%{$existing}))) {
6576: if ($key eq 'lonhost') {
6577: $oldlonhost = $existing->{'lonhost'};
6578: $currbalancer->{$oldlonhost} = 1;
6579: } elsif ($key eq 'targets') {
6580: if ($oldlonhost) {
6581: $currtargets->{$oldlonhost} = $existing->{'targets'};
6582: }
6583: } elsif ($key eq 'rules') {
6584: if ($oldlonhost) {
6585: $currrules->{$oldlonhost} = $existing->{'rules'};
6586: }
6587: } elsif (ref($existing->{$key}) eq 'HASH') {
6588: $currbalancer->{$key} = 1;
6589: $currtargets->{$key} = $existing->{$key}{'targets'};
6590: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 6591: if ($existing->{$key}{'cookie'}) {
6592: $currcookies->{$key} = 1;
6593: }
1.150 raeburn 6594: }
6595: }
1.171 raeburn 6596: } else {
6597: my ($balancerref,$targetsref) =
6598: &Apache::lonnet::get_lonbalancer_config($servers);
6599: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6600: foreach my $server (sort(keys(%{$balancerref}))) {
6601: $currbalancer->{$server} = 1;
6602: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6603: }
6604: }
6605: }
1.171 raeburn 6606: return;
1.150 raeburn 6607: }
6608:
6609: sub loadbalancing_rules {
6610: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 6611: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6612: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6613: my $output;
1.171 raeburn 6614: my $num = 0;
1.210 raeburn 6615: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6616: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6617: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6618: foreach my $type (@{$alltypes}) {
1.171 raeburn 6619: $num ++;
1.150 raeburn 6620: my $current;
6621: if (ref($currrules) eq 'HASH') {
6622: $current = $currrules->{$type};
6623: }
1.253 raeburn 6624: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 6625: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6626: $current = '';
6627: }
6628: }
6629: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 6630: $servers,$currbalancer,$lonhost,$dom,
6631: $targets_div_style,$homedom_div_style,
6632: $css_class,$balnum,$num,$islast);
1.150 raeburn 6633: }
6634: }
6635: return $output;
6636: }
6637:
6638: sub loadbalancing_titles {
6639: my ($dom,$intdom,$usertypes,$types) = @_;
6640: my %othertypes = (
6641: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6642: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6643: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6644: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 6645: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6646: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6647: );
1.209 raeburn 6648: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 6649: my @available;
1.150 raeburn 6650: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6651: @available = @{$types};
1.150 raeburn 6652: }
1.302 raeburn 6653: unless (grep(/^default$/,@available)) {
6654: push(@available,'default');
6655: }
6656: unshift(@alltypes,@available);
1.150 raeburn 6657: my %titles;
6658: foreach my $type (@alltypes) {
6659: if ($type =~ /^_LC_/) {
6660: $titles{$type} = $othertypes{$type};
6661: } elsif ($type eq 'default') {
6662: $titles{$type} = &mt('All users from [_1]',$dom);
6663: if (ref($types) eq 'ARRAY') {
6664: if (@{$types} > 0) {
6665: $titles{$type} = &mt('Other users from [_1]',$dom);
6666: }
6667: }
6668: } elsif (ref($usertypes) eq 'HASH') {
6669: $titles{$type} = $usertypes->{$type};
6670: }
6671: }
6672: return (\@alltypes,\%othertypes,\%titles);
6673: }
6674:
6675: sub loadbalance_rule_row {
1.171 raeburn 6676: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6677: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 6678: my @rulenames;
1.150 raeburn 6679: my %ruletitles = &offloadtype_text();
1.209 raeburn 6680: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 6681: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6682: } else {
1.209 raeburn 6683: @rulenames = ('default','homeserver');
6684: if ($type eq '_LC_external') {
6685: push(@rulenames,'externalbalancer');
6686: } else {
6687: push(@rulenames,'specific');
6688: }
6689: push(@rulenames,'none');
1.150 raeburn 6690: }
6691: my $style = $targets_div_style;
1.253 raeburn 6692: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6693: $style = $homedom_div_style;
6694: }
1.171 raeburn 6695: my $space;
6696: if ($islast && $num == 1) {
1.317 raeburn 6697: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 6698: }
1.210 raeburn 6699: my $output =
1.306 raeburn 6700: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 6701: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6702: '<td valaign="top">'.$space.
6703: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6704: for (my $i=0; $i<@rulenames; $i++) {
6705: my $rule = $rulenames[$i];
6706: my ($checked,$extra);
6707: if ($rulenames[$i] eq 'default') {
6708: $rule = '';
6709: }
6710: if ($rulenames[$i] eq 'specific') {
6711: if (ref($servers) eq 'HASH') {
6712: my $default;
6713: if (($current ne '') && (exists($servers->{$current}))) {
6714: $checked = ' checked="checked"';
6715: }
6716: unless ($checked) {
6717: $default = ' selected="selected"';
6718: }
1.210 raeburn 6719: $extra =
1.171 raeburn 6720: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6721: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6722: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6723: '<option value=""'.$default.'></option>'."\n";
6724: foreach my $server (sort(keys(%{$servers}))) {
6725: if (ref($currbalancer) eq 'HASH') {
6726: next if (exists($currbalancer->{$server}));
6727: }
1.150 raeburn 6728: my $selected;
1.171 raeburn 6729: if ($server eq $current) {
1.150 raeburn 6730: $selected = ' selected="selected"';
6731: }
1.171 raeburn 6732: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6733: }
6734: $extra .= '</select>';
6735: }
6736: } elsif ($rule eq $current) {
6737: $checked = ' checked="checked"';
6738: }
6739: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 6740: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6741: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6742: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 6743: ')"'.$checked.' /> ';
6744: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
6745: $output .= $ruletitles{'particular'};
6746: } else {
6747: $output .= $ruletitles{$rulenames[$i]};
6748: }
6749: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6750: }
6751: $output .= '</div></td></tr>'."\n";
6752: return $output;
6753: }
6754:
6755: sub offloadtype_text {
6756: my %ruletitles = &Apache::lonlocal::texthash (
6757: 'default' => 'Offloads to default destinations',
6758: 'homeserver' => "Offloads to user's home server",
6759: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6760: 'specific' => 'Offloads to specific server',
1.161 raeburn 6761: 'none' => 'No offload',
1.209 raeburn 6762: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6763: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 6764: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6765: );
6766: return %ruletitles;
6767: }
6768:
6769: sub sparestype_titles {
6770: my %typestitles = &Apache::lonlocal::texthash (
6771: 'primary' => 'primary',
6772: 'default' => 'default',
6773: );
6774: return %typestitles;
6775: }
6776:
1.28 raeburn 6777: sub contact_titles {
6778: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 6779: 'supportemail' => 'Support E-mail address',
6780: 'adminemail' => 'Default Server Admin E-mail address',
6781: 'errormail' => 'Error reports to be e-mailed to',
6782: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 6783: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6784: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 6785: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6786: 'requestsmail' => 'E-mail from course requests requiring approval',
6787: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 6788: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.340 raeburn 6789: 'errorthreshold' => 'Error/warning threshold for status e-mail',
6790: 'errorsysmail' => 'Error threshold for e-mail to core group',
6791: 'errorweights' => 'Weights used to compute error count',
6792: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 6793: );
6794: my %short_titles = &Apache::lonlocal::texthash (
6795: adminemail => 'Admin E-mail address',
6796: supportemail => 'Support E-mail',
6797: );
6798: return (\%titles,\%short_titles);
6799: }
6800:
1.286 raeburn 6801: sub helpform_fields {
6802: my %titles = &Apache::lonlocal::texthash (
6803: 'username' => 'Name',
6804: 'user' => 'Username/domain',
6805: 'phone' => 'Phone',
6806: 'cc' => 'Cc e-mail',
6807: 'course' => 'Course Details',
6808: 'section' => 'Sections',
1.289 raeburn 6809: 'screenshot' => 'File upload',
1.286 raeburn 6810: );
6811: my @fields = ('username','phone','user','course','section','cc','screenshot');
6812: my %possoptions = (
6813: username => ['yes','no','req'],
1.289 raeburn 6814: phone => ['yes','no','req'],
1.286 raeburn 6815: user => ['yes','no'],
1.289 raeburn 6816: cc => ['yes','no'],
1.286 raeburn 6817: course => ['yes','no'],
6818: section => ['yes','no'],
6819: screenshot => ['yes','no'],
6820: );
6821: my %fieldoptions = &Apache::lonlocal::texthash (
6822: 'yes' => 'Optional',
6823: 'req' => 'Required',
6824: 'no' => "Not shown",
6825: );
6826: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6827: }
6828:
1.72 raeburn 6829: sub tool_titles {
6830: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 6831: aboutme => 'Personal web page',
1.86 raeburn 6832: blog => 'Blog',
1.162 raeburn 6833: webdav => 'WebDAV',
1.86 raeburn 6834: portfolio => 'Portfolio',
1.88 bisitz 6835: official => 'Official courses (with institutional codes)',
6836: unofficial => 'Unofficial courses',
1.98 raeburn 6837: community => 'Communities',
1.216 raeburn 6838: textbook => 'Textbook courses',
1.271 raeburn 6839: placement => 'Placement tests',
1.86 raeburn 6840: );
1.72 raeburn 6841: return %titles;
6842: }
6843:
1.101 raeburn 6844: sub courserequest_titles {
6845: my %titles = &Apache::lonlocal::texthash (
6846: official => 'Official',
6847: unofficial => 'Unofficial',
6848: community => 'Communities',
1.216 raeburn 6849: textbook => 'Textbook',
1.271 raeburn 6850: placement => 'Placement tests',
1.325 raeburn 6851: lti => 'LTI Provider',
1.101 raeburn 6852: norequest => 'Not allowed',
1.325 raeburn 6853: approval => 'Approval by DC',
1.101 raeburn 6854: validate => 'With validation',
6855: autolimit => 'Numerical limit',
1.103 raeburn 6856: unlimited => '(blank for unlimited)',
1.101 raeburn 6857: );
6858: return %titles;
6859: }
6860:
1.163 raeburn 6861: sub authorrequest_titles {
6862: my %titles = &Apache::lonlocal::texthash (
6863: norequest => 'Not allowed',
6864: approval => 'Approval by Dom. Coord.',
6865: automatic => 'Automatic approval',
6866: );
6867: return %titles;
1.210 raeburn 6868: }
1.163 raeburn 6869:
1.101 raeburn 6870: sub courserequest_conditions {
6871: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6872: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 6873: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6874: );
6875: return %conditions;
6876: }
6877:
6878:
1.27 raeburn 6879: sub print_usercreation {
1.30 raeburn 6880: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6881: my $numinrow = 4;
1.28 raeburn 6882: my $datatable;
6883: if ($position eq 'top') {
1.30 raeburn 6884: $$rowtotal ++;
1.34 raeburn 6885: my $rowcount = 0;
1.32 raeburn 6886: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6887: if (ref($rules) eq 'HASH') {
6888: if (keys(%{$rules}) > 0) {
1.32 raeburn 6889: $datatable .= &user_formats_row('username',$settings,$rules,
6890: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6891: $$rowtotal ++;
1.32 raeburn 6892: $rowcount ++;
6893: }
6894: }
6895: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6896: if (ref($idrules) eq 'HASH') {
6897: if (keys(%{$idrules}) > 0) {
6898: $datatable .= &user_formats_row('id',$settings,$idrules,
6899: $idruleorder,$numinrow,$rowcount);
6900: $$rowtotal ++;
6901: $rowcount ++;
1.28 raeburn 6902: }
6903: }
1.39 raeburn 6904: if ($rowcount == 0) {
6905: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6906: $$rowtotal ++;
6907: $rowcount ++;
6908: }
1.34 raeburn 6909: } elsif ($position eq 'middle') {
1.224 raeburn 6910: my @creators = ('author','course','requestcrs');
1.37 raeburn 6911: my ($rules,$ruleorder) =
6912: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6913: my %lt = &usercreation_types();
6914: my %checked;
6915: if (ref($settings) eq 'HASH') {
6916: if (ref($settings->{'cancreate'}) eq 'HASH') {
6917: foreach my $item (@creators) {
6918: $checked{$item} = $settings->{'cancreate'}{$item};
6919: }
6920: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6921: foreach my $item (@creators) {
6922: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6923: $checked{$item} = 'none';
6924: }
6925: }
6926: }
6927: }
6928: my $rownum = 0;
6929: foreach my $item (@creators) {
6930: $rownum ++;
1.224 raeburn 6931: if ($checked{$item} eq '') {
6932: $checked{$item} = 'any';
1.34 raeburn 6933: }
6934: my $css_class;
6935: if ($rownum%2) {
6936: $css_class = '';
6937: } else {
6938: $css_class = ' class="LC_odd_row" ';
6939: }
6940: $datatable .= '<tr'.$css_class.'>'.
6941: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 6942: '</span></td><td style="text-align: right">';
1.224 raeburn 6943: my @options = ('any');
6944: if (ref($rules) eq 'HASH') {
6945: if (keys(%{$rules}) > 0) {
6946: push(@options,('official','unofficial'));
1.37 raeburn 6947: }
6948: }
1.224 raeburn 6949: push(@options,'none');
1.37 raeburn 6950: foreach my $option (@options) {
1.50 raeburn 6951: my $type = 'radio';
1.34 raeburn 6952: my $check = ' ';
1.224 raeburn 6953: if ($checked{$item} eq $option) {
6954: $check = ' checked="checked" ';
1.34 raeburn 6955: }
6956: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6957: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6958: $item.'" value="'.$option.'"'.$check.'/> '.
6959: $lt{$option}.'</label> </span>';
6960: }
6961: $datatable .= '</td></tr>';
6962: }
1.28 raeburn 6963: } else {
6964: my @contexts = ('author','course','domain');
1.325 raeburn 6965: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 6966: my %checked;
6967: if (ref($settings) eq 'HASH') {
6968: if (ref($settings->{'authtypes'}) eq 'HASH') {
6969: foreach my $item (@contexts) {
6970: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6971: foreach my $auth (@authtypes) {
6972: if ($settings->{'authtypes'}{$item}{$auth}) {
6973: $checked{$item}{$auth} = ' checked="checked" ';
6974: }
6975: }
6976: }
6977: }
1.27 raeburn 6978: }
1.35 raeburn 6979: } else {
6980: foreach my $item (@contexts) {
1.36 raeburn 6981: foreach my $auth (@authtypes) {
1.35 raeburn 6982: $checked{$item}{$auth} = ' checked="checked" ';
6983: }
6984: }
1.27 raeburn 6985: }
1.28 raeburn 6986: my %title = &context_names();
6987: my %authname = &authtype_names();
6988: my $rownum = 0;
6989: my $css_class;
6990: foreach my $item (@contexts) {
6991: if ($rownum%2) {
6992: $css_class = '';
6993: } else {
6994: $css_class = ' class="LC_odd_row" ';
6995: }
1.30 raeburn 6996: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6997: '<td>'.$title{$item}.
6998: '</td><td class="LC_left_item">'.
6999: '<span class="LC_nobreak">';
7000: foreach my $auth (@authtypes) {
7001: $datatable .= '<label>'.
7002: '<input type="checkbox" name="'.$item.'_auth" '.
7003: $checked{$item}{$auth}.' value="'.$auth.'" />'.
7004: $authname{$auth}.'</label> ';
7005: }
7006: $datatable .= '</span></td></tr>';
7007: $rownum ++;
1.27 raeburn 7008: }
1.30 raeburn 7009: $$rowtotal += $rownum;
1.27 raeburn 7010: }
7011: return $datatable;
7012: }
7013:
1.224 raeburn 7014: sub print_selfcreation {
7015: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 7016: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
7017: $emaildomain,$datatable);
1.224 raeburn 7018: if (ref($settings) eq 'HASH') {
7019: if (ref($settings->{'cancreate'}) eq 'HASH') {
7020: $createsettings = $settings->{'cancreate'};
1.236 raeburn 7021: if (ref($createsettings) eq 'HASH') {
7022: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
7023: @selfcreate = @{$createsettings->{'selfcreate'}};
7024: } elsif ($createsettings->{'selfcreate'} ne '') {
7025: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
7026: @selfcreate = ('email','login','sso');
7027: } elsif ($createsettings->{'selfcreate'} ne 'none') {
7028: @selfcreate = ($createsettings->{'selfcreate'});
7029: }
7030: }
7031: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
7032: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 7033: }
1.305 raeburn 7034: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
7035: $emailoptions = $createsettings->{'emailoptions'};
7036: }
1.303 raeburn 7037: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
7038: $emailverified = $createsettings->{'emailverified'};
7039: }
7040: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
7041: $emaildomain = $createsettings->{'emaildomain'};
7042: }
1.224 raeburn 7043: }
7044: }
7045: }
7046: my %radiohash;
7047: my $numinrow = 4;
7048: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 7049: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 7050: if ($position eq 'top') {
7051: my %choices = &Apache::lonlocal::texthash (
7052: cancreate_login => 'Institutional Login',
7053: cancreate_sso => 'Institutional Single Sign On',
7054: );
7055: my @toggles = sort(keys(%choices));
7056: my %defaultchecked = (
7057: 'cancreate_login' => 'off',
7058: 'cancreate_sso' => 'off',
7059: );
1.228 raeburn 7060: my ($onclick,$itemcount);
1.224 raeburn 7061: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7062: \%choices,$itemcount,$onclick);
1.228 raeburn 7063: $$rowtotal += $itemcount;
7064:
1.224 raeburn 7065: if (ref($usertypes) eq 'HASH') {
7066: if (keys(%{$usertypes}) > 0) {
7067: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
7068: $dom,$numinrow,$othertitle,
1.305 raeburn 7069: 'statustocreate',$rowtotal);
1.224 raeburn 7070: $$rowtotal ++;
7071: }
7072: }
1.240 raeburn 7073: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
7074: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7075: $fieldtitles{'inststatus'} = &mt('Institutional status');
7076: my $rem;
7077: my $numperrow = 2;
7078: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
7079: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 7080: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 7081: '<td class="LC_left_item">'."\n".
1.334 raeburn 7082: '<table>'."\n";
1.240 raeburn 7083: for (my $i=0; $i<@fields; $i++) {
7084: $rem = $i%($numperrow);
7085: if ($rem == 0) {
7086: if ($i > 0) {
7087: $datatable .= '</tr>';
7088: }
7089: $datatable .= '<tr>';
7090: }
7091: my $currval;
1.248 raeburn 7092: if (ref($createsettings) eq 'HASH') {
7093: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
7094: $currval = $createsettings->{'shibenv'}{$fields[$i]};
7095: }
1.240 raeburn 7096: }
7097: $datatable .= '<td class="LC_left_item">'.
7098: '<span class="LC_nobreak">'.
7099: '<input type="text" name="shibenv_'.$fields[$i].'" '.
7100: 'value="'.$currval.'" size="10" /> '.
7101: $fieldtitles{$fields[$i]}.'</span></td>';
7102: }
7103: my $colsleft = $numperrow - $rem;
7104: if ($colsleft > 1 ) {
7105: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7106: ' </td>';
7107: } elsif ($colsleft == 1) {
7108: $datatable .= '<td class="LC_left_item"> </td>';
7109: }
7110: $datatable .= '</tr></table></td></tr>';
7111: $$rowtotal ++;
1.224 raeburn 7112: } elsif ($position eq 'middle') {
7113: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 7114: my @posstypes;
1.224 raeburn 7115: if (ref($types) eq 'ARRAY') {
1.302 raeburn 7116: @posstypes = @{$types};
7117: }
7118: unless (grep(/^default$/,@posstypes)) {
7119: push(@posstypes,'default');
7120: }
7121: my %usertypeshash;
7122: if (ref($usertypes) eq 'HASH') {
7123: %usertypeshash = %{$usertypes};
7124: }
7125: $usertypeshash{'default'} = $othertitle;
7126: foreach my $status (@posstypes) {
7127: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
7128: $numinrow,$$rowtotal,\%usertypeshash);
7129: $$rowtotal ++;
1.224 raeburn 7130: }
7131: } else {
1.236 raeburn 7132: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 7133: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 7134: );
7135: my @toggles = sort(keys(%choices));
7136: my %defaultchecked = (
7137: 'cancreate_email' => 'off',
7138: );
1.305 raeburn 7139: my $customclass = 'LC_selfcreate_email';
7140: my $classprefix = 'LC_canmodify_emailusername_';
7141: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 7142: my $display = 'none';
1.305 raeburn 7143: my $rowstyle = 'display:none';
1.236 raeburn 7144: if (grep(/^\Qemail\E$/,@selfcreate)) {
7145: $display = 'block';
1.305 raeburn 7146: $rowstyle = 'display:table-row';
1.236 raeburn 7147: }
1.305 raeburn 7148: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
7149: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7150: \%choices,$$rowtotal,$onclick);
7151: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
7152: $rowstyle);
7153: $$rowtotal ++;
7154: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
7155: $rowstyle);
7156: $$rowtotal ++;
7157: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 7158: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 7159: my ($emailrules,$emailruleorder) =
7160: &Apache::lonnet::inst_userrules($dom,'email');
7161: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7162: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7163: if (ref($types) eq 'ARRAY') {
7164: @posstypes = @{$types};
7165: }
7166: if (@posstypes) {
7167: unless (grep(/^default$/,@posstypes)) {
7168: push(@posstypes,'default');
1.302 raeburn 7169: }
7170: if (ref($usertypes) eq 'HASH') {
7171: %usertypeshash = %{$usertypes};
7172: }
1.305 raeburn 7173: my $currassign;
7174: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
7175: $currassign = {
7176: selfassign => $domdefaults{'inststatusguest'},
7177: };
7178: @ordered = @{$domdefaults{'inststatusguest'}};
7179: } else {
7180: $currassign = { selfassign => [] };
7181: }
7182: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
7183: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
7184: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
7185: $numinrow,$othertitle,'selfassign',
7186: $rowtotal,$onclicktypes,$customclass,
7187: $rowstyle);
7188: $$rowtotal ++;
1.302 raeburn 7189: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7190: foreach my $status (@posstypes) {
7191: my $css_class;
7192: if ($$rowtotal%2) {
7193: $css_class = 'LC_odd_row ';
7194: }
7195: $css_class .= $customclass;
7196: my $rowid = $optionsprefix.$status;
7197: my $hidden = 1;
7198: my $currstyle = 'display:none';
7199: if (grep(/^\Q$status\E$/,@ordered)) {
7200: $currstyle = $rowstyle;
7201: $hidden = 0;
7202: }
7203: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7204: $emailrules,$emailruleorder,$settings,$status,$rowid,
7205: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7206: unless ($hidden) {
7207: $$rowtotal ++;
7208: }
1.224 raeburn 7209: }
1.302 raeburn 7210: } else {
1.305 raeburn 7211: my $css_class;
7212: if ($$rowtotal%2) {
7213: $css_class = 'LC_odd_row ';
7214: }
7215: $css_class .= $customclass;
1.302 raeburn 7216: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7217: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7218: $emailrules,$emailruleorder,$settings,'default','',
7219: $othertitle,$css_class,$rowstyle,$intdom);
7220: $$rowtotal ++;
1.224 raeburn 7221: }
7222: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 7223: $numinrow = 1;
1.305 raeburn 7224: if (@posstypes) {
7225: foreach my $status (@posstypes) {
7226: my $rowid = $classprefix.$status;
7227: my $datarowstyle = 'display:none';
7228: if (grep(/^\Q$status\E$/,@ordered)) {
7229: $datarowstyle = $rowstyle;
7230: }
7231: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7232: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7233: $infotitles,$rowid,$customclass,$datarowstyle);
7234: unless ($datarowstyle eq 'display:none') {
7235: $$rowtotal ++;
7236: }
1.224 raeburn 7237: }
1.305 raeburn 7238: } else {
7239: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7240: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7241: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 7242: }
7243: }
7244: return $datatable;
7245: }
7246:
1.305 raeburn 7247: sub selfcreate_javascript {
7248: return <<"ENDSCRIPT";
7249:
7250: <script type="text/javascript">
7251: // <![CDATA[
7252:
7253: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7254: var x = document.getElementsByClassName(target);
7255: var insttypes = 0;
7256: var insttypeRegExp = new RegExp(prefix);
7257: if ((x.length != undefined) && (x.length > 0)) {
7258: if (form.elements[radio].length != undefined) {
7259: for (var i=0; i<form.elements[radio].length; i++) {
7260: if (form.elements[radio][i].checked) {
7261: if (form.elements[radio][i].value == 1) {
7262: for (var j=0; j<x.length; j++) {
7263: if (x[j].id == 'undefined') {
7264: x[j].style.display = 'table-row';
7265: } else if (insttypeRegExp.test(x[j].id)) {
7266: insttypes ++;
7267: } else {
7268: x[j].style.display = 'table-row';
7269: }
7270: }
7271: } else {
7272: for (var j=0; j<x.length; j++) {
7273: x[j].style.display = 'none';
7274: }
1.236 raeburn 7275: }
1.305 raeburn 7276: break;
7277: }
7278: }
7279: if (insttypes > 0) {
7280: toggleDataRow(form,checkbox,target,altprefix);
7281: toggleDataRow(form,checkbox,target,prefix,1);
7282: }
7283: }
7284: }
7285: return;
7286: }
7287:
7288: function toggleDataRow(form,checkbox,target,prefix,docount) {
7289: if (form.elements[checkbox].length != undefined) {
7290: var count = 0;
7291: if (docount) {
7292: for (var i=0; i<form.elements[checkbox].length; i++) {
7293: if (form.elements[checkbox][i].checked) {
7294: count ++;
1.236 raeburn 7295: }
1.305 raeburn 7296: }
7297: }
7298: for (var i=0; i<form.elements[checkbox].length; i++) {
7299: var type = form.elements[checkbox][i].value;
7300: if (document.getElementById(prefix+type)) {
7301: if (form.elements[checkbox][i].checked) {
7302: document.getElementById(prefix+type).style.display = 'table-row';
7303: if (count % 2 == 1) {
7304: document.getElementById(prefix+type).className = target+' LC_odd_row';
7305: } else {
7306: document.getElementById(prefix+type).className = target;
1.236 raeburn 7307: }
1.305 raeburn 7308: count ++;
1.236 raeburn 7309: } else {
1.305 raeburn 7310: document.getElementById(prefix+type).style.display = 'none';
7311: }
7312: }
7313: }
7314: }
7315: return;
7316: }
7317:
7318: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7319: var caller = radio+'_'+status;
7320: if (form.elements[caller].length != undefined) {
7321: for (var i=0; i<form.elements[caller].length; i++) {
7322: if (form.elements[caller][i].checked) {
7323: if (document.getElementById(altprefix+'_inst_'+status)) {
7324: var curr = form.elements[caller][i].value;
7325: if (prefix) {
7326: document.getElementById(prefix+'_'+status).style.display = 'none';
7327: }
7328: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7329: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7330: if (curr == 'custom') {
7331: if (prefix) {
7332: document.getElementById(prefix+'_'+status).style.display = 'inline';
7333: }
7334: } else if (curr == 'inst') {
7335: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7336: } else if (curr == 'noninst') {
7337: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 7338: }
1.305 raeburn 7339: break;
1.236 raeburn 7340: }
7341: }
7342: }
7343: }
7344: }
7345:
1.305 raeburn 7346: // ]]>
7347: </script>
7348:
7349: ENDSCRIPT
7350: }
7351:
7352: sub noninst_users {
7353: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7354: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7355: my $class = 'LC_left_item';
7356: if ($css_class) {
7357: $css_class = ' class="'.$css_class.'"';
7358: }
7359: if ($rowid) {
7360: $rowid = ' id="'.$rowid.'"';
7361: }
7362: if ($rowstyle) {
7363: $rowstyle = ' style="'.$rowstyle.'"';
7364: }
7365: my ($output,$description);
7366: if ($type eq 'default') {
7367: $description = &mt('Requests for: [_1]',$typetitle);
7368: } else {
7369: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7370: }
7371: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7372: "<td>$description</td>\n".
7373: '<td class="'.$class.'" colspan="2">'.
7374: '<table><tr>';
7375: my %headers = &Apache::lonlocal::texthash(
7376: approve => 'Processing',
7377: email => 'E-mail',
7378: username => 'Username',
7379: );
7380: foreach my $item ('approve','email','username') {
7381: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 7382: }
1.305 raeburn 7383: $output .= '</tr><tr>';
7384: foreach my $item ('approve','email','username') {
1.306 raeburn 7385: $output .= '<td style="vertical-align: top">';
1.305 raeburn 7386: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7387: if ($item eq 'approve') {
7388: %choices = &Apache::lonlocal::texthash (
7389: automatic => 'Automatically approved',
7390: approval => 'Queued for approval',
7391: );
7392: @options = ('automatic','approval');
7393: $hashref = $processing;
7394: $defoption = 'automatic';
7395: $name = 'cancreate_emailprocess_'.$type;
7396: } elsif ($item eq 'email') {
7397: %choices = &Apache::lonlocal::texthash (
7398: any => 'Any e-mail',
7399: inst => 'Institutional only',
7400: noninst => 'Non-institutional only',
7401: custom => 'Custom restrictions',
7402: );
7403: @options = ('any','inst','noninst');
7404: my $showcustom;
7405: if (ref($emailrules) eq 'HASH') {
7406: if (keys(%{$emailrules}) > 0) {
7407: push(@options,'custom');
7408: $showcustom = 'cancreate_emailrule';
7409: if (ref($settings) eq 'HASH') {
7410: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7411: foreach my $rule (@{$settings->{'email_rule'}}) {
7412: if (exists($emailrules->{$rule})) {
7413: $hascustom ++;
7414: }
7415: }
7416: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7417: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7418: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7419: if (exists($emailrules->{$rule})) {
7420: $hascustom ++;
7421: }
7422: }
7423: }
7424: }
7425: }
7426: }
7427: }
7428: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7429: "'cancreate_emaildomain','$type'".');"';
7430: $hashref = $emailoptions;
7431: $defoption = 'any';
7432: $name = 'cancreate_emailoptions_'.$type;
7433: } elsif ($item eq 'username') {
7434: %choices = &Apache::lonlocal::texthash (
7435: all => 'Same as e-mail',
7436: first => 'Omit @domain',
7437: free => 'Free to choose',
7438: );
7439: @options = ('all','first','free');
7440: $hashref = $emailverified;
7441: $defoption = 'all';
7442: $name = 'cancreate_usernameoptions_'.$type;
7443: }
7444: foreach my $option (@options) {
7445: my $checked;
7446: if (ref($hashref) eq 'HASH') {
7447: if ($type eq '') {
7448: if (!exists($hashref->{'default'})) {
7449: if ($option eq $defoption) {
7450: $checked = ' checked="checked"';
7451: }
7452: } else {
7453: if ($hashref->{'default'} eq $option) {
7454: $checked = ' checked="checked"';
7455: }
1.303 raeburn 7456: }
7457: } else {
1.305 raeburn 7458: if (!exists($hashref->{$type})) {
7459: if ($option eq $defoption) {
7460: $checked = ' checked="checked"';
7461: }
7462: } else {
7463: if ($hashref->{$type} eq $option) {
7464: $checked = ' checked="checked"';
7465: }
1.303 raeburn 7466: }
7467: }
1.305 raeburn 7468: } elsif (($item eq 'email') && ($hascustom)) {
7469: if ($option eq 'custom') {
7470: $checked = ' checked="checked"';
7471: }
7472: } elsif ($option eq $defoption) {
7473: $checked = ' checked="checked"';
7474: }
7475: $output .= '<span class="LC_nobreak"><label>'.
7476: '<input type="radio" name="'.$name.'"'.
7477: $checked.' value="'.$option.'"'.$onclick.' />'.
7478: $choices{$option}.'</label></span><br />';
7479: if ($item eq 'email') {
7480: if ($option eq 'custom') {
7481: my $id = 'cancreate_emailrule_'.$type;
7482: my $display = 'none';
7483: if ($checked) {
7484: $display = 'inline';
1.303 raeburn 7485: }
1.305 raeburn 7486: my $numinrow = 2;
7487: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7488: '<legend>'.&mt('Disallow').'</legend><table>'.
7489: &user_formats_row('email',$settings,$emailrules,
7490: $emailruleorder,$numinrow,'',$type);
7491: '</table></fieldset>';
7492: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7493: my %text = &Apache::lonlocal::texthash (
7494: inst => 'must end:',
7495: noninst => 'cannot end:',
7496: );
7497: my $value;
7498: if (ref($emaildomain) eq 'HASH') {
7499: if (ref($emaildomain->{$type}) eq 'HASH') {
7500: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 7501: }
7502: }
1.305 raeburn 7503: if ($value eq '') {
7504: $value = '@'.$intdom;
7505: }
7506: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7507: my $display = 'none';
7508: if ($checked) {
7509: $display = 'inline';
7510: }
7511: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7512: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7513: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7514: '</div>';
1.303 raeburn 7515: }
7516: }
7517: }
1.305 raeburn 7518: $output .= '</td>'."\n";
1.303 raeburn 7519: }
1.305 raeburn 7520: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 7521: return $output;
7522: }
7523:
1.165 raeburn 7524: sub captcha_choice {
1.305 raeburn 7525: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 7526: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7527: $vertext,$currver);
1.165 raeburn 7528: my %lt = &captcha_phrases();
7529: $keyentry = 'hidden';
7530: if ($context eq 'cancreate') {
1.224 raeburn 7531: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 7532: } elsif ($context eq 'login') {
7533: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 7534: }
7535: if (ref($settings) eq 'HASH') {
7536: if ($settings->{'captcha'}) {
7537: $checked{$settings->{'captcha'}} = ' checked="checked"';
7538: } else {
7539: $checked{'original'} = ' checked="checked"';
7540: }
7541: if ($settings->{'captcha'} eq 'recaptcha') {
7542: $pubtext = $lt{'pub'};
7543: $privtext = $lt{'priv'};
7544: $keyentry = 'text';
1.269 raeburn 7545: $vertext = $lt{'ver'};
7546: $currver = $settings->{'recaptchaversion'};
7547: if ($currver ne '2') {
7548: $currver = 1;
7549: }
1.165 raeburn 7550: }
7551: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7552: $currpub = $settings->{'recaptchakeys'}{'public'};
7553: $currpriv = $settings->{'recaptchakeys'}{'private'};
7554: }
7555: } else {
7556: $checked{'original'} = ' checked="checked"';
7557: }
1.305 raeburn 7558: my $css_class;
7559: if ($itemcount%2) {
7560: $css_class = 'LC_odd_row';
7561: }
7562: if ($customcss) {
7563: $css_class .= " $customcss";
7564: }
7565: $css_class =~ s/^\s+//;
7566: if ($css_class) {
7567: $css_class = ' class="'.$css_class.'"';
7568: }
7569: if ($rowstyle) {
7570: $css_class .= ' style="'.$rowstyle.'"';
7571: }
1.169 raeburn 7572: my $output = '<tr'.$css_class.'>'.
7573: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 7574: '<table><tr><td>'."\n";
7575: foreach my $option ('original','recaptcha','notused') {
7576: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7577: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7578: $lt{$option}.'</label></span>';
7579: unless ($option eq 'notused') {
7580: $output .= (' 'x2)."\n";
7581: }
7582: }
7583: #
7584: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7585: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 7586: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 7587: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 7588: #
1.165 raeburn 7589: $output .= '</td></tr>'."\n".
1.305 raeburn 7590: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 7591: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7592: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7593: $currpub.'" size="40" /></span><br />'."\n".
7594: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7595: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 7596: $currpriv.'" size="40" /></span><br />'.
7597: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7598: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7599: $currver.'" size="3" /></span><br />'.
7600: '</td></tr></table>'."\n".
1.165 raeburn 7601: '</td></tr>';
7602: return $output;
7603: }
7604:
1.32 raeburn 7605: sub user_formats_row {
1.305 raeburn 7606: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7607: my $output;
7608: my %text = (
7609: 'username' => 'new usernames',
7610: 'id' => 'IDs',
7611: );
1.305 raeburn 7612: unless ($type eq 'email') {
7613: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7614: $output = '<tr '.$css_class.'>'.
7615: '<td><span class="LC_nobreak">'.
7616: &mt("Format rules to check for $text{$type}: ").
7617: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7618: }
1.27 raeburn 7619: my $rem;
7620: if (ref($ruleorder) eq 'ARRAY') {
7621: for (my $i=0; $i<@{$ruleorder}; $i++) {
7622: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7623: my $rem = $i%($numinrow);
7624: if ($rem == 0) {
7625: if ($i > 0) {
7626: $output .= '</tr>';
7627: }
7628: $output .= '<tr>';
7629: }
7630: my $check = ' ';
1.39 raeburn 7631: if (ref($settings) eq 'HASH') {
7632: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7633: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7634: $check = ' checked="checked" ';
7635: }
1.305 raeburn 7636: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7637: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7638: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7639: $check = ' checked="checked" ';
7640: }
7641: }
1.27 raeburn 7642: }
7643: }
1.305 raeburn 7644: my $name = $type.'_rule';
7645: if ($type eq 'email') {
7646: $name .= '_'.$status;
7647: }
1.27 raeburn 7648: $output .= '<td class="LC_left_item">'.
7649: '<span class="LC_nobreak"><label>'.
1.311 raeburn 7650: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7651: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7652: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7653: }
7654: }
7655: $rem = @{$ruleorder}%($numinrow);
7656: }
1.305 raeburn 7657: my $colsleft;
7658: if ($rem) {
7659: $colsleft = $numinrow - $rem;
7660: }
1.27 raeburn 7661: if ($colsleft > 1 ) {
7662: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7663: ' </td>';
7664: } elsif ($colsleft == 1) {
7665: $output .= '<td class="LC_left_item"> </td>';
7666: }
1.305 raeburn 7667: $output .= '</tr></table>';
7668: unless ($type eq 'email') {
7669: $output .= '</td></tr>';
7670: }
1.27 raeburn 7671: return $output;
7672: }
7673:
1.34 raeburn 7674: sub usercreation_types {
7675: my %lt = &Apache::lonlocal::texthash (
7676: author => 'When adding a co-author',
7677: course => 'When adding a user to a course',
1.100 raeburn 7678: requestcrs => 'When requesting a course',
1.34 raeburn 7679: any => 'Any',
7680: official => 'Institutional only ',
7681: unofficial => 'Non-institutional only',
7682: none => 'None',
7683: );
7684: return %lt;
1.48 raeburn 7685: }
1.34 raeburn 7686:
1.224 raeburn 7687: sub selfcreation_types {
7688: my %lt = &Apache::lonlocal::texthash (
7689: selfcreate => 'User creates own account',
7690: any => 'Any',
7691: official => 'Institutional only ',
7692: unofficial => 'Non-institutional only',
7693: email => 'E-mail address',
7694: login => 'Institutional Login',
7695: sso => 'SSO',
7696: );
7697: }
7698:
1.28 raeburn 7699: sub authtype_names {
7700: my %lt = &Apache::lonlocal::texthash(
7701: int => 'Internal',
7702: krb4 => 'Kerberos 4',
7703: krb5 => 'Kerberos 5',
7704: loc => 'Local',
1.325 raeburn 7705: lti => 'LTI',
1.28 raeburn 7706: );
7707: return %lt;
7708: }
7709:
7710: sub context_names {
7711: my %context_title = &Apache::lonlocal::texthash(
7712: author => 'Creating users when an Author',
7713: course => 'Creating users when in a course',
7714: domain => 'Creating users when a Domain Coordinator',
7715: );
7716: return %context_title;
7717: }
7718:
1.33 raeburn 7719: sub print_usermodification {
7720: my ($position,$dom,$settings,$rowtotal) = @_;
7721: my $numinrow = 4;
7722: my ($context,$datatable,$rowcount);
7723: if ($position eq 'top') {
7724: $rowcount = 0;
7725: $context = 'author';
7726: foreach my $role ('ca','aa') {
7727: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7728: $numinrow,$rowcount);
7729: $$rowtotal ++;
7730: $rowcount ++;
7731: }
1.230 raeburn 7732: } elsif ($position eq 'bottom') {
1.33 raeburn 7733: $context = 'course';
7734: $rowcount = 0;
7735: foreach my $role ('st','ep','ta','in','cr') {
7736: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7737: $numinrow,$rowcount);
7738: $$rowtotal ++;
7739: $rowcount ++;
7740: }
7741: }
7742: return $datatable;
7743: }
7744:
1.43 raeburn 7745: sub print_defaults {
1.236 raeburn 7746: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7747: my $rownum = 0;
1.294 raeburn 7748: my ($datatable,$css_class,$titles);
7749: unless ($position eq 'bottom') {
7750: $titles = &defaults_titles($dom);
7751: }
1.236 raeburn 7752: if ($position eq 'top') {
7753: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7754: 'datelocale_def','portal_def');
7755: my %defaults;
7756: if (ref($settings) eq 'HASH') {
7757: %defaults = %{$settings};
1.43 raeburn 7758: } else {
1.236 raeburn 7759: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7760: foreach my $item (@items) {
7761: $defaults{$item} = $domdefaults{$item};
7762: }
1.43 raeburn 7763: }
1.236 raeburn 7764: foreach my $item (@items) {
7765: if ($rownum%2) {
7766: $css_class = '';
7767: } else {
7768: $css_class = ' class="LC_odd_row" ';
7769: }
7770: $datatable .= '<tr'.$css_class.'>'.
7771: '<td><span class="LC_nobreak">'.$titles->{$item}.
7772: '</span></td><td class="LC_right_item" colspan="3">';
7773: if ($item eq 'auth_def') {
1.325 raeburn 7774: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 7775: my %shortauth = (
7776: internal => 'int',
7777: krb4 => 'krb4',
7778: krb5 => 'krb5',
1.325 raeburn 7779: localauth => 'loc',
7780: lti => 'lti',
1.236 raeburn 7781: );
7782: my %authnames = &authtype_names();
7783: foreach my $auth (@authtypes) {
7784: my $checked = ' ';
7785: if ($defaults{$item} eq $auth) {
7786: $checked = ' checked="checked" ';
7787: }
7788: $datatable .= '<label><input type="radio" name="'.$item.
7789: '" value="'.$auth.'"'.$checked.'/>'.
7790: $authnames{$shortauth{$auth}}.'</label> ';
7791: }
7792: } elsif ($item eq 'timezone_def') {
7793: my $includeempty = 1;
7794: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7795: } elsif ($item eq 'datelocale_def') {
7796: my $includeempty = 1;
7797: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7798: } elsif ($item eq 'lang_def') {
1.263 raeburn 7799: my $includeempty = 1;
7800: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 7801: } else {
7802: my $size;
7803: if ($item eq 'portal_def') {
7804: $size = ' size="25"';
7805: }
7806: $datatable .= '<input type="text" name="'.$item.'" value="'.
7807: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 7808: }
1.236 raeburn 7809: $datatable .= '</td></tr>';
7810: $rownum ++;
7811: }
1.294 raeburn 7812: } elsif ($position eq 'middle') {
7813: my @items = ('intauth_cost','intauth_check','intauth_switch');
7814: my %defaults;
7815: if (ref($settings) eq 'HASH') {
7816: %defaults = %{$settings};
7817: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7818: $defaults{'intauth_cost'} = 10;
7819: }
7820: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7821: $defaults{'intauth_check'} = 0;
7822: }
7823: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7824: $defaults{'intauth_switch'} = 0;
7825: }
7826: } else {
7827: %defaults = (
7828: 'intauth_cost' => 10,
7829: 'intauth_check' => 0,
7830: 'intauth_switch' => 0,
7831: );
7832: }
7833: foreach my $item (@items) {
7834: if ($rownum%2) {
7835: $css_class = '';
7836: } else {
7837: $css_class = ' class="LC_odd_row" ';
7838: }
7839: $datatable .= '<tr'.$css_class.'>'.
7840: '<td><span class="LC_nobreak">'.$titles->{$item}.
7841: '</span></td><td class="LC_left_item" colspan="3">';
7842: if ($item eq 'intauth_switch') {
7843: my @options = (0,1,2);
7844: my %optiondesc = &Apache::lonlocal::texthash (
7845: 0 => 'No',
7846: 1 => 'Yes',
7847: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7848: );
7849: $datatable .= '<table width="100%">';
7850: foreach my $option (@options) {
7851: my $checked = ' ';
7852: if ($defaults{$item} eq $option) {
7853: $checked = ' checked="checked"';
7854: }
7855: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7856: '<label><input type="radio" name="'.$item.
7857: '" value="'.$option.'"'.$checked.' />'.
7858: $optiondesc{$option}.'</label></span></td></tr>';
7859: }
7860: $datatable .= '</table>';
7861: } elsif ($item eq 'intauth_check') {
7862: my @options = (0,1,2);
7863: my %optiondesc = &Apache::lonlocal::texthash (
7864: 0 => 'No',
7865: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7866: 2 => 'Yes, disallow login if stored cost is less than domain default',
7867: );
1.332 raeburn 7868: $datatable .= '<table width="100%">';
1.294 raeburn 7869: foreach my $option (@options) {
7870: my $checked = ' ';
7871: my $onclick;
7872: if ($defaults{$item} eq $option) {
7873: $checked = ' checked="checked"';
7874: }
7875: if ($option == 2) {
7876: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7877: }
7878: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7879: '<label><input type="radio" name="'.$item.
7880: '" value="'.$option.'"'.$checked.$onclick.' />'.
7881: $optiondesc{$option}.'</label></span></td></tr>';
7882: }
7883: $datatable .= '</table>';
7884: } else {
7885: $datatable .= '<input type="text" name="'.$item.'" value="'.
7886: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7887: }
7888: $datatable .= '</td></tr>';
7889: $rownum ++;
7890: }
1.236 raeburn 7891: } else {
1.294 raeburn 7892: my %defaults;
1.236 raeburn 7893: if (ref($settings) eq 'HASH') {
1.305 raeburn 7894: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.236 raeburn 7895: my $maxnum = @{$settings->{'inststatusorder'}};
7896: for (my $i=0; $i<$maxnum; $i++) {
7897: $css_class = $rownum%2?' class="LC_odd_row"':'';
7898: my $item = $settings->{'inststatusorder'}->[$i];
7899: my $title = $settings->{'inststatustypes'}->{$item};
7900: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7901: $datatable .= '<tr'.$css_class.'>'.
7902: '<td><span class="LC_nobreak">'.
7903: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7904: for (my $k=0; $k<=$maxnum; $k++) {
7905: my $vpos = $k+1;
7906: my $selstr;
7907: if ($k == $i) {
7908: $selstr = ' selected="selected" ';
7909: }
7910: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7911: }
7912: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7913: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7914: &mt('delete').'</span></td>'.
1.305 raeburn 7915: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.236 raeburn 7916: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.305 raeburn 7917: '</span></td></tr>';
1.236 raeburn 7918: }
7919: $css_class = $rownum%2?' class="LC_odd_row"':'';
7920: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7921: $datatable .= '<tr '.$css_class.'>'.
7922: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7923: for (my $k=0; $k<=$maxnum; $k++) {
7924: my $vpos = $k+1;
7925: my $selstr;
7926: if ($k == $maxnum) {
7927: $selstr = ' selected="selected" ';
7928: }
7929: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7930: }
7931: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 7932: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 7933: ' '.&mt('(new)').
1.305 raeburn 7934: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.236 raeburn 7935: &mt('Name displayed:').
7936: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7937: '</tr>'."\n";
7938: $rownum ++;
1.141 raeburn 7939: }
1.43 raeburn 7940: }
7941: }
7942: $$rowtotal += $rownum;
7943: return $datatable;
7944: }
7945:
1.168 raeburn 7946: sub get_languages_hash {
7947: my %langchoices;
7948: foreach my $id (&Apache::loncommon::languageids()) {
7949: my $code = &Apache::loncommon::supportedlanguagecode($id);
7950: if ($code ne '') {
7951: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7952: }
7953: }
7954: return %langchoices;
7955: }
7956:
1.43 raeburn 7957: sub defaults_titles {
1.141 raeburn 7958: my ($dom) = @_;
1.43 raeburn 7959: my %titles = &Apache::lonlocal::texthash (
7960: 'auth_def' => 'Default authentication type',
7961: 'auth_arg_def' => 'Default authentication argument',
7962: 'lang_def' => 'Default language',
1.54 raeburn 7963: 'timezone_def' => 'Default timezone',
1.68 raeburn 7964: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7965: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 7966: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7967: 'intauth_check' => 'Check bcrypt cost if authenticated',
7968: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7969: );
1.141 raeburn 7970: if ($dom) {
7971: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7972: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7973: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7974: $protocol = 'http' if ($protocol ne 'https');
7975: if ($uint_dom) {
7976: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7977: $uint_dom);
7978: }
7979: }
1.43 raeburn 7980: return (\%titles);
7981: }
7982:
1.346 raeburn 7983: sub print_scantron {
7984: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
7985: if ($position eq 'top') {
7986: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
7987: } else {
7988: return &print_scantronconfig($dom,$settings,\$rowtotal);
7989: }
7990: }
7991:
7992: sub scantron_javascript {
7993: return <<"ENDSCRIPT";
7994:
7995: <script type="text/javascript">
7996: // <![CDATA[
7997:
7998: function toggleScantron(form) {
1.347 ! raeburn 7999: var csvfieldset = new Array();
1.346 raeburn 8000: if (document.getElementById('scantroncsv_cols')) {
1.347 ! raeburn 8001: csvfieldset.push(document.getElementById('scantroncsv_cols'));
! 8002: }
! 8003: if (document.getElementById('scantroncsv_options')) {
! 8004: csvfieldset.push(document.getElementById('scantroncsv_options'));
! 8005: }
! 8006: if (csvfieldset.length) {
1.346 raeburn 8007: if (document.getElementById('scantronconfcsv')) {
1.347 ! raeburn 8008: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 8009: if (scantroncsv.checked) {
1.347 ! raeburn 8010: for (var i=0; i<csvfieldset.length; i++) {
! 8011: csvfieldset[i].style.display = 'block';
! 8012: }
1.346 raeburn 8013: } else {
1.347 ! raeburn 8014: for (var i=0; i<csvfieldset.length; i++) {
! 8015: csvfieldset[i].style.display = 'none';
! 8016: }
1.346 raeburn 8017: var csvselects = document.getElementsByClassName('scantronconfig_csv');
8018: if (csvselects.length) {
8019: for (var j=0; j<csvselects.length; j++) {
8020: csvselects[j].selectedIndex = 0;
8021: }
8022: }
8023: }
8024: }
8025: }
8026: return;
8027: }
8028: // ]]>
8029: </script>
8030:
8031: ENDSCRIPT
8032:
8033: }
8034:
1.46 raeburn 8035: sub print_scantronformat {
8036: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
8037: my $itemcount = 1;
1.60 raeburn 8038: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
8039: %confhash);
1.46 raeburn 8040: my $switchserver = &check_switchserver($dom,$confname);
8041: my %lt = &Apache::lonlocal::texthash (
1.95 www 8042: default => 'Default bubblesheet format file error',
8043: custom => 'Custom bubblesheet format file error',
1.46 raeburn 8044: );
8045: my %scantronfiles = (
8046: default => 'default.tab',
8047: custom => 'custom.tab',
8048: );
8049: foreach my $key (keys(%scantronfiles)) {
8050: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
8051: .$scantronfiles{$key};
8052: }
8053: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
8054: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
8055: if (!$switchserver) {
8056: my $servadm = $r->dir_config('lonAdmEMail');
8057: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
8058: if ($configuserok eq 'ok') {
8059: if ($author_ok eq 'ok') {
8060: my %legacyfile = (
1.346 raeburn 8061: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
8062: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 8063: );
8064: my %md5chk;
8065: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 8066: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
8067: chomp($md5chk{$type});
1.46 raeburn 8068: }
8069: if ($md5chk{'default'} ne $md5chk{'custom'}) {
8070: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 8071: ($scantronurls{$type},my $error) =
1.46 raeburn 8072: &legacy_scantronformat($r,$dom,$confname,
8073: $type,$legacyfile{$type},
8074: $scantronurls{$type},
8075: $scantronfiles{$type});
1.60 raeburn 8076: if ($error ne '') {
8077: $error{$type} = $error;
8078: }
8079: }
8080: if (keys(%error) == 0) {
8081: $is_custom = 1;
1.346 raeburn 8082: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 8083: $scantronurls{'custom'};
1.346 raeburn 8084: my $putresult =
1.60 raeburn 8085: &Apache::lonnet::put_dom('configuration',
8086: \%confhash,$dom);
8087: if ($putresult ne 'ok') {
1.346 raeburn 8088: $error{'custom'} =
1.60 raeburn 8089: '<span class="LC_error">'.
8090: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8091: }
1.46 raeburn 8092: }
8093: } else {
1.60 raeburn 8094: ($scantronurls{'default'},my $error) =
1.46 raeburn 8095: &legacy_scantronformat($r,$dom,$confname,
8096: 'default',$legacyfile{'default'},
8097: $scantronurls{'default'},
8098: $scantronfiles{'default'});
1.60 raeburn 8099: if ($error eq '') {
8100: $confhash{'scantron'}{'scantronformat'} = '';
8101: my $putresult =
8102: &Apache::lonnet::put_dom('configuration',
8103: \%confhash,$dom);
8104: if ($putresult ne 'ok') {
8105: $error{'default'} =
8106: '<span class="LC_error">'.
8107: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8108: }
8109: } else {
8110: $error{'default'} = $error;
8111: }
1.46 raeburn 8112: }
8113: }
8114: }
8115: } else {
1.95 www 8116: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 8117: }
8118: }
8119: if (ref($settings) eq 'HASH') {
8120: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
8121: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
8122: if ((!@info) || ($info[0] eq 'no_such_dir')) {
8123: $scantronurl = '';
8124: } else {
8125: $scantronurl = $settings->{'scantronformat'};
8126: }
8127: $is_custom = 1;
8128: } else {
8129: $scantronurl = $scantronurls{'default'};
8130: }
8131: } else {
1.60 raeburn 8132: if ($is_custom) {
8133: $scantronurl = $scantronurls{'custom'};
8134: } else {
8135: $scantronurl = $scantronurls{'default'};
8136: }
1.46 raeburn 8137: }
8138: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8139: $datatable .= '<tr'.$css_class.'>';
8140: if (!$is_custom) {
1.65 raeburn 8141: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
8142: '<span class="LC_nobreak">';
1.46 raeburn 8143: if ($scantronurl) {
1.199 raeburn 8144: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
8145: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 8146: } else {
8147: $datatable = &mt('File unavailable for display');
8148: }
1.65 raeburn 8149: $datatable .= '</span></td>';
1.60 raeburn 8150: if (keys(%error) == 0) {
1.306 raeburn 8151: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 8152: if (!$switchserver) {
8153: $datatable .= &mt('Upload:').'<br />';
8154: }
8155: } else {
8156: my $errorstr;
8157: foreach my $key (sort(keys(%error))) {
8158: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8159: }
8160: $datatable .= '<td>'.$errorstr;
8161: }
1.46 raeburn 8162: } else {
8163: if (keys(%error) > 0) {
8164: my $errorstr;
8165: foreach my $key (sort(keys(%error))) {
8166: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8167: }
1.60 raeburn 8168: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 8169: } elsif ($scantronurl) {
1.199 raeburn 8170: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
8171: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 8172: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 8173: $link.
8174: '<label><input type="checkbox" name="scantronformat_del"'.
8175: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 8176: '<td><span class="LC_nobreak"> '.
8177: &mt('Replace:').'</span><br />';
1.46 raeburn 8178: }
8179: }
8180: if (keys(%error) == 0) {
8181: if ($switchserver) {
8182: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
8183: } else {
1.65 raeburn 8184: $datatable .='<span class="LC_nobreak"> '.
8185: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 8186: }
8187: }
8188: $datatable .= '</td></tr>';
8189: $$rowtotal ++;
8190: return $datatable;
8191: }
8192:
8193: sub legacy_scantronformat {
8194: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
8195: my ($url,$error);
8196: my @statinfo = &Apache::lonnet::stat_file($newurl);
8197: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
8198: (my $result,$url) =
8199: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
8200: '','',$newfile);
8201: if ($result ne 'ok') {
1.130 raeburn 8202: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 8203: }
8204: }
8205: return ($url,$error);
8206: }
1.43 raeburn 8207:
1.346 raeburn 8208: sub print_scantronconfig {
8209: my ($dom,$settings,$rowtotal) = @_;
8210: my $itemcount = 2;
8211: my $is_checked = ' checked="checked"';
1.347 ! raeburn 8212: my %optionson = (
! 8213: hdr => ' checked="checked"',
! 8214: pad => ' checked="checked"',
! 8215: rem => ' checked="checked"',
! 8216: );
! 8217: my %optionsoff = (
! 8218: hdr => '',
! 8219: pad => '',
! 8220: rem => '',
! 8221: );
1.346 raeburn 8222: my $currcsvsty = 'none';
1.347 ! raeburn 8223: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 8224: my @fields = &scantroncsv_fields();
8225: my %titles = &scantronconfig_titles();
8226: if (ref($settings) eq 'HASH') {
8227: if (ref($settings->{config}) eq 'HASH') {
8228: if ($settings->{config}->{dat}) {
8229: $checked{'dat'} = $is_checked;
8230: }
8231: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 ! raeburn 8232: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
! 8233: %csvfields = %{$settings->{config}->{csv}->{fields}};
! 8234: if (keys(%csvfields) > 0) {
! 8235: $checked{'csv'} = $is_checked;
! 8236: $currcsvsty = 'block';
! 8237: }
! 8238: }
! 8239: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
! 8240: %csvoptions = %{$settings->{config}->{csv}->{options}};
! 8241: foreach my $option (keys(%optionson)) {
! 8242: unless ($csvoptions{$option}) {
! 8243: $optionsoff{$option} = $optionson{$option};
! 8244: $optionson{$option} = '';
! 8245: }
! 8246: }
1.346 raeburn 8247: }
8248: }
8249: } else {
8250: $checked{'dat'} = $is_checked;
8251: }
8252: } else {
8253: $checked{'dat'} = $is_checked;
8254: }
8255: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8256: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8257: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8258: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8259: foreach my $item ('dat','csv') {
8260: my $id;
8261: if ($item eq 'csv') {
8262: $id = 'id="scantronconfcsv" ';
1.347 ! raeburn 8263: }
1.346 raeburn 8264: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8265: $titles{$item}.'</label>'.(' 'x3);
8266: if ($item eq 'csv') {
8267: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8268: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8269: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8270: foreach my $col (@fields) {
8271: my $selnone;
8272: if ($csvfields{$col} eq '') {
8273: $selnone = ' selected="selected"';
8274: }
8275: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8276: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8277: '<option value=""'.$selnone.'></option>';
8278: for (my $i=0; $i<20; $i++) {
8279: my $shown = $i+1;
8280: my $sel;
8281: unless ($selnone) {
8282: if (exists($csvfields{$col})) {
8283: if ($csvfields{$col} == $i) {
8284: $sel = ' selected="selected"';
8285: }
8286: }
8287: }
8288: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8289: }
8290: $datatable .= '</select></td></tr>';
8291: }
1.347 ! raeburn 8292: $datatable .= '</table></fieldset>'.
! 8293: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
! 8294: '<legend>'.&mt('CSV Options').'</legend>';
! 8295: foreach my $option ('hdr','pad','rem') {
! 8296: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
! 8297: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
! 8298: &mt('Yes').'</label>'.(' 'x2)."\n".
! 8299: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
! 8300: }
! 8301: $datatable .= '</fieldset>';
1.346 raeburn 8302: $itemcount ++;
8303: }
8304: }
8305: $datatable .= '</td></tr>';
8306: $$rowtotal ++;
8307: return $datatable;
8308: }
8309:
8310: sub scantronconfig_titles {
8311: return &Apache::lonlocal::texthash(
8312: dat => 'Standard format (.dat)',
8313: csv => 'Comma separated values (.csv)',
1.347 ! raeburn 8314: hdr => 'Remove first line in file (contains column titles)',
! 8315: pad => 'Prepend 0s to PaperID',
! 8316: rem => 'Remove leading spaces (except Q columns)',
1.346 raeburn 8317: CODE => 'CODE',
8318: ID => 'Student ID',
8319: PaperID => 'Paper ID',
8320: FirstName => 'First Name',
8321: LastName => 'Last Name',
8322: FirstQuestion => 'First Question Response',
8323: Section => 'Section',
8324: );
8325: }
8326:
8327: sub scantroncsv_fields {
8328: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
8329: }
8330:
1.49 raeburn 8331: sub print_coursecategories {
1.57 raeburn 8332: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8333: my $datatable;
8334: if ($position eq 'top') {
1.238 raeburn 8335: my (%checked);
8336: my @catitems = ('unauth','auth');
8337: my @cattypes = ('std','domonly','codesrch','none');
8338: $checked{'unauth'} = 'std';
8339: $checked{'auth'} = 'std';
8340: if (ref($settings) eq 'HASH') {
8341: foreach my $type (@cattypes) {
8342: if ($type eq $settings->{'unauth'}) {
8343: $checked{'unauth'} = $type;
8344: }
8345: if ($type eq $settings->{'auth'}) {
8346: $checked{'auth'} = $type;
8347: }
8348: }
8349: }
8350: my %lt = &Apache::lonlocal::texthash (
8351: unauth => 'Catalog type for unauthenticated users',
8352: auth => 'Catalog type for authenticated users',
8353: none => 'No catalog',
8354: std => 'Standard catalog',
8355: domonly => 'Domain-only catalog',
8356: codesrch => "Code search form",
8357: );
8358: my $itemcount = 0;
8359: foreach my $item (@catitems) {
8360: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8361: $datatable .= '<tr '.$css_class.'>'.
8362: '<td>'.$lt{$item}.'</td>'.
8363: '<td class="LC_right_item"><span class="LC_nobreak">';
8364: foreach my $type (@cattypes) {
8365: my $ischecked;
8366: if ($checked{$item} eq $type) {
8367: $ischecked=' checked="checked"';
8368: }
8369: $datatable .= '<label>'.
8370: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8371: ' />'.$lt{$type}.'</label> ';
8372: }
1.327 raeburn 8373: $datatable .= '</span></td></tr>';
1.238 raeburn 8374: $itemcount ++;
8375: }
8376: $$rowtotal += $itemcount;
8377: } elsif ($position eq 'middle') {
1.57 raeburn 8378: my $toggle_cats_crs = ' ';
8379: my $toggle_cats_dom = ' checked="checked" ';
8380: my $can_cat_crs = ' ';
8381: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8382: my $toggle_catscomm_comm = ' ';
8383: my $toggle_catscomm_dom = ' checked="checked" ';
8384: my $can_catcomm_comm = ' ';
8385: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 8386: my $toggle_catsplace_place = ' ';
8387: my $toggle_catsplace_dom = ' checked="checked" ';
8388: my $can_catplace_place = ' ';
8389: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 8390:
1.57 raeburn 8391: if (ref($settings) eq 'HASH') {
8392: if ($settings->{'togglecats'} eq 'crs') {
8393: $toggle_cats_crs = $toggle_cats_dom;
8394: $toggle_cats_dom = ' ';
8395: }
8396: if ($settings->{'categorize'} eq 'crs') {
8397: $can_cat_crs = $can_cat_dom;
8398: $can_cat_dom = ' ';
8399: }
1.120 raeburn 8400: if ($settings->{'togglecatscomm'} eq 'comm') {
8401: $toggle_catscomm_comm = $toggle_catscomm_dom;
8402: $toggle_catscomm_dom = ' ';
8403: }
8404: if ($settings->{'categorizecomm'} eq 'comm') {
8405: $can_catcomm_comm = $can_catcomm_dom;
8406: $can_catcomm_dom = ' ';
8407: }
1.272 raeburn 8408: if ($settings->{'togglecatsplace'} eq 'place') {
8409: $toggle_catsplace_place = $toggle_catsplace_dom;
8410: $toggle_catsplace_dom = ' ';
8411: }
8412: if ($settings->{'categorizeplace'} eq 'place') {
8413: $can_catplace_place = $can_catplace_dom;
8414: $can_catplace_dom = ' ';
8415: }
1.57 raeburn 8416: }
8417: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 8418: togglecats => 'Show/Hide a course in catalog',
8419: togglecatscomm => 'Show/Hide a community in catalog',
8420: togglecatsplace => 'Show/Hide a placement test in catalog',
8421: categorize => 'Assign a category to a course',
8422: categorizecomm => 'Assign a category to a community',
8423: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 8424: );
8425: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 8426: dom => 'Set in Domain',
8427: crs => 'Set in Course',
8428: comm => 'Set in Community',
8429: place => 'Set in Placement Test',
1.57 raeburn 8430: );
8431: $datatable = '<tr class="LC_odd_row">'.
8432: '<td>'.$title{'togglecats'}.'</td>'.
8433: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8434: '<input type="radio" name="togglecats"'.
8435: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8436: '<label><input type="radio" name="togglecats"'.
8437: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8438: '</tr><tr>'.
8439: '<td>'.$title{'categorize'}.'</td>'.
8440: '<td class="LC_right_item"><span class="LC_nobreak">'.
8441: '<label><input type="radio" name="categorize"'.
8442: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8443: '<label><input type="radio" name="categorize"'.
8444: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8445: '</tr><tr class="LC_odd_row">'.
8446: '<td>'.$title{'togglecatscomm'}.'</td>'.
8447: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8448: '<input type="radio" name="togglecatscomm"'.
8449: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8450: '<label><input type="radio" name="togglecatscomm"'.
8451: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8452: '</tr><tr>'.
8453: '<td>'.$title{'categorizecomm'}.'</td>'.
8454: '<td class="LC_right_item"><span class="LC_nobreak">'.
8455: '<label><input type="radio" name="categorizecomm"'.
8456: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8457: '<label><input type="radio" name="categorizecomm"'.
8458: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 8459: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 8460: '<td>'.$title{'togglecatsplace'}.'</td>'.
8461: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8462: '<input type="radio" name="togglecatsplace"'.
8463: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8464: '<label><input type="radio" name="togglecatscomm"'.
8465: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
8466: '</tr><tr>'.
8467: '<td>'.$title{'categorizeplace'}.'</td>'.
8468: '<td class="LC_right_item"><span class="LC_nobreak">'.
8469: '<label><input type="radio" name="categorizeplace"'.
8470: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8471: '<label><input type="radio" name="categorizeplace"'.
8472: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 8473: '</tr>';
1.272 raeburn 8474: $$rowtotal += 6;
1.57 raeburn 8475: } else {
8476: my $css_class;
8477: my $itemcount = 1;
8478: my $cathash;
8479: if (ref($settings) eq 'HASH') {
8480: $cathash = $settings->{'cats'};
8481: }
8482: if (ref($cathash) eq 'HASH') {
8483: my (@cats,@trails,%allitems,%idx,@jsarray);
8484: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8485: \%allitems,\%idx,\@jsarray);
8486: my $maxdepth = scalar(@cats);
8487: my $colattrib = '';
8488: if ($maxdepth > 2) {
8489: $colattrib = ' colspan="2" ';
8490: }
8491: my @path;
8492: if (@cats > 0) {
8493: if (ref($cats[0]) eq 'ARRAY') {
8494: my $numtop = @{$cats[0]};
8495: my $maxnum = $numtop;
1.120 raeburn 8496: my %default_names = (
8497: instcode => &mt('Official courses'),
8498: communities => &mt('Communities'),
1.272 raeburn 8499: placement => &mt('Placement Tests'),
1.120 raeburn 8500: );
8501:
8502: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8503: ($cathash->{'instcode::0'} eq '') ||
8504: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 8505: ($cathash->{'communities::0'} eq '') ||
8506: (!grep(/^placement$/,@{$cats[0]})) ||
8507: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 8508: $maxnum ++;
8509: }
8510: my $lastidx;
8511: for (my $i=0; $i<$numtop; $i++) {
8512: my $parent = $cats[0][$i];
8513: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8514: my $item = &escape($parent).'::0';
8515: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8516: $lastidx = $idx{$item};
8517: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8518: .'<select name="'.$item.'"'.$chgstr.'>';
8519: for (my $k=0; $k<=$maxnum; $k++) {
8520: my $vpos = $k+1;
8521: my $selstr;
8522: if ($k == $i) {
8523: $selstr = ' selected="selected" ';
8524: }
8525: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8526: }
1.214 raeburn 8527: $datatable .= '</select></span></td><td>';
1.272 raeburn 8528: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 8529: $datatable .= '<span class="LC_nobreak">'
8530: .$default_names{$parent}.'</span>';
8531: if ($parent eq 'instcode') {
8532: $datatable .= '<br /><span class="LC_nobreak">('
8533: .&mt('with institutional codes')
8534: .')</span></td><td'.$colattrib.'>';
8535: } else {
8536: $datatable .= '<table><tr><td>';
8537: }
8538: $datatable .= '<span class="LC_nobreak">'
8539: .'<label><input type="radio" name="'
8540: .$parent.'" value="1" checked="checked" />'
8541: .&mt('Display').'</label>';
8542: if ($parent eq 'instcode') {
8543: $datatable .= ' ';
8544: } else {
8545: $datatable .= '</span></td></tr><tr><td>'
8546: .'<span class="LC_nobreak">';
8547: }
8548: $datatable .= '<label><input type="radio" name="'
8549: .$parent.'" value="0" />'
8550: .&mt('Do not display').'</label></span>';
1.272 raeburn 8551: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 8552: $datatable .= '</td></tr></table>';
8553: }
8554: $datatable .= '</td>';
1.57 raeburn 8555: } else {
8556: $datatable .= $parent
1.214 raeburn 8557: .' <span class="LC_nobreak"><label>'
8558: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8559: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8560: }
8561: my $depth = 1;
8562: push(@path,$parent);
8563: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8564: pop(@path);
8565: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8566: $itemcount ++;
8567: }
1.48 raeburn 8568: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8569: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8570: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8571: for (my $k=0; $k<=$maxnum; $k++) {
8572: my $vpos = $k+1;
8573: my $selstr;
1.57 raeburn 8574: if ($k == $numtop) {
1.48 raeburn 8575: $selstr = ' selected="selected" ';
8576: }
8577: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8578: }
1.59 bisitz 8579: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8580: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8581: .'</tr>'."\n";
1.48 raeburn 8582: $itemcount ++;
1.272 raeburn 8583: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8584: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8585: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8586: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8587: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8588: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8589: for (my $k=0; $k<=$maxnum; $k++) {
8590: my $vpos = $k+1;
8591: my $selstr;
8592: if ($k == $maxnum) {
8593: $selstr = ' selected="selected" ';
8594: }
8595: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8596: }
1.120 raeburn 8597: $datatable .= '</select></span></td>'.
8598: '<td><span class="LC_nobreak">'.
8599: $default_names{$default}.'</span>';
8600: if ($default eq 'instcode') {
8601: $datatable .= '<br /><span class="LC_nobreak">('
8602: .&mt('with institutional codes').')</span>';
8603: }
8604: $datatable .= '</td>'
8605: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8606: .&mt('Display').'</label> '
8607: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8608: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8609: }
8610: }
8611: }
1.57 raeburn 8612: } else {
8613: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8614: }
8615: } else {
1.327 raeburn 8616: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 8617: .&initialize_categories($itemcount);
1.48 raeburn 8618: }
1.57 raeburn 8619: $$rowtotal += $itemcount;
1.48 raeburn 8620: }
8621: return $datatable;
8622: }
8623:
1.69 raeburn 8624: sub print_serverstatuses {
8625: my ($dom,$settings,$rowtotal) = @_;
8626: my $datatable;
8627: my @pages = &serverstatus_pages();
8628: my (%namedaccess,%machineaccess);
8629: foreach my $type (@pages) {
8630: $namedaccess{$type} = '';
8631: $machineaccess{$type}= '';
8632: }
8633: if (ref($settings) eq 'HASH') {
8634: foreach my $type (@pages) {
8635: if (exists($settings->{$type})) {
8636: if (ref($settings->{$type}) eq 'HASH') {
8637: foreach my $key (keys(%{$settings->{$type}})) {
8638: if ($key eq 'namedusers') {
8639: $namedaccess{$type} = $settings->{$type}->{$key};
8640: } elsif ($key eq 'machines') {
8641: $machineaccess{$type} = $settings->{$type}->{$key};
8642: }
8643: }
8644: }
8645: }
8646: }
8647: }
1.81 raeburn 8648: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8649: my $rownum = 0;
8650: my $css_class;
8651: foreach my $type (@pages) {
8652: $rownum ++;
8653: $css_class = $rownum%2?' class="LC_odd_row"':'';
8654: $datatable .= '<tr'.$css_class.'>'.
8655: '<td><span class="LC_nobreak">'.
8656: $titles->{$type}.'</span></td>'.
8657: '<td class="LC_left_item">'.
8658: '<input type="text" name="'.$type.'_namedusers" '.
8659: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8660: '<td class="LC_right_item">'.
8661: '<span class="LC_nobreak">'.
8662: '<input type="text" name="'.$type.'_machines" '.
8663: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 8664: '</span></td></tr>'."\n";
1.69 raeburn 8665: }
8666: $$rowtotal += $rownum;
8667: return $datatable;
8668: }
8669:
8670: sub serverstatus_pages {
8671: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 8672: 'checksums','clusterstatus','certstatus','metadata_keywords',
8673: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
8674: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8675: }
8676:
1.236 raeburn 8677: sub defaults_javascript {
8678: my ($settings) = @_;
1.294 raeburn 8679: 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.');
8680: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
8681: &js_escape(\$intauthcheck);
8682: &js_escape(\$intauthcost);
8683: my $intauthjs = <<"ENDSCRIPT";
8684:
8685: function warnIntAuth(field) {
8686: if (field.name == 'intauth_check') {
8687: if (field.value == '2') {
8688: alert('$intauthcheck');
8689: }
8690: }
8691: if (field.name == 'intauth_cost') {
8692: field.value.replace(/\s/g,'');
8693: if (field.value != '') {
8694: var regexdigit=/^\\d+\$/;
8695: if (!regexdigit.test(field.value)) {
8696: alert('$intauthcost');
8697: }
8698: }
8699: }
8700: return;
8701: }
8702:
8703: ENDSCRIPT
8704:
8705: if (ref($settings) ne 'HASH') {
8706: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8707: }
1.236 raeburn 8708: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8709: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8710: if ($maxnum eq '') {
8711: $maxnum = 0;
8712: }
8713: $maxnum ++;
1.249 raeburn 8714: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 8715: return <<"ENDSCRIPT";
8716: <script type="text/javascript">
8717: // <![CDATA[
8718: function reorderTypes(form,caller) {
8719: var changedVal;
8720: $jstext
8721: var newpos = 'addinststatus_pos';
8722: var current = new Array;
8723: var maxh = $maxnum;
8724: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8725: var oldVal;
8726: if (caller == newpos) {
8727: changedVal = newitemVal;
8728: } else {
8729: var curritem = 'inststatus_pos_'+caller;
8730: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8731: current[newitemVal] = newpos;
8732: }
8733: for (var i=0; i<inststatuses.length; i++) {
8734: if (inststatuses[i] != caller) {
8735: var elementName = 'inststatus_pos_'+inststatuses[i];
8736: if (form.elements[elementName]) {
8737: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8738: current[currVal] = elementName;
8739: }
8740: }
8741: }
8742: for (var j=0; j<maxh; j++) {
8743: if (current[j] == undefined) {
8744: oldVal = j;
8745: }
8746: }
8747: if (oldVal < changedVal) {
8748: for (var k=oldVal+1; k<=changedVal ; k++) {
8749: var elementName = current[k];
8750: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8751: }
8752: } else {
8753: for (var k=changedVal; k<oldVal; k++) {
8754: var elementName = current[k];
8755: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8756: }
8757: }
8758: return;
8759: }
8760:
1.294 raeburn 8761: $intauthjs
8762:
1.236 raeburn 8763: // ]]>
8764: </script>
8765:
8766: ENDSCRIPT
1.294 raeburn 8767: } else {
8768: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 8769: }
8770: }
8771:
1.49 raeburn 8772: sub coursecategories_javascript {
8773: my ($settings) = @_;
1.57 raeburn 8774: my ($output,$jstext,$cathash);
1.49 raeburn 8775: if (ref($settings) eq 'HASH') {
1.57 raeburn 8776: $cathash = $settings->{'cats'};
8777: }
8778: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8779: my (@cats,@jsarray,%idx);
1.57 raeburn 8780: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8781: if (@jsarray > 0) {
8782: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8783: for (my $i=0; $i<@jsarray; $i++) {
8784: if (ref($jsarray[$i]) eq 'ARRAY') {
8785: my $catstr = join('","',@{$jsarray[$i]});
8786: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8787: }
8788: }
8789: }
8790: } else {
8791: $jstext = ' var categories = Array(1);'."\n".
8792: ' categories[0] = Array("instcode_pos");'."\n";
8793: }
1.237 bisitz 8794: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8795: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 8796: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 8797: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8798: &js_escape(\$instcode_reserved);
8799: &js_escape(\$communities_reserved);
1.272 raeburn 8800: &js_escape(\$placement_reserved);
1.265 damieng 8801: &js_escape(\$choose_again);
1.49 raeburn 8802: $output = <<"ENDSCRIPT";
8803: <script type="text/javascript">
1.109 raeburn 8804: // <![CDATA[
1.49 raeburn 8805: function reorderCats(form,parent,item,idx) {
8806: var changedVal;
8807: $jstext
8808: var newpos = 'addcategory_pos';
8809: if (parent == '') {
8810: var has_instcode = 0;
8811: var maxtop = categories[idx].length;
8812: for (var j=0; j<maxtop; j++) {
8813: if (categories[idx][j] == 'instcode::0') {
8814: has_instcode == 1;
8815: }
8816: }
8817: if (has_instcode == 0) {
8818: categories[idx][maxtop] = 'instcode_pos';
8819: }
8820: } else {
8821: newpos += '_'+parent;
8822: }
8823: var maxh = 1 + categories[idx].length;
8824: var current = new Array;
8825: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8826: if (item == newpos) {
8827: changedVal = newitemVal;
8828: } else {
8829: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8830: current[newitemVal] = newpos;
8831: }
8832: for (var i=0; i<categories[idx].length; i++) {
8833: var elementName = categories[idx][i];
8834: if (elementName != item) {
8835: if (form.elements[elementName]) {
8836: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8837: current[currVal] = elementName;
8838: }
8839: }
8840: }
8841: var oldVal;
8842: for (var j=0; j<maxh; j++) {
8843: if (current[j] == undefined) {
8844: oldVal = j;
8845: }
8846: }
8847: if (oldVal < changedVal) {
8848: for (var k=oldVal+1; k<=changedVal ; k++) {
8849: var elementName = current[k];
8850: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8851: }
8852: } else {
8853: for (var k=changedVal; k<oldVal; k++) {
8854: var elementName = current[k];
8855: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8856: }
8857: }
8858: return;
8859: }
1.120 raeburn 8860:
8861: function categoryCheck(form) {
8862: if (form.elements['addcategory_name'].value == 'instcode') {
8863: alert('$instcode_reserved\\n$choose_again');
8864: return false;
8865: }
8866: if (form.elements['addcategory_name'].value == 'communities') {
8867: alert('$communities_reserved\\n$choose_again');
8868: return false;
8869: }
1.272 raeburn 8870: if (form.elements['addcategory_name'].value == 'placement') {
8871: alert('$placement_reserved\\n$choose_again');
8872: return false;
8873: }
1.120 raeburn 8874: return true;
8875: }
8876:
1.109 raeburn 8877: // ]]>
1.49 raeburn 8878: </script>
8879:
8880: ENDSCRIPT
8881: return $output;
8882: }
8883:
1.48 raeburn 8884: sub initialize_categories {
8885: my ($itemcount) = @_;
1.120 raeburn 8886: my ($datatable,$css_class,$chgstr);
8887: my %default_names = (
8888: instcode => 'Official courses (with institutional codes)',
8889: communities => 'Communities',
1.272 raeburn 8890: placement => 'Placement Tests',
1.120 raeburn 8891: );
1.328 raeburn 8892: my %selnum = (
8893: instcode => '0',
8894: communities => '1',
8895: placement => '2',
8896: );
8897: my %selected;
1.272 raeburn 8898: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8899: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 8900: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 8901: map { $selected{$selnum{$_}} = '' } keys(%selnum);
8902: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 8903: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 8904: .'<select name="'.$default.'_pos"'.$chgstr.'>'
8905: .'<option value="0"'.$selected{'0'}.'>1</option>'
8906: .'<option value="1"'.$selected{'1'}.'>2</option>'
8907: .'<option value="2"'.$selected{'2'}.'>3</option>'
8908: .'<option value="3">4</option></select> '
1.120 raeburn 8909: .$default_names{$default}
8910: .'</span></td><td><span class="LC_nobreak">'
8911: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8912: .&mt('Display').'</label> <label>'
8913: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8914: .'</label></span></td></tr>';
1.120 raeburn 8915: $itemcount ++;
8916: }
1.48 raeburn 8917: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8918: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8919: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8920: .'<select name="addcategory_pos"'.$chgstr.'>'
8921: .'<option value="0">1</option>'
8922: .'<option value="1">2</option>'
1.328 raeburn 8923: .'<option value="2">3</option>'
8924: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 8925: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
8926: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8927: .'</td></tr>';
1.48 raeburn 8928: return $datatable;
8929: }
8930:
8931: sub build_category_rows {
1.49 raeburn 8932: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8933: my ($text,$name,$item,$chgstr);
1.48 raeburn 8934: if (ref($cats) eq 'ARRAY') {
8935: my $maxdepth = scalar(@{$cats});
8936: if (ref($cats->[$depth]) eq 'HASH') {
8937: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8938: my $numchildren = @{$cats->[$depth]{$parent}};
8939: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 8940: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8941: my ($idxnum,$parent_name,$parent_item);
8942: my $higher = $depth - 1;
8943: if ($higher == 0) {
8944: $parent_name = &escape($parent).'::'.$higher;
8945: } else {
8946: if (ref($path) eq 'ARRAY') {
8947: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8948: }
8949: }
8950: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8951: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8952: if ($j < $numchildren) {
1.48 raeburn 8953: $name = $cats->[$depth]{$parent}[$j];
8954: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8955: $idxnum = $idx->{$item};
8956: } else {
8957: $name = $parent_name;
8958: $item = $parent_item;
1.48 raeburn 8959: }
1.49 raeburn 8960: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8961: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8962: for (my $i=0; $i<=$numchildren; $i++) {
8963: my $vpos = $i+1;
8964: my $selstr;
8965: if ($j == $i) {
8966: $selstr = ' selected="selected" ';
8967: }
8968: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8969: }
8970: $text .= '</select> ';
8971: if ($j < $numchildren) {
8972: my $deeper = $depth+1;
8973: $text .= $name.' '
8974: .'<label><input type="checkbox" name="deletecategory" value="'
8975: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8976: if(ref($path) eq 'ARRAY') {
8977: push(@{$path},$name);
1.49 raeburn 8978: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8979: pop(@{$path});
8980: }
8981: } else {
1.330 raeburn 8982: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 8983: if ($j == $numchildren) {
8984: $text .= $name;
8985: } else {
8986: $text .= $item;
8987: }
8988: $text .= '" value="" />';
8989: }
8990: $text .= '</td></tr>';
8991: }
8992: $text .= '</table></td>';
8993: } else {
8994: my $higher = $depth-1;
8995: if ($higher == 0) {
8996: $name = &escape($parent).'::'.$higher;
8997: } else {
8998: if (ref($path) eq 'ARRAY') {
8999: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9000: }
9001: }
9002: my $colspan;
9003: if ($parent ne 'instcode') {
9004: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 9005: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 9006: }
9007: }
9008: }
9009: }
9010: return $text;
9011: }
9012:
1.33 raeburn 9013: sub modifiable_userdata_row {
1.305 raeburn 9014: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
9015: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 9016: my ($role,$rolename,$statustype);
9017: $role = $item;
1.224 raeburn 9018: if ($context eq 'cancreate') {
1.305 raeburn 9019: if ($item =~ /^(emailusername)_(.+)$/) {
9020: $role = $1;
9021: $statustype = $2;
1.228 raeburn 9022: if (ref($usertypes) eq 'HASH') {
9023: if ($usertypes->{$statustype}) {
9024: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
9025: } else {
9026: $rolename = &mt('Data provided by user');
9027: }
9028: }
1.224 raeburn 9029: }
9030: } elsif ($context eq 'selfcreate') {
1.63 raeburn 9031: if (ref($usertypes) eq 'HASH') {
9032: $rolename = $usertypes->{$role};
9033: } else {
9034: $rolename = $role;
9035: }
1.325 raeburn 9036: } elsif ($context eq 'lti') {
9037: $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 9038: } else {
1.63 raeburn 9039: if ($role eq 'cr') {
9040: $rolename = &mt('Custom role');
9041: } else {
9042: $rolename = &Apache::lonnet::plaintext($role);
9043: }
1.33 raeburn 9044: }
1.224 raeburn 9045: my (@fields,%fieldtitles);
9046: if (ref($fieldsref) eq 'ARRAY') {
9047: @fields = @{$fieldsref};
9048: } else {
9049: @fields = ('lastname','firstname','middlename','generation',
9050: 'permanentemail','id');
9051: }
9052: if ((ref($titlesref) eq 'HASH')) {
9053: %fieldtitles = %{$titlesref};
9054: } else {
9055: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9056: }
1.33 raeburn 9057: my $output;
1.305 raeburn 9058: my $css_class;
9059: if ($rowcount%2) {
9060: $css_class = 'LC_odd_row';
9061: }
9062: if ($customcss) {
9063: $css_class .= " $customcss";
9064: }
9065: $css_class =~ s/^\s+//;
9066: if ($css_class) {
9067: $css_class = ' class="'.$css_class.'"';
9068: }
9069: if ($rowstyle) {
9070: $css_class .= ' style="'.$rowstyle.'"';
9071: }
9072: if ($rowid) {
9073: $rowid = ' id="'.$rowid.'"';
9074: }
9075: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 9076: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
9077: '<td class="LC_left_item" colspan="2"><table>';
9078: my $rem;
9079: my %checks;
1.325 raeburn 9080: my %current;
1.33 raeburn 9081: if (ref($settings) eq 'HASH') {
1.325 raeburn 9082: my $hashref;
9083: if ($context eq 'lti') {
9084: if (ref($settings) eq 'HASH') {
9085: $hashref = $settings->{'instdata'};
9086: }
9087: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 9088: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 9089: $hashref = $settings->{'lti_instdata'};
9090: }
9091: if ($role eq 'emailusername') {
9092: if ($statustype) {
9093: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
9094: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 9095: }
1.325 raeburn 9096: }
9097: }
9098: }
9099: if (ref($hashref) eq 'HASH') {
9100: foreach my $field (@fields) {
9101: if ($hashref->{$field}) {
9102: if ($role eq 'emailusername') {
9103: $checks{$field} = $hashref->{$field};
9104: } else {
9105: $checks{$field} = ' checked="checked" ';
1.33 raeburn 9106: }
9107: }
9108: }
9109: }
9110: }
1.305 raeburn 9111:
9112: my $total = scalar(@fields);
9113: for (my $i=0; $i<$total; $i++) {
9114: $rem = $i%($numinrow);
1.33 raeburn 9115: if ($rem == 0) {
9116: if ($i > 0) {
9117: $output .= '</tr>';
9118: }
9119: $output .= '<tr>';
9120: }
9121: my $check = ' ';
1.228 raeburn 9122: unless ($role eq 'emailusername') {
9123: if (exists($checks{$fields[$i]})) {
9124: $check = $checks{$fields[$i]}
1.325 raeburn 9125: } elsif ($context ne 'lti') {
1.228 raeburn 9126: if ($role eq 'st') {
9127: if (ref($settings) ne 'HASH') {
9128: $check = ' checked="checked" ';
9129: }
1.33 raeburn 9130: }
9131: }
9132: }
9133: $output .= '<td class="LC_left_item">'.
1.228 raeburn 9134: '<span class="LC_nobreak">';
1.325 raeburn 9135: my $prefix = 'canmodify';
1.228 raeburn 9136: if ($role eq 'emailusername') {
9137: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
9138: $checks{$fields[$i]} = 'omit';
9139: }
9140: foreach my $option ('required','optional','omit') {
9141: my $checked='';
9142: if ($checks{$fields[$i]} eq $option) {
9143: $checked='checked="checked" ';
9144: }
9145: $output .= '<label>'.
1.325 raeburn 9146: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 9147: &mt($option).'</label>'.(' ' x2);
9148: }
9149: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
9150: } else {
1.325 raeburn 9151: if ($context eq 'lti') {
9152: $prefix = 'lti';
9153: }
1.228 raeburn 9154: $output .= '<label>'.
1.325 raeburn 9155: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 9156: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
9157: '</label>';
9158: }
9159: $output .= '</span></td>';
1.33 raeburn 9160: }
1.305 raeburn 9161: $rem = $total%$numinrow;
9162: my $colsleft;
9163: if ($rem) {
9164: $colsleft = $numinrow - $rem;
9165: }
9166: if ($colsleft > 1) {
1.33 raeburn 9167: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9168: ' </td>';
9169: } elsif ($colsleft == 1) {
9170: $output .= '<td class="LC_left_item"> </td>';
9171: }
9172: $output .= '</tr></table></td></tr>';
9173: return $output;
9174: }
1.28 raeburn 9175:
1.93 raeburn 9176: sub insttypes_row {
1.305 raeburn 9177: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
9178: $customcss,$rowstyle) = @_;
1.93 raeburn 9179: my %lt = &Apache::lonlocal::texthash (
9180: cansearch => 'Users allowed to search',
9181: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 9182: lockablenames => 'User preference to lock name',
1.305 raeburn 9183: selfassign => 'Self-reportable affiliations',
1.315 raeburn 9184: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 9185: );
9186: my $showdom;
9187: if ($context eq 'cansearch') {
9188: $showdom = ' ('.$dom.')';
9189: }
1.165 raeburn 9190: my $class = 'LC_left_item';
9191: if ($context eq 'statustocreate') {
9192: $class = 'LC_right_item';
9193: }
1.305 raeburn 9194: my $css_class;
9195: if ($$rowtotal%2) {
9196: $css_class = 'LC_odd_row';
9197: }
9198: if ($customcss) {
9199: $css_class .= ' '.$customcss;
9200: }
9201: $css_class =~ s/^\s+//;
9202: if ($css_class) {
9203: $css_class = ' class="'.$css_class.'"';
9204: }
9205: if ($rowstyle) {
9206: $css_class .= ' style="'.$rowstyle.'"';
9207: }
9208: if ($onclick) {
9209: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 9210: }
9211: my $output = '<tr'.$css_class.'>'.
9212: '<td>'.$lt{$context}.$showdom.
9213: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 9214: my $rem;
9215: if (ref($types) eq 'ARRAY') {
9216: for (my $i=0; $i<@{$types}; $i++) {
9217: if (defined($usertypes->{$types->[$i]})) {
9218: my $rem = $i%($numinrow);
9219: if ($rem == 0) {
9220: if ($i > 0) {
9221: $output .= '</tr>';
9222: }
9223: $output .= '<tr>';
1.23 raeburn 9224: }
1.26 raeburn 9225: my $check = ' ';
1.99 raeburn 9226: if (ref($settings) eq 'HASH') {
9227: if (ref($settings->{$context}) eq 'ARRAY') {
9228: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
9229: $check = ' checked="checked" ';
9230: }
1.315 raeburn 9231: } elsif (ref($settings->{$context}) eq 'HASH') {
9232: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
9233: $check = ' checked="checked" ';
9234: }
1.99 raeburn 9235: } elsif ($context eq 'statustocreate') {
1.26 raeburn 9236: $check = ' checked="checked" ';
9237: }
1.23 raeburn 9238: }
1.26 raeburn 9239: $output .= '<td class="LC_left_item">'.
9240: '<span class="LC_nobreak"><label>'.
1.93 raeburn 9241: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 9242: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 9243: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 9244: }
9245: }
1.26 raeburn 9246: $rem = @{$types}%($numinrow);
1.23 raeburn 9247: }
9248: my $colsleft = $numinrow - $rem;
1.315 raeburn 9249: if ($context eq 'overrides') {
9250: if ($colsleft > 1) {
9251: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9252: } else {
9253: $output .= '<td class="LC_left_item">';
9254: }
9255: $output .= ' ';
1.23 raeburn 9256: } else {
1.334 raeburn 9257: if ($rem == 0) {
1.315 raeburn 9258: $output .= '<tr>';
9259: }
9260: if ($colsleft > 1) {
9261: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9262: } else {
9263: $output .= '<td class="LC_left_item">';
9264: }
9265: my $defcheck = ' ';
9266: if (ref($settings) eq 'HASH') {
9267: if (ref($settings->{$context}) eq 'ARRAY') {
9268: if (grep(/^default$/,@{$settings->{$context}})) {
9269: $defcheck = ' checked="checked" ';
9270: }
9271: } elsif ($context eq 'statustocreate') {
1.99 raeburn 9272: $defcheck = ' checked="checked" ';
9273: }
1.26 raeburn 9274: }
1.315 raeburn 9275: $output .= '<span class="LC_nobreak"><label>'.
9276: '<input type="checkbox" name="'.$context.'" '.
9277: 'value="default"'.$defcheck.$onclick.' />'.
9278: $othertitle.'</label></span>';
1.23 raeburn 9279: }
1.315 raeburn 9280: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 9281: return $output;
1.23 raeburn 9282: }
9283:
9284: sub sorted_searchtitles {
9285: my %searchtitles = &Apache::lonlocal::texthash(
9286: 'uname' => 'username',
9287: 'lastname' => 'last name',
9288: 'lastfirst' => 'last name, first name',
9289: );
9290: my @titleorder = ('uname','lastname','lastfirst');
9291: return (\%searchtitles,\@titleorder);
9292: }
9293:
1.25 raeburn 9294: sub sorted_searchtypes {
9295: my %srchtypes_desc = (
9296: exact => 'is exact match',
9297: contains => 'contains ..',
9298: begins => 'begins with ..',
9299: );
9300: my @srchtypeorder = ('exact','begins','contains');
9301: return (\%srchtypes_desc,\@srchtypeorder);
9302: }
9303:
1.3 raeburn 9304: sub usertype_update_row {
9305: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9306: my $datatable;
9307: my $numinrow = 4;
9308: foreach my $type (@{$types}) {
9309: if (defined($usertypes->{$type})) {
9310: $$rownums ++;
9311: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9312: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9313: '</td><td class="LC_left_item"><table>';
9314: for (my $i=0; $i<@{$fields}; $i++) {
9315: my $rem = $i%($numinrow);
9316: if ($rem == 0) {
9317: if ($i > 0) {
9318: $datatable .= '</tr>';
9319: }
9320: $datatable .= '<tr>';
9321: }
9322: my $check = ' ';
1.39 raeburn 9323: if (ref($settings) eq 'HASH') {
9324: if (ref($settings->{'fields'}) eq 'HASH') {
9325: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9326: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9327: $check = ' checked="checked" ';
9328: }
1.3 raeburn 9329: }
9330: }
9331: }
9332:
9333: if ($i == @{$fields}-1) {
9334: my $colsleft = $numinrow - $rem;
9335: if ($colsleft > 1) {
9336: $datatable .= '<td colspan="'.$colsleft.'">';
9337: } else {
9338: $datatable .= '<td>';
9339: }
9340: } else {
9341: $datatable .= '<td>';
9342: }
1.8 raeburn 9343: $datatable .= '<span class="LC_nobreak"><label>'.
9344: '<input type="checkbox" name="updateable_'.$type.
9345: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9346: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 9347: }
9348: $datatable .= '</tr></table></td></tr>';
9349: }
9350: }
9351: return $datatable;
1.1 raeburn 9352: }
9353:
9354: sub modify_login {
1.205 raeburn 9355: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 9356: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
9357: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
9358: %title = ( coursecatalog => 'Display course catalog',
9359: adminmail => 'Display administrator E-mail address',
1.188 raeburn 9360: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 9361: newuser => 'Link for visitors to create a user account',
9362: loginheader => 'Log-in box header');
9363: @offon = ('off','on');
1.112 raeburn 9364: if (ref($domconfig{login}) eq 'HASH') {
9365: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9366: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9367: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9368: }
9369: }
9370: }
1.9 raeburn 9371: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9372: \%domconfig,\%loginhash);
1.188 raeburn 9373: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9374: foreach my $item (@toggles) {
9375: $loginhash{login}{$item} = $env{'form.'.$item};
9376: }
1.41 raeburn 9377: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 9378: if (ref($colchanges{'login'}) eq 'HASH') {
9379: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9380: \%loginhash);
9381: }
1.110 raeburn 9382:
1.149 raeburn 9383: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 9384: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 9385: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 9386: if (keys(%servers) > 1) {
9387: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 9388: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9389: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9390: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9391: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9392: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9393: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9394: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9395: $changes{'loginvia'}{$lonhost} = 1;
9396: } else {
9397: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9398: $changes{'loginvia'}{$lonhost} = 1;
9399: }
9400: } else {
9401: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9402: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9403: $changes{'loginvia'}{$lonhost} = 1;
9404: }
9405: }
9406: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9407: foreach my $item (@loginvia_attribs) {
9408: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9409: }
9410: } else {
9411: foreach my $item (@loginvia_attribs) {
9412: my $new = $env{'form.'.$lonhost.'_'.$item};
9413: if (($item eq 'serverpath') && ($new eq 'custom')) {
9414: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9415: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9416: $new = '/';
9417: }
9418: }
9419: if (($item eq 'custompath') &&
9420: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9421: $new = '';
9422: }
9423: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9424: $changes{'loginvia'}{$lonhost} = 1;
9425: }
9426: if ($item eq 'exempt') {
1.256 raeburn 9427: $new = &check_exempt_addresses($new);
1.128 raeburn 9428: }
9429: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9430: }
9431: }
1.112 raeburn 9432: } else {
1.128 raeburn 9433: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9434: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9435: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9436: foreach my $item (@loginvia_attribs) {
9437: my $new = $env{'form.'.$lonhost.'_'.$item};
9438: if (($item eq 'serverpath') && ($new eq 'custom')) {
9439: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9440: $new = '/';
9441: }
9442: }
9443: if (($item eq 'custompath') &&
9444: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9445: $new = '';
9446: }
9447: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9448: }
1.110 raeburn 9449: }
9450: }
9451: }
9452: }
1.119 raeburn 9453:
1.168 raeburn 9454: my $servadm = $r->dir_config('lonAdmEMail');
9455: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9456: if (ref($domconfig{'login'}) eq 'HASH') {
9457: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9458: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9459: if ($lang eq 'nolang') {
9460: push(@currlangs,$lang);
9461: } elsif (defined($langchoices{$lang})) {
9462: push(@currlangs,$lang);
9463: } else {
9464: next;
9465: }
9466: }
9467: }
9468: }
9469: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9470: if (@currlangs > 0) {
9471: foreach my $lang (@currlangs) {
9472: if (grep(/^\Q$lang\E$/,@delurls)) {
9473: $changes{'helpurl'}{$lang} = 1;
9474: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9475: $changes{'helpurl'}{$lang} = 1;
9476: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9477: push(@newlangs,$lang);
9478: } else {
9479: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9480: }
9481: }
9482: }
9483: unless (grep(/^nolang$/,@currlangs)) {
9484: if ($env{'form.loginhelpurl_nolang.filename'}) {
9485: $changes{'helpurl'}{'nolang'} = 1;
9486: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9487: push(@newlangs,'nolang');
9488: }
9489: }
9490: if ($env{'form.loginhelpurl_add_lang'}) {
9491: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9492: ($env{'form.loginhelpurl_add_file.filename'})) {
9493: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9494: $addedfile = $env{'form.loginhelpurl_add_lang'};
9495: }
9496: }
9497: if ((@newlangs > 0) || ($addedfile)) {
9498: my $error;
9499: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9500: if ($configuserok eq 'ok') {
9501: if ($switchserver) {
9502: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9503: } elsif ($author_ok eq 'ok') {
9504: my @allnew = @newlangs;
9505: if ($addedfile ne '') {
9506: push(@allnew,$addedfile);
9507: }
9508: foreach my $lang (@allnew) {
9509: my $formelem = 'loginhelpurl_'.$lang;
9510: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9511: $formelem = 'loginhelpurl_add_file';
9512: }
9513: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9514: "help/$lang",'','',$newfile{$lang});
9515: if ($result eq 'ok') {
9516: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9517: $changes{'helpurl'}{$lang} = 1;
9518: } else {
9519: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9520: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 9521: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 9522: (!grep(/^\Q$lang\E$/,@delurls))) {
9523: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9524: }
9525: }
9526: }
9527: } else {
9528: $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);
9529: }
9530: } else {
9531: $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);
9532: }
9533: if ($error) {
9534: &Apache::lonnet::logthis($error);
9535: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9536: }
9537: }
1.256 raeburn 9538:
9539: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9540: if (ref($domconfig{'login'}) eq 'HASH') {
9541: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9542: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9543: if ($domservers{$lonhost}) {
9544: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9545: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 9546: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 9547: }
9548: }
9549: }
9550: }
9551: }
9552: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9553: foreach my $lonhost (sort(keys(%domservers))) {
9554: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9555: $changes{'headtag'}{$lonhost} = 1;
9556: } else {
9557: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9558: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9559: }
9560: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9561: push(@newhosts,$lonhost);
9562: } elsif ($currheadtagurls{$lonhost}) {
9563: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9564: if ($currexempt{$lonhost}) {
1.289 raeburn 9565: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 9566: $changes{'headtag'}{$lonhost} = 1;
9567: }
9568: } elsif ($possexempt{$lonhost}) {
9569: $changes{'headtag'}{$lonhost} = 1;
9570: }
9571: if ($possexempt{$lonhost}) {
9572: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9573: }
9574: }
9575: }
9576: }
9577: if (@newhosts) {
9578: my $error;
9579: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9580: if ($configuserok eq 'ok') {
9581: if ($switchserver) {
9582: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9583: } elsif ($author_ok eq 'ok') {
9584: foreach my $lonhost (@newhosts) {
9585: my $formelem = 'loginheadtag_'.$lonhost;
9586: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9587: "login/headtag/$lonhost",'','',
9588: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9589: if ($result eq 'ok') {
9590: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9591: $changes{'headtag'}{$lonhost} = 1;
9592: if ($possexempt{$lonhost}) {
9593: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9594: }
9595: } else {
9596: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9597: $newheadtagurls{$lonhost},$result);
9598: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9599: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9600: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9601: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9602: }
9603: }
9604: }
9605: } else {
9606: $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);
9607: }
9608: } else {
9609: $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);
9610: }
9611: if ($error) {
9612: &Apache::lonnet::logthis($error);
9613: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9614: }
9615: }
1.169 raeburn 9616: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 9617:
9618: my $defaulthelpfile = '/adm/loginproblems.html';
9619: my $defaulttext = &mt('Default in use');
9620:
1.1 raeburn 9621: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9622: $dom);
9623: if ($putresult eq 'ok') {
1.188 raeburn 9624: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9625: my %defaultchecked = (
9626: 'coursecatalog' => 'on',
1.188 raeburn 9627: 'helpdesk' => 'on',
1.42 raeburn 9628: 'adminmail' => 'off',
1.43 raeburn 9629: 'newuser' => 'off',
1.42 raeburn 9630: );
1.55 raeburn 9631: if (ref($domconfig{'login'}) eq 'HASH') {
9632: foreach my $item (@toggles) {
9633: if ($defaultchecked{$item} eq 'on') {
9634: if (($domconfig{'login'}{$item} eq '0') &&
9635: ($env{'form.'.$item} eq '1')) {
9636: $changes{$item} = 1;
9637: } elsif (($domconfig{'login'}{$item} eq '' ||
9638: $domconfig{'login'}{$item} eq '1') &&
9639: ($env{'form.'.$item} eq '0')) {
9640: $changes{$item} = 1;
9641: }
9642: } elsif ($defaultchecked{$item} eq 'off') {
9643: if (($domconfig{'login'}{$item} eq '1') &&
9644: ($env{'form.'.$item} eq '0')) {
9645: $changes{$item} = 1;
9646: } elsif (($domconfig{'login'}{$item} eq '' ||
9647: $domconfig{'login'}{$item} eq '0') &&
9648: ($env{'form.'.$item} eq '1')) {
9649: $changes{$item} = 1;
9650: }
1.42 raeburn 9651: }
9652: }
1.41 raeburn 9653: }
1.6 raeburn 9654: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9655: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9656: if (ref($lastactref) eq 'HASH') {
9657: $lastactref->{'domainconfig'} = 1;
9658: }
1.1 raeburn 9659: $resulttext = &mt('Changes made:').'<ul>';
9660: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9661: if ($item eq 'loginvia') {
1.112 raeburn 9662: if (ref($changes{$item}) eq 'HASH') {
9663: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9664: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9665: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9666: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9667: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9668: $protocol = 'http' if ($protocol ne 'https');
9669: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9670:
9671: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9672: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9673: } else {
9674: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9675: }
9676: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9677: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9678: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9679: }
9680: $resulttext .= '</li>';
9681: } else {
9682: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9683: }
1.112 raeburn 9684: } else {
1.128 raeburn 9685: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9686: }
9687: }
1.128 raeburn 9688: $resulttext .= '</ul></li>';
1.112 raeburn 9689: }
1.168 raeburn 9690: } elsif ($item eq 'helpurl') {
9691: if (ref($changes{$item}) eq 'HASH') {
9692: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9693: if (grep(/^\Q$lang\E$/,@delurls)) {
9694: my ($chg,$link);
9695: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9696: if ($lang eq 'nolang') {
9697: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9698: } else {
9699: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9700: }
9701: $resulttext .= '<li>'.$chg.'</li>';
9702: } else {
9703: my $chg;
9704: if ($lang eq 'nolang') {
9705: $chg = &mt('custom log-in help file for no preferred language');
9706: } else {
9707: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9708: }
9709: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9710: $loginhash{'login'}{'helpurl'}{$lang}.
9711: '?inhibitmenu=yes',$chg,600,500).
9712: '</li>';
9713: }
9714: }
9715: }
1.256 raeburn 9716: } elsif ($item eq 'headtag') {
9717: if (ref($changes{$item}) eq 'HASH') {
9718: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9719: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9720: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9721: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9722: $resulttext .= '<li><a href="'.
9723: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9724: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9725: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9726: if ($possexempt{$lonhost}) {
9727: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9728: } else {
9729: $resulttext .= &mt('included for any client IP');
9730: }
9731: $resulttext .= '</li>';
9732: }
9733: }
9734: }
1.169 raeburn 9735: } elsif ($item eq 'captcha') {
9736: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 9737: my $chgtxt;
1.169 raeburn 9738: if ($loginhash{'login'}{$item} eq 'notused') {
9739: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9740: } else {
9741: my %captchas = &captcha_phrases();
9742: if ($captchas{$loginhash{'login'}{$item}}) {
9743: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9744: } else {
9745: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9746: }
9747: }
9748: $resulttext .= '<li>'.$chgtxt.'</li>';
9749: }
9750: } elsif ($item eq 'recaptchakeys') {
9751: if (ref($loginhash{'login'}) eq 'HASH') {
9752: my ($privkey,$pubkey);
9753: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9754: $pubkey = $loginhash{'login'}{$item}{'public'};
9755: $privkey = $loginhash{'login'}{$item}{'private'};
9756: }
9757: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9758: if (!$pubkey) {
9759: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9760: } else {
9761: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9762: }
9763: if (!$privkey) {
9764: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9765: } else {
1.251 raeburn 9766: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 9767: }
9768: $chgtxt .= '</ul>';
9769: $resulttext .= '<li>'.$chgtxt.'</li>';
9770: }
1.269 raeburn 9771: } elsif ($item eq 'recaptchaversion') {
9772: if (ref($loginhash{'login'}) eq 'HASH') {
9773: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 9774: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 9775: '</li>';
9776: }
9777: }
1.41 raeburn 9778: } else {
9779: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9780: }
1.1 raeburn 9781: }
1.6 raeburn 9782: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9783: } else {
9784: $resulttext = &mt('No changes made to log-in page settings');
9785: }
9786: } else {
1.11 albertel 9787: $resulttext = '<span class="LC_error">'.
9788: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9789: }
1.6 raeburn 9790: if ($errors) {
1.9 raeburn 9791: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9792: $errors.'</ul>';
9793: }
9794: return $resulttext;
9795: }
9796:
1.256 raeburn 9797: sub check_exempt_addresses {
9798: my ($iplist) = @_;
9799: $iplist =~ s/^\s+//;
9800: $iplist =~ s/\s+$//;
9801: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9802: my (@okips,$new);
9803: foreach my $ip (@poss_ips) {
9804: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9805: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9806: push(@okips,$ip);
9807: }
9808: }
9809: }
9810: if (@okips > 0) {
9811: $new = join(',',@okips);
9812: } else {
9813: $new = '';
9814: }
9815: return $new;
9816: }
9817:
1.6 raeburn 9818: sub color_font_choices {
9819: my %choices =
9820: &Apache::lonlocal::texthash (
9821: img => "Header",
9822: bgs => "Background colors",
9823: links => "Link colors",
1.55 raeburn 9824: images => "Images",
1.6 raeburn 9825: font => "Font color",
1.201 raeburn 9826: fontmenu => "Font menu",
1.76 raeburn 9827: pgbg => "Page",
1.6 raeburn 9828: tabbg => "Header",
9829: sidebg => "Border",
9830: link => "Link",
9831: alink => "Active link",
9832: vlink => "Visited link",
9833: );
9834: return %choices;
9835: }
9836:
9837: sub modify_rolecolors {
1.205 raeburn 9838: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9839: my ($resulttext,%rolehash);
9840: $rolehash{'rolecolors'} = {};
1.55 raeburn 9841: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9842: if ($domconfig{'rolecolors'} eq '') {
9843: $domconfig{'rolecolors'} = {};
9844: }
9845: }
1.9 raeburn 9846: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9847: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9848: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9849: $dom);
9850: if ($putresult eq 'ok') {
9851: if (keys(%changes) > 0) {
1.41 raeburn 9852: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9853: if (ref($lastactref) eq 'HASH') {
9854: $lastactref->{'domainconfig'} = 1;
9855: }
1.6 raeburn 9856: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9857: $rolehash{'rolecolors'});
9858: } else {
9859: $resulttext = &mt('No changes made to default color schemes');
9860: }
9861: } else {
1.11 albertel 9862: $resulttext = '<span class="LC_error">'.
9863: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9864: }
9865: if ($errors) {
9866: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9867: $errors.'</ul>';
9868: }
9869: return $resulttext;
9870: }
9871:
9872: sub modify_colors {
1.9 raeburn 9873: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9874: my (%changes,%choices);
1.51 raeburn 9875: my @bgs;
1.6 raeburn 9876: my @links = ('link','alink','vlink');
1.41 raeburn 9877: my @logintext;
1.6 raeburn 9878: my @images;
9879: my $servadm = $r->dir_config('lonAdmEMail');
9880: my $errors;
1.200 raeburn 9881: my %defaults;
1.6 raeburn 9882: foreach my $role (@{$roles}) {
9883: if ($role eq 'login') {
1.12 raeburn 9884: %choices = &login_choices();
1.41 raeburn 9885: @logintext = ('textcol','bgcol');
1.12 raeburn 9886: } else {
9887: %choices = &color_font_choices();
9888: }
9889: if ($role eq 'login') {
1.41 raeburn 9890: @images = ('img','logo','domlogo','login');
1.51 raeburn 9891: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9892: } else {
9893: @images = ('img');
1.200 raeburn 9894: @bgs = ('pgbg','tabbg','sidebg');
9895: }
9896: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9897: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9898: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9899: }
9900: if ($role eq 'login') {
9901: foreach my $item (@logintext) {
1.234 raeburn 9902: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9903: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9904: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9905: }
9906: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 9907: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9908: }
9909: }
9910: } else {
1.234 raeburn 9911: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9912: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9913: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9914: }
9915: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 9916: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9917: }
1.6 raeburn 9918: }
1.200 raeburn 9919: foreach my $item (@bgs) {
1.234 raeburn 9920: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9921: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9922: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9923: }
9924: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 9925: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9926: }
9927: }
9928: foreach my $item (@links) {
1.234 raeburn 9929: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9930: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9931: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9932: }
9933: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 9934: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9935: }
1.6 raeburn 9936: }
1.46 raeburn 9937: my ($configuserok,$author_ok,$switchserver) =
9938: &config_check($dom,$confname,$servadm);
1.9 raeburn 9939: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 9940: if (ref($domconfig->{$role}) ne 'HASH') {
9941: $domconfig->{$role} = {};
9942: }
1.8 raeburn 9943: foreach my $img (@images) {
1.70 raeburn 9944: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9945: if (defined($env{'form.login_showlogo_'.$img})) {
9946: $confhash->{$role}{'showlogo'}{$img} = 1;
9947: } else {
9948: $confhash->{$role}{'showlogo'}{$img} = 0;
9949: }
9950: }
1.18 albertel 9951: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9952: && !defined($domconfig->{$role}{$img})
9953: && !$env{'form.'.$role.'_del_'.$img}
9954: && $env{'form.'.$role.'_import_'.$img}) {
9955: # import the old configured image from the .tab setting
9956: # if they haven't provided a new one
9957: $domconfig->{$role}{$img} =
9958: $env{'form.'.$role.'_import_'.$img};
9959: }
1.6 raeburn 9960: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9961: my $error;
1.6 raeburn 9962: if ($configuserok eq 'ok') {
1.9 raeburn 9963: if ($switchserver) {
1.12 raeburn 9964: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9965: } else {
9966: if ($author_ok eq 'ok') {
9967: my ($result,$logourl) =
9968: &publishlogo($r,'upload',$role.'_'.$img,
9969: $dom,$confname,$img,$width,$height);
9970: if ($result eq 'ok') {
9971: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9972: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9973: } else {
1.12 raeburn 9974: $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 9975: }
9976: } else {
1.46 raeburn 9977: $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 9978: }
9979: }
9980: } else {
1.46 raeburn 9981: $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 9982: }
9983: if ($error) {
1.8 raeburn 9984: &Apache::lonnet::logthis($error);
1.11 albertel 9985: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9986: }
9987: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9988: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9989: my $error;
9990: if ($configuserok eq 'ok') {
9991: # is confname an author?
9992: if ($switchserver eq '') {
9993: if ($author_ok eq 'ok') {
9994: my ($result,$logourl) =
9995: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9996: $dom,$confname,$img,$width,$height);
9997: if ($result eq 'ok') {
9998: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9999: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10000: }
10001: }
10002: }
10003: }
1.6 raeburn 10004: }
10005: }
10006: }
10007: if (ref($domconfig) eq 'HASH') {
10008: if (ref($domconfig->{$role}) eq 'HASH') {
10009: foreach my $img (@images) {
10010: if ($domconfig->{$role}{$img} ne '') {
10011: if ($env{'form.'.$role.'_del_'.$img}) {
10012: $confhash->{$role}{$img} = '';
1.12 raeburn 10013: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10014: } else {
1.9 raeburn 10015: if ($confhash->{$role}{$img} eq '') {
10016: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
10017: }
1.6 raeburn 10018: }
10019: } else {
10020: if ($env{'form.'.$role.'_del_'.$img}) {
10021: $confhash->{$role}{$img} = '';
1.12 raeburn 10022: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10023: }
10024: }
1.70 raeburn 10025: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
10026: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
10027: if ($confhash->{$role}{'showlogo'}{$img} ne
10028: $domconfig->{$role}{'showlogo'}{$img}) {
10029: $changes{$role}{'showlogo'}{$img} = 1;
10030: }
10031: } else {
10032: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10033: $changes{$role}{'showlogo'}{$img} = 1;
10034: }
10035: }
10036: }
10037: }
1.6 raeburn 10038: if ($domconfig->{$role}{'font'} ne '') {
10039: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
10040: $changes{$role}{'font'} = 1;
10041: }
10042: } else {
10043: if ($confhash->{$role}{'font'}) {
10044: $changes{$role}{'font'} = 1;
10045: }
10046: }
1.107 raeburn 10047: if ($role ne 'login') {
10048: if ($domconfig->{$role}{'fontmenu'} ne '') {
10049: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
10050: $changes{$role}{'fontmenu'} = 1;
10051: }
10052: } else {
10053: if ($confhash->{$role}{'fontmenu'}) {
10054: $changes{$role}{'fontmenu'} = 1;
10055: }
1.97 tempelho 10056: }
10057: }
1.6 raeburn 10058: foreach my $item (@bgs) {
10059: if ($domconfig->{$role}{$item} ne '') {
10060: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10061: $changes{$role}{'bgs'}{$item} = 1;
10062: }
10063: } else {
10064: if ($confhash->{$role}{$item}) {
10065: $changes{$role}{'bgs'}{$item} = 1;
10066: }
10067: }
10068: }
10069: foreach my $item (@links) {
10070: if ($domconfig->{$role}{$item} ne '') {
10071: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10072: $changes{$role}{'links'}{$item} = 1;
10073: }
10074: } else {
10075: if ($confhash->{$role}{$item}) {
10076: $changes{$role}{'links'}{$item} = 1;
10077: }
10078: }
10079: }
1.41 raeburn 10080: foreach my $item (@logintext) {
10081: if ($domconfig->{$role}{$item} ne '') {
10082: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10083: $changes{$role}{'logintext'}{$item} = 1;
10084: }
10085: } else {
10086: if ($confhash->{$role}{$item}) {
10087: $changes{$role}{'logintext'}{$item} = 1;
10088: }
10089: }
10090: }
1.6 raeburn 10091: } else {
10092: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10093: \@logintext,$confhash,\%changes);
1.6 raeburn 10094: }
10095: } else {
10096: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10097: \@logintext,$confhash,\%changes);
1.6 raeburn 10098: }
10099: }
10100: return ($errors,%changes);
10101: }
10102:
1.46 raeburn 10103: sub config_check {
10104: my ($dom,$confname,$servadm) = @_;
10105: my ($configuserok,$author_ok,$switchserver,%currroles);
10106: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
10107: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
10108: $confname,$servadm);
10109: if ($configuserok eq 'ok') {
10110: $switchserver = &check_switchserver($dom,$confname);
10111: if ($switchserver eq '') {
10112: $author_ok = &check_authorstatus($dom,$confname,%currroles);
10113: }
10114: }
10115: return ($configuserok,$author_ok,$switchserver);
10116: }
10117:
1.6 raeburn 10118: sub default_change_checker {
1.41 raeburn 10119: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 10120: foreach my $item (@{$links}) {
10121: if ($confhash->{$role}{$item}) {
10122: $changes->{$role}{'links'}{$item} = 1;
10123: }
10124: }
10125: foreach my $item (@{$bgs}) {
10126: if ($confhash->{$role}{$item}) {
10127: $changes->{$role}{'bgs'}{$item} = 1;
10128: }
10129: }
1.41 raeburn 10130: foreach my $item (@{$logintext}) {
10131: if ($confhash->{$role}{$item}) {
10132: $changes->{$role}{'logintext'}{$item} = 1;
10133: }
10134: }
1.6 raeburn 10135: foreach my $img (@{$images}) {
10136: if ($env{'form.'.$role.'_del_'.$img}) {
10137: $confhash->{$role}{$img} = '';
1.12 raeburn 10138: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 10139: }
1.70 raeburn 10140: if ($role eq 'login') {
10141: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10142: $changes->{$role}{'showlogo'}{$img} = 1;
10143: }
10144: }
1.6 raeburn 10145: }
10146: if ($confhash->{$role}{'font'}) {
10147: $changes->{$role}{'font'} = 1;
10148: }
1.48 raeburn 10149: }
1.6 raeburn 10150:
10151: sub display_colorchgs {
10152: my ($dom,$changes,$roles,$confhash) = @_;
10153: my (%choices,$resulttext);
10154: if (!grep(/^login$/,@{$roles})) {
10155: $resulttext = &mt('Changes made:').'<br />';
10156: }
10157: foreach my $role (@{$roles}) {
10158: if ($role eq 'login') {
10159: %choices = &login_choices();
10160: } else {
10161: %choices = &color_font_choices();
10162: }
10163: if (ref($changes->{$role}) eq 'HASH') {
10164: if ($role ne 'login') {
10165: $resulttext .= '<h4>'.&mt($role).'</h4>';
10166: }
10167: foreach my $key (sort(keys(%{$changes->{$role}}))) {
10168: if ($role ne 'login') {
10169: $resulttext .= '<ul>';
10170: }
10171: if (ref($changes->{$role}{$key}) eq 'HASH') {
10172: if ($role ne 'login') {
10173: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
10174: }
10175: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 10176: if (($role eq 'login') && ($key eq 'showlogo')) {
10177: if ($confhash->{$role}{$key}{$item}) {
10178: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
10179: } else {
10180: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
10181: }
10182: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 10183: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
10184: } else {
1.12 raeburn 10185: my $newitem = $confhash->{$role}{$item};
10186: if ($key eq 'images') {
1.306 raeburn 10187: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 10188: }
10189: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 10190: }
10191: }
10192: if ($role ne 'login') {
10193: $resulttext .= '</ul></li>';
10194: }
10195: } else {
10196: if ($confhash->{$role}{$key} eq '') {
10197: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
10198: } else {
10199: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
10200: }
10201: }
10202: if ($role ne 'login') {
10203: $resulttext .= '</ul>';
10204: }
10205: }
10206: }
10207: }
1.3 raeburn 10208: return $resulttext;
1.1 raeburn 10209: }
10210:
1.9 raeburn 10211: sub thumb_dimensions {
10212: return ('200','50');
10213: }
10214:
1.16 raeburn 10215: sub check_dimensions {
10216: my ($inputfile) = @_;
10217: my ($fullwidth,$fullheight);
10218: if ($inputfile =~ m|^[/\w.\-]+$|) {
10219: if (open(PIPE,"identify $inputfile 2>&1 |")) {
10220: my $imageinfo = <PIPE>;
10221: if (!close(PIPE)) {
10222: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
10223: }
10224: chomp($imageinfo);
10225: my ($fullsize) =
1.21 raeburn 10226: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 10227: if ($fullsize) {
10228: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10229: }
10230: }
10231: }
10232: return ($fullwidth,$fullheight);
10233: }
10234:
1.9 raeburn 10235: sub check_configuser {
10236: my ($uhome,$dom,$confname,$servadm) = @_;
10237: my ($configuserok,%currroles);
10238: if ($uhome eq 'no_host') {
10239: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
10240: my $configpass = &LONCAPA::Enrollment::create_password();
10241: $configuserok =
10242: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10243: $configpass,'','','','','',undef,$servadm);
10244: } else {
10245: $configuserok = 'ok';
10246: %currroles =
10247: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10248: }
10249: return ($configuserok,%currroles);
10250: }
10251:
10252: sub check_authorstatus {
10253: my ($dom,$confname,%currroles) = @_;
10254: my $author_ok;
1.40 raeburn 10255: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 10256: my $start = time;
10257: my $end = 0;
10258: $author_ok =
10259: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 10260: 'au',$end,$start,'','','domconfig');
1.9 raeburn 10261: } else {
10262: $author_ok = 'ok';
10263: }
10264: return $author_ok;
10265: }
10266:
10267: sub publishlogo {
1.46 raeburn 10268: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 10269: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 10270: if ($action eq 'upload') {
10271: $fname=$env{'form.'.$formname.'.filename'};
10272: chop($env{'form.'.$formname});
10273: } else {
10274: ($fname) = ($formname =~ /([^\/]+)$/);
10275: }
1.46 raeburn 10276: if ($savefileas ne '') {
10277: $fname = $savefileas;
10278: }
1.9 raeburn 10279: $fname=&Apache::lonnet::clean_filename($fname);
10280: # See if there is anything left
10281: unless ($fname) { return ('error: no uploaded file'); }
10282: $fname="$subdir/$fname";
1.210 raeburn 10283: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 10284: my $filepath="$docroot/priv";
10285: my $relpath = "$dom/$confname";
1.9 raeburn 10286: my ($fnamepath,$file,$fetchthumb);
10287: $file=$fname;
10288: if ($fname=~m|/|) {
10289: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
10290: }
1.164 raeburn 10291: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 10292: my $count;
1.164 raeburn 10293: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 10294: $filepath.="/$parts[$count]";
10295: if ((-e $filepath)!=1) {
10296: mkdir($filepath,02770);
10297: }
10298: }
10299: # Check for bad extension and disallow upload
10300: if ($file=~/\.(\w+)$/ &&
10301: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
10302: $output =
1.207 bisitz 10303: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 10304: } elsif ($file=~/\.(\w+)$/ &&
10305: !defined(&Apache::loncommon::fileembstyle($1))) {
10306: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
10307: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 10308: $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 10309: } elsif (-d "$filepath/$file") {
1.195 bisitz 10310: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 10311: } else {
10312: my $source = $filepath.'/'.$file;
10313: my $logfile;
1.316 raeburn 10314: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 10315: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 10316: }
10317: print $logfile
10318: "\n================= Publish ".localtime()." ================\n".
10319: $env{'user.name'}.':'.$env{'user.domain'}."\n";
10320: # Save the file
1.316 raeburn 10321: if (!open(FH,">",$source)) {
1.9 raeburn 10322: &Apache::lonnet::logthis('Failed to create '.$source);
10323: return (&mt('Failed to create file'));
10324: }
10325: if ($action eq 'upload') {
10326: if (!print FH ($env{'form.'.$formname})) {
10327: &Apache::lonnet::logthis('Failed to write to '.$source);
10328: return (&mt('Failed to write file'));
10329: }
10330: } else {
10331: my $original = &Apache::lonnet::filelocation('',$formname);
10332: if(!copy($original,$source)) {
10333: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
10334: return (&mt('Failed to write file'));
10335: }
10336: }
10337: close(FH);
10338: chmod(0660, $source); # Permissions to rw-rw---.
10339:
10340: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
10341: my $copyfile=$targetdir.'/'.$file;
10342:
10343: my @parts=split(/\//,$targetdir);
10344: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
10345: for (my $count=5;$count<=$#parts;$count++) {
10346: $path.="/$parts[$count]";
10347: if (!-e $path) {
10348: print $logfile "\nCreating directory ".$path;
10349: mkdir($path,02770);
10350: }
10351: }
10352: my $versionresult;
10353: if (-e $copyfile) {
10354: $versionresult = &logo_versioning($targetdir,$file,$logfile);
10355: } else {
10356: $versionresult = 'ok';
10357: }
10358: if ($versionresult eq 'ok') {
10359: if (copy($source,$copyfile)) {
10360: print $logfile "\nCopied original source to ".$copyfile."\n";
10361: $output = 'ok';
10362: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 10363: push(@{$modified_urls},[$copyfile,$source]);
10364: my $metaoutput =
10365: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
10366: unless ($registered_cleanup) {
10367: my $handlers = $r->get_handlers('PerlCleanupHandler');
10368: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10369: $registered_cleanup=1;
10370: }
1.9 raeburn 10371: } else {
10372: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
10373: $output = &mt('Failed to copy file to RES space').", $!";
10374: }
10375: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
10376: my $inputfile = $filepath.'/'.$file;
10377: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 10378: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
10379: if ($fullwidth ne '' && $fullheight ne '') {
10380: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
10381: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 10382: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
10383: system({$args[0]} @args);
1.16 raeburn 10384: chmod(0660, $filepath.'/tn-'.$file);
10385: if (-e $outfile) {
10386: my $copyfile=$targetdir.'/tn-'.$file;
10387: if (copy($outfile,$copyfile)) {
10388: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 10389: my $thumb_metaoutput =
10390: &write_metadata($dom,$confname,$formname,
10391: $targetdir,'tn-'.$file,$logfile);
10392: push(@{$modified_urls},[$copyfile,$outfile]);
10393: unless ($registered_cleanup) {
10394: my $handlers = $r->get_handlers('PerlCleanupHandler');
10395: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10396: $registered_cleanup=1;
10397: }
1.267 raeburn 10398: $madethumb = 1;
1.16 raeburn 10399: } else {
10400: print $logfile "\nUnable to write ".$copyfile.
10401: ':'.$!."\n";
10402: }
10403: }
1.9 raeburn 10404: }
10405: }
10406: }
10407: } else {
10408: $output = $versionresult;
10409: }
10410: }
1.267 raeburn 10411: return ($output,$logourl,$madethumb);
1.9 raeburn 10412: }
10413:
10414: sub logo_versioning {
10415: my ($targetdir,$file,$logfile) = @_;
10416: my $target = $targetdir.'/'.$file;
10417: my ($maxversion,$fn,$extn,$output);
10418: $maxversion = 0;
10419: if ($file =~ /^(.+)\.(\w+)$/) {
10420: $fn=$1;
10421: $extn=$2;
10422: }
10423: opendir(DIR,$targetdir);
10424: while (my $filename=readdir(DIR)) {
10425: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10426: $maxversion=($1>$maxversion)?$1:$maxversion;
10427: }
10428: }
10429: $maxversion++;
10430: print $logfile "\nCreating old version ".$maxversion."\n";
10431: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10432: if (copy($target,$copyfile)) {
10433: print $logfile "Copied old target to ".$copyfile."\n";
10434: $copyfile=$copyfile.'.meta';
10435: if (copy($target.'.meta',$copyfile)) {
10436: print $logfile "Copied old target metadata to ".$copyfile."\n";
10437: $output = 'ok';
10438: } else {
10439: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10440: $output = &mt('Failed to copy old meta').", $!, ";
10441: }
10442: } else {
10443: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10444: $output = &mt('Failed to copy old target').", $!, ";
10445: }
10446: return $output;
10447: }
10448:
10449: sub write_metadata {
10450: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10451: my (%metadatafields,%metadatakeys,$output);
10452: $metadatafields{'title'}=$formname;
10453: $metadatafields{'creationdate'}=time;
10454: $metadatafields{'lastrevisiondate'}=time;
10455: $metadatafields{'copyright'}='public';
10456: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10457: $env{'user.domain'};
10458: $metadatafields{'authorspace'}=$confname.':'.$dom;
10459: $metadatafields{'domain'}=$dom;
10460: {
10461: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10462: my $mfh;
1.316 raeburn 10463: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 10464: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10465: unless ($_=~/\./) {
10466: my $unikey=$_;
10467: $unikey=~/^([A-Za-z]+)/;
10468: my $tag=$1;
10469: $tag=~tr/A-Z/a-z/;
10470: print $mfh "\n\<$tag";
10471: foreach (split(/\,/,$metadatakeys{$unikey})) {
10472: my $value=$metadatafields{$unikey.'.'.$_};
10473: $value=~s/\"/\'\'/g;
10474: print $mfh ' '.$_.'="'.$value.'"';
10475: }
10476: print $mfh '>'.
10477: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10478: .'</'.$tag.'>';
10479: }
10480: }
10481: $output = 'ok';
10482: print $logfile "\nWrote metadata";
10483: close($mfh);
10484: } else {
10485: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10486: $output = &mt('Could not write metadata');
10487: }
10488: }
1.155 raeburn 10489: return $output;
10490: }
10491:
10492: sub notifysubscribed {
10493: foreach my $targetsource (@{$modified_urls}){
10494: next unless (ref($targetsource) eq 'ARRAY');
10495: my ($target,$source)=@{$targetsource};
10496: if ($source ne '') {
1.316 raeburn 10497: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10498: print $logfh "\nCleanup phase: Notifications\n";
10499: my @subscribed=&subscribed_hosts($target);
10500: foreach my $subhost (@subscribed) {
10501: print $logfh "\nNotifying host ".$subhost.':';
10502: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10503: print $logfh $reply;
10504: }
10505: my @subscribedmeta=&subscribed_hosts("$target.meta");
10506: foreach my $subhost (@subscribedmeta) {
10507: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10508: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10509: $subhost);
10510: print $logfh $reply;
10511: }
10512: print $logfh "\n============ Done ============\n";
1.160 raeburn 10513: close($logfh);
1.155 raeburn 10514: }
10515: }
10516: }
10517: return OK;
10518: }
10519:
10520: sub subscribed_hosts {
10521: my ($target) = @_;
10522: my @subscribed;
1.316 raeburn 10523: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10524: while (my $subline=<$fh>) {
10525: if ($subline =~ /^($match_lonid):/) {
10526: my $host = $1;
10527: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10528: unless (grep(/^\Q$host\E$/,@subscribed)) {
10529: push(@subscribed,$host);
10530: }
10531: }
10532: }
10533: }
10534: }
10535: return @subscribed;
1.9 raeburn 10536: }
10537:
10538: sub check_switchserver {
10539: my ($dom,$confname) = @_;
10540: my ($allowed,$switchserver);
10541: my $home = &Apache::lonnet::homeserver($confname,$dom);
10542: if ($home eq 'no_host') {
10543: $home = &Apache::lonnet::domain($dom,'primary');
10544: }
10545: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10546: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10547: if (!$allowed) {
1.180 raeburn 10548: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10549: }
10550: return $switchserver;
10551: }
10552:
1.1 raeburn 10553: sub modify_quotas {
1.216 raeburn 10554: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10555: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 10556: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 10557: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10558: $validationfieldsref);
1.86 raeburn 10559: if ($action eq 'quotas') {
10560: $context = 'tools';
1.163 raeburn 10561: } else {
1.86 raeburn 10562: $context = $action;
10563: }
10564: if ($context eq 'requestcourses') {
1.325 raeburn 10565: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 10566: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10567: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10568: %titles = &courserequest_titles();
10569: $toolregexp = join('|',@usertools);
10570: %conditions = &courserequest_conditions();
1.216 raeburn 10571: $confname = $dom.'-domainconfig';
10572: my $servadm = $r->dir_config('lonAdmEMail');
10573: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 10574: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10575: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 10576: } elsif ($context eq 'requestauthor') {
10577: @usertools = ('author');
10578: %titles = &authorrequest_titles();
1.86 raeburn 10579: } else {
1.162 raeburn 10580: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10581: %titles = &tool_titles();
1.86 raeburn 10582: }
1.212 raeburn 10583: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10584: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10585: foreach my $key (keys(%env)) {
1.101 raeburn 10586: if ($context eq 'requestcourses') {
10587: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10588: my $item = $1;
10589: my $type = $2;
10590: if ($type =~ /^limit_(.+)/) {
10591: $limithash{$item}{$1} = $env{$key};
10592: } else {
10593: $confhash{$item}{$type} = $env{$key};
10594: }
10595: }
1.163 raeburn 10596: } elsif ($context eq 'requestauthor') {
10597: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10598: $confhash{$1} = $env{$key};
10599: }
1.101 raeburn 10600: } else {
1.86 raeburn 10601: if ($key =~ /^form\.quota_(.+)$/) {
10602: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 10603: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10604: $confhash{'authorquota'}{$1} = $env{$key};
10605: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10606: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10607: }
1.72 raeburn 10608: }
10609: }
1.163 raeburn 10610: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 10611: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10612: @approvalnotify = sort(@approvalnotify);
10613: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 10614: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 10615: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10616: foreach my $type (@hasuniquecode) {
10617: if (grep(/^\Q$type\E$/,@crstypes)) {
10618: $confhash{'uniquecode'}{$type} = 1;
10619: }
1.216 raeburn 10620: }
1.242 raeburn 10621: my (%newbook,%allpos);
1.216 raeburn 10622: if ($context eq 'requestcourses') {
1.242 raeburn 10623: foreach my $type ('textbooks','templates') {
10624: @{$allpos{$type}} = ();
10625: my $invalid;
10626: if ($type eq 'textbooks') {
10627: $invalid = &mt('Invalid LON-CAPA course for textbook');
10628: } else {
10629: $invalid = &mt('Invalid LON-CAPA course for template');
10630: }
10631: if ($env{'form.'.$type.'_addbook'}) {
10632: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10633: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10634: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10635: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10636: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10637: } else {
10638: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10639: my $position = $env{'form.'.$type.'_addbook_pos'};
10640: $position =~ s/\D+//g;
10641: if ($position ne '') {
10642: $allpos{$type}[$position] = $newbook{$type};
10643: }
1.216 raeburn 10644: }
1.242 raeburn 10645: } else {
10646: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 10647: }
10648: }
1.242 raeburn 10649: }
1.216 raeburn 10650: }
1.102 raeburn 10651: if (ref($domconfig{$action}) eq 'HASH') {
10652: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10653: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10654: $changes{'notify'}{'approval'} = 1;
10655: }
10656: } else {
1.144 raeburn 10657: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10658: $changes{'notify'}{'approval'} = 1;
10659: }
10660: }
1.218 raeburn 10661: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10662: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10663: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10664: unless ($confhash{'uniquecode'}{$crstype}) {
10665: $changes{'uniquecode'} = 1;
10666: }
10667: }
10668: unless ($changes{'uniquecode'}) {
10669: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10670: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10671: $changes{'uniquecode'} = 1;
10672: }
10673: }
10674: }
10675: } else {
10676: $changes{'uniquecode'} = 1;
10677: }
10678: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10679: $changes{'uniquecode'} = 1;
1.216 raeburn 10680: }
10681: if ($context eq 'requestcourses') {
1.242 raeburn 10682: foreach my $type ('textbooks','templates') {
10683: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10684: my %deletions;
10685: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10686: if (@todelete) {
10687: map { $deletions{$_} = 1; } @todelete;
10688: }
10689: my %imgdeletions;
10690: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10691: if (@todeleteimages) {
10692: map { $imgdeletions{$_} = 1; } @todeleteimages;
10693: }
10694: my $maxnum = $env{'form.'.$type.'_maxnum'};
10695: for (my $i=0; $i<=$maxnum; $i++) {
10696: my $itemid = $env{'form.'.$type.'_id_'.$i};
10697: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10698: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10699: if ($deletions{$key}) {
10700: if ($domconfig{$action}{$type}{$key}{'image'}) {
10701: #FIXME need to obsolete item in RES space
10702: }
10703: next;
10704: } else {
10705: my $newpos = $env{'form.'.$itemid};
10706: $newpos =~ s/\D+//g;
1.243 raeburn 10707: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 10708: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 10709: ($type eq 'templates'));
1.242 raeburn 10710: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10711: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10712: $changes{$type}{$key} = 1;
10713: }
10714: }
10715: $allpos{$type}[$newpos] = $key;
10716: }
10717: if ($imgdeletions{$key}) {
10718: $changes{$type}{$key} = 1;
1.216 raeburn 10719: #FIXME need to obsolete item in RES space
1.242 raeburn 10720: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10721: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 10722: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10723: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10724: } else {
10725: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10726: $cdom,$cnum,$type,$configuserok,
10727: $switchserver,$author_ok);
10728: if ($imgurl) {
10729: $confhash{$type}{$key}{'image'} = $imgurl;
10730: $changes{$type}{$key} = 1;
10731: }
10732: if ($error) {
10733: &Apache::lonnet::logthis($error);
10734: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10735: }
10736: }
1.242 raeburn 10737: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10738: $confhash{$type}{$key}{'image'} =
10739: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 10740: }
10741: }
10742: }
10743: }
10744: }
10745: }
1.102 raeburn 10746: } else {
1.144 raeburn 10747: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10748: $changes{'notify'}{'approval'} = 1;
10749: }
1.218 raeburn 10750: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 10751: $changes{'uniquecode'} = 1;
10752: }
10753: }
10754: if ($context eq 'requestcourses') {
1.242 raeburn 10755: foreach my $type ('textbooks','templates') {
10756: if ($newbook{$type}) {
10757: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 10758: foreach my $item ('subject','title','publisher','author') {
10759: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10760: ($type eq 'template'));
1.242 raeburn 10761: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10762: if ($env{'form.'.$type.'_addbook_'.$item}) {
10763: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10764: }
10765: }
10766: if ($type eq 'textbooks') {
10767: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10768: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 10769: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10770: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10771: } else {
10772: my ($imageurl,$error) =
10773: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10774: $configuserok,$switchserver,$author_ok);
10775: if ($imageurl) {
10776: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10777: }
10778: if ($error) {
10779: &Apache::lonnet::logthis($error);
10780: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10781: }
1.242 raeburn 10782: }
10783: }
1.216 raeburn 10784: }
10785: }
1.242 raeburn 10786: if (@{$allpos{$type}} > 0) {
10787: my $idx = 0;
10788: foreach my $item (@{$allpos{$type}}) {
10789: if ($item ne '') {
10790: $confhash{$type}{$item}{'order'} = $idx;
10791: if (ref($domconfig{$action}) eq 'HASH') {
10792: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10793: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10794: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10795: $changes{$type}{$item} = 1;
10796: }
1.216 raeburn 10797: }
10798: }
10799: }
1.242 raeburn 10800: $idx ++;
1.216 raeburn 10801: }
10802: }
10803: }
10804: }
1.235 raeburn 10805: if (ref($validationitemsref) eq 'ARRAY') {
10806: foreach my $item (@{$validationitemsref}) {
10807: if ($item eq 'fields') {
10808: my @changed;
10809: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10810: if (@{$confhash{'validation'}{$item}} > 0) {
10811: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10812: }
1.266 raeburn 10813: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10814: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10815: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10816: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10817: $domconfig{'requestcourses'}{'validation'}{$item});
10818: } else {
10819: @changed = @{$confhash{'validation'}{$item}};
10820: }
1.235 raeburn 10821: } else {
10822: @changed = @{$confhash{'validation'}{$item}};
10823: }
10824: } else {
10825: @changed = @{$confhash{'validation'}{$item}};
10826: }
10827: if (@changed) {
10828: if ($confhash{'validation'}{$item}) {
10829: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10830: } else {
10831: $changes{'validation'}{$item} = &mt('None');
10832: }
10833: }
10834: } else {
10835: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10836: if ($item eq 'markup') {
10837: if ($env{'form.requestcourses_validation_'.$item}) {
10838: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10839: }
10840: }
1.266 raeburn 10841: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10842: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10843: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10844: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10845: }
10846: } else {
10847: if ($confhash{'validation'}{$item} ne '') {
10848: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10849: }
1.235 raeburn 10850: }
10851: } else {
10852: if ($confhash{'validation'}{$item} ne '') {
10853: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10854: }
10855: }
10856: }
10857: }
10858: }
10859: if ($env{'form.validationdc'}) {
10860: my $newval = $env{'form.validationdc'};
1.285 raeburn 10861: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 10862: if (exists($domcoords{$newval})) {
10863: $confhash{'validation'}{'dc'} = $newval;
10864: }
10865: }
10866: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 10867: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10868: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10869: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10870: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10871: if ($confhash{'validation'}{'dc'} eq '') {
10872: $changes{'validation'}{'dc'} = &mt('None');
10873: } else {
10874: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10875: }
1.235 raeburn 10876: }
1.266 raeburn 10877: } elsif ($confhash{'validation'}{'dc'} ne '') {
10878: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 10879: }
10880: } elsif ($confhash{'validation'}{'dc'} ne '') {
10881: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10882: }
10883: } elsif ($confhash{'validation'}{'dc'} ne '') {
10884: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 10885: }
1.266 raeburn 10886: } else {
10887: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10888: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10889: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10890: $changes{'validation'}{'dc'} = &mt('None');
10891: }
10892: }
1.235 raeburn 10893: }
10894: }
1.102 raeburn 10895: }
10896: } else {
1.86 raeburn 10897: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 10898: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10899: }
1.72 raeburn 10900: foreach my $item (@usertools) {
10901: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10902: my $unset;
1.101 raeburn 10903: if ($context eq 'requestcourses') {
1.104 raeburn 10904: $unset = '0';
10905: if ($type eq '_LC_adv') {
10906: $unset = '';
10907: }
1.101 raeburn 10908: if ($confhash{$item}{$type} eq 'autolimit') {
10909: $confhash{$item}{$type} .= '=';
10910: unless ($limithash{$item}{$type} =~ /\D/) {
10911: $confhash{$item}{$type} .= $limithash{$item}{$type};
10912: }
10913: }
1.163 raeburn 10914: } elsif ($context eq 'requestauthor') {
10915: $unset = '0';
10916: if ($type eq '_LC_adv') {
10917: $unset = '';
10918: }
1.72 raeburn 10919: } else {
1.101 raeburn 10920: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10921: $confhash{$item}{$type} = 1;
10922: } else {
10923: $confhash{$item}{$type} = 0;
10924: }
1.72 raeburn 10925: }
1.86 raeburn 10926: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 10927: if ($action eq 'requestauthor') {
10928: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10929: $changes{$type} = 1;
10930: }
10931: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10932: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10933: $changes{$item}{$type} = 1;
10934: }
10935: } else {
10936: if ($context eq 'requestcourses') {
1.104 raeburn 10937: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 10938: $changes{$item}{$type} = 1;
10939: }
10940: } else {
10941: if (!$confhash{$item}{$type}) {
10942: $changes{$item}{$type} = 1;
10943: }
10944: }
10945: }
10946: } else {
10947: if ($context eq 'requestcourses') {
1.104 raeburn 10948: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10949: $changes{$item}{$type} = 1;
10950: }
1.163 raeburn 10951: } elsif ($context eq 'requestauthor') {
10952: if ($confhash{$type} ne $unset) {
10953: $changes{$type} = 1;
10954: }
1.72 raeburn 10955: } else {
10956: if (!$confhash{$item}{$type}) {
10957: $changes{$item}{$type} = 1;
10958: }
10959: }
10960: }
1.1 raeburn 10961: }
10962: }
1.163 raeburn 10963: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10964: if (ref($domconfig{'quotas'}) eq 'HASH') {
10965: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10966: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10967: if (exists($confhash{'defaultquota'}{$key})) {
10968: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10969: $changes{'defaultquota'}{$key} = 1;
10970: }
10971: } else {
10972: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10973: }
10974: }
1.86 raeburn 10975: } else {
10976: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10977: if (exists($confhash{'defaultquota'}{$key})) {
10978: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10979: $changes{'defaultquota'}{$key} = 1;
10980: }
10981: } else {
10982: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10983: }
1.1 raeburn 10984: }
10985: }
1.197 raeburn 10986: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10987: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10988: if (exists($confhash{'authorquota'}{$key})) {
10989: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10990: $changes{'authorquota'}{$key} = 1;
10991: }
10992: } else {
10993: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10994: }
10995: }
10996: }
1.1 raeburn 10997: }
1.86 raeburn 10998: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10999: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
11000: if (ref($domconfig{'quotas'}) eq 'HASH') {
11001: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11002: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
11003: $changes{'defaultquota'}{$key} = 1;
11004: }
11005: } else {
11006: if (!exists($domconfig{'quotas'}{$key})) {
11007: $changes{'defaultquota'}{$key} = 1;
11008: }
1.72 raeburn 11009: }
11010: } else {
1.86 raeburn 11011: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 11012: }
1.1 raeburn 11013: }
11014: }
1.197 raeburn 11015: if (ref($confhash{'authorquota'}) eq 'HASH') {
11016: foreach my $key (keys(%{$confhash{'authorquota'}})) {
11017: if (ref($domconfig{'quotas'}) eq 'HASH') {
11018: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11019: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
11020: $changes{'authorquota'}{$key} = 1;
11021: }
11022: } else {
11023: $changes{'authorquota'}{$key} = 1;
11024: }
11025: } else {
11026: $changes{'authorquota'}{$key} = 1;
11027: }
11028: }
11029: }
1.1 raeburn 11030: }
1.72 raeburn 11031:
1.163 raeburn 11032: if ($context eq 'requestauthor') {
11033: $domdefaults{'requestauthor'} = \%confhash;
11034: } else {
11035: foreach my $key (keys(%confhash)) {
1.242 raeburn 11036: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 11037: $domdefaults{$key} = $confhash{$key};
11038: }
1.163 raeburn 11039: }
1.72 raeburn 11040: }
1.163 raeburn 11041:
1.1 raeburn 11042: my %quotahash = (
1.86 raeburn 11043: $action => { %confhash }
1.1 raeburn 11044: );
11045: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
11046: $dom);
11047: if ($putresult eq 'ok') {
11048: if (keys(%changes) > 0) {
1.72 raeburn 11049: my $cachetime = 24*60*60;
11050: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11051: if (ref($lastactref) eq 'HASH') {
11052: $lastactref->{'domdefaults'} = 1;
11053: }
1.1 raeburn 11054: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 11055: unless (($context eq 'requestcourses') ||
1.163 raeburn 11056: ($context eq 'requestauthor')) {
1.86 raeburn 11057: if (ref($changes{'defaultquota'}) eq 'HASH') {
11058: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
11059: foreach my $type (@{$types},'default') {
11060: if (defined($changes{'defaultquota'}{$type})) {
11061: my $typetitle = $usertypes->{$type};
11062: if ($type eq 'default') {
11063: $typetitle = $othertitle;
11064: }
1.213 raeburn 11065: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 11066: }
11067: }
1.86 raeburn 11068: $resulttext .= '</ul></li>';
1.72 raeburn 11069: }
1.197 raeburn 11070: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 11071: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 11072: foreach my $type (@{$types},'default') {
11073: if (defined($changes{'authorquota'}{$type})) {
11074: my $typetitle = $usertypes->{$type};
11075: if ($type eq 'default') {
11076: $typetitle = $othertitle;
11077: }
1.213 raeburn 11078: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 11079: }
11080: }
11081: $resulttext .= '</ul></li>';
11082: }
1.72 raeburn 11083: }
1.80 raeburn 11084: my %newenv;
1.72 raeburn 11085: foreach my $item (@usertools) {
1.163 raeburn 11086: my (%haschgs,%inconf);
11087: if ($context eq 'requestauthor') {
11088: %haschgs = %changes;
1.210 raeburn 11089: %inconf = %confhash;
1.163 raeburn 11090: } else {
11091: if (ref($changes{$item}) eq 'HASH') {
11092: %haschgs = %{$changes{$item}};
11093: }
11094: if (ref($confhash{$item}) eq 'HASH') {
11095: %inconf = %{$confhash{$item}};
11096: }
11097: }
11098: if (keys(%haschgs) > 0) {
1.80 raeburn 11099: my $newacc =
11100: &Apache::lonnet::usertools_access($env{'user.name'},
11101: $env{'user.domain'},
1.86 raeburn 11102: $item,'reload',$context);
1.210 raeburn 11103: if (($context eq 'requestcourses') ||
1.163 raeburn 11104: ($context eq 'requestauthor')) {
1.108 raeburn 11105: if ($env{'environment.canrequest.'.$item} ne $newacc) {
11106: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 11107: }
11108: } else {
11109: if ($env{'environment.availabletools.'.$item} ne $newacc) {
11110: $newenv{'environment.availabletools.'.$item} = $newacc;
11111: }
1.80 raeburn 11112: }
1.163 raeburn 11113: unless ($context eq 'requestauthor') {
11114: $resulttext .= '<li>'.$titles{$item}.'<ul>';
11115: }
1.72 raeburn 11116: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 11117: if ($haschgs{$type}) {
1.72 raeburn 11118: my $typetitle = $usertypes->{$type};
11119: if ($type eq 'default') {
11120: $typetitle = $othertitle;
11121: } elsif ($type eq '_LC_adv') {
11122: $typetitle = 'LON-CAPA Advanced Users';
11123: }
1.163 raeburn 11124: if ($inconf{$type}) {
1.101 raeburn 11125: if ($context eq 'requestcourses') {
11126: my $cond;
1.163 raeburn 11127: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 11128: if ($1 eq '') {
11129: $cond = &mt('(Automatic processing of any request).');
11130: } else {
11131: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
11132: }
11133: } else {
1.163 raeburn 11134: $cond = $conditions{$inconf{$type}};
1.101 raeburn 11135: }
11136: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 11137: } elsif ($context eq 'requestauthor') {
11138: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
11139: $titles{$inconf{$type}},$typetitle);
11140:
1.101 raeburn 11141: } else {
11142: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
11143: }
1.72 raeburn 11144: } else {
1.104 raeburn 11145: if ($type eq '_LC_adv') {
1.163 raeburn 11146: if ($inconf{$type} eq '0') {
1.104 raeburn 11147: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11148: } else {
11149: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
11150: }
11151: } else {
11152: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11153: }
1.72 raeburn 11154: }
11155: }
1.26 raeburn 11156: }
1.163 raeburn 11157: unless ($context eq 'requestauthor') {
11158: $resulttext .= '</ul></li>';
11159: }
1.26 raeburn 11160: }
1.1 raeburn 11161: }
1.163 raeburn 11162: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 11163: if (ref($changes{'notify'}) eq 'HASH') {
11164: if ($changes{'notify'}{'approval'}) {
11165: if (ref($confhash{'notify'}) eq 'HASH') {
11166: if ($confhash{'notify'}{'approval'}) {
11167: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
11168: } else {
1.163 raeburn 11169: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 11170: }
11171: }
11172: }
11173: }
11174: }
1.216 raeburn 11175: if ($action eq 'requestcourses') {
11176: my @offon = ('off','on');
11177: if ($changes{'uniquecode'}) {
1.218 raeburn 11178: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11179: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
11180: $resulttext .= '<li>'.
11181: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
11182: '</li>';
11183: } else {
11184: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
11185: '</li>';
11186: }
1.216 raeburn 11187: }
1.242 raeburn 11188: foreach my $type ('textbooks','templates') {
11189: if (ref($changes{$type}) eq 'HASH') {
11190: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
11191: foreach my $key (sort(keys(%{$changes{$type}}))) {
11192: my %coursehash = &Apache::lonnet::coursedescription($key);
11193: my $coursetitle = $coursehash{'description'};
11194: my $position = $confhash{$type}{$key}{'order'} + 1;
11195: $resulttext .= '<li>';
1.243 raeburn 11196: foreach my $item ('subject','title','publisher','author') {
11197: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11198: ($type eq 'templates'));
1.242 raeburn 11199: my $name = $item.':';
11200: $name =~ s/^(\w)/\U$1/;
11201: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
11202: }
11203: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
11204: if ($type eq 'textbooks') {
11205: if ($confhash{$type}{$key}{'image'}) {
11206: $resulttext .= ' '.&mt('Image: [_1]',
11207: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
11208: ' alt="Textbook cover" />').'<br />';
11209: }
11210: }
11211: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 11212: }
1.242 raeburn 11213: $resulttext .= '</ul></li>';
1.216 raeburn 11214: }
11215: }
1.235 raeburn 11216: if (ref($changes{'validation'}) eq 'HASH') {
11217: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
11218: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
11219: foreach my $item (@{$validationitemsref}) {
11220: if (exists($changes{'validation'}{$item})) {
11221: if ($item eq 'markup') {
11222: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11223: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
11224: } else {
11225: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11226: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
11227: }
11228: }
11229: }
11230: if (exists($changes{'validation'}{'dc'})) {
11231: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11232: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11233: }
11234: }
11235: }
1.216 raeburn 11236: }
1.1 raeburn 11237: $resulttext .= '</ul>';
1.80 raeburn 11238: if (keys(%newenv)) {
11239: &Apache::lonnet::appenv(\%newenv);
11240: }
1.1 raeburn 11241: } else {
1.86 raeburn 11242: if ($context eq 'requestcourses') {
11243: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 11244: } elsif ($context eq 'requestauthor') {
11245: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 11246: } else {
1.90 weissno 11247: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 11248: }
1.1 raeburn 11249: }
11250: } else {
1.11 albertel 11251: $resulttext = '<span class="LC_error">'.
11252: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11253: }
1.216 raeburn 11254: if ($errors) {
11255: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
11256: '<ul>'.$errors.'</ul></p>';
11257: }
1.3 raeburn 11258: return $resulttext;
1.1 raeburn 11259: }
11260:
1.216 raeburn 11261: sub process_textbook_image {
1.242 raeburn 11262: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 11263: my $filename = $env{'form.'.$caller.'.filename'};
11264: my ($error,$url);
11265: my ($width,$height) = (50,50);
11266: if ($configuserok eq 'ok') {
11267: if ($switchserver) {
11268: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
11269: $switchserver);
11270: } elsif ($author_ok eq 'ok') {
11271: my ($result,$imageurl) =
11272: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 11273: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 11274: if ($result eq 'ok') {
11275: $url = $imageurl;
11276: } else {
11277: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11278: }
11279: } else {
11280: $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);
11281: }
11282: } else {
11283: $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);
11284: }
11285: return ($url,$error);
11286: }
11287:
1.267 raeburn 11288: sub modify_ltitools {
11289: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11290: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 11291: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 11292: my $confname = $dom.'-domainconfig';
11293: my $servadm = $r->dir_config('lonAdmEMail');
11294: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11295: my (%posslti,%possfield);
11296: my @courseroles = ('cc','in','ta','ep','st');
11297: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
11298: map { $posslti{$_} = 1; } @ltiroles;
11299: my @allfields = ('fullname','firstname','lastname','email','user','roles');
11300: map { $possfield{$_} = 1; } @allfields;
11301: my %lt = <itools_names();
11302: if ($env{'form.ltitools_add'}) {
11303: my $title = $env{'form.ltitools_add_title'};
11304: $title =~ s/(`)/'/g;
11305: ($newid,my $error) = &get_ltitools_id($dom,$title);
11306: if ($newid) {
11307: my $position = $env{'form.ltitools_add_pos'};
11308: $position =~ s/\D+//g;
11309: if ($position ne '') {
11310: $allpos[$position] = $newid;
11311: }
11312: $changes{$newid} = 1;
1.322 raeburn 11313: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 11314: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 11315: if ($item eq 'lifetime') {
11316: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
11317: }
1.267 raeburn 11318: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 11319: if (($item eq 'key') || ($item eq 'secret')) {
11320: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11321: } else {
11322: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11323: }
1.267 raeburn 11324: }
11325: }
11326: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
11327: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
11328: }
11329: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
11330: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
11331: }
1.323 raeburn 11332: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
11333: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
11334: } else {
11335: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
11336: }
1.296 raeburn 11337: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 11338: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
11339: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 11340: if (($item eq 'width') || ($item eq 'height')) {
11341: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
11342: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11343: }
11344: } else {
11345: if ($env{'form.ltitools_add_'.$item} ne '') {
11346: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11347: }
1.267 raeburn 11348: }
11349: }
11350: if ($env{'form.ltitools_add_target'} eq 'window') {
11351: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 11352: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
11353: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 11354: } else {
11355: $confhash{$newid}{'display'}{'target'} = 'iframe';
11356: }
11357: foreach my $item ('passback','roster') {
1.319 raeburn 11358: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 11359: $confhash{$newid}{$item} = 1;
1.319 raeburn 11360: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
11361: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
11362: $lifetime =~ s/^\s+|\s+$//g;
11363: if ($lifetime =~ /^\d+\.?\d*$/) {
11364: $confhash{$newid}{$item.'valid'} = $lifetime;
11365: }
11366: }
1.267 raeburn 11367: }
11368: }
11369: if ($env{'form.ltitools_add_image.filename'} ne '') {
11370: my ($imageurl,$error) =
1.307 raeburn 11371: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 11372: $configuserok,$switchserver,$author_ok);
11373: if ($imageurl) {
11374: $confhash{$newid}{'image'} = $imageurl;
11375: }
11376: if ($error) {
11377: &Apache::lonnet::logthis($error);
11378: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11379: }
11380: }
11381: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
11382: foreach my $field (@fields) {
11383: if ($possfield{$field}) {
11384: if ($field eq 'roles') {
11385: foreach my $role (@courseroles) {
11386: my $choice = $env{'form.ltitools_add_roles_'.$role};
11387: if (($choice ne '') && ($posslti{$choice})) {
11388: $confhash{$newid}{'roles'}{$role} = $choice;
11389: if ($role eq 'cc') {
11390: $confhash{$newid}{'roles'}{'co'} = $choice;
11391: }
11392: }
11393: }
11394: } else {
11395: $confhash{$newid}{'fields'}{$field} = 1;
11396: }
11397: }
11398: }
1.324 raeburn 11399: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
11400: if ($confhash{$newid}{'fields'}{'user'}) {
11401: if ($env{'form.ltitools_userincdom_add'}) {
11402: $confhash{$newid}{'incdom'} = 1;
11403: }
11404: }
11405: }
1.273 raeburn 11406: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
11407: foreach my $item (@courseconfig) {
11408: $confhash{$newid}{'crsconf'}{$item} = 1;
11409: }
1.267 raeburn 11410: if ($env{'form.ltitools_add_custom'}) {
11411: my $name = $env{'form.ltitools_add_custom_name'};
11412: my $value = $env{'form.ltitools_add_custom_value'};
11413: $value =~ s/(`)/'/g;
11414: $name =~ s/(`)/'/g;
11415: $confhash{$newid}{'custom'}{$name} = $value;
11416: }
11417: } else {
11418: my $error = &mt('Failed to acquire unique ID for new external tool');
11419: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11420: }
11421: }
11422: if (ref($domconfig{$action}) eq 'HASH') {
11423: my %deletions;
11424: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
11425: if (@todelete) {
11426: map { $deletions{$_} = 1; } @todelete;
11427: }
11428: my %customadds;
11429: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
11430: if (@newcustom) {
11431: map { $customadds{$_} = 1; } @newcustom;
11432: }
11433: my %imgdeletions;
11434: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
11435: if (@todeleteimages) {
11436: map { $imgdeletions{$_} = 1; } @todeleteimages;
11437: }
11438: my $maxnum = $env{'form.ltitools_maxnum'};
11439: for (my $i=0; $i<=$maxnum; $i++) {
11440: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 11441: $itemid =~ s/\D+//g;
1.267 raeburn 11442: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11443: if ($deletions{$itemid}) {
11444: if ($domconfig{$action}{$itemid}{'image'}) {
11445: #FIXME need to obsolete item in RES space
11446: }
11447: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
11448: next;
11449: } else {
11450: my $newpos = $env{'form.ltitools_'.$itemid};
11451: $newpos =~ s/\D+//g;
1.322 raeburn 11452: foreach my $item ('title','url','lifetime') {
1.267 raeburn 11453: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11454: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11455: $changes{$itemid} = 1;
11456: }
11457: }
1.297 raeburn 11458: foreach my $item ('key','secret') {
11459: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11460: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
11461: $changes{$itemid} = 1;
11462: }
11463: }
1.267 raeburn 11464: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
11465: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
11466: }
11467: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
11468: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
11469: }
1.323 raeburn 11470: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
11471: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
11472: } else {
11473: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
11474: }
11475: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
11476: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
11477: $changes{$itemid} = 1;
11478: }
11479: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
11480: $changes{$itemid} = 1;
11481: }
1.267 raeburn 11482: foreach my $size ('width','height') {
11483: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
11484: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
11485: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
11486: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
11487: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11488: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
11489: $changes{$itemid} = 1;
11490: }
11491: } else {
11492: $changes{$itemid} = 1;
11493: }
1.296 raeburn 11494: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11495: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
11496: $changes{$itemid} = 1;
11497: }
11498: }
11499: }
11500: foreach my $item ('linktext','explanation') {
11501: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
11502: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
11503: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
11504: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11505: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11506: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
11507: $changes{$itemid} = 1;
11508: }
11509: } else {
11510: $changes{$itemid} = 1;
11511: }
11512: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11513: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
11514: $changes{$itemid} = 1;
11515: }
1.267 raeburn 11516: }
11517: }
11518: if ($env{'form.ltitools_target_'.$i} eq 'window') {
11519: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 11520: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
11521: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 11522: } else {
11523: $confhash{$itemid}{'display'}{'target'} = 'iframe';
11524: }
11525: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11526: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
11527: $changes{$itemid} = 1;
11528: }
11529: } else {
11530: $changes{$itemid} = 1;
11531: }
11532: foreach my $extra ('passback','roster') {
11533: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
11534: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 11535: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 11536: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 11537: $lifetime =~ s/^\s+|\s+$//g;
11538: if ($lifetime =~ /^\d+\.?\d*$/) {
11539: $confhash{$itemid}{$extra.'valid'} = $lifetime;
11540: }
11541: }
1.267 raeburn 11542: }
11543: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
11544: $changes{$itemid} = 1;
11545: }
1.319 raeburn 11546: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
11547: $changes{$itemid} = 1;
11548: }
1.267 raeburn 11549: }
1.273 raeburn 11550: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 11551: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 11552: if (grep(/^\Q$item\E$/,@courseconfig)) {
11553: $confhash{$itemid}{'crsconf'}{$item} = 1;
11554: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
11555: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
11556: $changes{$itemid} = 1;
11557: }
11558: } else {
11559: $changes{$itemid} = 1;
11560: }
11561: }
11562: }
1.267 raeburn 11563: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
11564: foreach my $field (@fields) {
11565: if ($possfield{$field}) {
11566: if ($field eq 'roles') {
11567: foreach my $role (@courseroles) {
11568: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
11569: if (($choice ne '') && ($posslti{$choice})) {
11570: $confhash{$itemid}{'roles'}{$role} = $choice;
11571: if ($role eq 'cc') {
11572: $confhash{$itemid}{'roles'}{'co'} = $choice;
11573: }
11574: }
11575: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
11576: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
11577: $changes{$itemid} = 1;
11578: }
11579: } elsif ($confhash{$itemid}{'roles'}{$role}) {
11580: $changes{$itemid} = 1;
11581: }
11582: }
11583: } else {
11584: $confhash{$itemid}{'fields'}{$field} = 1;
11585: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
11586: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
11587: $changes{$itemid} = 1;
11588: }
11589: } else {
11590: $changes{$itemid} = 1;
11591: }
11592: }
11593: }
11594: }
1.324 raeburn 11595: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11596: if ($confhash{$itemid}{'fields'}{'user'}) {
11597: if ($env{'form.ltitools_userincdom_'.$i}) {
11598: $confhash{$itemid}{'incdom'} = 1;
11599: }
11600: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
11601: $changes{$itemid} = 1;
11602: }
11603: }
11604: }
1.267 raeburn 11605: $allpos[$newpos] = $itemid;
11606: }
11607: if ($imgdeletions{$itemid}) {
11608: $changes{$itemid} = 1;
11609: #FIXME need to obsolete item in RES space
11610: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
11611: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
11612: $itemid,$configuserok,$switchserver,
11613: $author_ok);
11614: if ($imgurl) {
11615: $confhash{$itemid}{'image'} = $imgurl;
11616: $changes{$itemid} = 1;
11617: }
11618: if ($error) {
11619: &Apache::lonnet::logthis($error);
11620: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11621: }
11622: } elsif ($domconfig{$action}{$itemid}{'image'}) {
11623: $confhash{$itemid}{'image'} =
11624: $domconfig{$action}{$itemid}{'image'};
11625: }
11626: if ($customadds{$i}) {
11627: my $name = $env{'form.ltitools_custom_name_'.$i};
11628: $name =~ s/(`)/'/g;
11629: $name =~ s/^\s+//;
11630: $name =~ s/\s+$//;
11631: my $value = $env{'form.ltitools_custom_value_'.$i};
11632: $value =~ s/(`)/'/g;
11633: $value =~ s/^\s+//;
11634: $value =~ s/\s+$//;
11635: if ($name ne '') {
11636: $confhash{$itemid}{'custom'}{$name} = $value;
11637: $changes{$itemid} = 1;
11638: }
11639: }
11640: my %customdels;
11641: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
11642: if (@customdeletions) {
11643: $changes{$itemid} = 1;
11644: }
11645: map { $customdels{$_} = 1; } @customdeletions;
11646: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
11647: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
11648: unless ($customdels{$key}) {
11649: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
11650: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
11651: }
11652: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
11653: $changes{$itemid} = 1;
11654: }
11655: }
11656: }
11657: }
11658: unless ($changes{$itemid}) {
11659: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
11660: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
11661: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
11662: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
11663: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
11664: $changes{$itemid} = 1;
11665: last;
11666: }
11667: }
11668: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
11669: $changes{$itemid} = 1;
11670: }
11671: }
11672: last if ($changes{$itemid});
11673: }
11674: }
11675: }
11676: }
11677: }
11678: if (@allpos > 0) {
11679: my $idx = 0;
11680: foreach my $itemid (@allpos) {
11681: if ($itemid ne '') {
11682: $confhash{$itemid}{'order'} = $idx;
11683: if (ref($domconfig{$action}) eq 'HASH') {
11684: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11685: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11686: $changes{$itemid} = 1;
11687: }
11688: }
11689: }
11690: $idx ++;
11691: }
11692: }
11693: }
11694: my %ltitoolshash = (
11695: $action => { %confhash }
11696: );
11697: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
11698: $dom);
11699: if ($putresult eq 'ok') {
1.297 raeburn 11700: my %ltienchash = (
11701: $action => { %encconfig }
11702: );
11703: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 11704: if (keys(%changes) > 0) {
11705: my $cachetime = 24*60*60;
1.297 raeburn 11706: my %ltiall = %confhash;
11707: foreach my $id (keys(%ltiall)) {
11708: if (ref($encconfig{$id}) eq 'HASH') {
11709: foreach my $item ('key','secret') {
11710: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11711: }
11712: }
11713: }
11714: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 11715: if (ref($lastactref) eq 'HASH') {
11716: $lastactref->{'ltitools'} = 1;
11717: }
11718: $resulttext = &mt('Changes made:').'<ul>';
11719: my %bynum;
11720: foreach my $itemid (sort(keys(%changes))) {
11721: my $position = $confhash{$itemid}{'order'};
11722: $bynum{$position} = $itemid;
11723: }
11724: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11725: my $itemid = $bynum{$pos};
11726: if (ref($confhash{$itemid}) ne 'HASH') {
11727: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11728: } else {
11729: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
11730: if ($confhash{$itemid}{'image'}) {
11731: $resulttext .= ' '.
11732: '<img src="'.$confhash{$itemid}{'image'}.'"'.
11733: ' alt="'.&mt('Tool Provider icon').'" />';
11734: }
11735: $resulttext .= '</li><ul>';
11736: my $position = $pos + 1;
11737: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 11738: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 11739: if ($confhash{$itemid}{$item} ne '') {
11740: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11741: }
11742: }
1.297 raeburn 11743: if ($encconfig{$itemid}{'key'} ne '') {
11744: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11745: }
11746: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 11747: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 11748: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 11749: $resulttext .= ('*'x$num).'</li>';
11750: }
1.273 raeburn 11751: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 11752: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 11753: my $numconfig = 0;
11754: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
11755: foreach my $item (@possconfig) {
11756: if ($confhash{$itemid}{'crsconf'}{$item}) {
11757: $numconfig ++;
1.296 raeburn 11758: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 11759: }
11760: }
11761: }
11762: if (!$numconfig) {
11763: $resulttext .= &mt('None');
11764: }
11765: $resulttext .= '</li>';
1.267 raeburn 11766: foreach my $item ('passback','roster') {
11767: $resulttext .= '<li>'.$lt{$item}.' ';
11768: if ($confhash{$itemid}{$item}) {
11769: $resulttext .= &mt('Yes');
1.319 raeburn 11770: if ($confhash{$itemid}{$item.'valid'}) {
11771: if ($item eq 'passback') {
11772: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
11773: $confhash{$itemid}{$item.'valid'});
11774: } else {
11775: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
11776: $confhash{$itemid}{$item.'valid'});
11777: }
11778: }
1.267 raeburn 11779: } else {
11780: $resulttext .= &mt('No');
11781: }
11782: $resulttext .= '</li>';
11783: }
11784: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11785: my $displaylist;
11786: if ($confhash{$itemid}{'display'}{'target'}) {
11787: $displaylist = &mt('Display target').': '.
11788: $confhash{$itemid}{'display'}{'target'}.',';
11789: }
11790: foreach my $size ('width','height') {
11791: if ($confhash{$itemid}{'display'}{$size}) {
11792: $displaylist .= (' 'x2).$lt{$size}.': '.
11793: $confhash{$itemid}{'display'}{$size}.',';
11794: }
11795: }
11796: if ($displaylist) {
11797: $displaylist =~ s/,$//;
11798: $resulttext .= '<li>'.$displaylist.'</li>';
11799: }
1.296 raeburn 11800: foreach my $item ('linktext','explanation') {
11801: if ($confhash{$itemid}{'display'}{$item}) {
11802: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11803: }
11804: }
11805: }
1.267 raeburn 11806: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11807: my $fieldlist;
11808: foreach my $field (@allfields) {
11809: if ($confhash{$itemid}{'fields'}{$field}) {
11810: $fieldlist .= (' 'x2).$lt{$field}.',';
11811: }
11812: }
11813: if ($fieldlist) {
11814: $fieldlist =~ s/,$//;
1.324 raeburn 11815: if ($confhash{$itemid}{'fields'}{'user'}) {
11816: if ($confhash{$itemid}{'incdom'}) {
11817: $fieldlist .= ' ('.&mt('username:domain').')';
11818: } else {
11819: $fieldlist .= ' ('.&mt('username').')';
11820: }
11821: }
1.267 raeburn 11822: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11823: }
11824: }
11825: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11826: my $rolemaps;
11827: foreach my $role (@courseroles) {
11828: if ($confhash{$itemid}{'roles'}{$role}) {
11829: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11830: $confhash{$itemid}{'roles'}{$role}.',';
11831: }
11832: }
11833: if ($rolemaps) {
11834: $rolemaps =~ s/,$//;
11835: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11836: }
11837: }
11838: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11839: my $customlist;
11840: if (keys(%{$confhash{$itemid}{'custom'}})) {
11841: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11842: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11843: }
11844: }
11845: if ($customlist) {
1.317 raeburn 11846: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 11847: }
11848: }
11849: $resulttext .= '</ul></li>';
11850: }
11851: }
11852: $resulttext .= '</ul>';
11853: } else {
11854: $resulttext = &mt('No changes made.');
11855: }
11856: } else {
11857: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11858: }
11859: if ($errors) {
11860: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11861: $errors.'</ul>';
11862: }
11863: return $resulttext;
11864: }
11865:
11866: sub process_ltitools_image {
11867: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11868: my $filename = $env{'form.'.$caller.'.filename'};
11869: my ($error,$url);
11870: my ($width,$height) = (21,21);
11871: if ($configuserok eq 'ok') {
11872: if ($switchserver) {
11873: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11874: $switchserver);
11875: } elsif ($author_ok eq 'ok') {
11876: my ($result,$imageurl,$madethumb) =
11877: &publishlogo($r,'upload',$caller,$dom,$confname,
11878: "ltitools/$itemid/icon",$width,$height);
11879: if ($result eq 'ok') {
11880: if ($madethumb) {
11881: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11882: my $imagethumb = "$path/tn-".$imagefile;
11883: $url = $imagethumb;
11884: } else {
11885: $url = $imageurl;
11886: }
11887: } else {
11888: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11889: }
11890: } else {
11891: $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);
11892: }
11893: } else {
11894: $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);
11895: }
11896: return ($url,$error);
11897: }
11898:
11899: sub get_ltitools_id {
11900: my ($cdom,$title) = @_;
11901: # get lock on ltitools db
11902: my $lockhash = {
11903: lock => $env{'user.name'}.
11904: ':'.$env{'user.domain'},
11905: };
11906: my $tries = 0;
11907: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11908: my ($id,$error);
11909:
11910: while (($gotlock ne 'ok') && ($tries<10)) {
11911: $tries ++;
11912: sleep (0.1);
11913: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11914: }
11915: if ($gotlock eq 'ok') {
11916: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11917: if ($currids{'lock'}) {
11918: delete($currids{'lock'});
11919: if (keys(%currids)) {
11920: my @curr = sort { $a <=> $b } keys(%currids);
11921: if ($curr[-1] =~ /^\d+$/) {
11922: $id = 1 + $curr[-1];
11923: }
11924: } else {
11925: $id = 1;
11926: }
11927: if ($id) {
11928: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11929: $error = 'nostore';
11930: }
11931: } else {
11932: $error = 'nonumber';
11933: }
11934: }
11935: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11936: } else {
11937: $error = 'nolock';
11938: }
11939: return ($id,$error);
11940: }
11941:
1.320 raeburn 11942: sub modify_lti {
11943: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11944: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11945: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
11946: my (%posslti,%posslticrs,%posscrstype);
11947: my @courseroles = ('cc','in','ta','ep','st');
11948: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
11949: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
11950: my @coursetypes = ('official','unofficial','community','textbook','placement');
11951: my %coursetypetitles = &Apache::lonlocal::texthash (
11952: official => 'Official',
11953: unofficial => 'Unofficial',
11954: community => 'Community',
11955: textbook => 'Textbook',
11956: placement => 'Placement Test',
11957: );
1.325 raeburn 11958: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 11959: my %lt = <i_names();
11960: map { $posslti{$_} = 1; } @ltiroles;
11961: map { $posslticrs{$_} = 1; } @lticourseroles;
11962: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 11963:
1.326 raeburn 11964: my %menutitles = <imenu_titles();
11965:
1.320 raeburn 11966: my (@items,%deletions,%itemids);
11967: if ($env{'form.lti_add'}) {
11968: my $consumer = $env{'form.lti_consumer_add'};
11969: $consumer =~ s/(`)/'/g;
11970: ($newid,my $error) = &get_lti_id($dom,$consumer);
11971: if ($newid) {
11972: $itemids{'add'} = $newid;
11973: push(@items,'add');
11974: $changes{$newid} = 1;
11975: } else {
11976: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
11977: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11978: }
11979: }
11980: if (ref($domconfig{$action}) eq 'HASH') {
11981: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
11982: if (@todelete) {
11983: map { $deletions{$_} = 1; } @todelete;
11984: }
11985: my $maxnum = $env{'form.lti_maxnum'};
11986: for (my $i=0; $i<=$maxnum; $i++) {
11987: my $itemid = $env{'form.lti_id_'.$i};
11988: $itemid =~ s/\D+//g;
11989: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11990: if ($deletions{$itemid}) {
11991: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
11992: } else {
11993: push(@items,$i);
11994: $itemids{$i} = $itemid;
11995: }
11996: }
11997: }
11998: }
11999: foreach my $idx (@items) {
12000: my $itemid = $itemids{$idx};
12001: next unless ($itemid);
12002: my $position = $env{'form.lti_pos_'.$idx};
12003: $position =~ s/\D+//g;
12004: if ($position ne '') {
12005: $allpos[$position] = $itemid;
12006: }
1.345 raeburn 12007: foreach my $item ('consumer','key','secret','lifetime','requser') {
1.320 raeburn 12008: my $formitem = 'form.lti_'.$item.'_'.$idx;
12009: $env{$formitem} =~ s/(`)/'/g;
12010: if ($item eq 'lifetime') {
12011: $env{$formitem} =~ s/[^\d.]//g;
12012: }
12013: if ($env{$formitem} ne '') {
12014: if (($item eq 'key') || ($item eq 'secret')) {
12015: $encconfig{$itemid}{$item} = $env{$formitem};
12016: } else {
12017: $confhash{$itemid}{$item} = $env{$formitem};
12018: unless (($idx eq 'add') || ($changes{$itemid})) {
12019: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
12020: $changes{$itemid} = 1;
12021: }
12022: }
12023: }
12024: }
12025: }
12026: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
12027: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
12028: }
1.345 raeburn 12029: if ($confhash{$itemid}{'requser'}) {
12030: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
12031: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
12032: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
12033: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
12034: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
12035: my $mapuser = $env{'form.lti_customuser_'.$idx};
12036: $mapuser =~ s/(`)/'/g;
12037: $mapuser =~ s/^\s+|\s+$//g;
12038: $confhash{$itemid}{'mapuser'} = $mapuser;
12039: }
12040: foreach my $ltirole (@lticourseroles) {
12041: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
12042: if (grep(/^\Q$possrole\E$/,@courseroles)) {
12043: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
12044: }
12045: }
12046: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
12047: my @makeuser;
12048: foreach my $ltirole (sort(@possmakeuser)) {
12049: if ($posslti{$ltirole}) {
12050: push(@makeuser,$ltirole);
12051: }
12052: }
12053: $confhash{$itemid}{'makeuser'} = \@makeuser;
12054: if (@makeuser) {
12055: my $lcauth = $env{'form.lti_lcauth_'.$idx};
12056: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
12057: $confhash{$itemid}{'lcauth'} = $lcauth;
12058: if ($lcauth ne 'internal') {
12059: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
12060: $lcauthparm =~ s/^(\s+|\s+)$//g;
12061: $lcauthparm =~ s/`//g;
12062: if ($lcauthparm ne '') {
12063: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
12064: }
12065: }
12066: } else {
12067: $confhash{$itemid}{'lcauth'} = 'lti';
12068: }
1.320 raeburn 12069: }
1.345 raeburn 12070: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
12071: if (@possinstdata) {
12072: foreach my $field (@possinstdata) {
12073: if (exists($fieldtitles{$field})) {
12074: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 12075: }
12076: }
12077: }
1.345 raeburn 12078: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
12079: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
12080: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
12081: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
12082: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
12083: $mapcrs =~ s/(`)/'/g;
12084: $mapcrs =~ s/^\s+|\s+$//g;
12085: $confhash{$itemid}{'mapcrs'} = $mapcrs;
12086: }
12087: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
12088: my @crstypes;
12089: foreach my $type (sort(@posstypes)) {
12090: if ($posscrstype{$type}) {
12091: push(@crstypes,$type);
1.325 raeburn 12092: }
12093: }
1.345 raeburn 12094: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
12095: if ($env{'form.lti_makecrs_'.$idx}) {
12096: $confhash{$itemid}{'makecrs'} = 1;
1.320 raeburn 12097: }
1.345 raeburn 12098: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
12099: my @selfenroll;
12100: foreach my $type (sort(@possenroll)) {
12101: if ($posslticrs{$type}) {
12102: push(@selfenroll,$type);
12103: }
1.320 raeburn 12104: }
1.345 raeburn 12105: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
12106: if ($env{'form.lti_crssec_'.$idx}) {
12107: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
12108: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
12109: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
12110: my $section = $env{'form.lti_customsection_'.$idx};
12111: $section =~ s/(`)/'/g;
12112: $section =~ s/^\s+|\s+$//g;
12113: if ($section ne '') {
12114: $confhash{$itemid}{'section'} = $section;
12115: }
1.320 raeburn 12116: }
12117: }
1.345 raeburn 12118: foreach my $field ('passback','roster','topmenu','inlinemenu') {
12119: if ($env{'form.lti_'.$field.'_'.$idx}) {
12120: $confhash{$itemid}{$field} = 1;
12121: }
1.320 raeburn 12122: }
1.345 raeburn 12123: if ($env{'form.lti_passback_'.$idx}) {
12124: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
12125: $confhash{$itemid}{'passbackformat'} = '1.0';
12126: } else {
12127: $confhash{$itemid}{'passbackformat'} = '1.1';
12128: }
1.337 raeburn 12129: }
1.345 raeburn 12130: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
12131: $confhash{$itemid}{lcmenu} = [];
12132: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
12133: foreach my $field (@possmenu) {
12134: if (exists($menutitles{$field})) {
12135: if ($field eq 'grades') {
12136: next unless ($env{'form.lti_inlinemenu_'.$idx});
12137: }
12138: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 12139: }
12140: }
12141: }
1.345 raeburn 12142: unless (($idx eq 'add') || ($changes{$itemid})) {
12143: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu') {
12144: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.337 raeburn 12145: $changes{$itemid} = 1;
12146: }
12147: }
1.320 raeburn 12148: unless ($changes{$itemid}) {
1.345 raeburn 12149: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
12150: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 12151: $changes{$itemid} = 1;
12152: }
1.345 raeburn 12153: }
1.320 raeburn 12154: }
1.345 raeburn 12155: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
12156: unless ($changes{$itemid}) {
12157: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
12158: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
12159: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
12160: $confhash{$itemid}{$field});
12161: if (@diffs) {
12162: $changes{$itemid} = 1;
12163: }
12164: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
12165: $changes{$itemid} = 1;
12166: }
12167: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
12168: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 12169: $changes{$itemid} = 1;
12170: }
12171: }
1.345 raeburn 12172: }
12173: }
12174: unless ($changes{$itemid}) {
12175: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
12176: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12177: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
12178: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
12179: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.320 raeburn 12180: $changes{$itemid} = 1;
12181: last;
12182: }
12183: }
1.345 raeburn 12184: unless ($changes{$itemid}) {
12185: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
12186: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
12187: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
12188: $changes{$itemid} = 1;
12189: last;
12190: }
12191: }
12192: }
12193: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
12194: $changes{$itemid} = 1;
1.320 raeburn 12195: }
1.345 raeburn 12196: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12197: unless ($changes{$itemid}) {
12198: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
12199: $changes{$itemid} = 1;
12200: }
1.320 raeburn 12201: }
12202: }
12203: }
12204: }
12205: }
12206: }
12207: if (@allpos > 0) {
12208: my $idx = 0;
12209: foreach my $itemid (@allpos) {
12210: if ($itemid ne '') {
12211: $confhash{$itemid}{'order'} = $idx;
12212: if (ref($domconfig{$action}) eq 'HASH') {
12213: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12214: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12215: $changes{$itemid} = 1;
12216: }
12217: }
12218: }
12219: $idx ++;
12220: }
12221: }
12222: }
12223: my %ltihash = (
12224: $action => { %confhash }
12225: );
12226: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
12227: $dom);
12228: if ($putresult eq 'ok') {
12229: my %ltienchash = (
12230: $action => { %encconfig }
12231: );
12232: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
12233: if (keys(%changes) > 0) {
12234: my $cachetime = 24*60*60;
12235: my %ltiall = %confhash;
12236: foreach my $id (keys(%ltiall)) {
12237: if (ref($encconfig{$id}) eq 'HASH') {
12238: foreach my $item ('key','secret') {
12239: $ltiall{$id}{$item} = $encconfig{$id}{$item};
12240: }
12241: }
12242: }
12243: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
12244: if (ref($lastactref) eq 'HASH') {
12245: $lastactref->{'lti'} = 1;
12246: }
12247: $resulttext = &mt('Changes made:').'<ul>';
12248: my %bynum;
12249: foreach my $itemid (sort(keys(%changes))) {
12250: my $position = $confhash{$itemid}{'order'};
12251: $bynum{$position} = $itemid;
12252: }
12253: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12254: my $itemid = $bynum{$pos};
12255: if (ref($confhash{$itemid}) ne 'HASH') {
12256: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12257: } else {
12258: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
12259: my $position = $pos + 1;
12260: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12261: foreach my $item ('version','lifetime') {
12262: if ($confhash{$itemid}{$item} ne '') {
12263: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12264: }
12265: }
12266: if ($encconfig{$itemid}{'key'} ne '') {
12267: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12268: }
12269: if ($encconfig{$itemid}{'secret'} ne '') {
12270: $resulttext .= '<li>'.$lt{'secret'}.': ';
12271: my $num = length($encconfig{$itemid}{'secret'});
12272: $resulttext .= ('*'x$num).'</li>';
12273: }
1.345 raeburn 12274: if ($confhash{$itemid}{'requser'}) {
12275: if ($confhash{$itemid}{'mapuser'}) {
12276: my $shownmapuser;
12277: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
12278: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
12279: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
12280: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
12281: } else {
12282: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 12283: }
1.345 raeburn 12284: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 12285: }
1.345 raeburn 12286: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12287: my $rolemaps;
12288: foreach my $role (@ltiroles) {
12289: if ($confhash{$itemid}{'maproles'}{$role}) {
12290: $rolemaps .= (' 'x2).$role.'='.
12291: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
12292: 'Course').',';
12293: }
12294: }
12295: if ($rolemaps) {
12296: $rolemaps =~ s/,$//;
12297: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12298: }
12299: }
12300: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
12301: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
12302: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
12303: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
12304: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
12305: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
12306: } else {
12307: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
12308: $confhash{$itemid}{'lcauth'});
12309: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
12310: $resulttext .= '; '.&mt('a randomly generated password will be created');
12311: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
12312: if ($confhash{$itemid}{'lcauthparm'} ne '') {
12313: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
12314: }
12315: } else {
12316: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
12317: }
12318: }
12319: $resulttext .= '</li>';
12320: } else {
12321: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
12322: }
1.320 raeburn 12323: }
1.345 raeburn 12324: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
12325: if (@{$confhash{$itemid}{'instdata'}} > 0) {
12326: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
12327: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 12328: } else {
1.345 raeburn 12329: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 12330: }
1.320 raeburn 12331: }
1.345 raeburn 12332: if ($confhash{$itemid}{'mapcrs'}) {
12333: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
12334: }
12335: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
12336: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
12337: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
12338: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
12339: '</li>';
12340: } else {
12341: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
12342: }
1.325 raeburn 12343: }
1.345 raeburn 12344: if ($confhash{$itemid}{'makecrs'}) {
12345: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
1.320 raeburn 12346: } else {
1.345 raeburn 12347: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
1.320 raeburn 12348: }
1.345 raeburn 12349: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
12350: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
12351: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
12352: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
12353: '</li>';
12354: } else {
12355: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
12356: }
1.320 raeburn 12357: }
1.345 raeburn 12358: if ($confhash{$itemid}{'section'}) {
12359: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
12360: $resulttext .= '<li>'.&mt('User section from standard field:').
12361: ' (course_section_sourcedid)'.'</li>';
12362: } else {
12363: $resulttext .= '<li>'.&mt('User section from:').' '.
12364: $confhash{$itemid}{'section'}.'</li>';
12365: }
1.320 raeburn 12366: } else {
1.345 raeburn 12367: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
1.320 raeburn 12368: }
1.345 raeburn 12369: foreach my $item ('passback','roster','topmenu','inlinemenu') {
12370: $resulttext .= '<li>'.$lt{$item}.': ';
12371: if ($confhash{$itemid}{$item}) {
12372: $resulttext .= &mt('Yes');
12373: if ($item eq 'passback') {
12374: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
12375: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
12376: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
12377: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
12378: }
1.337 raeburn 12379: }
1.345 raeburn 12380: } else {
12381: $resulttext .= &mt('No');
1.337 raeburn 12382: }
1.345 raeburn 12383: $resulttext .= '</li>';
1.320 raeburn 12384: }
1.345 raeburn 12385: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
12386: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
12387: $resulttext .= '<li>'.&mt('Menu items:').' '.
12388: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
12389: } else {
12390: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
12391: }
1.326 raeburn 12392: }
12393: }
1.320 raeburn 12394: $resulttext .= '</ul></li>';
12395: }
12396: }
12397: $resulttext .= '</ul>';
12398: } else {
12399: $resulttext = &mt('No changes made.');
12400: }
12401: } else {
12402: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12403: }
12404: if ($errors) {
12405: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12406: $errors.'</ul>';
12407: }
12408: return $resulttext;
12409: }
12410:
12411: sub get_lti_id {
12412: my ($domain,$consumer) = @_;
12413: # get lock on lti db
12414: my $lockhash = {
12415: lock => $env{'user.name'}.
12416: ':'.$env{'user.domain'},
12417: };
12418: my $tries = 0;
12419: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12420: my ($id,$error);
12421:
12422: while (($gotlock ne 'ok') && ($tries<10)) {
12423: $tries ++;
12424: sleep (0.1);
12425: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12426: }
12427: if ($gotlock eq 'ok') {
12428: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
12429: if ($currids{'lock'}) {
12430: delete($currids{'lock'});
12431: if (keys(%currids)) {
12432: my @curr = sort { $a <=> $b } keys(%currids);
12433: if ($curr[-1] =~ /^\d+$/) {
12434: $id = 1 + $curr[-1];
12435: }
12436: } else {
12437: $id = 1;
12438: }
12439: if ($id) {
12440: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
12441: $error = 'nostore';
12442: }
12443: } else {
12444: $error = 'nonumber';
12445: }
12446: }
12447: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
12448: } else {
12449: $error = 'nolock';
12450: }
12451: return ($id,$error);
12452: }
12453:
1.3 raeburn 12454: sub modify_autoenroll {
1.205 raeburn 12455: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 12456: my ($resulttext,%changes);
12457: my %currautoenroll;
12458: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
12459: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
12460: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
12461: }
12462: }
12463: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
12464: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 12465: sender => 'Sender for notification messages',
1.274 raeburn 12466: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
12467: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 12468: my @offon = ('off','on');
1.17 raeburn 12469: my $sender_uname = $env{'form.sender_uname'};
12470: my $sender_domain = $env{'form.sender_domain'};
12471: if ($sender_domain eq '') {
12472: $sender_uname = '';
12473: } elsif ($sender_uname eq '') {
12474: $sender_domain = '';
12475: }
1.129 raeburn 12476: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 12477: my $failsafe = $env{'form.autoenroll_failsafe'};
12478: $failsafe =~ s{^\s+|\s+$}{}g;
12479: if ($failsafe =~ /\D/) {
12480: undef($failsafe);
12481: }
1.1 raeburn 12482: my %autoenrollhash = (
1.129 raeburn 12483: autoenroll => { 'run' => $env{'form.autoenroll_run'},
12484: 'sender_uname' => $sender_uname,
12485: 'sender_domain' => $sender_domain,
12486: 'co-owners' => $coowners,
1.274 raeburn 12487: 'autofailsafe' => $failsafe,
1.1 raeburn 12488: }
12489: );
1.4 raeburn 12490: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
12491: $dom);
1.1 raeburn 12492: if ($putresult eq 'ok') {
12493: if (exists($currautoenroll{'run'})) {
12494: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
12495: $changes{'run'} = 1;
12496: }
12497: } elsif ($autorun) {
12498: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 12499: $changes{'run'} = 1;
1.1 raeburn 12500: }
12501: }
1.17 raeburn 12502: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 12503: $changes{'sender'} = 1;
12504: }
1.17 raeburn 12505: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 12506: $changes{'sender'} = 1;
12507: }
1.129 raeburn 12508: if ($currautoenroll{'co-owners'} ne '') {
12509: if ($currautoenroll{'co-owners'} ne $coowners) {
12510: $changes{'coowners'} = 1;
12511: }
12512: } elsif ($coowners) {
12513: $changes{'coowners'} = 1;
1.274 raeburn 12514: }
12515: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
12516: $changes{'autofailsafe'} = 1;
12517: }
1.1 raeburn 12518: if (keys(%changes) > 0) {
12519: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 12520: if ($changes{'run'}) {
1.1 raeburn 12521: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
12522: }
12523: if ($changes{'sender'}) {
1.17 raeburn 12524: if ($sender_uname eq '' || $sender_domain eq '') {
12525: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
12526: } else {
12527: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
12528: }
1.1 raeburn 12529: }
1.129 raeburn 12530: if ($changes{'coowners'}) {
12531: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
12532: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12533: if (ref($lastactref) eq 'HASH') {
12534: $lastactref->{'domainconfig'} = 1;
12535: }
1.129 raeburn 12536: }
1.274 raeburn 12537: if ($changes{'autofailsafe'}) {
12538: if ($failsafe ne '') {
1.299 raeburn 12539: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 12540: } else {
1.299 raeburn 12541: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 12542: }
12543: &Apache::lonnet::get_domain_defaults($dom,1);
12544: if (ref($lastactref) eq 'HASH') {
12545: $lastactref->{'domdefaults'} = 1;
12546: }
12547: }
1.1 raeburn 12548: $resulttext .= '</ul>';
12549: } else {
12550: $resulttext = &mt('No changes made to auto-enrollment settings');
12551: }
12552: } else {
1.11 albertel 12553: $resulttext = '<span class="LC_error">'.
12554: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12555: }
1.3 raeburn 12556: return $resulttext;
1.1 raeburn 12557: }
12558:
12559: sub modify_autoupdate {
1.3 raeburn 12560: my ($dom,%domconfig) = @_;
1.1 raeburn 12561: my ($resulttext,%currautoupdate,%fields,%changes);
12562: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
12563: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
12564: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
12565: }
12566: }
12567: my @offon = ('off','on');
12568: my %title = &Apache::lonlocal::texthash (
12569: run => 'Auto-update:',
12570: classlists => 'Updates to user information in classlists?'
12571: );
1.44 raeburn 12572: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12573: my %fieldtitles = &Apache::lonlocal::texthash (
12574: id => 'Student/Employee ID',
1.20 raeburn 12575: permanentemail => 'E-mail address',
1.1 raeburn 12576: lastname => 'Last Name',
12577: firstname => 'First Name',
12578: middlename => 'Middle Name',
1.132 raeburn 12579: generation => 'Generation',
1.1 raeburn 12580: );
1.142 raeburn 12581: $othertitle = &mt('All users');
1.1 raeburn 12582: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 12583: $othertitle = &mt('Other users');
1.1 raeburn 12584: }
12585: foreach my $key (keys(%env)) {
12586: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 12587: my ($usertype,$item) = ($1,$2);
12588: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
12589: if ($usertype eq 'default') {
12590: push(@{$fields{$1}},$2);
12591: } elsif (ref($types) eq 'ARRAY') {
12592: if (grep(/^\Q$usertype\E$/,@{$types})) {
12593: push(@{$fields{$1}},$2);
12594: }
12595: }
12596: }
1.1 raeburn 12597: }
12598: }
1.131 raeburn 12599: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
12600: @lockablenames = sort(@lockablenames);
12601: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
12602: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12603: if (@changed) {
12604: $changes{'lockablenames'} = 1;
12605: }
12606: } else {
12607: if (@lockablenames) {
12608: $changes{'lockablenames'} = 1;
12609: }
12610: }
1.1 raeburn 12611: my %updatehash = (
12612: autoupdate => { run => $env{'form.autoupdate_run'},
12613: classlists => $env{'form.classlists'},
12614: fields => {%fields},
1.131 raeburn 12615: lockablenames => \@lockablenames,
1.1 raeburn 12616: }
12617: );
12618: foreach my $key (keys(%currautoupdate)) {
12619: if (($key eq 'run') || ($key eq 'classlists')) {
12620: if (exists($updatehash{autoupdate}{$key})) {
12621: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
12622: $changes{$key} = 1;
12623: }
12624: }
12625: } elsif ($key eq 'fields') {
12626: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 12627: foreach my $item (@{$types},'default') {
1.1 raeburn 12628: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
12629: my $change = 0;
12630: foreach my $type (@{$currautoupdate{$key}{$item}}) {
12631: if (!exists($fields{$item})) {
12632: $change = 1;
1.132 raeburn 12633: last;
1.1 raeburn 12634: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 12635: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 12636: $change = 1;
1.132 raeburn 12637: last;
1.1 raeburn 12638: }
12639: }
12640: }
12641: if ($change) {
12642: push(@{$changes{$key}},$item);
12643: }
1.26 raeburn 12644: }
1.1 raeburn 12645: }
12646: }
1.131 raeburn 12647: } elsif ($key eq 'lockablenames') {
12648: if (ref($currautoupdate{$key}) eq 'ARRAY') {
12649: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12650: if (@changed) {
12651: $changes{'lockablenames'} = 1;
12652: }
12653: } else {
12654: if (@lockablenames) {
12655: $changes{'lockablenames'} = 1;
12656: }
12657: }
12658: }
12659: }
12660: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
12661: if (@lockablenames) {
12662: $changes{'lockablenames'} = 1;
1.1 raeburn 12663: }
12664: }
1.26 raeburn 12665: foreach my $item (@{$types},'default') {
12666: if (defined($fields{$item})) {
12667: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 12668: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
12669: my $change = 0;
12670: if (ref($fields{$item}) eq 'ARRAY') {
12671: foreach my $type (@{$fields{$item}}) {
12672: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
12673: $change = 1;
12674: last;
12675: }
12676: }
12677: }
12678: if ($change) {
12679: push(@{$changes{'fields'}},$item);
12680: }
12681: } else {
1.26 raeburn 12682: push(@{$changes{'fields'}},$item);
12683: }
12684: } else {
12685: push(@{$changes{'fields'}},$item);
1.1 raeburn 12686: }
12687: }
12688: }
12689: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
12690: $dom);
12691: if ($putresult eq 'ok') {
12692: if (keys(%changes) > 0) {
12693: $resulttext = &mt('Changes made:').'<ul>';
12694: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 12695: if ($key eq 'lockablenames') {
12696: $resulttext .= '<li>';
12697: if (@lockablenames) {
12698: $usertypes->{'default'} = $othertitle;
12699: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
12700: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
12701: } else {
12702: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
12703: }
12704: $resulttext .= '</li>';
12705: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 12706: foreach my $item (@{$changes{$key}}) {
12707: my @newvalues;
12708: foreach my $type (@{$fields{$item}}) {
12709: push(@newvalues,$fieldtitles{$type});
12710: }
1.3 raeburn 12711: my $newvaluestr;
12712: if (@newvalues > 0) {
12713: $newvaluestr = join(', ',@newvalues);
12714: } else {
12715: $newvaluestr = &mt('none');
1.6 raeburn 12716: }
1.1 raeburn 12717: if ($item eq 'default') {
1.26 raeburn 12718: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 12719: } else {
1.26 raeburn 12720: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 12721: }
12722: }
12723: } else {
12724: my $newvalue;
12725: if ($key eq 'run') {
12726: $newvalue = $offon[$env{'form.autoupdate_run'}];
12727: } else {
12728: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 12729: }
1.1 raeburn 12730: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
12731: }
12732: }
12733: $resulttext .= '</ul>';
12734: } else {
1.3 raeburn 12735: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 12736: }
12737: } else {
1.11 albertel 12738: $resulttext = '<span class="LC_error">'.
12739: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12740: }
1.3 raeburn 12741: return $resulttext;
1.1 raeburn 12742: }
12743:
1.125 raeburn 12744: sub modify_autocreate {
12745: my ($dom,%domconfig) = @_;
12746: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
12747: if (ref($domconfig{'autocreate'}) eq 'HASH') {
12748: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
12749: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
12750: }
12751: }
12752: my %title= ( xml => 'Auto-creation of courses in XML course description files',
12753: req => 'Auto-creation of validated requests for official courses',
12754: xmldc => 'Identity of course creator of courses from XML files',
12755: );
12756: my @types = ('xml','req');
12757: foreach my $item (@types) {
12758: $newvals{$item} = $env{'form.autocreate_'.$item};
12759: $newvals{$item} =~ s/\D//g;
12760: $newvals{$item} = 0 if ($newvals{$item} eq '');
12761: }
12762: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 12763: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 12764: unless (exists($domcoords{$newvals{'xmldc'}})) {
12765: $newvals{'xmldc'} = '';
12766: }
12767: %autocreatehash = (
12768: autocreate => { xml => $newvals{'xml'},
12769: req => $newvals{'req'},
12770: }
12771: );
12772: if ($newvals{'xmldc'} ne '') {
12773: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
12774: }
12775: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
12776: $dom);
12777: if ($putresult eq 'ok') {
12778: my @items = @types;
12779: if ($newvals{'xml'}) {
12780: push(@items,'xmldc');
12781: }
12782: foreach my $item (@items) {
12783: if (exists($currautocreate{$item})) {
12784: if ($currautocreate{$item} ne $newvals{$item}) {
12785: $changes{$item} = 1;
12786: }
12787: } elsif ($newvals{$item}) {
12788: $changes{$item} = 1;
12789: }
12790: }
12791: if (keys(%changes) > 0) {
12792: my @offon = ('off','on');
12793: $resulttext = &mt('Changes made:').'<ul>';
12794: foreach my $item (@types) {
12795: if ($changes{$item}) {
12796: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 12797: $resulttext .= '<li>'.
12798: &mt("$title{$item} set to [_1]$newtxt [_2]",
12799: '<b>','</b>').
12800: '</li>';
1.125 raeburn 12801: }
12802: }
12803: if ($changes{'xmldc'}) {
12804: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
12805: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 12806: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 12807: }
12808: $resulttext .= '</ul>';
12809: } else {
12810: $resulttext = &mt('No changes made to auto-creation settings');
12811: }
12812: } else {
12813: $resulttext = '<span class="LC_error">'.
12814: &mt('An error occurred: [_1]',$putresult).'</span>';
12815: }
12816: return $resulttext;
12817: }
12818:
1.23 raeburn 12819: sub modify_directorysrch {
1.295 raeburn 12820: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 12821: my ($resulttext,%changes);
12822: my %currdirsrch;
12823: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
12824: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
12825: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
12826: }
12827: }
1.277 raeburn 12828: my %title = ( available => 'Institutional directory search available',
12829: localonly => 'Other domains can search institution',
12830: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 12831: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 12832: searchby => 'Search types',
12833: searchtypes => 'Search latitude');
12834: my @offon = ('off','on');
1.24 raeburn 12835: my @otherdoms = ('Yes','No');
1.23 raeburn 12836:
1.25 raeburn 12837: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 12838: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
12839: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
12840:
1.44 raeburn 12841: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 12842: if (keys(%{$usertypes}) == 0) {
12843: @cansearch = ('default');
12844: } else {
12845: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
12846: foreach my $type (@{$currdirsrch{'cansearch'}}) {
12847: if (!grep(/^\Q$type\E$/,@cansearch)) {
12848: push(@{$changes{'cansearch'}},$type);
12849: }
1.23 raeburn 12850: }
1.26 raeburn 12851: foreach my $type (@cansearch) {
12852: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
12853: push(@{$changes{'cansearch'}},$type);
12854: }
1.23 raeburn 12855: }
1.26 raeburn 12856: } else {
12857: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 12858: }
12859: }
12860:
12861: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
12862: foreach my $by (@{$currdirsrch{'searchby'}}) {
12863: if (!grep(/^\Q$by\E$/,@searchby)) {
12864: push(@{$changes{'searchby'}},$by);
12865: }
12866: }
12867: foreach my $by (@searchby) {
12868: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
12869: push(@{$changes{'searchby'}},$by);
12870: }
12871: }
12872: } else {
12873: push(@{$changes{'searchby'}},@searchby);
12874: }
1.25 raeburn 12875:
12876: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
12877: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
12878: if (!grep(/^\Q$type\E$/,@searchtypes)) {
12879: push(@{$changes{'searchtypes'}},$type);
12880: }
12881: }
12882: foreach my $type (@searchtypes) {
12883: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
12884: push(@{$changes{'searchtypes'}},$type);
12885: }
12886: }
12887: } else {
12888: if (exists($currdirsrch{'searchtypes'})) {
12889: foreach my $type (@searchtypes) {
12890: if ($type ne $currdirsrch{'searchtypes'}) {
12891: push(@{$changes{'searchtypes'}},$type);
12892: }
12893: }
12894: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
12895: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12896: }
12897: } else {
12898: push(@{$changes{'searchtypes'}},@searchtypes);
12899: }
12900: }
12901:
1.23 raeburn 12902: my %dirsrch_hash = (
12903: directorysrch => { available => $env{'form.dirsrch_available'},
12904: cansearch => \@cansearch,
1.277 raeburn 12905: localonly => $env{'form.dirsrch_instlocalonly'},
12906: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12907: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 12908: searchby => \@searchby,
1.25 raeburn 12909: searchtypes => \@searchtypes,
1.23 raeburn 12910: }
12911: );
12912: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12913: $dom);
12914: if ($putresult eq 'ok') {
12915: if (exists($currdirsrch{'available'})) {
12916: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12917: $changes{'available'} = 1;
12918: }
12919: } else {
12920: if ($env{'form.dirsrch_available'} eq '1') {
12921: $changes{'available'} = 1;
12922: }
12923: }
1.277 raeburn 12924: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 12925: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12926: $changes{'lcavailable'} = 1;
12927: }
1.277 raeburn 12928: } else {
12929: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12930: $changes{'lcavailable'} = 1;
12931: }
12932: }
1.24 raeburn 12933: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 12934: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
12935: $changes{'localonly'} = 1;
12936: }
1.24 raeburn 12937: } else {
1.277 raeburn 12938: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 12939: $changes{'localonly'} = 1;
12940: }
12941: }
1.277 raeburn 12942: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 12943: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12944: $changes{'lclocalonly'} = 1;
12945: }
1.277 raeburn 12946: } else {
12947: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12948: $changes{'lclocalonly'} = 1;
12949: }
12950: }
1.23 raeburn 12951: if (keys(%changes) > 0) {
12952: $resulttext = &mt('Changes made:').'<ul>';
12953: if ($changes{'available'}) {
12954: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12955: }
1.277 raeburn 12956: if ($changes{'lcavailable'}) {
12957: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12958: }
1.24 raeburn 12959: if ($changes{'localonly'}) {
1.277 raeburn 12960: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 12961: }
1.277 raeburn 12962: if ($changes{'lclocalonly'}) {
12963: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 12964: }
1.23 raeburn 12965: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12966: my $chgtext;
1.26 raeburn 12967: if (ref($usertypes) eq 'HASH') {
12968: if (keys(%{$usertypes}) > 0) {
12969: foreach my $type (@{$types}) {
12970: if (grep(/^\Q$type\E$/,@cansearch)) {
12971: $chgtext .= $usertypes->{$type}.'; ';
12972: }
12973: }
12974: if (grep(/^default$/,@cansearch)) {
12975: $chgtext .= $othertitle;
12976: } else {
12977: $chgtext =~ s/\; $//;
12978: }
1.210 raeburn 12979: $resulttext .=
1.178 raeburn 12980: '<li>'.
12981: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12982: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12983: '</li>';
1.23 raeburn 12984: }
12985: }
12986: }
12987: if (ref($changes{'searchby'}) eq 'ARRAY') {
12988: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12989: my $chgtext;
12990: foreach my $type (@{$titleorder}) {
12991: if (grep(/^\Q$type\E$/,@searchby)) {
12992: if (defined($searchtitles->{$type})) {
12993: $chgtext .= $searchtitles->{$type}.'; ';
12994: }
12995: }
12996: }
12997: $chgtext =~ s/\; $//;
12998: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12999: }
1.25 raeburn 13000: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
13001: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
13002: my $chgtext;
13003: foreach my $type (@{$srchtypeorder}) {
13004: if (grep(/^\Q$type\E$/,@searchtypes)) {
13005: if (defined($srchtypes_desc->{$type})) {
13006: $chgtext .= $srchtypes_desc->{$type}.'; ';
13007: }
13008: }
13009: }
13010: $chgtext =~ s/\; $//;
1.178 raeburn 13011: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 13012: }
13013: $resulttext .= '</ul>';
1.295 raeburn 13014: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
13015: if (ref($lastactref) eq 'HASH') {
13016: $lastactref->{'directorysrch'} = 1;
13017: }
1.23 raeburn 13018: } else {
1.277 raeburn 13019: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 13020: }
13021: } else {
13022: $resulttext = '<span class="LC_error">'.
1.27 raeburn 13023: &mt('An error occurred: [_1]',$putresult).'</span>';
13024: }
13025: return $resulttext;
13026: }
13027:
1.28 raeburn 13028: sub modify_contacts {
1.205 raeburn 13029: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 13030: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
13031: if (ref($domconfig{'contacts'}) eq 'HASH') {
13032: foreach my $key (keys(%{$domconfig{'contacts'}})) {
13033: $currsetting{$key} = $domconfig{'contacts'}{$key};
13034: }
13035: }
1.286 raeburn 13036: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 13037: my @contacts = ('supportemail','adminemail');
1.286 raeburn 13038: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
13039: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.340 raeburn 13040: my @toggles = ('reporterrors','reportupdates','reportstatus');
13041: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 13042: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 13043: foreach my $type (@mailings) {
13044: @{$newsetting{$type}} =
13045: &Apache::loncommon::get_env_multiple('form.'.$type);
13046: foreach my $item (@contacts) {
13047: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
13048: $contacts_hash{contacts}{$type}{$item} = 1;
13049: } else {
13050: $contacts_hash{contacts}{$type}{$item} = 0;
13051: }
1.289 raeburn 13052: }
1.28 raeburn 13053: $others{$type} = $env{'form.'.$type.'_others'};
13054: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 13055: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13056: $bcc{$type} = $env{'form.'.$type.'_bcc'};
13057: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 13058: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
13059: $includestr{$type} = $env{'form.'.$type.'_includestr'};
13060: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
13061: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13062: }
1.134 raeburn 13063: }
1.28 raeburn 13064: }
13065: foreach my $item (@contacts) {
13066: $to{$item} = $env{'form.'.$item};
13067: $contacts_hash{'contacts'}{$item} = $to{$item};
13068: }
1.203 raeburn 13069: foreach my $item (@toggles) {
13070: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13071: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
13072: }
13073: }
1.340 raeburn 13074: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
13075: foreach my $item (@lonstatus) {
13076: if ($item eq 'excluded') {
13077: my (%serverhomes,@excluded);
13078: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
13079: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
13080: if (@possexcluded) {
13081: foreach my $id (sort(@possexcluded)) {
13082: if ($serverhomes{$id}) {
13083: push(@excluded,$id);
13084: }
13085: }
13086: }
13087: if (@excluded) {
13088: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
13089: }
13090: } elsif ($item eq 'weights') {
13091: foreach my $type ('E','W','N') {
13092: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
13093: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
13094: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
13095: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
13096: $env{'form.error'.$item.'_'.$type};
13097: }
13098: }
13099: }
13100: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
13101: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
13102: if ($env{'form.error'.$item} =~ /^\d+$/) {
13103: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
13104: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
13105: }
13106: }
13107: }
13108: }
1.286 raeburn 13109: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
13110: foreach my $field (@{$fields}) {
13111: if (ref($possoptions->{$field}) eq 'ARRAY') {
13112: my $value = $env{'form.helpform_'.$field};
13113: $value =~ s/^\s+|\s+$//g;
13114: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 13115: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 13116: if ($field eq 'screenshot') {
13117: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
13118: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 13119: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 13120: }
13121: }
13122: }
13123: }
13124: }
13125: }
1.315 raeburn 13126: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13127: my (@statuses,%usertypeshash,@overrides);
13128: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
13129: @statuses = @{$types};
13130: if (ref($usertypes) eq 'HASH') {
13131: %usertypeshash = %{$usertypes};
13132: }
13133: }
13134: if (@statuses) {
13135: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
13136: foreach my $type (@possoverrides) {
13137: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
13138: push(@overrides,$type);
13139: }
13140: }
13141: if (@overrides) {
13142: foreach my $type (@overrides) {
13143: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
13144: foreach my $item (@contacts) {
13145: if (grep(/^\Q$item\E$/,@standard)) {
13146: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
13147: $newsetting{'override_'.$type}{$item} = 1;
13148: } else {
13149: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
13150: $newsetting{'override_'.$type}{$item} = 0;
13151: }
13152: }
13153: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
13154: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13155: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
13156: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13157: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
13158: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
13159: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
13160: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13161: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
13162: }
13163: }
13164: }
13165: }
1.28 raeburn 13166: if (keys(%currsetting) > 0) {
13167: foreach my $item (@contacts) {
13168: if ($to{$item} ne $currsetting{$item}) {
13169: $changes{$item} = 1;
13170: }
13171: }
13172: foreach my $type (@mailings) {
13173: foreach my $item (@contacts) {
13174: if (ref($currsetting{$type}) eq 'HASH') {
13175: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
13176: push(@{$changes{$type}},$item);
13177: }
13178: } else {
13179: push(@{$changes{$type}},@{$newsetting{$type}});
13180: }
13181: }
13182: if ($others{$type} ne $currsetting{$type}{'others'}) {
13183: push(@{$changes{$type}},'others');
13184: }
1.289 raeburn 13185: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13186: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
13187: push(@{$changes{$type}},'bcc');
13188: }
1.286 raeburn 13189: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
13190: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
13191: push(@{$changes{$type}},'include');
13192: }
13193: }
13194: }
13195: if (ref($fields) eq 'ARRAY') {
13196: if (ref($currsetting{'helpform'}) eq 'HASH') {
13197: foreach my $field (@{$fields}) {
13198: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
13199: push(@{$changes{'helpform'}},$field);
13200: }
13201: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13202: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
13203: push(@{$changes{'helpform'}},'maxsize');
13204: }
13205: }
13206: }
13207: } else {
13208: foreach my $field (@{$fields}) {
13209: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13210: push(@{$changes{'helpform'}},$field);
13211: }
13212: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13213: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13214: push(@{$changes{'helpform'}},'maxsize');
13215: }
13216: }
13217: }
1.134 raeburn 13218: }
1.28 raeburn 13219: }
1.315 raeburn 13220: if (@statuses) {
13221: if (ref($currsetting{'overrides'}) eq 'HASH') {
13222: foreach my $key (keys(%{$currsetting{'overrides'}})) {
13223: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
13224: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
13225: foreach my $item (@contacts,'bcc','others','include') {
13226: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
13227: push(@{$changes{'overrides'}},$key);
13228: last;
13229: }
13230: }
13231: } else {
13232: push(@{$changes{'overrides'}},$key);
13233: }
13234: }
13235: }
13236: foreach my $key (@overrides) {
13237: unless (exists($currsetting{'overrides'}{$key})) {
13238: push(@{$changes{'overrides'}},$key);
13239: }
13240: }
13241: } else {
13242: foreach my $key (@overrides) {
13243: push(@{$changes{'overrides'}},$key);
13244: }
13245: }
13246: }
1.340 raeburn 13247: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
13248: foreach my $key ('excluded','weights','threshold','sysmail') {
13249: if ($key eq 'excluded') {
13250: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13251: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
13252: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13253: (@{$currsetting{'lonstatus'}{$key}})) {
13254: my @diffs =
13255: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
13256: $currsetting{'lonstatus'}{$key});
13257: if (@diffs) {
13258: push(@{$changes{'lonstatus'}},$key);
13259: }
13260: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
13261: push(@{$changes{'lonstatus'}},$key);
13262: }
13263: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13264: (@{$currsetting{'lonstatus'}{$key}})) {
13265: push(@{$changes{'lonstatus'}},$key);
13266: }
13267: } elsif ($key eq 'weights') {
13268: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13269: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
13270: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13271: foreach my $type ('E','W','N','U') {
1.340 raeburn 13272: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
13273: $currsetting{'lonstatus'}{$key}{$type}) {
13274: push(@{$changes{'lonstatus'}},$key);
13275: last;
13276: }
13277: }
13278: } else {
1.341 raeburn 13279: foreach my $type ('E','W','N','U') {
1.340 raeburn 13280: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
13281: push(@{$changes{'lonstatus'}},$key);
13282: last;
13283: }
13284: }
13285: }
13286: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13287: foreach my $type ('E','W','N','U') {
1.340 raeburn 13288: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
13289: push(@{$changes{'lonstatus'}},$key);
13290: last;
13291: }
13292: }
13293: }
13294: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
13295: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13296: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13297: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
13298: push(@{$changes{'lonstatus'}},$key);
13299: }
13300: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
13301: push(@{$changes{'lonstatus'}},$key);
13302: }
13303: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13304: push(@{$changes{'lonstatus'}},$key);
13305: }
13306: }
13307: }
13308: } else {
13309: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13310: foreach my $key ('excluded','weights','threshold','sysmail') {
13311: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13312: push(@{$changes{'lonstatus'}},$key);
13313: }
13314: }
13315: }
13316: }
1.28 raeburn 13317: } else {
13318: my %default;
13319: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
13320: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
13321: $default{'errormail'} = 'adminemail';
13322: $default{'packagesmail'} = 'adminemail';
13323: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 13324: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 13325: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 13326: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 13327: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 13328: foreach my $item (@contacts) {
13329: if ($to{$item} ne $default{$item}) {
1.286 raeburn 13330: $changes{$item} = 1;
1.203 raeburn 13331: }
1.28 raeburn 13332: }
13333: foreach my $type (@mailings) {
13334: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
13335: push(@{$changes{$type}},@{$newsetting{$type}});
13336: }
13337: if ($others{$type} ne '') {
13338: push(@{$changes{$type}},'others');
1.134 raeburn 13339: }
1.286 raeburn 13340: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13341: if ($bcc{$type} ne '') {
13342: push(@{$changes{$type}},'bcc');
13343: }
1.286 raeburn 13344: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
13345: push(@{$changes{$type}},'include');
13346: }
1.134 raeburn 13347: }
1.28 raeburn 13348: }
1.286 raeburn 13349: if (ref($fields) eq 'ARRAY') {
13350: foreach my $field (@{$fields}) {
13351: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13352: push(@{$changes{'helpform'}},$field);
13353: }
13354: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13355: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13356: push(@{$changes{'helpform'}},'maxsize');
13357: }
13358: }
13359: }
1.289 raeburn 13360: }
1.340 raeburn 13361: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13362: foreach my $key ('excluded','weights','threshold','sysmail') {
13363: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13364: push(@{$changes{'lonstatus'}},$key);
13365: }
13366: }
13367: }
1.28 raeburn 13368: }
1.203 raeburn 13369: foreach my $item (@toggles) {
13370: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
13371: $changes{$item} = 1;
13372: } elsif ((!$env{'form.'.$item}) &&
13373: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
13374: $changes{$item} = 1;
13375: }
13376: }
1.28 raeburn 13377: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
13378: $dom);
13379: if ($putresult eq 'ok') {
13380: if (keys(%changes) > 0) {
1.205 raeburn 13381: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13382: if (ref($lastactref) eq 'HASH') {
13383: $lastactref->{'domainconfig'} = 1;
13384: }
1.28 raeburn 13385: my ($titles,$short_titles) = &contact_titles();
13386: $resulttext = &mt('Changes made:').'<ul>';
13387: foreach my $item (@contacts) {
13388: if ($changes{$item}) {
13389: $resulttext .= '<li>'.$titles->{$item}.
13390: &mt(' set to: ').
13391: '<span class="LC_cusr_emph">'.
13392: $to{$item}.'</span></li>';
13393: }
13394: }
13395: foreach my $type (@mailings) {
13396: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 13397: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 13398: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 13399: } else {
13400: $resulttext .= '<li>'.$titles->{$type}.': ';
13401: }
1.28 raeburn 13402: my @text;
13403: foreach my $item (@{$newsetting{$type}}) {
13404: push(@text,$short_titles->{$item});
13405: }
13406: if ($others{$type} ne '') {
13407: push(@text,$others{$type});
13408: }
1.286 raeburn 13409: if (@text) {
13410: $resulttext .= '<span class="LC_cusr_emph">'.
13411: join(', ',@text).'</span>';
13412: }
13413: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13414: if ($bcc{$type} ne '') {
1.286 raeburn 13415: my $bcctext;
13416: if (@text) {
1.289 raeburn 13417: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 13418: } else {
13419: $bcctext = '(Bcc)';
13420: }
13421: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
13422: } elsif (!@text) {
13423: $resulttext .= &mt('No one');
13424: }
1.289 raeburn 13425: if ($includestr{$type} ne '') {
1.286 raeburn 13426: if ($includeloc{$type} eq 'b') {
13427: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
13428: } elsif ($includeloc{$type} eq 's') {
13429: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
13430: }
1.134 raeburn 13431: }
1.286 raeburn 13432: } elsif (!@text) {
13433: $resulttext .= &mt('No recipients');
1.134 raeburn 13434: }
13435: $resulttext .= '</li>';
1.28 raeburn 13436: }
13437: }
1.315 raeburn 13438: if (ref($changes{'overrides'}) eq 'ARRAY') {
13439: my @deletions;
13440: foreach my $type (@{$changes{'overrides'}}) {
13441: if ($usertypeshash{$type}) {
13442: if (grep(/^\Q$type\E/,@overrides)) {
13443: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
13444: $usertypeshash{$type}).'<ul><li>';
13445: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
13446: my @text;
13447: foreach my $item (@contacts) {
13448: if ($newsetting{'override_'.$type}{$item}) {
13449: push(@text,$short_titles->{$item});
13450: }
13451: }
13452: if ($newsetting{'override_'.$type}{'others'} ne '') {
13453: push(@text,$newsetting{'override_'.$type}{'others'});
13454: }
13455:
13456: if (@text) {
13457: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
13458: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
13459: }
13460: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
13461: my $bcctext;
13462: if (@text) {
13463: $bcctext = ' '.&mt('with Bcc to');
13464: } else {
13465: $bcctext = '(Bcc)';
13466: }
13467: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
13468: } elsif (!@text) {
13469: $resulttext .= &mt('Helpdesk e-mail sent to no one');
13470: }
13471: $resulttext .= '</li>';
13472: if ($newsetting{'override_'.$type}{'include'} ne '') {
13473: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
13474: if ($loc eq 'b') {
13475: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
13476: } elsif ($loc eq 's') {
13477: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
13478: }
13479: }
13480: }
13481: $resulttext .= '</li></ul></li>';
13482: } else {
13483: push(@deletions,$usertypeshash{$type});
13484: }
13485: }
13486: }
13487: if (@deletions) {
13488: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
13489: join(', ',@deletions)).'</li>';
13490: }
13491: }
1.203 raeburn 13492: my @offon = ('off','on');
1.340 raeburn 13493: my $corelink = &core_link_msu();
1.203 raeburn 13494: if ($changes{'reporterrors'}) {
13495: $resulttext .= '<li>'.
13496: &mt('E-mail error reports to [_1] set to "'.
13497: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 13498: $corelink).
1.203 raeburn 13499: '</li>';
13500: }
13501: if ($changes{'reportupdates'}) {
13502: $resulttext .= '<li>'.
13503: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
13504: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 13505: $corelink).
1.203 raeburn 13506: '</li>';
13507: }
1.340 raeburn 13508: if ($changes{'reportstatus'}) {
13509: $resulttext .= '<li>'.
13510: &mt('E-mail status if errors above threshold to [_1] set to "'.
13511: $offon[$env{'form.reportstatus'}].'".',
13512: $corelink).
13513: '</li>';
13514: }
13515: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
13516: $resulttext .= '<li>'.
13517: &mt('Nightly status check e-mail settings').':<ul>';
13518: my (%defval,%use_def,%shown);
13519: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
13520: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
13521: $defval{'weights'} =
1.341 raeburn 13522: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 13523: $defval{'excluded'} = &mt('None');
13524: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
13525: foreach my $item ('threshold','sysmail','weights','excluded') {
13526: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
13527: if (($item eq 'threshold') || ($item eq 'sysmail')) {
13528: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
13529: } elsif ($item eq 'weights') {
13530: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 13531: foreach my $type ('E','W','N','U') {
1.340 raeburn 13532: $shown{$item} .= $lonstatus_names->{$type}.'=';
13533: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
13534: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
13535: } else {
13536: $shown{$item} .= $lonstatus_defs->{$type};
13537: }
13538: $shown{$item} .= ', ';
13539: }
13540: $shown{$item} =~ s/, $//;
13541: } else {
13542: $shown{$item} = $defval{$item};
13543: }
13544: } elsif ($item eq 'excluded') {
13545: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
13546: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
13547: } else {
13548: $shown{$item} = $defval{$item};
13549: }
13550: }
13551: } else {
13552: $shown{$item} = $defval{$item};
13553: }
13554: }
13555: } else {
13556: foreach my $item ('threshold','weights','excluded','sysmail') {
13557: $shown{$item} = $defval{$item};
13558: }
13559: }
13560: foreach my $item ('threshold','weights','excluded','sysmail') {
13561: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
13562: $shown{$item}).'</li>';
13563: }
13564: $resulttext .= '</ul></li>';
13565: }
1.286 raeburn 13566: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
13567: my (@optional,@required,@unused,$maxsizechg);
13568: foreach my $field (@{$changes{'helpform'}}) {
13569: if ($field eq 'maxsize') {
13570: $maxsizechg = 1;
13571: next;
13572: }
13573: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 13574: push(@optional,$field);
1.286 raeburn 13575: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
13576: push(@unused,$field);
13577: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 13578: push(@required,$field);
1.286 raeburn 13579: }
13580: }
13581: if (@optional) {
13582: $resulttext .= '<li>'.
13583: &mt('Help form fields changed to "Optional": [_1].',
13584: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
13585: '</li>';
13586: }
13587: if (@required) {
13588: $resulttext .= '<li>'.
13589: &mt('Help form fields changed to "Required": [_1].',
13590: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
13591: '</li>';
13592: }
13593: if (@unused) {
13594: $resulttext .= '<li>'.
13595: &mt('Help form fields changed to "Not shown": [_1].',
13596: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
13597: '</li>';
13598: }
13599: if ($maxsizechg) {
13600: $resulttext .= '<li>'.
13601: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
13602: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
13603: '</li>';
13604: }
13605: }
1.28 raeburn 13606: $resulttext .= '</ul>';
13607: } else {
1.288 raeburn 13608: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 13609: }
13610: } else {
13611: $resulttext = '<span class="LC_error">'.
13612: &mt('An error occurred: [_1].',$putresult).'</span>';
13613: }
13614: return $resulttext;
13615: }
13616:
13617: sub modify_usercreation {
1.27 raeburn 13618: my ($dom,%domconfig) = @_;
1.224 raeburn 13619: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 13620: my $warningmsg;
1.27 raeburn 13621: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13622: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 13623: if ($key eq 'cancreate') {
13624: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13625: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 13626: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
13627: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13628: } else {
1.224 raeburn 13629: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13630: }
13631: }
13632: }
13633: } elsif ($key eq 'email_rule') {
13634: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13635: } else {
13636: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13637: }
1.27 raeburn 13638: }
13639: }
13640: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 13641: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 13642: my @contexts = ('author','course','requestcrs');
1.34 raeburn 13643: foreach my $item(@contexts) {
1.224 raeburn 13644: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 13645: }
1.34 raeburn 13646: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13647: foreach my $item (@contexts) {
1.224 raeburn 13648: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
13649: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 13650: }
1.27 raeburn 13651: }
1.34 raeburn 13652: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
13653: foreach my $item (@contexts) {
1.43 raeburn 13654: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 13655: if ($cancreate{$item} ne 'any') {
13656: push(@{$changes{'cancreate'}},$item);
13657: }
13658: } else {
13659: if ($cancreate{$item} ne 'none') {
13660: push(@{$changes{'cancreate'}},$item);
13661: }
1.27 raeburn 13662: }
13663: }
13664: } else {
1.43 raeburn 13665: foreach my $item (@contexts) {
1.34 raeburn 13666: push(@{$changes{'cancreate'}},$item);
13667: }
1.27 raeburn 13668: }
1.34 raeburn 13669:
1.27 raeburn 13670: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
13671: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
13672: if (!grep(/^\Q$type\E$/,@username_rule)) {
13673: push(@{$changes{'username_rule'}},$type);
13674: }
13675: }
13676: foreach my $type (@username_rule) {
13677: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
13678: push(@{$changes{'username_rule'}},$type);
13679: }
13680: }
13681: } else {
13682: push(@{$changes{'username_rule'}},@username_rule);
13683: }
13684:
1.32 raeburn 13685: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
13686: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
13687: if (!grep(/^\Q$type\E$/,@id_rule)) {
13688: push(@{$changes{'id_rule'}},$type);
13689: }
13690: }
13691: foreach my $type (@id_rule) {
13692: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
13693: push(@{$changes{'id_rule'}},$type);
13694: }
13695: }
13696: } else {
13697: push(@{$changes{'id_rule'}},@id_rule);
13698: }
13699:
1.43 raeburn 13700: my @authen_contexts = ('author','course','domain');
1.325 raeburn 13701: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 13702: my %authhash;
1.43 raeburn 13703: foreach my $item (@authen_contexts) {
1.28 raeburn 13704: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
13705: foreach my $auth (@authtypes) {
13706: if (grep(/^\Q$auth\E$/,@authallowed)) {
13707: $authhash{$item}{$auth} = 1;
13708: } else {
13709: $authhash{$item}{$auth} = 0;
13710: }
13711: }
13712: }
13713: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 13714: foreach my $item (@authen_contexts) {
1.28 raeburn 13715: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
13716: foreach my $auth (@authtypes) {
13717: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
13718: push(@{$changes{'authtypes'}},$item);
13719: last;
13720: }
13721: }
13722: }
13723: }
13724: } else {
1.43 raeburn 13725: foreach my $item (@authen_contexts) {
1.28 raeburn 13726: push(@{$changes{'authtypes'}},$item);
13727: }
13728: }
13729:
1.224 raeburn 13730: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13731: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13732: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13733: $save_usercreate{'id_rule'} = \@id_rule;
13734: $save_usercreate{'username_rule'} = \@username_rule,
13735: $save_usercreate{'authtypes'} = \%authhash;
13736:
1.27 raeburn 13737: my %usercreation_hash = (
1.224 raeburn 13738: usercreation => \%save_usercreate,
13739: );
1.27 raeburn 13740:
13741: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13742: $dom);
1.50 raeburn 13743:
1.224 raeburn 13744: if ($putresult eq 'ok') {
13745: if (keys(%changes) > 0) {
13746: $resulttext = &mt('Changes made:').'<ul>';
13747: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13748: my %lt = &usercreation_types();
13749: foreach my $type (@{$changes{'cancreate'}}) {
13750: my $chgtext = $lt{$type}.', ';
13751: if ($cancreate{$type} eq 'none') {
13752: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13753: } elsif ($cancreate{$type} eq 'any') {
13754: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13755: } elsif ($cancreate{$type} eq 'official') {
13756: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13757: } elsif ($cancreate{$type} eq 'unofficial') {
13758: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13759: }
13760: $resulttext .= '<li>'.$chgtext.'</li>';
13761: }
13762: }
13763: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13764: my ($rules,$ruleorder) =
13765: &Apache::lonnet::inst_userrules($dom,'username');
13766: my $chgtext = '<ul>';
13767: foreach my $type (@username_rule) {
13768: if (ref($rules->{$type}) eq 'HASH') {
13769: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13770: }
13771: }
13772: $chgtext .= '</ul>';
13773: if (@username_rule > 0) {
13774: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13775: } else {
13776: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13777: }
13778: }
13779: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13780: my ($idrules,$idruleorder) =
13781: &Apache::lonnet::inst_userrules($dom,'id');
13782: my $chgtext = '<ul>';
13783: foreach my $type (@id_rule) {
13784: if (ref($idrules->{$type}) eq 'HASH') {
13785: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13786: }
13787: }
13788: $chgtext .= '</ul>';
13789: if (@id_rule > 0) {
13790: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13791: } else {
13792: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13793: }
13794: }
13795: my %authname = &authtype_names();
13796: my %context_title = &context_names();
13797: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13798: my $chgtext = '<ul>';
13799: foreach my $type (@{$changes{'authtypes'}}) {
13800: my @allowed;
13801: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13802: foreach my $auth (@authtypes) {
13803: if ($authhash{$type}{$auth}) {
13804: push(@allowed,$authname{$auth});
13805: }
13806: }
13807: if (@allowed > 0) {
13808: $chgtext .= join(', ',@allowed).'</li>';
13809: } else {
13810: $chgtext .= &mt('none').'</li>';
13811: }
13812: }
13813: $chgtext .= '</ul>';
13814: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13815: $resulttext .= '</li>';
13816: }
13817: $resulttext .= '</ul>';
13818: } else {
13819: $resulttext = &mt('No changes made to user creation settings');
13820: }
13821: } else {
13822: $resulttext = '<span class="LC_error">'.
13823: &mt('An error occurred: [_1]',$putresult).'</span>';
13824: }
13825: if ($warningmsg ne '') {
13826: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13827: }
13828: return $resulttext;
13829: }
13830:
13831: sub modify_selfcreation {
1.305 raeburn 13832: my ($dom,$lastactref,%domconfig) = @_;
13833: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13834: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13835: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 13836: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13837: if (ref($typesref) eq 'ARRAY') {
13838: @types = @{$typesref};
13839: }
13840: if (ref($usertypesref) eq 'HASH') {
13841: %usertypes = %{$usertypesref};
1.228 raeburn 13842: }
1.303 raeburn 13843: $usertypes{'default'} = $othertitle;
1.224 raeburn 13844: #
13845: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13846: #
13847: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13848: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13849: if ($key eq 'cancreate') {
13850: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13851: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13852: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 13853: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13854: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13855: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13856: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 13857: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 13858: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13859: } else {
13860: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13861: }
13862: }
13863: }
13864: } elsif ($key eq 'email_rule') {
13865: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13866: } else {
13867: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13868: }
13869: }
13870: }
13871: #
13872: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13873: #
13874: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13875: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13876: if ($key eq 'selfcreate') {
13877: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13878: } else {
13879: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13880: }
13881: }
13882: }
1.305 raeburn 13883: #
13884: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13885: #
13886: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13887: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13888: if ($key eq 'inststatusguest') {
13889: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13890: } else {
13891: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13892: }
13893: }
13894: }
1.224 raeburn 13895:
13896: my @contexts = ('selfcreate');
13897: @{$cancreate{'selfcreate'}} = ();
13898: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 13899: if (@types) {
13900: @{$cancreate{'statustocreate'}} = ();
13901: }
1.236 raeburn 13902: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 13903: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 13904: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 13905: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 13906: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13907: my %selfcreatetypes = (
13908: sso => 'users authenticated by institutional single sign on',
13909: login => 'users authenticated by institutional log-in',
1.303 raeburn 13910: email => 'users verified by e-mail',
1.50 raeburn 13911: );
1.224 raeburn 13912: #
13913: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13914: # is permitted.
13915: #
1.305 raeburn 13916: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 13917:
1.305 raeburn 13918: my (@statuses,%email_rule);
1.228 raeburn 13919: foreach my $item ('login','sso','email') {
1.224 raeburn 13920: if ($item eq 'email') {
1.236 raeburn 13921: if ($env{'form.cancreate_email'}) {
1.305 raeburn 13922: if (@types) {
13923: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13924: foreach my $status (@poss_statuses) {
13925: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13926: push(@statuses,$status);
13927: }
13928: }
13929: $save_inststatus{'inststatusguest'} = \@statuses;
13930: } else {
13931: push(@statuses,'default');
13932: }
13933: if (@statuses) {
13934: my %curr_rule;
13935: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13936: foreach my $type (@statuses) {
13937: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 13938: }
1.305 raeburn 13939: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13940: foreach my $type (@statuses) {
13941: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13942: }
13943: }
13944: push(@{$cancreate{'selfcreate'}},'email');
13945: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13946: my %curremaildom;
13947: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13948: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13949: }
13950: foreach my $type (@statuses) {
13951: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13952: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13953: }
13954: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13955: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13956: }
13957: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13958: #
13959: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13960: #
13961: my $chosen = $1;
13962: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13963: my $emaildom;
13964: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13965: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13966: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13967: if (ref($curremaildom{$type}) eq 'HASH') {
13968: if (exists($curremaildom{$type}{$chosen})) {
13969: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13970: push(@{$changes{'cancreate'}},'emaildomain');
13971: }
13972: } elsif ($emaildom ne '') {
13973: push(@{$changes{'cancreate'}},'emaildomain');
13974: }
13975: } elsif ($emaildom ne '') {
13976: push(@{$changes{'cancreate'}},'emaildomain');
13977: }
13978: }
13979: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13980: } elsif ($chosen eq 'custom') {
13981: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13982: $email_rule{$type} = [];
13983: if (ref($emailrules) eq 'HASH') {
13984: foreach my $rule (@possemail_rules) {
13985: if (exists($emailrules->{$rule})) {
13986: push(@{$email_rule{$type}},$rule);
13987: }
13988: }
13989: }
13990: if (@{$email_rule{$type}}) {
13991: $cancreate{'emailoptions'}{$type} = 'custom';
13992: if (ref($curr_rule{$type}) eq 'ARRAY') {
13993: if (@{$curr_rule{$type}} > 0) {
13994: foreach my $rule (@{$curr_rule{$type}}) {
13995: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13996: push(@{$changes{'email_rule'}},$type);
13997: }
13998: }
13999: }
14000: foreach my $type (@{$email_rule{$type}}) {
14001: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
14002: push(@{$changes{'email_rule'}},$type);
14003: }
14004: }
14005: } else {
14006: push(@{$changes{'email_rule'}},$type);
14007: }
14008: }
14009: } else {
14010: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
14011: }
14012: }
14013: }
14014: if (@types) {
14015: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14016: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
14017: if (@changed) {
14018: push(@{$changes{'inststatus'}},'inststatusguest');
14019: }
14020: } else {
14021: push(@{$changes{'inststatus'}},'inststatusguest');
14022: }
14023: }
14024: } else {
14025: delete($env{'form.cancreate_email'});
14026: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14027: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
14028: push(@{$changes{'inststatus'}},'inststatusguest');
14029: }
14030: }
14031: }
14032: } else {
14033: $save_inststatus{'inststatusguest'} = [];
14034: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14035: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
14036: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 14037: }
14038: }
1.224 raeburn 14039: }
14040: } else {
14041: if ($env{'form.cancreate_'.$item}) {
14042: push(@{$cancreate{'selfcreate'}},$item);
14043: }
14044: }
14045: }
1.305 raeburn 14046: my (%userinfo,%savecaptcha);
1.224 raeburn 14047: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
14048: #
1.228 raeburn 14049: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
14050: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 14051: #
1.236 raeburn 14052:
1.244 raeburn 14053: if ($env{'form.cancreate_email'}) {
1.228 raeburn 14054: push(@contexts,'emailusername');
1.305 raeburn 14055: if (@statuses) {
14056: foreach my $type (@statuses) {
1.228 raeburn 14057: if (ref($infofields) eq 'ARRAY') {
14058: foreach my $field (@{$infofields}) {
14059: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
14060: $cancreate{'emailusername'}{$type}{$field} = $1;
14061: }
14062: }
1.224 raeburn 14063: }
14064: }
14065: }
14066: #
14067: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 14068: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 14069: #
14070:
14071: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
14072: @approvalnotify = sort(@approvalnotify);
14073: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
14074: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14075: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
14076: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
14077: push(@{$changes{'cancreate'}},'notify');
14078: }
14079: } else {
14080: if ($cancreate{'notify'}{'approval'}) {
14081: push(@{$changes{'cancreate'}},'notify');
14082: }
14083: }
14084: } elsif ($cancreate{'notify'}{'approval'}) {
14085: push(@{$changes{'cancreate'}},'notify');
14086: }
14087:
14088: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
14089: }
14090: #
1.236 raeburn 14091: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 14092: # institutional log-in.
14093: #
14094: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
14095: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
14096: ($domdefaults{'auth_def'} eq 'localauth'))) {
14097: $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.').' '.
14098: &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.');
14099: }
14100: }
14101: my @fields = ('lastname','firstname','middlename','generation',
14102: 'permanentemail','id');
1.240 raeburn 14103: my @shibfields = (@fields,'inststatus');
1.224 raeburn 14104: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14105: #
14106: # Where usernames may created for institutional log-in and/or institutional single sign on:
14107: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
14108: # may self-create accounts
14109: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
14110: # which the user may supply, if institutional data is unavailable.
14111: #
14112: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 14113: if (@types) {
1.305 raeburn 14114: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
14115: push(@contexts,'statustocreate');
1.303 raeburn 14116: foreach my $type (@types) {
1.224 raeburn 14117: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
14118: foreach my $field (@fields) {
14119: if (grep(/^\Q$field\E$/,@modifiable)) {
14120: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
14121: } else {
14122: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
14123: }
14124: }
14125: }
14126: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 14127: foreach my $type (@types) {
1.224 raeburn 14128: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
14129: foreach my $field (@fields) {
14130: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
14131: $curr_usermodify{'selfcreate'}{$type}{$field}) {
14132: push(@{$changes{'selfcreate'}},$type);
14133: last;
14134: }
14135: }
14136: }
14137: }
14138: } else {
1.303 raeburn 14139: foreach my $type (@types) {
1.224 raeburn 14140: push(@{$changes{'selfcreate'}},$type);
14141: }
14142: }
14143: }
1.240 raeburn 14144: foreach my $field (@shibfields) {
14145: if ($env{'form.shibenv_'.$field} ne '') {
14146: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
14147: }
14148: }
14149: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14150: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
14151: foreach my $field (@shibfields) {
14152: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
14153: push(@{$changes{'cancreate'}},'shibenv');
14154: }
14155: }
14156: } else {
14157: foreach my $field (@shibfields) {
14158: if ($env{'form.shibenv_'.$field}) {
14159: push(@{$changes{'cancreate'}},'shibenv');
14160: last;
14161: }
14162: }
14163: }
14164: }
1.224 raeburn 14165: }
14166: foreach my $item (@contexts) {
14167: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
14168: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
14169: if (ref($cancreate{$item}) eq 'ARRAY') {
14170: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
14171: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14172: push(@{$changes{'cancreate'}},$item);
14173: }
14174: }
14175: }
14176: }
14177: if (ref($cancreate{$item}) eq 'ARRAY') {
14178: foreach my $type (@{$cancreate{$item}}) {
14179: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
14180: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14181: push(@{$changes{'cancreate'}},$item);
14182: }
14183: }
14184: }
14185: }
14186: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
14187: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 14188: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
14189: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
14190: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
14191: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 14192: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14193: push(@{$changes{'cancreate'}},$item);
14194: }
14195: }
14196: }
1.305 raeburn 14197: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
14198: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 14199: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14200: push(@{$changes{'cancreate'}},$item);
14201: }
1.224 raeburn 14202: }
14203: }
14204: }
1.305 raeburn 14205: foreach my $type (keys(%{$cancreate{$item}})) {
14206: if (ref($cancreate{$item}{$type}) eq 'HASH') {
14207: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
14208: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
14209: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 14210: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14211: push(@{$changes{'cancreate'}},$item);
14212: }
14213: }
14214: } else {
14215: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14216: push(@{$changes{'cancreate'}},$item);
14217: }
14218: }
14219: }
1.305 raeburn 14220: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
14221: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 14222: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14223: push(@{$changes{'cancreate'}},$item);
14224: }
1.224 raeburn 14225: }
14226: }
14227: }
14228: }
14229: } elsif ($curr_usercreation{'cancreate'}{$item}) {
14230: if (ref($cancreate{$item}) eq 'ARRAY') {
14231: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
14232: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14233: push(@{$changes{'cancreate'}},$item);
14234: }
14235: }
1.305 raeburn 14236: }
14237: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
14238: if (ref($cancreate{$item}) eq 'HASH') {
14239: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14240: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 14241: }
14242: }
14243: } elsif ($item eq 'emailusername') {
1.228 raeburn 14244: if (ref($cancreate{$item}) eq 'HASH') {
14245: foreach my $type (keys(%{$cancreate{$item}})) {
14246: if (ref($cancreate{$item}{$type}) eq 'HASH') {
14247: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
14248: if ($cancreate{$item}{$type}{$field}) {
14249: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14250: push(@{$changes{'cancreate'}},$item);
14251: }
14252: last;
14253: }
14254: }
14255: }
14256: }
1.224 raeburn 14257: }
14258: }
14259: }
14260: #
14261: # Populate %save_usercreate hash with updates to self-creation configuration.
14262: #
14263: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
14264: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 14265: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 14266: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
14267: if (ref($cancreate{'notify'}) eq 'HASH') {
14268: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
14269: }
1.236 raeburn 14270: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
14271: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
14272: }
1.303 raeburn 14273: if (ref($cancreate{'emailverified'}) eq 'HASH') {
14274: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
14275: }
1.305 raeburn 14276: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
14277: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
14278: }
1.303 raeburn 14279: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
14280: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
14281: }
1.224 raeburn 14282: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
14283: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
14284: }
1.240 raeburn 14285: if (ref($cancreate{'shibenv'}) eq 'HASH') {
14286: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
14287: }
1.224 raeburn 14288: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 14289: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 14290:
14291: my %userconfig_hash = (
14292: usercreation => \%save_usercreate,
14293: usermodification => \%save_usermodify,
1.305 raeburn 14294: inststatus => \%save_inststatus,
1.224 raeburn 14295: );
1.305 raeburn 14296:
1.224 raeburn 14297: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
14298: $dom);
14299: #
1.305 raeburn 14300: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 14301: #
1.27 raeburn 14302: if ($putresult eq 'ok') {
14303: if (keys(%changes) > 0) {
14304: $resulttext = &mt('Changes made:').'<ul>';
14305: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 14306: my %lt = &selfcreation_types();
1.34 raeburn 14307: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 14308: my $chgtext = '';
1.45 raeburn 14309: if ($type eq 'selfcreate') {
1.50 raeburn 14310: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 14311: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 14312: } else {
1.224 raeburn 14313: $chgtext .= &mt('Self-creation of a new account is permitted for:').
14314: '<ul>';
1.50 raeburn 14315: foreach my $case (@{$cancreate{$type}}) {
14316: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
14317: }
14318: $chgtext .= '</ul>';
1.100 raeburn 14319: if (ref($cancreate{$type}) eq 'ARRAY') {
14320: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
14321: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
14322: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 14323: $chgtext .= '<span class="LC_warning">'.
14324: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
14325: '</span><br />';
14326: }
14327: }
14328: }
14329: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 14330: if (!@statuses) {
14331: $chgtext .= '<span class="LC_warning">'.
14332: &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.").
14333: '</span><br />';
1.303 raeburn 14334:
1.100 raeburn 14335: }
14336: }
14337: }
1.43 raeburn 14338: }
1.240 raeburn 14339: } elsif ($type eq 'shibenv') {
14340: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 14341: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 14342: } else {
14343: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
14344: '<ul>';
14345: foreach my $field (@shibfields) {
14346: next if ($cancreate{$type}{$field} eq '');
14347: if ($field eq 'inststatus') {
14348: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
14349: } else {
14350: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
14351: }
14352: }
14353: $chgtext .= '</ul>';
1.303 raeburn 14354: }
1.93 raeburn 14355: } elsif ($type eq 'statustocreate') {
1.96 raeburn 14356: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
14357: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
14358: if (@{$cancreate{'selfcreate'}} > 0) {
14359: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 14360: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 14361: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 14362: $chgtext .= '<br />'.
14363: '<span class="LC_warning">'.
14364: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
14365: '</span>';
14366: }
1.303 raeburn 14367: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 14368: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 14369: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
14370: } else {
14371: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
14372: }
14373: $chgtext .= '<ul>';
14374: foreach my $case (@{$cancreate{$type}}) {
14375: if ($case eq 'default') {
14376: $chgtext .= '<li>'.$othertitle.'</li>';
14377: } else {
1.303 raeburn 14378: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 14379: }
14380: }
1.100 raeburn 14381: $chgtext .= '</ul>';
14382: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 14383: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 14384: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
14385: '</span>';
1.100 raeburn 14386: }
14387: }
14388: } else {
14389: if (@{$cancreate{$type}} == 0) {
14390: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
14391: } else {
14392: $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 14393: }
14394: }
1.303 raeburn 14395: $chgtext .= '<br />';
1.93 raeburn 14396: }
1.236 raeburn 14397: } elsif ($type eq 'selfcreateprocessing') {
14398: my %choices = &Apache::lonlocal::texthash (
14399: automatic => 'Automatic approval',
14400: approval => 'Queued for approval',
14401: );
1.305 raeburn 14402: if (@types) {
14403: if (@statuses) {
1.303 raeburn 14404: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 14405: '<ul>';
1.305 raeburn 14406: foreach my $status (@statuses) {
14407: if ($status eq 'default') {
14408: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 14409: } else {
1.305 raeburn 14410: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 14411: }
14412: }
14413: $chgtext .= '</ul>';
14414: }
14415: } else {
14416: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
14417: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
14418: }
14419: } elsif ($type eq 'emailverified') {
14420: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 14421: all => 'Same as e-mail',
14422: first => 'Omit @domain',
14423: free => 'Free to choose',
1.303 raeburn 14424: );
1.305 raeburn 14425: if (@types) {
14426: if (@statuses) {
1.303 raeburn 14427: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
14428: '<ul>';
1.305 raeburn 14429: foreach my $status (@statuses) {
1.303 raeburn 14430: if ($type eq 'default') {
1.305 raeburn 14431: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 14432: } else {
1.305 raeburn 14433: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 14434: }
14435: }
14436: $chgtext .= '</ul>';
14437: }
14438: } else {
1.305 raeburn 14439: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 14440: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 14441: }
1.305 raeburn 14442: } elsif ($type eq 'emailoptions') {
14443: my %options = &Apache::lonlocal::texthash (
14444: any => 'Any e-mail',
14445: inst => 'Institutional only',
14446: noninst => 'Non-institutional only',
14447: custom => 'Custom restrictions',
14448: );
14449: if (@types) {
14450: if (@statuses) {
14451: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
14452: '<ul>';
14453: foreach my $status (@statuses) {
14454: if ($type eq 'default') {
14455: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
14456: } else {
14457: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 14458: }
14459: }
1.305 raeburn 14460: $chgtext .= '</ul>';
14461: }
14462: } else {
14463: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
14464: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
14465: } else {
14466: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
14467: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 14468: }
1.305 raeburn 14469: }
14470: } elsif ($type eq 'emaildomain') {
14471: my $output;
14472: if (@statuses) {
14473: foreach my $type (@statuses) {
14474: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
14475: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
14476: if ($type eq 'default') {
14477: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14478: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
14479: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
14480: } else {
14481: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
14482: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
14483: }
1.303 raeburn 14484: } else {
1.305 raeburn 14485: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14486: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
14487: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
14488: } else {
14489: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
14490: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
14491: }
1.303 raeburn 14492: }
1.305 raeburn 14493: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
14494: if ($type eq 'default') {
14495: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14496: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
14497: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
14498: } else {
14499: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
14500: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
14501: }
1.303 raeburn 14502: } else {
1.305 raeburn 14503: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14504: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
14505: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
14506: } else {
14507: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
14508: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
14509: }
1.303 raeburn 14510: }
14511: }
14512: }
14513: }
1.305 raeburn 14514: }
14515: if ($output ne '') {
14516: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
14517: '<ul>'.$output.'</ul>';
1.236 raeburn 14518: }
1.165 raeburn 14519: } elsif ($type eq 'captcha') {
1.224 raeburn 14520: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 14521: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
14522: } else {
14523: my %captchas = &captcha_phrases();
1.224 raeburn 14524: if ($captchas{$savecaptcha{$type}}) {
14525: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 14526: } else {
1.210 raeburn 14527: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 14528: }
14529: }
14530: } elsif ($type eq 'recaptchakeys') {
14531: my ($privkey,$pubkey);
1.224 raeburn 14532: if (ref($savecaptcha{$type}) eq 'HASH') {
14533: $pubkey = $savecaptcha{$type}{'public'};
14534: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 14535: }
14536: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
14537: if (!$pubkey) {
14538: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
14539: } else {
14540: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
14541: }
14542: if (!$privkey) {
14543: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
14544: } else {
14545: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
14546: }
14547: $chgtext .= '</ul>';
1.269 raeburn 14548: } elsif ($type eq 'recaptchaversion') {
14549: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 14550: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 14551: }
1.224 raeburn 14552: } elsif ($type eq 'emailusername') {
14553: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 14554: if (@statuses) {
14555: foreach my $type (@statuses) {
1.228 raeburn 14556: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
14557: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 14558: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 14559: '<ul>';
14560: foreach my $field (@{$infofields}) {
14561: if ($cancreate{'emailusername'}{$type}{$field}) {
14562: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
14563: }
14564: }
1.245 raeburn 14565: $chgtext .= '</ul>';
14566: } else {
1.303 raeburn 14567: $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 14568: }
14569: } else {
1.303 raeburn 14570: $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 14571: }
14572: }
14573: }
14574: }
14575: } elsif ($type eq 'notify') {
1.303 raeburn 14576: my $numapprove = 0;
1.224 raeburn 14577: if (ref($changes{'cancreate'}) eq 'ARRAY') {
14578: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
14579: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 14580: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
14581: $numapprove ++;
1.224 raeburn 14582: }
14583: }
1.43 raeburn 14584: }
1.303 raeburn 14585: unless ($numapprove) {
14586: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
14587: }
1.34 raeburn 14588: }
1.224 raeburn 14589: if ($chgtext) {
14590: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 14591: }
14592: }
14593: }
1.305 raeburn 14594: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 14595: my ($emailrules,$emailruleorder) =
14596: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 14597: foreach my $type (@{$changes{'email_rule'}}) {
14598: if (ref($email_rule{$type}) eq 'ARRAY') {
14599: my $chgtext = '<ul>';
14600: foreach my $rule (@{$email_rule{$type}}) {
14601: if (ref($emailrules->{$rule}) eq 'HASH') {
14602: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
14603: }
14604: }
14605: $chgtext .= '</ul>';
1.310 raeburn 14606: my $typename;
1.305 raeburn 14607: if (@types) {
14608: if ($type eq 'default') {
14609: $typename = $othertitle;
14610: } else {
14611: $typename = $usertypes{$type};
14612: }
14613: $chgtext .= &mt('(Affiliation: [_1])',$typename);
14614: }
14615: if (@{$email_rule{$type}} > 0) {
14616: $resulttext .= '<li>'.
14617: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
14618: $usertypes{$type}).
14619: $chgtext.
14620: '</li>';
14621: } else {
14622: $resulttext .= '<li>'.
1.310 raeburn 14623: &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 14624: '</li>'.
1.310 raeburn 14625: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 14626: }
1.43 raeburn 14627: }
14628: }
1.305 raeburn 14629: }
14630: if (ref($changes{'inststatus'}) eq 'ARRAY') {
14631: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
14632: if (@{$save_inststatus{'inststatusguest'}} > 0) {
14633: my $chgtext = '<ul>';
14634: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
14635: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
14636: }
14637: $chgtext .= '</ul>';
14638: $resulttext .= '<li>'.
14639: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
14640: $chgtext.
14641: '</li>';
14642: } else {
14643: $resulttext .= '<li>'.
14644: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
14645: '</li>';
14646: }
1.43 raeburn 14647: }
14648: }
1.224 raeburn 14649: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
14650: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
14651: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14652: foreach my $type (@{$changes{'selfcreate'}}) {
14653: my $typename = $type;
1.303 raeburn 14654: if (keys(%usertypes) > 0) {
14655: if ($usertypes{$type} ne '') {
14656: $typename = $usertypes{$type};
1.224 raeburn 14657: }
14658: }
14659: my @modifiable;
14660: $resulttext .= '<li>'.
14661: &mt('Self-creation of account by users with status: [_1]',
14662: '<span class="LC_cusr_emph">'.$typename.'</span>').
14663: ' - '.&mt('modifiable fields (if institutional data blank): ');
14664: foreach my $field (@fields) {
14665: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
14666: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 14667: }
14668: }
1.224 raeburn 14669: if (@modifiable > 0) {
14670: $resulttext .= join(', ',@modifiable);
1.43 raeburn 14671: } else {
1.224 raeburn 14672: $resulttext .= &mt('none');
1.43 raeburn 14673: }
1.224 raeburn 14674: $resulttext .= '</li>';
1.28 raeburn 14675: }
1.224 raeburn 14676: $resulttext .= '</ul></li>';
1.28 raeburn 14677: }
1.27 raeburn 14678: $resulttext .= '</ul>';
1.305 raeburn 14679: my $cachetime = 24*60*60;
14680: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
14681: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14682: if (ref($lastactref) eq 'HASH') {
14683: $lastactref->{'domdefaults'} = 1;
14684: }
1.27 raeburn 14685: } else {
1.224 raeburn 14686: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 14687: }
14688: } else {
14689: $resulttext = '<span class="LC_error">'.
1.23 raeburn 14690: &mt('An error occurred: [_1]',$putresult).'</span>';
14691: }
1.43 raeburn 14692: if ($warningmsg ne '') {
14693: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14694: }
1.23 raeburn 14695: return $resulttext;
14696: }
14697:
1.165 raeburn 14698: sub process_captcha {
14699: my ($container,$changes,$newsettings,$current) = @_;
14700: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
14701: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
14702: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
14703: $newsettings->{'captcha'} = 'original';
14704: }
14705: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 14706: if ($container eq 'cancreate') {
1.169 raeburn 14707: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14708: push(@{$changes->{'cancreate'}},'captcha');
14709: } elsif (!defined($changes->{'cancreate'})) {
14710: $changes->{'cancreate'} = ['captcha'];
14711: }
14712: } else {
14713: $changes->{'captcha'} = 1;
1.165 raeburn 14714: }
14715: }
1.269 raeburn 14716: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 14717: if ($newsettings->{'captcha'} eq 'recaptcha') {
14718: $newpub = $env{'form.'.$container.'_recaptchapub'};
14719: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 14720: $newpub =~ s/[^\w\-]//g;
14721: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 14722: $newsettings->{'recaptchakeys'} = {
14723: public => $newpub,
14724: private => $newpriv,
14725: };
1.269 raeburn 14726: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14727: $newversion =~ s/\D//g;
14728: if ($newversion ne '2') {
14729: $newversion = 1;
14730: }
14731: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 14732: }
14733: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
14734: $currpub = $current->{'recaptchakeys'}{'public'};
14735: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 14736: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14737: $newsettings->{'recaptchakeys'} = {
14738: public => '',
14739: private => '',
14740: }
14741: }
1.165 raeburn 14742: }
1.269 raeburn 14743: if ($current->{'captcha'} eq 'recaptcha') {
14744: $currversion = $current->{'recaptchaversion'};
14745: if ($currversion ne '2') {
14746: $currversion = 1;
14747: }
14748: }
14749: if ($currversion ne $newversion) {
14750: if ($container eq 'cancreate') {
14751: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14752: push(@{$changes->{'cancreate'}},'recaptchaversion');
14753: } elsif (!defined($changes->{'cancreate'})) {
14754: $changes->{'cancreate'} = ['recaptchaversion'];
14755: }
14756: } else {
14757: $changes->{'recaptchaversion'} = 1;
14758: }
14759: }
1.165 raeburn 14760: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 14761: if ($container eq 'cancreate') {
14762: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14763: push(@{$changes->{'cancreate'}},'recaptchakeys');
14764: } elsif (!defined($changes->{'cancreate'})) {
14765: $changes->{'cancreate'} = ['recaptchakeys'];
14766: }
14767: } else {
1.210 raeburn 14768: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 14769: }
14770: }
14771: return;
14772: }
14773:
1.33 raeburn 14774: sub modify_usermodification {
14775: my ($dom,%domconfig) = @_;
1.224 raeburn 14776: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14777: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14778: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 14779: if ($key eq 'selfcreate') {
14780: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14781: } else {
14782: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14783: }
1.33 raeburn 14784: }
14785: }
1.224 raeburn 14786: my @contexts = ('author','course');
1.33 raeburn 14787: my %context_title = (
14788: author => 'In author context',
14789: course => 'In course context',
14790: );
14791: my @fields = ('lastname','firstname','middlename','generation',
14792: 'permanentemail','id');
14793: my %roles = (
14794: author => ['ca','aa'],
14795: course => ['st','ep','ta','in','cr'],
14796: );
14797: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14798: foreach my $context (@contexts) {
14799: foreach my $role (@{$roles{$context}}) {
14800: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14801: foreach my $item (@fields) {
14802: if (grep(/^\Q$item\E$/,@modifiable)) {
14803: $modifyhash{$context}{$role}{$item} = 1;
14804: } else {
14805: $modifyhash{$context}{$role}{$item} = 0;
14806: }
14807: }
14808: }
14809: if (ref($curr_usermodification{$context}) eq 'HASH') {
14810: foreach my $role (@{$roles{$context}}) {
14811: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14812: foreach my $field (@fields) {
14813: if ($modifyhash{$context}{$role}{$field} ne
14814: $curr_usermodification{$context}{$role}{$field}) {
14815: push(@{$changes{$context}},$role);
14816: last;
14817: }
14818: }
14819: }
14820: }
14821: } else {
14822: foreach my $context (@contexts) {
14823: foreach my $role (@{$roles{$context}}) {
14824: push(@{$changes{$context}},$role);
14825: }
14826: }
14827: }
14828: }
14829: my %usermodification_hash = (
14830: usermodification => \%modifyhash,
14831: );
14832: my $putresult = &Apache::lonnet::put_dom('configuration',
14833: \%usermodification_hash,$dom);
14834: if ($putresult eq 'ok') {
14835: if (keys(%changes) > 0) {
14836: $resulttext = &mt('Changes made: ').'<ul>';
14837: foreach my $context (@contexts) {
14838: if (ref($changes{$context}) eq 'ARRAY') {
14839: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14840: if (ref($changes{$context}) eq 'ARRAY') {
14841: foreach my $role (@{$changes{$context}}) {
14842: my $rolename;
1.224 raeburn 14843: if ($role eq 'cr') {
14844: $rolename = &mt('Custom');
1.33 raeburn 14845: } else {
1.224 raeburn 14846: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14847: }
14848: my @modifiable;
1.224 raeburn 14849: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14850: foreach my $field (@fields) {
14851: if ($modifyhash{$context}{$role}{$field}) {
14852: push(@modifiable,$fieldtitles{$field});
14853: }
14854: }
14855: if (@modifiable > 0) {
14856: $resulttext .= join(', ',@modifiable);
14857: } else {
14858: $resulttext .= &mt('none');
14859: }
14860: $resulttext .= '</li>';
14861: }
14862: $resulttext .= '</ul></li>';
14863: }
14864: }
14865: }
14866: $resulttext .= '</ul>';
14867: } else {
14868: $resulttext = &mt('No changes made to user modification settings');
14869: }
14870: } else {
14871: $resulttext = '<span class="LC_error">'.
14872: &mt('An error occurred: [_1]',$putresult).'</span>';
14873: }
14874: return $resulttext;
14875: }
14876:
1.43 raeburn 14877: sub modify_defaults {
1.212 raeburn 14878: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14879: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 14880: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 14881: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
14882: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.325 raeburn 14883: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 14884: foreach my $item (@items) {
14885: $newvalues{$item} = $env{'form.'.$item};
14886: if ($item eq 'auth_def') {
14887: if ($newvalues{$item} ne '') {
14888: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14889: push(@errors,$item);
14890: }
14891: }
14892: } elsif ($item eq 'lang_def') {
14893: if ($newvalues{$item} ne '') {
14894: if ($newvalues{$item} =~ /^(\w+)/) {
14895: my $langcode = $1;
1.103 raeburn 14896: if ($langcode ne 'x_chef') {
14897: if (code2language($langcode) eq '') {
14898: push(@errors,$item);
14899: }
1.43 raeburn 14900: }
14901: } else {
14902: push(@errors,$item);
14903: }
14904: }
1.54 raeburn 14905: } elsif ($item eq 'timezone_def') {
14906: if ($newvalues{$item} ne '') {
1.62 raeburn 14907: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14908: push(@errors,$item);
14909: }
14910: }
1.68 raeburn 14911: } elsif ($item eq 'datelocale_def') {
14912: if ($newvalues{$item} ne '') {
14913: my @datelocale_ids = DateTime::Locale->ids();
14914: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14915: push(@errors,$item);
14916: }
14917: }
1.141 raeburn 14918: } elsif ($item eq 'portal_def') {
14919: if ($newvalues{$item} ne '') {
14920: 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])\/?$/) {
14921: push(@errors,$item);
14922: }
14923: }
1.294 raeburn 14924: } elsif ($item eq 'intauth_cost') {
14925: if ($newvalues{$item} ne '') {
14926: if ($newvalues{$item} =~ /\D/) {
14927: push(@errors,$item);
14928: }
14929: }
14930: } elsif ($item eq 'intauth_check') {
14931: if ($newvalues{$item} ne '') {
14932: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14933: push(@errors,$item);
14934: }
14935: }
14936: } elsif ($item eq 'intauth_switch') {
14937: if ($newvalues{$item} ne '') {
14938: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14939: push(@errors,$item);
14940: }
14941: }
1.43 raeburn 14942: }
14943: if (grep(/^\Q$item\E$/,@errors)) {
14944: $newvalues{$item} = $domdefaults{$item};
14945: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14946: $changes{$item} = 1;
14947: }
1.72 raeburn 14948: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14949: }
14950: my %defaults_hash = (
1.72 raeburn 14951: defaults => \%newvalues,
14952: );
1.43 raeburn 14953: my $title = &defaults_titles();
1.236 raeburn 14954:
14955: my $currinststatus;
14956: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14957: $currinststatus = $domconfig{'inststatus'};
14958: } else {
14959: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14960: $currinststatus = {
14961: inststatustypes => $usertypes,
14962: inststatusorder => $types,
14963: inststatusguest => [],
14964: };
14965: }
14966: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14967: my @allpos;
14968: my %alltypes;
1.305 raeburn 14969: my @inststatusguest;
14970: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14971: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14972: unless (grep(/^\Q$type\E$/,@todelete)) {
14973: push(@inststatusguest,$type);
14974: }
14975: }
14976: }
14977: my ($currtitles,$currorder);
1.236 raeburn 14978: if (ref($currinststatus) eq 'HASH') {
14979: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14980: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14981: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14982: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14983: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14984: }
14985: }
14986: unless (grep(/^\Q$type\E$/,@todelete)) {
14987: my $position = $env{'form.inststatus_pos_'.$type};
14988: $position =~ s/\D+//g;
14989: $allpos[$position] = $type;
14990: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14991: $alltypes{$type} =~ s/`//g;
14992: }
14993: }
14994: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14995: $currtitles =~ s/,$//;
14996: }
14997: }
14998: if ($env{'form.addinststatus'}) {
14999: my $newtype = $env{'form.addinststatus'};
15000: $newtype =~ s/\W//g;
15001: unless (exists($alltypes{$newtype})) {
15002: $alltypes{$newtype} = $env{'form.addinststatus_title'};
15003: $alltypes{$newtype} =~ s/`//g;
15004: my $position = $env{'form.addinststatus_pos'};
15005: $position =~ s/\D+//g;
15006: if ($position ne '') {
15007: $allpos[$position] = $newtype;
15008: }
15009: }
15010: }
1.305 raeburn 15011: my @orderedstatus;
1.236 raeburn 15012: foreach my $type (@allpos) {
15013: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
15014: push(@orderedstatus,$type);
15015: }
15016: }
15017: foreach my $type (keys(%alltypes)) {
15018: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
15019: delete($alltypes{$type});
15020: }
15021: }
15022: $defaults_hash{'inststatus'} = {
15023: inststatustypes => \%alltypes,
15024: inststatusorder => \@orderedstatus,
1.305 raeburn 15025: inststatusguest => \@inststatusguest,
1.236 raeburn 15026: };
15027: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
15028: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
15029: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
15030: }
15031: }
15032: if ($currorder ne join(',',@orderedstatus)) {
15033: $changes{'inststatus'}{'inststatusorder'} = 1;
15034: }
15035: my $newtitles;
15036: foreach my $item (@orderedstatus) {
15037: $newtitles .= $alltypes{$item}.',';
15038: }
15039: $newtitles =~ s/,$//;
15040: if ($currtitles ne $newtitles) {
15041: $changes{'inststatus'}{'inststatustypes'} = 1;
15042: }
1.43 raeburn 15043: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
15044: $dom);
15045: if ($putresult eq 'ok') {
15046: if (keys(%changes) > 0) {
15047: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 15048: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 15049: 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";
15050: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 15051: if ($item eq 'inststatus') {
15052: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 15053: if (@orderedstatus) {
1.236 raeburn 15054: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
15055: foreach my $type (@orderedstatus) {
15056: $resulttext .= $alltypes{$type}.', ';
15057: }
15058: $resulttext =~ s/, $//;
15059: $resulttext .= '</li>';
1.305 raeburn 15060: } else {
15061: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 15062: }
15063: }
15064: } else {
15065: my $value = $env{'form.'.$item};
15066: if ($value eq '') {
15067: $value = &mt('none');
15068: } elsif ($item eq 'auth_def') {
15069: my %authnames = &authtype_names();
15070: my %shortauth = (
15071: internal => 'int',
15072: krb4 => 'krb4',
15073: krb5 => 'krb5',
15074: localauth => 'loc',
1.325 raeburn 15075: lti => 'lti',
1.236 raeburn 15076: );
15077: $value = $authnames{$shortauth{$value}};
1.294 raeburn 15078: } elsif ($item eq 'intauth_switch') {
15079: my %optiondesc = &Apache::lonlocal::texthash (
15080: 0 => 'No',
15081: 1 => 'Yes',
15082: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
15083: );
15084: if ($value =~ /^(0|1|2)$/) {
15085: $value = $optiondesc{$value};
15086: } else {
15087: $value = &mt('none -- defaults to No');
15088: }
15089: } elsif ($item eq 'intauth_check') {
15090: my %optiondesc = &Apache::lonlocal::texthash (
15091: 0 => 'No',
15092: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
15093: 2 => 'Yes, disallow login if stored cost is less than domain default',
15094: );
15095: if ($value =~ /^(0|1|2)$/) {
15096: $value = $optiondesc{$value};
15097: } else {
15098: $value = &mt('none -- defaults to No');
15099: }
1.236 raeburn 15100: }
15101: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
15102: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 15103: }
15104: }
15105: $resulttext .= '</ul>';
15106: $mailmsgtext .= "\n";
15107: my $cachetime = 24*60*60;
1.72 raeburn 15108: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 15109: if (ref($lastactref) eq 'HASH') {
15110: $lastactref->{'domdefaults'} = 1;
15111: }
1.68 raeburn 15112: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 15113: my $notify = 1;
15114: if (ref($domconfig{'contacts'}) eq 'HASH') {
15115: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
15116: $notify = 0;
15117: }
15118: }
15119: if ($notify) {
15120: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
15121: "LON-CAPA Domain Settings Change - $dom",
15122: $mailmsgtext);
15123: }
1.54 raeburn 15124: }
1.43 raeburn 15125: } else {
1.54 raeburn 15126: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 15127: }
15128: } else {
15129: $resulttext = '<span class="LC_error">'.
15130: &mt('An error occurred: [_1]',$putresult).'</span>';
15131: }
15132: if (@errors > 0) {
15133: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
15134: foreach my $item (@errors) {
15135: $resulttext .= ' "'.$title->{$item}.'",';
15136: }
15137: $resulttext =~ s/,$//;
15138: }
15139: return $resulttext;
15140: }
15141:
1.46 raeburn 15142: sub modify_scantron {
1.205 raeburn 15143: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 15144: my ($resulttext,%confhash,%changes,$errors);
15145: my $custom = 'custom.tab';
15146: my $default = 'default.tab';
15147: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 15148: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 15149: &config_check($dom,$confname,$servadm);
15150: if ($env{'form.scantronformat.filename'} ne '') {
15151: my $error;
15152: if ($configuserok eq 'ok') {
15153: if ($switchserver) {
1.130 raeburn 15154: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 15155: } else {
15156: if ($author_ok eq 'ok') {
15157: my ($result,$scantronurl) =
15158: &publishlogo($r,'upload','scantronformat',$dom,
15159: $confname,'scantron','','',$custom);
15160: if ($result eq 'ok') {
15161: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 15162: $changes{'scantronformat'} = 1;
1.46 raeburn 15163: } else {
15164: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
15165: }
15166: } else {
15167: $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);
15168: }
15169: }
15170: } else {
15171: $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);
15172: }
15173: if ($error) {
15174: &Apache::lonnet::logthis($error);
15175: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15176: }
15177: }
1.48 raeburn 15178: if (ref($domconfig{'scantron'}) eq 'HASH') {
15179: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
15180: if ($env{'form.scantronformat_del'}) {
15181: $confhash{'scantron'}{'scantronformat'} = '';
15182: $changes{'scantronformat'} = 1;
1.347 ! raeburn 15183: } else {
! 15184: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 15185: }
15186: }
15187: }
1.347 ! raeburn 15188: my @options = ('hdr','pad','rem');
1.346 raeburn 15189: my @fields = &scantroncsv_fields();
15190: my %titles = &scantronconfig_titles();
1.347 ! raeburn 15191: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 15192: my ($newdat,$currdat,%newcol,%currcol);
15193: if (grep(/^dat$/,@formats)) {
15194: $confhash{'scantron'}{config}{dat} = 1;
15195: $newdat = 1;
15196: } else {
15197: $newdat = 0;
15198: }
15199: if (grep(/^csv$/,@formats)) {
15200: my %bynum;
15201: foreach my $field (@fields) {
15202: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
15203: my $posscol = $1;
15204: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 ! raeburn 15205: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 15206: $bynum{$posscol} = $field;
15207: $newcol{$field} = $posscol;
15208: }
15209: }
15210: }
1.347 ! raeburn 15211: if (keys(%newcol)) {
! 15212: foreach my $option (@options) {
! 15213: if ($env{'form.scantroncsv_'.$option}) {
! 15214: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
! 15215: }
! 15216: }
! 15217: }
1.346 raeburn 15218: }
15219: $currdat = 1;
15220: if (ref($domconfig{'scantron'}) eq 'HASH') {
15221: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 ! raeburn 15222: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 15223: $currdat = 0;
15224: }
15225: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 ! raeburn 15226: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
! 15227: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
! 15228: }
1.346 raeburn 15229: }
15230: }
15231: }
15232: if ($currdat != $newdat) {
15233: $changes{'config'} = 1;
15234: } else {
15235: foreach my $field (@fields) {
15236: if ($currcol{$field} ne '') {
15237: if ($currcol{$field} ne $newcol{$field}) {
15238: $changes{'config'} = 1;
15239: last;
1.347 ! raeburn 15240: }
1.346 raeburn 15241: } elsif ($newcol{$field} ne '') {
15242: $changes{'config'} = 1;
15243: last;
15244: }
15245: }
15246: }
1.46 raeburn 15247: if (keys(%confhash) > 0) {
15248: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
15249: $dom);
15250: if ($putresult eq 'ok') {
15251: if (keys(%changes) > 0) {
1.48 raeburn 15252: if (ref($confhash{'scantron'}) eq 'HASH') {
15253: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 15254: if ($changes{'scantronformat'}) {
15255: if ($confhash{'scantron'}{'scantronformat'} eq '') {
15256: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
15257: } else {
15258: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
15259: }
15260: }
1.347 ! raeburn 15261: if ($changes{'config'}) {
1.346 raeburn 15262: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
15263: if ($confhash{'scantron'}{'config'}{'dat'}) {
15264: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
15265: }
15266: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 ! raeburn 15267: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
! 15268: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
! 15269: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
! 15270: foreach my $field (@fields) {
! 15271: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
! 15272: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
! 15273: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
! 15274: }
! 15275: }
! 15276: $resulttext .= '</ul></li>';
! 15277: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
! 15278: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
! 15279: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
! 15280: foreach my $option (@options) {
! 15281: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
! 15282: $resulttext .= '<li>'.$titles{$option}.'</li>';
! 15283: }
! 15284: }
! 15285: $resulttext .= '</ul></li>';
! 15286: }
1.346 raeburn 15287: }
15288: }
15289: }
15290: }
15291: } else {
15292: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
15293: }
1.46 raeburn 15294: }
1.48 raeburn 15295: $resulttext .= '</ul>';
15296: } else {
1.130 raeburn 15297: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 15298: }
15299: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 15300: if (ref($lastactref) eq 'HASH') {
15301: $lastactref->{'domainconfig'} = 1;
15302: }
1.46 raeburn 15303: } else {
1.346 raeburn 15304: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 15305: }
15306: } else {
15307: $resulttext = '<span class="LC_error">'.
15308: &mt('An error occurred: [_1]',$putresult).'</span>';
15309: }
15310: } else {
1.130 raeburn 15311: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 15312: }
15313: if ($errors) {
15314: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15315: $errors.'</ul>';
15316: }
15317: return $resulttext;
15318: }
15319:
1.48 raeburn 15320: sub modify_coursecategories {
1.239 raeburn 15321: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 15322: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
15323: $cathash);
1.48 raeburn 15324: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 15325: my @catitems = ('unauth','auth');
15326: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 15327: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 15328: $cathash = $domconfig{'coursecategories'}{'cats'};
15329: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
15330: $changes{'togglecats'} = 1;
15331: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
15332: }
15333: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
15334: $changes{'categorize'} = 1;
15335: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
15336: }
1.120 raeburn 15337: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
15338: $changes{'togglecatscomm'} = 1;
15339: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
15340: }
15341: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
15342: $changes{'categorizecomm'} = 1;
15343: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 15344:
15345: }
15346: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
15347: $changes{'togglecatsplace'} = 1;
15348: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
15349: }
15350: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
15351: $changes{'categorizeplace'} = 1;
15352: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 15353: }
1.238 raeburn 15354: foreach my $item (@catitems) {
15355: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
15356: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
15357: $changes{$item} = 1;
15358: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
15359: }
15360: }
15361: }
1.57 raeburn 15362: } else {
15363: $changes{'togglecats'} = 1;
15364: $changes{'categorize'} = 1;
1.124 raeburn 15365: $changes{'togglecatscomm'} = 1;
15366: $changes{'categorizecomm'} = 1;
1.272 raeburn 15367: $changes{'togglecatsplace'} = 1;
15368: $changes{'categorizeplace'} = 1;
1.87 raeburn 15369: $domconfig{'coursecategories'} = {
15370: togglecats => $env{'form.togglecats'},
15371: categorize => $env{'form.categorize'},
1.124 raeburn 15372: togglecatscomm => $env{'form.togglecatscomm'},
15373: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 15374: togglecatsplace => $env{'form.togglecatsplace'},
15375: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 15376: };
1.238 raeburn 15377: foreach my $item (@catitems) {
15378: if ($env{'form.coursecat_'.$item} ne 'std') {
15379: $changes{$item} = 1;
15380: }
15381: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
15382: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
15383: }
15384: }
1.57 raeburn 15385: }
15386: if (ref($cathash) eq 'HASH') {
15387: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 15388: push (@deletecategory,'instcode::0');
15389: }
1.120 raeburn 15390: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
15391: push(@deletecategory,'communities::0');
15392: }
1.272 raeburn 15393: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
15394: push(@deletecategory,'placement::0');
15395: }
1.48 raeburn 15396: }
1.57 raeburn 15397: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
15398: if (ref($cathash) eq 'HASH') {
1.48 raeburn 15399: if (@deletecategory > 0) {
15400: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 15401: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 15402: foreach my $item (@deletecategory) {
1.57 raeburn 15403: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
15404: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 15405: $deletions{$item} = 1;
1.57 raeburn 15406: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 15407: }
15408: }
15409: }
1.57 raeburn 15410: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 15411: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 15412: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 15413: $reorderings{$item} = 1;
1.57 raeburn 15414: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 15415: }
15416: if ($env{'form.addcategory_name_'.$item} ne '') {
15417: my $newcat = $env{'form.addcategory_name_'.$item};
15418: my $newdepth = $depth+1;
15419: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 15420: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 15421: $adds{$newitem} = 1;
15422: }
15423: if ($env{'form.subcat_'.$item} ne '') {
15424: my $newcat = $env{'form.subcat_'.$item};
15425: my $newdepth = $depth+1;
15426: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 15427: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 15428: $adds{$newitem} = 1;
15429: }
15430: }
15431: }
15432: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 15433: if (ref($cathash) eq 'HASH') {
1.48 raeburn 15434: my $newitem = 'instcode::0';
1.57 raeburn 15435: if ($cathash->{$newitem} eq '') {
15436: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 15437: $adds{$newitem} = 1;
15438: }
15439: } else {
15440: my $newitem = 'instcode::0';
1.57 raeburn 15441: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 15442: $adds{$newitem} = 1;
15443: }
15444: }
1.120 raeburn 15445: if ($env{'form.communities'} eq '1') {
15446: if (ref($cathash) eq 'HASH') {
15447: my $newitem = 'communities::0';
15448: if ($cathash->{$newitem} eq '') {
15449: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
15450: $adds{$newitem} = 1;
15451: }
15452: } else {
15453: my $newitem = 'communities::0';
15454: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
15455: $adds{$newitem} = 1;
15456: }
15457: }
1.272 raeburn 15458: if ($env{'form.placement'} eq '1') {
15459: if (ref($cathash) eq 'HASH') {
15460: my $newitem = 'placement::0';
15461: if ($cathash->{$newitem} eq '') {
15462: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
15463: $adds{$newitem} = 1;
15464: }
15465: } else {
15466: my $newitem = 'placement::0';
15467: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
15468: $adds{$newitem} = 1;
15469: }
15470: }
1.48 raeburn 15471: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 15472: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 15473: ($env{'form.addcategory_name'} ne 'communities') &&
15474: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 15475: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
15476: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
15477: $adds{$newitem} = 1;
15478: }
1.48 raeburn 15479: }
1.57 raeburn 15480: my $putresult;
1.48 raeburn 15481: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15482: if (keys(%deletions) > 0) {
15483: foreach my $key (keys(%deletions)) {
15484: if ($predelallitems{$key} ne '') {
15485: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
15486: }
15487: }
15488: }
15489: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 15490: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 15491: if (ref($chkcats[0]) eq 'ARRAY') {
15492: my $depth = 0;
15493: my $chg = 0;
15494: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
15495: my $name = $chkcats[0][$i];
15496: my $item;
15497: if ($name eq '') {
15498: $chg ++;
15499: } else {
15500: $item = &escape($name).'::0';
15501: if ($chg) {
1.57 raeburn 15502: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 15503: }
15504: $depth ++;
1.57 raeburn 15505: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 15506: $depth --;
15507: }
15508: }
15509: }
1.57 raeburn 15510: }
15511: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15512: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 15513: if ($putresult eq 'ok') {
1.57 raeburn 15514: my %title = (
1.120 raeburn 15515: togglecats => 'Show/Hide a course in catalog',
15516: categorize => 'Assign a category to a course',
15517: togglecatscomm => 'Show/Hide a community in catalog',
15518: categorizecomm => 'Assign a category to a community',
1.57 raeburn 15519: );
15520: my %level = (
1.120 raeburn 15521: dom => 'set in Domain ("Modify Course/Community")',
15522: crs => 'set in Course ("Course Configuration")',
15523: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 15524: none => 'No catalog',
15525: std => 'Standard catalog',
15526: domonly => 'Domain-only catalog',
15527: codesrch => 'Code search form',
1.57 raeburn 15528: );
1.48 raeburn 15529: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 15530: if ($changes{'togglecats'}) {
15531: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
15532: }
15533: if ($changes{'categorize'}) {
15534: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 15535: }
1.120 raeburn 15536: if ($changes{'togglecatscomm'}) {
15537: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
15538: }
15539: if ($changes{'categorizecomm'}) {
15540: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
15541: }
1.238 raeburn 15542: if ($changes{'unauth'}) {
15543: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
15544: }
15545: if ($changes{'auth'}) {
15546: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
15547: }
1.57 raeburn 15548: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15549: my $cathash;
15550: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
15551: $cathash = $domconfig{'coursecategories'}{'cats'};
15552: } else {
15553: $cathash = {};
15554: }
15555: my (@cats,@trails,%allitems);
15556: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
15557: if (keys(%deletions) > 0) {
15558: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
15559: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
15560: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
15561: }
15562: $resulttext .= '</ul></li>';
15563: }
15564: if (keys(%reorderings) > 0) {
15565: my %sort_by_trail;
15566: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
15567: foreach my $key (keys(%reorderings)) {
15568: if ($allitems{$key} ne '') {
15569: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15570: }
1.48 raeburn 15571: }
1.57 raeburn 15572: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15573: $resulttext .= '<li>'.$trails[$trail].'</li>';
15574: }
15575: $resulttext .= '</ul></li>';
1.48 raeburn 15576: }
1.57 raeburn 15577: if (keys(%adds) > 0) {
15578: my %sort_by_trail;
15579: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
15580: foreach my $key (keys(%adds)) {
15581: if ($allitems{$key} ne '') {
15582: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15583: }
15584: }
15585: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15586: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 15587: }
1.57 raeburn 15588: $resulttext .= '</ul></li>';
1.48 raeburn 15589: }
15590: }
15591: $resulttext .= '</ul>';
1.239 raeburn 15592: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 15593: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15594: if ($changes{'auth'}) {
15595: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
15596: }
15597: if ($changes{'unauth'}) {
15598: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
15599: }
15600: my $cachetime = 24*60*60;
15601: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 15602: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 15603: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 15604: }
15605: }
1.48 raeburn 15606: } else {
15607: $resulttext = '<span class="LC_error">'.
1.57 raeburn 15608: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 15609: }
15610: } else {
1.120 raeburn 15611: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 15612: }
15613: return $resulttext;
15614: }
15615:
1.69 raeburn 15616: sub modify_serverstatuses {
15617: my ($dom,%domconfig) = @_;
15618: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
15619: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
15620: %currserverstatus = %{$domconfig{'serverstatuses'}};
15621: }
15622: my @pages = &serverstatus_pages();
15623: foreach my $type (@pages) {
15624: $newserverstatus{$type}{'namedusers'} = '';
15625: $newserverstatus{$type}{'machines'} = '';
15626: if (defined($env{'form.'.$type.'_namedusers'})) {
15627: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
15628: my @okusers;
15629: foreach my $user (@users) {
15630: my ($uname,$udom) = split(/:/,$user);
15631: if (($udom =~ /^$match_domain$/) &&
15632: (&Apache::lonnet::domain($udom)) &&
15633: ($uname =~ /^$match_username$/)) {
15634: if (!grep(/^\Q$user\E/,@okusers)) {
15635: push(@okusers,$user);
15636: }
15637: }
15638: }
15639: if (@okusers > 0) {
15640: @okusers = sort(@okusers);
15641: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
15642: }
15643: }
15644: if (defined($env{'form.'.$type.'_machines'})) {
15645: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
15646: my @okmachines;
15647: foreach my $ip (@machines) {
15648: my @parts = split(/\./,$ip);
15649: next if (@parts < 4);
15650: my $badip = 0;
15651: for (my $i=0; $i<4; $i++) {
15652: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
15653: $badip = 1;
15654: last;
15655: }
15656: }
15657: if (!$badip) {
15658: push(@okmachines,$ip);
15659: }
15660: }
15661: @okmachines = sort(@okmachines);
15662: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
15663: }
15664: }
15665: my %serverstatushash = (
15666: serverstatuses => \%newserverstatus,
15667: );
15668: foreach my $type (@pages) {
1.83 raeburn 15669: foreach my $setting ('namedusers','machines') {
1.84 raeburn 15670: my (@current,@new);
1.83 raeburn 15671: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 15672: if ($currserverstatus{$type}{$setting} ne '') {
15673: @current = split(/,/,$currserverstatus{$type}{$setting});
15674: }
15675: }
15676: if ($newserverstatus{$type}{$setting} ne '') {
15677: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 15678: }
15679: if (@current > 0) {
15680: if (@new > 0) {
15681: foreach my $item (@current) {
15682: if (!grep(/^\Q$item\E$/,@new)) {
15683: $changes{$type}{$setting} = 1;
1.82 raeburn 15684: last;
15685: }
15686: }
1.84 raeburn 15687: foreach my $item (@new) {
15688: if (!grep(/^\Q$item\E$/,@current)) {
15689: $changes{$type}{$setting} = 1;
15690: last;
1.82 raeburn 15691: }
15692: }
15693: } else {
1.83 raeburn 15694: $changes{$type}{$setting} = 1;
1.69 raeburn 15695: }
1.83 raeburn 15696: } elsif (@new > 0) {
15697: $changes{$type}{$setting} = 1;
1.69 raeburn 15698: }
15699: }
15700: }
15701: if (keys(%changes) > 0) {
1.81 raeburn 15702: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 15703: my $putresult = &Apache::lonnet::put_dom('configuration',
15704: \%serverstatushash,$dom);
15705: if ($putresult eq 'ok') {
15706: $resulttext .= &mt('Changes made:').'<ul>';
15707: foreach my $type (@pages) {
1.84 raeburn 15708: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 15709: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 15710: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 15711: if ($newserverstatus{$type}{'namedusers'} eq '') {
15712: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
15713: } else {
15714: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
15715: }
1.84 raeburn 15716: }
15717: if ($changes{$type}{'machines'}) {
1.69 raeburn 15718: if ($newserverstatus{$type}{'machines'} eq '') {
15719: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
15720: } else {
15721: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
15722: }
15723:
15724: }
15725: $resulttext .= '</ul></li>';
15726: }
15727: }
15728: $resulttext .= '</ul>';
15729: } else {
15730: $resulttext = '<span class="LC_error">'.
15731: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
15732:
15733: }
15734: } else {
15735: $resulttext = &mt('No changes made to access to server status pages');
15736: }
15737: return $resulttext;
15738: }
15739:
1.118 jms 15740: sub modify_helpsettings {
1.285 raeburn 15741: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 15742: my ($resulttext,$errors,%changes,%helphash);
15743: my %defaultchecked = ('submitbugs' => 'on');
15744: my @offon = ('off','on');
1.118 jms 15745: my @toggles = ('submitbugs');
1.285 raeburn 15746: my %current = ('submitbugs' => '',
15747: 'adhoc' => {},
15748: );
1.118 jms 15749: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 15750: %current = %{$domconfig{'helpsettings'}};
15751: }
1.285 raeburn 15752: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 15753: foreach my $item (@toggles) {
15754: if ($defaultchecked{$item} eq 'on') {
15755: if ($current{$item} eq '') {
15756: if ($env{'form.'.$item} eq '0') {
15757: $changes{$item} = 1;
15758: }
15759: } elsif ($current{$item} ne $env{'form.'.$item}) {
15760: $changes{$item} = 1;
15761: }
15762: } elsif ($defaultchecked{$item} eq 'off') {
15763: if ($current{$item} eq '') {
15764: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 15765: $changes{$item} = 1;
15766: }
1.282 raeburn 15767: } elsif ($current{$item} ne $env{'form.'.$item}) {
15768: $changes{$item} = 1;
15769: }
15770: }
15771: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
15772: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
15773: }
15774: }
1.285 raeburn 15775: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 15776: my $confname = $dom.'-domainconfig';
15777: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 15778: my (@allpos,%newsettings,%changedprivs,$newrole);
15779: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 15780: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 15781: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 15782: my %lt = &Apache::lonlocal::texthash(
15783: s => 'system',
15784: d => 'domain',
15785: order => 'Display order',
15786: access => 'Role usage',
1.291 raeburn 15787: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 15788: dh => 'All with domain helpdesk role',
15789: da => 'All with domain helpdesk assistant role',
1.285 raeburn 15790: none => 'None',
15791: status => 'Determined based on institutional status',
15792: inc => 'Include all, but exclude specific personnel',
15793: exc => 'Exclude all, but include specific personnel',
15794: );
15795: for (my $num=0; $num<=$maxnum; $num++) {
15796: my ($prefix,$identifier,$rolename,%curr);
15797: if ($num == $maxnum) {
15798: next unless ($env{'form.newcusthelp'} == $maxnum);
15799: $identifier = 'custhelp'.$num;
15800: $prefix = 'helproles_'.$num;
15801: $rolename = $env{'form.custhelpname'.$num};
15802: $rolename=~s/[^A-Za-z0-9]//gs;
15803: next if ($rolename eq '');
15804: next if (exists($existing{'rolesdef_'.$rolename}));
15805: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15806: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15807: $newprivs{'c'},$confname,$dom);
15808: if ($result ne 'ok') {
15809: $errors .= '<li><span class="LC_error">'.
15810: &mt('An error occurred storing the new custom role: [_1]',
15811: $result).'</span></li>';
15812: next;
15813: } else {
15814: $changedprivs{$rolename} = \%newprivs;
15815: $newrole = $rolename;
15816: }
15817: } else {
15818: $prefix = 'helproles_'.$num;
15819: $rolename = $env{'form.'.$prefix};
15820: next if ($rolename eq '');
15821: next unless (exists($existing{'rolesdef_'.$rolename}));
15822: $identifier = 'custhelp'.$num;
15823: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15824: my %currprivs;
1.289 raeburn 15825: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 15826: split(/\_/,$existing{'rolesdef_'.$rolename});
15827: foreach my $level ('c','d','s') {
15828: if ($newprivs{$level} ne $currprivs{$level}) {
15829: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15830: $newprivs{'c'},$confname,$dom);
15831: if ($result ne 'ok') {
15832: $errors .= '<li><span class="LC_error">'.
15833: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15834: $rolename,$result).'</span></li>';
15835: } else {
15836: $changedprivs{$rolename} = \%newprivs;
15837: }
15838: last;
15839: }
15840: }
15841: if (ref($current{'adhoc'}) eq 'HASH') {
15842: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15843: %curr = %{$current{'adhoc'}{$rolename}};
15844: }
15845: }
15846: }
15847: my $newpos = $env{'form.'.$prefix.'_pos'};
15848: $newpos =~ s/\D+//g;
15849: $allpos[$newpos] = $rolename;
15850: my $newdesc = $env{'form.'.$prefix.'_desc'};
15851: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15852: if ($curr{'desc'}) {
15853: if ($curr{'desc'} ne $newdesc) {
15854: $changes{'customrole'}{$rolename}{'desc'} = 1;
15855: $newsettings{$rolename}{'desc'} = $newdesc;
15856: }
15857: } elsif ($newdesc ne '') {
15858: $changes{'customrole'}{$rolename}{'desc'} = 1;
15859: $newsettings{$rolename}{'desc'} = $newdesc;
15860: }
15861: my $access = $env{'form.'.$prefix.'_access'};
15862: if (grep(/^\Q$access\E$/,@accesstypes)) {
15863: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15864: if ($access eq 'status') {
15865: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15866: if (scalar(@statuses) == 0) {
1.289 raeburn 15867: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 15868: } else {
15869: my (@shownstatus,$numtypes);
15870: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15871: if (ref($types) eq 'ARRAY') {
15872: $numtypes = scalar(@{$types});
15873: foreach my $type (sort(@statuses)) {
15874: if ($type eq 'default') {
15875: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15876: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15877: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15878: push(@shownstatus,$usertypes->{$type});
15879: }
15880: }
15881: }
15882: if (grep(/^default$/,@statuses)) {
15883: push(@shownstatus,$othertitle);
15884: }
15885: if (scalar(@shownstatus) == 1+$numtypes) {
15886: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15887: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15888: } else {
15889: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15890: if (ref($curr{'status'}) eq 'ARRAY') {
15891: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15892: if (@diffs) {
15893: $changes{'customrole'}{$rolename}{$access} = 1;
15894: }
15895: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15896: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 15897: }
1.166 raeburn 15898: }
15899: }
1.285 raeburn 15900: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15901: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15902: my @newspecstaff;
15903: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15904: foreach my $person (sort(@personnel)) {
15905: if ($domhelpdesk{$person}) {
15906: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15907: }
15908: }
15909: if (ref($curr{$access}) eq 'ARRAY') {
15910: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15911: if (@diffs) {
15912: $changes{'customrole'}{$rolename}{$access} = 1;
15913: }
15914: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15915: $changes{'customrole'}{$rolename}{$access} = 1;
15916: }
15917: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15918: my ($uname,$udom) = split(/:/,$person);
15919: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15920: }
15921: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 15922: }
1.285 raeburn 15923: } else {
15924: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15925: }
15926: unless ($curr{'access'} eq $access) {
15927: $changes{'customrole'}{$rolename}{'access'} = 1;
15928: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 15929: }
15930: }
1.285 raeburn 15931: if (@allpos > 0) {
15932: my $idx = 0;
15933: foreach my $rolename (@allpos) {
15934: if ($rolename ne '') {
15935: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15936: if (ref($current{'adhoc'}) eq 'HASH') {
15937: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15938: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15939: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 15940: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 15941: }
15942: }
1.282 raeburn 15943: }
1.285 raeburn 15944: $idx ++;
1.166 raeburn 15945: }
15946: }
1.118 jms 15947: }
1.123 jms 15948: my $putresult;
15949: if (keys(%changes) > 0) {
1.166 raeburn 15950: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 15951: if ($putresult eq 'ok') {
1.285 raeburn 15952: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15953: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15954: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15955: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15956: }
15957: }
15958: my $cachetime = 24*60*60;
15959: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15960: if (ref($lastactref) eq 'HASH') {
15961: $lastactref->{'domdefaults'} = 1;
15962: }
15963: } else {
15964: $errors .= '<li><span class="LC_error">'.
15965: &mt('An error occurred storing the settings: [_1]',
15966: $putresult).'</span></li>';
15967: }
15968: }
15969: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15970: $resulttext = &mt('Changes made:').'<ul>';
15971: my (%shownprivs,@levelorder);
15972: @levelorder = ('c','d','s');
15973: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 15974: foreach my $item (sort(keys(%changes))) {
15975: if ($item eq 'submitbugs') {
15976: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15977: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15978: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 15979: } elsif ($item eq 'customrole') {
15980: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 15981: my @keyorder = ('order','desc','access','status','exc','inc');
15982: my %keytext = &Apache::lonlocal::texthash(
15983: order => 'Order',
15984: desc => 'Role description',
15985: access => 'Role usage',
1.300 droeschl 15986: status => 'Allowed institutional types',
1.285 raeburn 15987: exc => 'Allowed personnel',
15988: inc => 'Disallowed personnel',
15989: );
1.282 raeburn 15990: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 15991: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15992: if ($role eq $newrole) {
15993: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15994: $role).'<ul>';
15995: } else {
15996: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15997: $role).'<ul>';
15998: }
15999: foreach my $key (@keyorder) {
16000: if ($changes{'customrole'}{$role}{$key}) {
16001: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
16002: $keytext{$key},$newsettings{$role}{$key}).
16003: '</li>';
16004: }
16005: }
16006: if (ref($changedprivs{$role}) eq 'HASH') {
16007: $shownprivs{$role} = 1;
16008: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
16009: foreach my $level (@levelorder) {
16010: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
16011: next if ($item eq '');
16012: my ($priv) = split(/\&/,$item,2);
16013: if (&Apache::lonnet::plaintext($priv)) {
16014: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
16015: unless ($level eq 'c') {
16016: $resulttext .= ' ('.$lt{$level}.')';
16017: }
16018: $resulttext .= '</li>';
16019: }
16020: }
16021: }
16022: $resulttext .= '</ul>';
16023: }
16024: $resulttext .= '</ul></li>';
16025: }
16026: }
16027: }
16028: }
16029: }
16030: }
16031: if (keys(%changedprivs)) {
16032: foreach my $role (sort(keys(%changedprivs))) {
16033: unless ($shownprivs{$role}) {
16034: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
16035: $role).'<ul>'.
16036: '<li>'.&mt('Privileges set to :').'<ul>';
16037: foreach my $level (@levelorder) {
16038: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
16039: next if ($item eq '');
16040: my ($priv) = split(/\&/,$item,2);
16041: if (&Apache::lonnet::plaintext($priv)) {
16042: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
16043: unless ($level eq 'c') {
16044: $resulttext .= ' ('.$lt{$level}.')';
16045: }
16046: $resulttext .= '</li>';
16047: }
1.282 raeburn 16048: }
16049: }
1.285 raeburn 16050: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 16051: }
16052: }
16053: }
1.285 raeburn 16054: $resulttext .= '</ul>';
16055: } else {
16056: $resulttext = &mt('No changes made to help settings');
1.118 jms 16057: }
16058: if ($errors) {
1.168 raeburn 16059: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 16060: $errors.'</ul>';
1.118 jms 16061: }
16062: return $resulttext;
16063: }
16064:
1.121 raeburn 16065: sub modify_coursedefaults {
1.212 raeburn 16066: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 16067: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 16068: my %defaultchecked = (
16069: 'canuse_pdfforms' => 'off',
16070: 'uselcmath' => 'on',
16071: 'usejsme' => 'on'
16072: );
16073: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 16074: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 16075: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
16076: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
16077: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 16078: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 16079: my %staticdefaults = (
16080: anonsurvey_threshold => 10,
16081: uploadquota => 500,
1.257 raeburn 16082: postsubmit => 60,
1.276 raeburn 16083: mysqltables => 172800,
1.198 raeburn 16084: );
1.314 raeburn 16085: my %texoptions = (
16086: MathJax => 'MathJax',
16087: mimetex => &mt('Convert to Images'),
16088: tth => &mt('TeX to HTML'),
16089: );
1.121 raeburn 16090: $defaultshash{'coursedefaults'} = {};
16091:
16092: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
16093: if ($domconfig{'coursedefaults'} eq '') {
16094: $domconfig{'coursedefaults'} = {};
16095: }
16096: }
16097:
16098: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
16099: foreach my $item (@toggles) {
16100: if ($defaultchecked{$item} eq 'on') {
16101: if (($domconfig{'coursedefaults'}{$item} eq '') &&
16102: ($env{'form.'.$item} eq '0')) {
16103: $changes{$item} = 1;
1.192 raeburn 16104: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 16105: $changes{$item} = 1;
16106: }
16107: } elsif ($defaultchecked{$item} eq 'off') {
16108: if (($domconfig{'coursedefaults'}{$item} eq '') &&
16109: ($env{'form.'.$item} eq '1')) {
16110: $changes{$item} = 1;
16111: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
16112: $changes{$item} = 1;
16113: }
16114: }
16115: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
16116: }
1.198 raeburn 16117: foreach my $item (@numbers) {
16118: my ($currdef,$newdef);
1.208 raeburn 16119: $newdef = $env{'form.'.$item};
1.198 raeburn 16120: if ($item eq 'anonsurvey_threshold') {
16121: $currdef = $domconfig{'coursedefaults'}{$item};
16122: $newdef =~ s/\D//g;
16123: if ($newdef eq '' || $newdef < 1) {
16124: $newdef = 1;
16125: }
16126: $defaultshash{'coursedefaults'}{$item} = $newdef;
16127: } else {
1.276 raeburn 16128: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
16129: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
16130: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 16131: }
16132: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 16133: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 16134: }
16135: if ($currdef ne $newdef) {
16136: my $staticdef;
16137: if ($item eq 'anonsurvey_threshold') {
16138: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
16139: $changes{$item} = 1;
16140: }
1.276 raeburn 16141: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 16142: my $setting = $1;
1.276 raeburn 16143: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
16144: $changes{$setting} = 1;
1.198 raeburn 16145: }
16146: }
1.139 raeburn 16147: }
16148: }
1.314 raeburn 16149: my $texengine;
16150: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
16151: $texengine = $env{'form.texengine'};
16152: if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {
16153: unless ($texengine eq 'MathJax') {
16154: $changes{'texengine'} = 1;
16155: }
16156: } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {
16157: $changes{'texengine'} = 1;
16158: }
16159: }
16160: if ($texengine ne '') {
16161: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
16162: }
1.264 raeburn 16163: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
16164: my @currclonecode;
16165: if (ref($currclone) eq 'HASH') {
16166: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
16167: @currclonecode = @{$currclone->{'instcode'}};
16168: }
16169: }
16170: my $newclone;
1.289 raeburn 16171: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 16172: $newclone = $env{'form.canclone'};
16173: }
16174: if ($newclone eq 'instcode') {
16175: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
16176: my (%codedefaults,@code_order,@clonecode);
16177: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
16178: \@code_order);
16179: foreach my $item (@code_order) {
16180: if (grep(/^\Q$item\E$/,@newcodes)) {
16181: push(@clonecode,$item);
16182: }
16183: }
16184: if (@clonecode) {
16185: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
16186: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
16187: if (@diffs) {
16188: $changes{'canclone'} = 1;
16189: }
16190: } else {
16191: $newclone eq '';
16192: }
16193: } elsif ($newclone ne '') {
1.289 raeburn 16194: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
16195: }
1.264 raeburn 16196: if ($newclone ne $currclone) {
16197: $changes{'canclone'} = 1;
16198: }
1.257 raeburn 16199: my %credits;
16200: foreach my $type (@types) {
16201: unless ($type eq 'community') {
16202: $credits{$type} = $env{'form.'.$type.'_credits'};
16203: $credits{$type} =~ s/[^\d.]+//g;
16204: }
16205: }
16206: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
16207: ($env{'form.coursecredits'} eq '1')) {
16208: $changes{'coursecredits'} = 1;
16209: foreach my $type (keys(%credits)) {
16210: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
16211: }
16212: } else {
1.289 raeburn 16213: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 16214: foreach my $type (@types) {
16215: unless ($type eq 'community') {
1.289 raeburn 16216: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 16217: $changes{'coursecredits'} = 1;
16218: }
16219: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
16220: }
16221: }
16222: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
16223: foreach my $type (@types) {
16224: unless ($type eq 'community') {
16225: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
16226: $changes{'coursecredits'} = 1;
16227: last;
16228: }
16229: }
16230: }
16231: }
16232: }
16233: if ($env{'form.postsubmit'} eq '1') {
16234: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
16235: my %currtimeout;
16236: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
16237: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
16238: $changes{'postsubmit'} = 1;
16239: }
16240: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
16241: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
16242: }
16243: } else {
16244: $changes{'postsubmit'} = 1;
16245: }
16246: foreach my $type (@types) {
16247: my $timeout = $env{'form.'.$type.'_timeout'};
16248: $timeout =~ s/\D//g;
16249: if ($timeout == $staticdefaults{'postsubmit'}) {
16250: $timeout = '';
16251: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
16252: $timeout = '0';
16253: }
16254: unless ($timeout eq '') {
16255: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
16256: }
16257: if (exists($currtimeout{$type})) {
16258: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 16259: $changes{'postsubmit'} = 1;
1.257 raeburn 16260: }
16261: } elsif ($timeout ne '') {
16262: $changes{'postsubmit'} = 1;
16263: }
16264: }
16265: } else {
16266: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
16267: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
16268: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
16269: $changes{'postsubmit'} = 1;
16270: }
16271: } else {
16272: $changes{'postsubmit'} = 1;
16273: }
1.192 raeburn 16274: }
1.121 raeburn 16275: }
16276: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16277: $dom);
16278: if ($putresult eq 'ok') {
16279: if (keys(%changes) > 0) {
1.213 raeburn 16280: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 16281: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 16282: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 16283: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
16284: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 16285: if ($changes{$item}) {
16286: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
16287: }
1.289 raeburn 16288: }
1.192 raeburn 16289: if ($changes{'coursecredits'}) {
16290: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 16291: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
16292: $domdefaults{$type.'credits'} =
16293: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
16294: }
16295: }
16296: }
16297: if ($changes{'postsubmit'}) {
16298: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
16299: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
16300: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
16301: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
16302: $domdefaults{$type.'postsubtimeout'} =
16303: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
16304: }
16305: }
1.192 raeburn 16306: }
16307: }
1.198 raeburn 16308: if ($changes{'uploadquota'}) {
16309: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
16310: foreach my $type (@types) {
16311: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
16312: }
16313: }
16314: }
1.264 raeburn 16315: if ($changes{'canclone'}) {
16316: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
16317: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
16318: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
16319: if (@clonecodes) {
16320: $domdefaults{'canclone'} = join('+',@clonecodes);
16321: }
16322: }
16323: } else {
16324: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
16325: }
16326: }
1.121 raeburn 16327: my $cachetime = 24*60*60;
16328: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 16329: if (ref($lastactref) eq 'HASH') {
16330: $lastactref->{'domdefaults'} = 1;
16331: }
1.121 raeburn 16332: }
16333: $resulttext = &mt('Changes made:').'<ul>';
16334: foreach my $item (sort(keys(%changes))) {
16335: if ($item eq 'canuse_pdfforms') {
16336: if ($env{'form.'.$item} eq '1') {
16337: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
16338: } else {
16339: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
16340: }
1.257 raeburn 16341: } elsif ($item eq 'uselcmath') {
16342: if ($env{'form.'.$item} eq '1') {
16343: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
16344: } else {
16345: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
16346: }
16347: } elsif ($item eq 'usejsme') {
16348: if ($env{'form.'.$item} eq '1') {
16349: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
16350: } else {
1.289 raeburn 16351: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 16352: }
1.314 raeburn 16353: } elsif ($item eq 'texengine') {
16354: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
16355: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
16356: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
16357: }
1.139 raeburn 16358: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 16359: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 16360: } elsif ($item eq 'uploadquota') {
16361: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
16362: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
16363: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
16364: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 16365: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 16366: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 16367: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
16368: '</ul>'.
16369: '</li>';
16370: } else {
16371: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
16372: }
1.276 raeburn 16373: } elsif ($item eq 'mysqltables') {
16374: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
16375: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
16376: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
16377: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
16378: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
16379: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
16380: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
16381: '</ul>'.
16382: '</li>';
16383: } else {
16384: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
16385: }
1.257 raeburn 16386: } elsif ($item eq 'postsubmit') {
16387: if ($domdefaults{'postsubmit'} eq 'off') {
16388: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
16389: } else {
16390: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 16391: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 16392: $resulttext .= &mt('durations:').'<ul>';
16393: foreach my $type (@types) {
16394: $resulttext .= '<li>';
16395: my $timeout;
16396: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
16397: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
16398: }
16399: my $display;
16400: if ($timeout eq '0') {
16401: $display = &mt('unlimited');
16402: } elsif ($timeout eq '') {
16403: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
16404: } else {
16405: $display = &mt('[quant,_1,second]',$timeout);
16406: }
16407: if ($type eq 'community') {
16408: $resulttext .= &mt('Communities');
16409: } elsif ($type eq 'official') {
16410: $resulttext .= &mt('Official courses');
16411: } elsif ($type eq 'unofficial') {
16412: $resulttext .= &mt('Unofficial courses');
16413: } elsif ($type eq 'textbook') {
16414: $resulttext .= &mt('Textbook courses');
1.271 raeburn 16415: } elsif ($type eq 'placement') {
16416: $resulttext .= &mt('Placement tests');
1.257 raeburn 16417: }
16418: $resulttext .= ' -- '.$display.'</li>';
16419: }
16420: $resulttext .= '</ul>';
16421: }
1.289 raeburn 16422: $resulttext .= '</li>';
1.257 raeburn 16423: }
1.192 raeburn 16424: } elsif ($item eq 'coursecredits') {
16425: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
16426: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 16427: ($domdefaults{'unofficialcredits'} eq '') &&
16428: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 16429: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
16430: } else {
16431: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
16432: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
16433: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 16434: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 16435: '</ul>'.
16436: '</li>';
16437: }
16438: } else {
16439: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
16440: }
1.264 raeburn 16441: } elsif ($item eq 'canclone') {
16442: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
16443: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
16444: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
16445: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
16446: }
16447: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
16448: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
16449: } else {
1.289 raeburn 16450: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 16451: }
1.140 raeburn 16452: }
1.121 raeburn 16453: }
16454: $resulttext .= '</ul>';
16455: } else {
16456: $resulttext = &mt('No changes made to course defaults');
16457: }
16458: } else {
16459: $resulttext = '<span class="LC_error">'.
16460: &mt('An error occurred: [_1]',$putresult).'</span>';
16461: }
16462: return $resulttext;
16463: }
16464:
1.231 raeburn 16465: sub modify_selfenrollment {
16466: my ($dom,$lastactref,%domconfig) = @_;
16467: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 16468: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 16469: my %titles = &tool_titles();
1.232 raeburn 16470: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
16471: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 16472: $ordered{'default'} = ['types','registered','approval','limit'];
16473:
16474: my (%roles,%shown,%toplevel);
16475: $roles{'0'} = &Apache::lonnet::plaintext('dc');
16476:
16477: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
16478: if ($domconfig{'selfenrollment'} eq '') {
16479: $domconfig{'selfenrollment'} = {};
16480: }
16481: }
16482: %toplevel = (
16483: admin => 'Configuration Rights',
16484: default => 'Default settings',
16485: validation => 'Validation of self-enrollment requests',
16486: );
1.233 raeburn 16487: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 16488:
16489: if (ref($ordered{'admin'}) eq 'ARRAY') {
16490: foreach my $item (@{$ordered{'admin'}}) {
16491: foreach my $type (@types) {
16492: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
16493: $selfenrollhash{'admin'}{$type}{$item} = 1;
16494: } else {
16495: $selfenrollhash{'admin'}{$type}{$item} = 0;
16496: }
16497: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
16498: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
16499: if ($selfenrollhash{'admin'}{$type}{$item} ne
16500: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
16501: push(@{$changes{'admin'}{$type}},$item);
16502: }
16503: } else {
16504: if (!$selfenrollhash{'admin'}{$type}{$item}) {
16505: push(@{$changes{'admin'}{$type}},$item);
16506: }
16507: }
16508: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
16509: push(@{$changes{'admin'}{$type}},$item);
16510: }
16511: }
16512: }
16513: }
16514:
16515: foreach my $item (@{$ordered{'default'}}) {
16516: foreach my $type (@types) {
16517: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
16518: if ($item eq 'types') {
16519: unless (($value eq 'all') || ($value eq 'dom')) {
16520: $value = '';
16521: }
16522: } elsif ($item eq 'registered') {
16523: unless ($value eq '1') {
16524: $value = 0;
16525: }
16526: } elsif ($item eq 'approval') {
16527: unless ($value =~ /^[012]$/) {
16528: $value = 0;
16529: }
16530: } else {
16531: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
16532: $value = 'none';
16533: }
16534: }
16535: $selfenrollhash{'default'}{$type}{$item} = $value;
16536: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
16537: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
16538: if ($selfenrollhash{'default'}{$type}{$item} ne
16539: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
16540: push(@{$changes{'default'}{$type}},$item);
16541: }
16542: } else {
16543: push(@{$changes{'default'}{$type}},$item);
16544: }
16545: } else {
16546: push(@{$changes{'default'}{$type}},$item);
16547: }
16548: if ($item eq 'limit') {
16549: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
16550: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
16551: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
16552: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
16553: }
16554: } else {
16555: $selfenrollhash{'default'}{$type}{'cap'} = '';
16556: }
16557: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
16558: if ($selfenrollhash{'default'}{$type}{'cap'} ne
16559: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
16560: push(@{$changes{'default'}{$type}},'cap');
16561: }
16562: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
16563: push(@{$changes{'default'}{$type}},'cap');
16564: }
16565: }
16566: }
16567: }
16568:
16569: foreach my $item (@{$itemsref}) {
16570: if ($item eq 'fields') {
16571: my @changed;
16572: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
16573: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
16574: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
16575: }
16576: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16577: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
16578: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
16579: $domconfig{'selfenrollment'}{'validation'}{$item});
16580: } else {
16581: @changed = @{$selfenrollhash{'validation'}{$item}};
16582: }
16583: } else {
16584: @changed = @{$selfenrollhash{'validation'}{$item}};
16585: }
16586: if (@changed) {
16587: if ($selfenrollhash{'validation'}{$item}) {
16588: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
16589: } else {
16590: $changes{'validation'}{$item} = &mt('None');
16591: }
16592: }
16593: } else {
16594: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
16595: if ($item eq 'markup') {
16596: if ($env{'form.selfenroll_validation_'.$item}) {
16597: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
16598: }
16599: }
16600: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16601: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
16602: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
16603: }
16604: }
16605: }
16606: }
16607:
16608: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
16609: $dom);
16610: if ($putresult eq 'ok') {
16611: if (keys(%changes) > 0) {
16612: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16613: $resulttext = &mt('Changes made:').'<ul>';
16614: foreach my $key ('admin','default','validation') {
16615: if (ref($changes{$key}) eq 'HASH') {
16616: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
16617: if ($key eq 'validation') {
16618: foreach my $item (@{$itemsref}) {
16619: if (exists($changes{$key}{$item})) {
16620: if ($item eq 'markup') {
16621: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16622: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
16623: } else {
16624: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16625: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
16626: }
16627: }
16628: }
16629: } else {
16630: foreach my $type (@types) {
16631: if ($type eq 'community') {
16632: $roles{'1'} = &mt('Community personnel');
16633: } else {
16634: $roles{'1'} = &mt('Course personnel');
16635: }
16636: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 16637: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16638: if ($key eq 'admin') {
16639: my @mgrdc = ();
16640: if (ref($ordered{$key}) eq 'ARRAY') {
16641: foreach my $item (@{$ordered{'admin'}}) {
16642: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16643: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
16644: push(@mgrdc,$item);
16645: }
16646: }
16647: }
16648: if (@mgrdc) {
16649: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
16650: } else {
16651: delete($domdefaults{$type.'selfenrolladmdc'});
16652: }
16653: }
16654: } else {
16655: if (ref($ordered{$key}) eq 'ARRAY') {
16656: foreach my $item (@{$ordered{$key}}) {
16657: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16658: $domdefaults{$type.'selfenroll'.$item} =
16659: $selfenrollhash{$key}{$type}{$item};
16660: }
16661: }
16662: }
16663: }
16664: }
1.231 raeburn 16665: $resulttext .= '<li>'.$titles{$type}.'<ul>';
16666: foreach my $item (@{$ordered{$key}}) {
16667: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16668: $resulttext .= '<li>';
16669: if ($key eq 'admin') {
16670: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
16671: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
16672: } else {
16673: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
16674: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
16675: }
16676: $resulttext .= '</li>';
16677: }
16678: }
16679: $resulttext .= '</ul></li>';
16680: }
16681: }
16682: $resulttext .= '</ul></li>';
16683: }
16684: }
1.305 raeburn 16685: }
16686: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
16687: my $cachetime = 24*60*60;
16688: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16689: if (ref($lastactref) eq 'HASH') {
16690: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 16691: }
1.231 raeburn 16692: }
16693: $resulttext .= '</ul>';
16694: } else {
16695: $resulttext = &mt('No changes made to self-enrollment settings');
16696: }
16697: } else {
16698: $resulttext = '<span class="LC_error">'.
16699: &mt('An error occurred: [_1]',$putresult).'</span>';
16700: }
16701: return $resulttext;
16702: }
16703:
1.137 raeburn 16704: sub modify_usersessions {
1.212 raeburn 16705: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 16706: my @hostingtypes = ('version','excludedomain','includedomain');
16707: my @offloadtypes = ('primary','default');
16708: my %types = (
16709: remote => \@hostingtypes,
16710: hosted => \@hostingtypes,
16711: spares => \@offloadtypes,
16712: );
16713: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 16714: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 16715: my (%by_ip,%by_location,@intdoms,@instdoms);
16716: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 16717: my @locations = sort(keys(%by_location));
1.137 raeburn 16718: my (%defaultshash,%changes);
16719: foreach my $prefix (@prefixes) {
16720: $defaultshash{'usersessions'}{$prefix} = {};
16721: }
1.212 raeburn 16722: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 16723: my $resulttext;
1.138 raeburn 16724: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 16725: foreach my $prefix (@prefixes) {
1.145 raeburn 16726: next if ($prefix eq 'spares');
16727: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 16728: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16729: if ($type eq 'version') {
16730: my $value = $env{'form.'.$prefix.'_'.$type};
16731: my $okvalue;
16732: if ($value ne '') {
16733: if (grep(/^\Q$value\E$/,@lcversions)) {
16734: $okvalue = $value;
16735: }
16736: }
16737: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16738: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16739: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
16740: if ($inuse == 0) {
16741: $changes{$prefix}{$type} = 1;
16742: } else {
16743: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
16744: $changes{$prefix}{$type} = 1;
16745: }
16746: if ($okvalue ne '') {
16747: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16748: }
16749: }
16750: } else {
16751: if (($inuse == 1) && ($okvalue ne '')) {
16752: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16753: $changes{$prefix}{$type} = 1;
16754: }
16755: }
16756: } else {
16757: if (($inuse == 1) && ($okvalue ne '')) {
16758: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16759: $changes{$prefix}{$type} = 1;
16760: }
16761: }
16762: } else {
16763: if (($inuse == 1) && ($okvalue ne '')) {
16764: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16765: $changes{$prefix}{$type} = 1;
16766: }
16767: }
16768: } else {
16769: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16770: my @okvals;
16771: foreach my $val (@vals) {
1.138 raeburn 16772: if ($val =~ /:/) {
16773: my @items = split(/:/,$val);
16774: foreach my $item (@items) {
16775: if (ref($by_location{$item}) eq 'ARRAY') {
16776: push(@okvals,$item);
16777: }
16778: }
16779: } else {
16780: if (ref($by_location{$val}) eq 'ARRAY') {
16781: push(@okvals,$val);
16782: }
1.137 raeburn 16783: }
16784: }
16785: @okvals = sort(@okvals);
16786: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16787: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16788: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16789: if ($inuse == 0) {
16790: $changes{$prefix}{$type} = 1;
16791: } else {
16792: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16793: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
16794: if (@changed > 0) {
16795: $changes{$prefix}{$type} = 1;
16796: }
16797: }
16798: } else {
16799: if ($inuse == 1) {
16800: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16801: $changes{$prefix}{$type} = 1;
16802: }
16803: }
16804: } else {
16805: if ($inuse == 1) {
16806: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16807: $changes{$prefix}{$type} = 1;
16808: }
16809: }
16810: } else {
16811: if ($inuse == 1) {
16812: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16813: $changes{$prefix}{$type} = 1;
16814: }
16815: }
16816: }
16817: }
16818: }
1.145 raeburn 16819:
16820: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16821: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16822: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16823: my $savespares;
16824:
16825: foreach my $lonhost (sort(keys(%servers))) {
16826: my $serverhomeID =
16827: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16828: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16829: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16830: my %spareschg;
16831: foreach my $type (@{$types{'spares'}}) {
16832: my @okspares;
16833: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16834: foreach my $server (@checked) {
1.152 raeburn 16835: if (&Apache::lonnet::hostname($server) ne '') {
16836: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16837: unless (grep(/^\Q$server\E$/,@okspares)) {
16838: push(@okspares,$server);
16839: }
1.145 raeburn 16840: }
16841: }
16842: }
16843: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16844: my $newspare;
1.152 raeburn 16845: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16846: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16847: $newspare = $new;
16848: }
16849: }
1.152 raeburn 16850: my @spares;
16851: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16852: @spares = sort(@okspares,$newspare);
16853: } else {
16854: @spares = sort(@okspares);
16855: }
16856: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16857: if (ref($spareid{$lonhost}) eq 'HASH') {
16858: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16859: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16860: if (@diffs > 0) {
16861: $spareschg{$type} = 1;
16862: }
16863: }
16864: }
16865: }
16866: if (keys(%spareschg) > 0) {
16867: $changes{'spares'}{$lonhost} = \%spareschg;
16868: }
16869: }
1.261 raeburn 16870: $defaultshash{'usersessions'}{'offloadnow'} = {};
16871: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16872: my @okoffload;
16873: if (@offloadnow) {
16874: foreach my $server (@offloadnow) {
16875: if (&Apache::lonnet::hostname($server) ne '') {
16876: unless (grep(/^\Q$server\E$/,@okoffload)) {
16877: push(@okoffload,$server);
16878: }
16879: }
16880: }
16881: if (@okoffload) {
16882: foreach my $lonhost (@okoffload) {
16883: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16884: }
16885: }
16886: }
1.145 raeburn 16887: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16888: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16889: if (ref($changes{'spares'}) eq 'HASH') {
16890: if (keys(%{$changes{'spares'}}) > 0) {
16891: $savespares = 1;
16892: }
16893: }
16894: } else {
16895: $savespares = 1;
16896: }
1.261 raeburn 16897: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
16898: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
16899: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
16900: $changes{'offloadnow'} = 1;
16901: last;
16902: }
16903: }
16904: unless ($changes{'offloadnow'}) {
1.289 raeburn 16905: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 16906: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
16907: $changes{'offloadnow'} = 1;
16908: last;
16909: }
16910: }
16911: }
16912: } elsif (@okoffload) {
16913: $changes{'offloadnow'} = 1;
16914: }
16915: } elsif (@okoffload) {
16916: $changes{'offloadnow'} = 1;
1.145 raeburn 16917: }
1.147 raeburn 16918: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16919: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16920: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16921: $dom);
16922: if ($putresult eq 'ok') {
16923: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16924: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16925: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16926: }
16927: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16928: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16929: }
1.261 raeburn 16930: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16931: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16932: }
1.137 raeburn 16933: }
16934: my $cachetime = 24*60*60;
16935: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 16936: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 16937: if (ref($lastactref) eq 'HASH') {
16938: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 16939: $lastactref->{'usersessions'} = 1;
1.212 raeburn 16940: }
1.147 raeburn 16941: if (keys(%changes) > 0) {
16942: my %lt = &usersession_titles();
16943: $resulttext = &mt('Changes made:').'<ul>';
16944: foreach my $prefix (@prefixes) {
16945: if (ref($changes{$prefix}) eq 'HASH') {
16946: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16947: if ($prefix eq 'spares') {
16948: if (ref($changes{$prefix}) eq 'HASH') {
16949: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16950: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16951: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 16952: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16953: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16954: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16955: foreach my $type (@{$types{$prefix}}) {
16956: if ($changes{$prefix}{$lonhost}{$type}) {
16957: my $offloadto = &mt('None');
16958: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16959: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16960: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16961: }
1.145 raeburn 16962: }
1.147 raeburn 16963: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16964: }
1.137 raeburn 16965: }
16966: }
1.147 raeburn 16967: $resulttext .= '</li>';
1.137 raeburn 16968: }
16969: }
1.147 raeburn 16970: } else {
16971: foreach my $type (@{$types{$prefix}}) {
16972: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 16973: my ($newvalue,$notinuse);
1.147 raeburn 16974: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16975: if (ref($defaultshash{'usersessions'}{$prefix})) {
16976: if ($type eq 'version') {
16977: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 16978: } else {
16979: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16980: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16981: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16982: }
16983: } else {
16984: $notinuse = 1;
1.147 raeburn 16985: }
1.145 raeburn 16986: }
16987: }
16988: }
1.147 raeburn 16989: if ($newvalue eq '') {
16990: if ($type eq 'version') {
16991: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 16992: } elsif ($notinuse) {
16993: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 16994: } else {
16995: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16996: }
1.145 raeburn 16997: } else {
1.147 raeburn 16998: if ($type eq 'version') {
1.344 raeburn 16999: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 17000: }
17001: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 17002: }
1.137 raeburn 17003: }
17004: }
17005: }
1.147 raeburn 17006: $resulttext .= '</ul>';
1.137 raeburn 17007: }
17008: }
1.261 raeburn 17009: if ($changes{'offloadnow'}) {
17010: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
17011: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
17012: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
17013: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
17014: $resulttext .= '<li>'.$lonhost.'</li>';
17015: }
17016: $resulttext .= '</ul>';
17017: } else {
17018: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
17019: }
17020: } else {
17021: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
17022: }
17023: }
1.147 raeburn 17024: $resulttext .= '</ul>';
17025: } else {
17026: $resulttext = $nochgmsg;
1.137 raeburn 17027: }
17028: } else {
17029: $resulttext = '<span class="LC_error">'.
17030: &mt('An error occurred: [_1]',$putresult).'</span>';
17031: }
17032: } else {
1.147 raeburn 17033: $resulttext = $nochgmsg;
1.137 raeburn 17034: }
17035: return $resulttext;
17036: }
17037:
1.275 raeburn 17038: sub modify_ssl {
17039: my ($dom,$lastactref,%domconfig) = @_;
17040: my (%by_ip,%by_location,@intdoms,@instdoms);
17041: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17042: my @locations = sort(keys(%by_location));
17043: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17044: my (%defaultshash,%changes);
17045: my $action = 'ssl';
1.293 raeburn 17046: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 17047: foreach my $prefix (@prefixes) {
17048: $defaultshash{$action}{$prefix} = {};
17049: }
17050: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17051: my $resulttext;
17052: my %iphost = &Apache::lonnet::get_iphost();
17053: my @reptypes = ('certreq','nocertreq');
17054: my @connecttypes = ('dom','intdom','other');
17055: my %types = (
1.293 raeburn 17056: connto => \@connecttypes,
17057: connfrom => \@connecttypes,
17058: replication => \@reptypes,
1.275 raeburn 17059: );
17060: foreach my $prefix (sort(keys(%types))) {
17061: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 17062: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 17063: my $value = 'yes';
17064: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
17065: $value = $env{'form.'.$prefix.'_'.$type};
17066: }
1.335 raeburn 17067: if (ref($domconfig{$action}) eq 'HASH') {
17068: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
17069: if ($domconfig{$action}{$prefix}{$type} ne '') {
17070: if ($value ne $domconfig{$action}{$prefix}{$type}) {
17071: $changes{$prefix}{$type} = 1;
17072: }
17073: $defaultshash{$action}{$prefix}{$type} = $value;
17074: } else {
17075: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 17076: $changes{$prefix}{$type} = 1;
17077: }
17078: } else {
17079: $defaultshash{$action}{$prefix}{$type} = $value;
17080: $changes{$prefix}{$type} = 1;
17081: }
17082: } else {
17083: $defaultshash{$action}{$prefix}{$type} = $value;
17084: $changes{$prefix}{$type} = 1;
17085: }
17086: if (($type eq 'dom') && (keys(%servers) == 1)) {
17087: delete($changes{$prefix}{$type});
17088: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
17089: delete($changes{$prefix}{$type});
17090: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
17091: delete($changes{$prefix}{$type});
17092: }
17093: } elsif ($prefix eq 'replication') {
17094: if (@locations > 0) {
17095: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
17096: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
17097: my @okvals;
17098: foreach my $val (@vals) {
17099: if ($val =~ /:/) {
17100: my @items = split(/:/,$val);
17101: foreach my $item (@items) {
17102: if (ref($by_location{$item}) eq 'ARRAY') {
17103: push(@okvals,$item);
17104: }
17105: }
17106: } else {
17107: if (ref($by_location{$val}) eq 'ARRAY') {
17108: push(@okvals,$val);
17109: }
17110: }
17111: }
17112: @okvals = sort(@okvals);
17113: if (ref($domconfig{$action}) eq 'HASH') {
17114: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
17115: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
17116: if ($inuse == 0) {
17117: $changes{$prefix}{$type} = 1;
17118: } else {
17119: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17120: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
17121: if (@changed > 0) {
17122: $changes{$prefix}{$type} = 1;
17123: }
17124: }
17125: } else {
17126: if ($inuse == 1) {
17127: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17128: $changes{$prefix}{$type} = 1;
17129: }
17130: }
17131: } else {
17132: if ($inuse == 1) {
17133: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17134: $changes{$prefix}{$type} = 1;
17135: }
17136: }
17137: } else {
17138: if ($inuse == 1) {
17139: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17140: $changes{$prefix}{$type} = 1;
17141: }
17142: }
17143: }
17144: }
17145: }
17146: }
1.336 raeburn 17147: if (keys(%changes)) {
17148: foreach my $prefix (keys(%changes)) {
17149: if (ref($changes{$prefix}) eq 'HASH') {
17150: if (scalar(keys(%{$changes{$prefix}})) == 0) {
17151: delete($changes{$prefix});
17152: }
17153: } else {
17154: delete($changes{$prefix});
17155: }
17156: }
17157: }
1.275 raeburn 17158: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
17159: if (keys(%changes) > 0) {
17160: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17161: $dom);
17162: if ($putresult eq 'ok') {
17163: if (ref($defaultshash{$action}) eq 'HASH') {
17164: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
17165: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
17166: }
1.293 raeburn 17167: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 17168: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 17169: }
17170: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 17171: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 17172: }
17173: }
17174: my $cachetime = 24*60*60;
17175: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17176: if (ref($lastactref) eq 'HASH') {
17177: $lastactref->{'domdefaults'} = 1;
17178: }
17179: if (keys(%changes) > 0) {
17180: my %titles = &ssl_titles();
17181: $resulttext = &mt('Changes made:').'<ul>';
17182: foreach my $prefix (@prefixes) {
17183: if (ref($changes{$prefix}) eq 'HASH') {
17184: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
17185: foreach my $type (@{$types{$prefix}}) {
17186: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 17187: my ($newvalue,$notinuse);
1.275 raeburn 17188: if (ref($defaultshash{$action}) eq 'HASH') {
17189: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 17190: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 17191: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 17192: } else {
17193: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
17194: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
17195: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
17196: }
17197: } else {
17198: $notinuse = 1;
1.275 raeburn 17199: }
17200: }
17201: }
1.344 raeburn 17202: if ($notinuse) {
17203: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
17204: } elsif ($newvalue eq '') {
1.275 raeburn 17205: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
17206: } else {
17207: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
17208: }
17209: }
17210: }
17211: }
17212: $resulttext .= '</ul>';
17213: }
17214: }
17215: } else {
17216: $resulttext = $nochgmsg;
17217: }
17218: } else {
17219: $resulttext = '<span class="LC_error">'.
17220: &mt('An error occurred: [_1]',$putresult).'</span>';
17221: }
17222: } else {
17223: $resulttext = $nochgmsg;
17224: }
17225: return $resulttext;
17226: }
17227:
1.279 raeburn 17228: sub modify_trust {
17229: my ($dom,$lastactref,%domconfig) = @_;
17230: my (%by_ip,%by_location,@intdoms,@instdoms);
17231: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17232: my @locations = sort(keys(%by_location));
17233: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
17234: my @types = ('exc','inc');
17235: my (%defaultshash,%changes);
17236: foreach my $prefix (@prefixes) {
17237: $defaultshash{'trust'}{$prefix} = {};
17238: }
17239: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17240: my $resulttext;
17241: foreach my $prefix (@prefixes) {
17242: foreach my $type (@types) {
17243: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
17244: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
17245: my @okvals;
17246: foreach my $val (@vals) {
17247: if ($val =~ /:/) {
17248: my @items = split(/:/,$val);
17249: foreach my $item (@items) {
17250: if (ref($by_location{$item}) eq 'ARRAY') {
17251: push(@okvals,$item);
17252: }
17253: }
17254: } else {
17255: if (ref($by_location{$val}) eq 'ARRAY') {
17256: push(@okvals,$val);
17257: }
17258: }
17259: }
17260: @okvals = sort(@okvals);
17261: if (ref($domconfig{'trust'}) eq 'HASH') {
17262: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
17263: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
17264: if ($inuse == 0) {
17265: $changes{$prefix}{$type} = 1;
17266: } else {
17267: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
17268: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
17269: if (@changed > 0) {
17270: $changes{$prefix}{$type} = 1;
17271: }
17272: }
17273: } else {
17274: if ($inuse == 1) {
17275: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
17276: $changes{$prefix}{$type} = 1;
17277: }
17278: }
17279: } else {
17280: if ($inuse == 1) {
17281: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
17282: $changes{$prefix}{$type} = 1;
17283: }
17284: }
17285: } else {
17286: if ($inuse == 1) {
17287: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
17288: $changes{$prefix}{$type} = 1;
17289: }
17290: }
17291: }
17292: }
17293: my $nochgmsg = &mt('No changes made to trust settings.');
17294: if (keys(%changes) > 0) {
17295: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17296: $dom);
17297: if ($putresult eq 'ok') {
17298: if (ref($defaultshash{'trust'}) eq 'HASH') {
17299: foreach my $prefix (@prefixes) {
17300: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
17301: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
17302: }
17303: }
17304: }
17305: my $cachetime = 24*60*60;
17306: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17307: if (ref($lastactref) eq 'HASH') {
17308: $lastactref->{'domdefaults'} = 1;
17309: }
17310: if (keys(%changes) > 0) {
17311: my %lt = &trust_titles();
17312: $resulttext = &mt('Changes made:').'<ul>';
17313: foreach my $prefix (@prefixes) {
17314: if (ref($changes{$prefix}) eq 'HASH') {
17315: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
17316: foreach my $type (@types) {
17317: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 17318: my ($newvalue,$notinuse);
1.279 raeburn 17319: if (ref($defaultshash{'trust'}) eq 'HASH') {
17320: if (ref($defaultshash{'trust'}{$prefix})) {
17321: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
17322: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
17323: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
17324: }
1.344 raeburn 17325: } else {
17326: $notinuse = 1;
1.279 raeburn 17327: }
17328: }
17329: }
1.344 raeburn 17330: if ($notinuse) {
17331: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
17332: } elsif ($newvalue eq '') {
1.279 raeburn 17333: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
17334: } else {
17335: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
17336: }
17337: }
17338: }
17339: $resulttext .= '</ul>';
17340: }
17341: }
17342: $resulttext .= '</ul>';
17343: } else {
17344: $resulttext = $nochgmsg;
17345: }
17346: } else {
17347: $resulttext = '<span class="LC_error">'.
17348: &mt('An error occurred: [_1]',$putresult).'</span>';
17349: }
17350: } else {
17351: $resulttext = $nochgmsg;
17352: }
17353: return $resulttext;
17354: }
17355:
1.150 raeburn 17356: sub modify_loadbalancing {
17357: my ($dom,%domconfig) = @_;
17358: my $primary_id = &Apache::lonnet::domain($dom,'primary');
17359: my $intdom = &Apache::lonnet::internet_dom($primary_id);
17360: my ($othertitle,$usertypes,$types) =
17361: &Apache::loncommon::sorted_inst_types($dom);
17362: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 17363: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 17364: my @sparestypes = ('primary','default');
17365: my %typetitles = &sparestype_titles();
17366: my $resulttext;
1.342 raeburn 17367: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 17368: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
17369: %existing = %{$domconfig{'loadbalancing'}};
17370: }
17371: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 17372: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 17373: my ($saveloadbalancing,%defaultshash,%changes);
17374: my ($alltypes,$othertypes,$titles) =
17375: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
17376: my %ruletitles = &offloadtype_text();
17377: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
17378: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
17379: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
17380: if ($balancer eq '') {
17381: next;
17382: }
1.210 raeburn 17383: if (!exists($servers{$balancer})) {
1.171 raeburn 17384: if (exists($currbalancer{$balancer})) {
17385: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 17386: }
1.171 raeburn 17387: next;
17388: }
17389: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
17390: push(@{$changes{'delete'}},$balancer);
17391: next;
17392: }
17393: if (!exists($currbalancer{$balancer})) {
17394: push(@{$changes{'add'}},$balancer);
17395: }
17396: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
17397: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
17398: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
17399: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
17400: $saveloadbalancing = 1;
17401: }
17402: foreach my $sparetype (@sparestypes) {
17403: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
17404: my @offloadto;
17405: foreach my $target (@targets) {
17406: if (($servers{$target}) && ($target ne $balancer)) {
17407: if ($sparetype eq 'default') {
17408: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
17409: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 17410: }
17411: }
1.171 raeburn 17412: unless(grep(/^\Q$target\E$/,@offloadto)) {
17413: push(@offloadto,$target);
17414: }
1.150 raeburn 17415: }
17416: }
1.284 raeburn 17417: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
17418: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
17419: push(@offloadto,$balancer);
17420: }
17421: }
17422: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 17423: }
1.342 raeburn 17424: if ($env{'form.loadbalancing_cookie_'.$i}) {
17425: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
17426: if (exists($currbalancer{$balancer})) {
17427: unless ($currcookies{$balancer}) {
17428: $changes{'curr'}{$balancer}{'cookie'} = 1;
17429: }
17430: }
17431: } elsif (exists($currbalancer{$balancer})) {
17432: if ($currcookies{$balancer}) {
17433: $changes{'curr'}{$balancer}{'cookie'} = 1;
17434: }
17435: }
1.171 raeburn 17436: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 17437: foreach my $sparetype (@sparestypes) {
1.171 raeburn 17438: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
17439: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 17440: if (@targetdiffs > 0) {
1.171 raeburn 17441: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 17442: }
1.171 raeburn 17443: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17444: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17445: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 17446: }
17447: }
17448: }
17449: } else {
1.171 raeburn 17450: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 17451: foreach my $sparetype (@sparestypes) {
1.171 raeburn 17452: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17453: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17454: $changes{'curr'}{$balancer}{'targets'} = 1;
17455: }
1.150 raeburn 17456: }
17457: }
1.210 raeburn 17458: }
1.150 raeburn 17459: }
17460: my $ishomedom;
1.171 raeburn 17461: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
17462: $ishomedom = 1;
1.150 raeburn 17463: }
17464: if (ref($alltypes) eq 'ARRAY') {
17465: foreach my $type (@{$alltypes}) {
17466: my $rule;
1.210 raeburn 17467: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 17468: (!$ishomedom)) {
1.171 raeburn 17469: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
17470: }
17471: if ($rule eq 'specific') {
1.255 raeburn 17472: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 17473: if (exists($servers{$specifiedhost})) {
1.255 raeburn 17474: $rule = $specifiedhost;
17475: }
1.150 raeburn 17476: }
1.171 raeburn 17477: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
17478: if (ref($currrules{$balancer}) eq 'HASH') {
17479: if ($rule ne $currrules{$balancer}{$type}) {
17480: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 17481: }
17482: } elsif ($rule ne '') {
1.171 raeburn 17483: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 17484: }
17485: }
17486: }
1.171 raeburn 17487: }
17488: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
17489: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
17490: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
17491: $defaultshash{'loadbalancing'} = {};
17492: }
17493: my $putresult = &Apache::lonnet::put_dom('configuration',
17494: \%defaultshash,$dom);
17495: if ($putresult eq 'ok') {
17496: if (keys(%changes) > 0) {
1.252 raeburn 17497: my %toupdate;
1.171 raeburn 17498: if (ref($changes{'delete'}) eq 'ARRAY') {
17499: foreach my $balancer (sort(@{$changes{'delete'}})) {
17500: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 17501: $toupdate{$balancer} = 1;
1.150 raeburn 17502: }
1.171 raeburn 17503: }
17504: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 17505: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 17506: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 17507: $toupdate{$balancer} = 1;
1.171 raeburn 17508: }
17509: }
17510: if (ref($changes{'curr'}) eq 'HASH') {
17511: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 17512: $toupdate{$balancer} = 1;
1.171 raeburn 17513: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
17514: if ($changes{'curr'}{$balancer}{'targets'}) {
17515: my %offloadstr;
17516: foreach my $sparetype (@sparestypes) {
17517: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17518: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17519: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17520: }
17521: }
1.150 raeburn 17522: }
1.171 raeburn 17523: if (keys(%offloadstr) == 0) {
17524: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 17525: } else {
1.171 raeburn 17526: my $showoffload;
17527: foreach my $sparetype (@sparestypes) {
17528: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
17529: if (defined($offloadstr{$sparetype})) {
17530: $showoffload .= $offloadstr{$sparetype};
17531: } else {
17532: $showoffload .= &mt('None');
17533: }
17534: $showoffload .= (' 'x3);
17535: }
17536: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 17537: }
17538: }
17539: }
1.171 raeburn 17540: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
17541: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
17542: foreach my $type (@{$alltypes}) {
17543: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
17544: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17545: my $balancetext;
17546: if ($rule eq '') {
17547: $balancetext = $ruletitles{'default'};
1.209 raeburn 17548: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 17549: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 17550: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 17551: foreach my $sparetype (@sparestypes) {
17552: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17553: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17554: }
17555: }
1.253 raeburn 17556: foreach my $item (@{$alltypes}) {
17557: next if ($item =~ /^_LC_ipchange/);
17558: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
17559: if ($hasrule eq 'homeserver') {
17560: map { $toupdate{$_} = 1; } (keys(%libraryservers));
17561: } else {
17562: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
17563: if ($servers{$hasrule}) {
17564: $toupdate{$hasrule} = 1;
17565: }
17566: }
17567: }
17568: }
1.254 raeburn 17569: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
17570: $balancetext = $ruletitles{$rule};
17571: } else {
17572: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17573: $balancetext = $ruletitles{'particular'}.' '.$receiver;
17574: if ($receiver) {
17575: $toupdate{$receiver};
17576: }
17577: }
17578: } else {
17579: $balancetext = $ruletitles{$rule};
1.252 raeburn 17580: }
1.171 raeburn 17581: } else {
17582: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
17583: }
1.210 raeburn 17584: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 17585: }
17586: }
17587: }
17588: }
1.342 raeburn 17589: if ($changes{'curr'}{$balancer}{'cookie'}) {
17590: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
17591: $balancer).'</li>';
17592: }
1.252 raeburn 17593: if (keys(%toupdate)) {
17594: my %thismachine;
17595: my $updatedhere;
17596: my $cachetime = 60*60*24;
17597: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
17598: foreach my $lonhost (keys(%toupdate)) {
17599: if ($thismachine{$lonhost}) {
17600: unless ($updatedhere) {
17601: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
17602: $defaultshash{'loadbalancing'},
17603: $cachetime);
17604: $updatedhere = 1;
17605: }
17606: } else {
17607: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
17608: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
17609: }
17610: }
17611: }
1.150 raeburn 17612: }
1.171 raeburn 17613: }
17614: if ($resulttext ne '') {
17615: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 17616: } else {
17617: $resulttext = $nochgmsg;
17618: }
17619: } else {
1.171 raeburn 17620: $resulttext = $nochgmsg;
1.150 raeburn 17621: }
17622: } else {
1.171 raeburn 17623: $resulttext = '<span class="LC_error">'.
17624: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 17625: }
17626: } else {
1.171 raeburn 17627: $resulttext = $nochgmsg;
1.150 raeburn 17628: }
17629: return $resulttext;
17630: }
17631:
1.48 raeburn 17632: sub recurse_check {
17633: my ($chkcats,$categories,$depth,$name) = @_;
17634: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
17635: my $chg = 0;
17636: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
17637: my $category = $chkcats->[$depth]{$name}[$j];
17638: my $item;
17639: if ($category eq '') {
17640: $chg ++;
17641: } else {
17642: my $deeper = $depth + 1;
17643: $item = &escape($category).':'.&escape($name).':'.$depth;
17644: if ($chg) {
17645: $categories->{$item} -= $chg;
17646: }
17647: &recurse_check($chkcats,$categories,$deeper,$category);
17648: $deeper --;
17649: }
17650: }
17651: }
17652: return;
17653: }
17654:
17655: sub recurse_cat_deletes {
17656: my ($item,$coursecategories,$deletions) = @_;
17657: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
17658: my $subdepth = $depth + 1;
17659: if (ref($coursecategories) eq 'HASH') {
17660: foreach my $subitem (keys(%{$coursecategories})) {
17661: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
17662: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
17663: delete($coursecategories->{$subitem});
17664: $deletions->{$subitem} = 1;
17665: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 17666: }
1.48 raeburn 17667: }
17668: }
17669: return;
17670: }
17671:
1.125 raeburn 17672: sub active_dc_picker {
1.191 raeburn 17673: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 17674: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 17675: my @domcoord = keys(%domcoords);
17676: if (keys(%currhash)) {
17677: foreach my $dc (keys(%currhash)) {
17678: unless (exists($domcoords{$dc})) {
17679: push(@domcoord,$dc);
17680: }
17681: }
17682: }
17683: @domcoord = sort(@domcoord);
1.210 raeburn 17684: my $numdcs = scalar(@domcoord);
1.191 raeburn 17685: my $rows = 0;
17686: my $table;
1.125 raeburn 17687: if ($numdcs > 1) {
1.191 raeburn 17688: $table = '<table>';
17689: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 17690: my $rem = $i%($numinrow);
17691: if ($rem == 0) {
17692: if ($i > 0) {
1.191 raeburn 17693: $table .= '</tr>';
1.125 raeburn 17694: }
1.191 raeburn 17695: $table .= '<tr>';
17696: $rows ++;
1.125 raeburn 17697: }
1.191 raeburn 17698: my $check = '';
17699: if ($inputtype eq 'radio') {
17700: if (keys(%currhash) == 0) {
17701: if (!$i) {
17702: $check = ' checked="checked"';
17703: }
17704: } elsif (exists($currhash{$domcoord[$i]})) {
17705: $check = ' checked="checked"';
17706: }
17707: } else {
17708: if (exists($currhash{$domcoord[$i]})) {
17709: $check = ' checked="checked"';
1.125 raeburn 17710: }
17711: }
1.191 raeburn 17712: if ($i == @domcoord - 1) {
1.125 raeburn 17713: my $colsleft = $numinrow - $rem;
17714: if ($colsleft > 1) {
1.191 raeburn 17715: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 17716: } else {
1.191 raeburn 17717: $table .= '<td class="LC_left_item">';
1.125 raeburn 17718: }
17719: } else {
1.191 raeburn 17720: $table .= '<td class="LC_left_item">';
17721: }
17722: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
17723: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
17724: $table .= '<span class="LC_nobreak"><label>'.
17725: '<input type="'.$inputtype.'" name="'.$name.'"'.
17726: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
17727: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 17728: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 17729: }
1.219 raeburn 17730: $table .= '</label></span></td>';
1.191 raeburn 17731: }
17732: $table .= '</tr></table>';
17733: } elsif ($numdcs == 1) {
1.219 raeburn 17734: my ($dcname,$dcdom) = split(':',$domcoord[0]);
17735: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 17736: if ($inputtype eq 'radio') {
1.247 raeburn 17737: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 17738: if ($user ne $dcname.':'.$dcdom) {
17739: $table .= ' ('.$dcname.':'.$dcdom.')';
17740: }
1.191 raeburn 17741: } else {
17742: my $check;
17743: if (exists($currhash{$domcoord[0]})) {
17744: $check = ' checked="checked"';
1.125 raeburn 17745: }
1.247 raeburn 17746: $table = '<span class="LC_nobreak"><label>'.
17747: '<input type="checkbox" name="'.$name.'" '.
17748: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 17749: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 17750: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 17751: }
1.220 raeburn 17752: $table .= '</label></span>';
1.191 raeburn 17753: $rows ++;
1.125 raeburn 17754: }
17755: }
1.191 raeburn 17756: return ($numdcs,$table,$rows);
1.125 raeburn 17757: }
17758:
1.137 raeburn 17759: sub usersession_titles {
17760: return &Apache::lonlocal::texthash(
17761: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
17762: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 17763: spares => 'Servers offloaded to, when busy',
1.137 raeburn 17764: version => 'LON-CAPA version requirement',
1.138 raeburn 17765: excludedomain => 'Allow all, but exclude specific domains',
17766: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 17767: primary => 'Primary (checked first)',
1.154 raeburn 17768: default => 'Default',
1.137 raeburn 17769: );
17770: }
17771:
1.152 raeburn 17772: sub id_for_thisdom {
17773: my (%servers) = @_;
17774: my %altids;
17775: foreach my $server (keys(%servers)) {
17776: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17777: if ($serverhome ne $server) {
17778: $altids{$serverhome} = $server;
17779: }
17780: }
17781: return %altids;
17782: }
17783:
1.150 raeburn 17784: sub count_servers {
17785: my ($currbalancer,%servers) = @_;
17786: my (@spares,$numspares);
17787: foreach my $lonhost (sort(keys(%servers))) {
17788: next if ($currbalancer eq $lonhost);
17789: push(@spares,$lonhost);
17790: }
17791: if ($currbalancer) {
17792: $numspares = scalar(@spares);
17793: } else {
17794: $numspares = scalar(@spares) - 1;
17795: }
17796: return ($numspares,@spares);
17797: }
17798:
17799: sub lonbalance_targets_js {
1.171 raeburn 17800: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 17801: my $select = &mt('Select');
17802: my ($alltargets,$allishome,$allinsttypes,@alltypes);
17803: if (ref($servers) eq 'HASH') {
17804: $alltargets = join("','",sort(keys(%{$servers})));
17805: my @homedoms;
17806: foreach my $server (sort(keys(%{$servers}))) {
17807: if (&Apache::lonnet::host_domain($server) eq $dom) {
17808: push(@homedoms,'1');
17809: } else {
17810: push(@homedoms,'0');
17811: }
17812: }
17813: $allishome = join("','",@homedoms);
17814: }
17815: if (ref($types) eq 'ARRAY') {
17816: if (@{$types} > 0) {
17817: @alltypes = @{$types};
17818: }
17819: }
17820: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
17821: $allinsttypes = join("','",@alltypes);
1.342 raeburn 17822: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 17823: if (ref($settings) eq 'HASH') {
17824: %existing = %{$settings};
17825: }
17826: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 17827: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 17828: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 17829: return <<"END";
17830:
17831: <script type="text/javascript">
17832: // <![CDATA[
17833:
1.171 raeburn 17834: currBalancers = new Array('$balancers');
17835:
17836: function toggleTargets(balnum) {
17837: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17838: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
17839: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
17840: var prevbalancer = prevhostitem.value;
17841: var baltotal = document.getElementById('loadbalancing_total').value;
17842: prevhostitem.value = balancer;
17843: if (prevbalancer != '') {
17844: var prevIdx = currBalancers.indexOf(prevbalancer);
17845: if (prevIdx != -1) {
17846: currBalancers.splice(prevIdx,1);
17847: }
17848: }
1.150 raeburn 17849: if (balancer == '') {
1.171 raeburn 17850: hideSpares(balnum);
1.150 raeburn 17851: } else {
1.171 raeburn 17852: var currIdx = currBalancers.indexOf(balancer);
17853: if (currIdx == -1) {
17854: currBalancers.push(balancer);
17855: }
1.150 raeburn 17856: var homedoms = new Array('$allishome');
1.171 raeburn 17857: var ishomedom = homedoms[lonhostitem.selectedIndex];
17858: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 17859: }
1.171 raeburn 17860: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 17861: return;
17862: }
17863:
1.171 raeburn 17864: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 17865: var alltargets = new Array('$alltargets');
17866: var insttypes = new Array('$allinsttypes');
1.151 raeburn 17867: var offloadtypes = new Array('primary','default');
17868:
1.171 raeburn 17869: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17870: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 17871:
1.151 raeburn 17872: for (var i=0; i<offloadtypes.length; i++) {
17873: var count = 0;
17874: for (var j=0; j<alltargets.length; j++) {
17875: if (alltargets[j] != balancer) {
1.171 raeburn 17876: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17877: item.value = alltargets[j];
17878: item.style.textAlign='left';
17879: item.style.textFace='normal';
17880: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17881: if (currBalancers.indexOf(alltargets[j]) == -1) {
17882: item.disabled = '';
17883: } else {
17884: item.disabled = 'disabled';
17885: item.checked = false;
17886: }
1.151 raeburn 17887: count ++;
17888: }
1.150 raeburn 17889: }
17890: }
1.151 raeburn 17891: for (var k=0; k<insttypes.length; k++) {
17892: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 17893: if (ishomedom == 1) {
1.171 raeburn 17894: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17895: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17896: } else {
1.171 raeburn 17897: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17898: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 17899: }
17900: } else {
1.171 raeburn 17901: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17902: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17903: }
1.151 raeburn 17904: if ((insttypes[k] != '_LC_external') &&
17905: ((insttypes[k] != '_LC_internetdom') ||
17906: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 17907: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17908: item.options.length = 0;
17909: item.options[0] = new Option("","",true,true);
1.210 raeburn 17910: var idx = 0;
1.151 raeburn 17911: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 17912: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17913: idx ++;
17914: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 17915: }
17916: }
17917: }
17918: }
17919: return;
17920: }
17921:
1.171 raeburn 17922: function hideSpares(balnum) {
1.150 raeburn 17923: var alltargets = new Array('$alltargets');
17924: var insttypes = new Array('$allinsttypes');
17925: var offloadtypes = new Array('primary','default');
17926:
1.171 raeburn 17927: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17928: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 17929:
17930: var total = alltargets.length - 1;
17931: for (var i=0; i<offloadtypes; i++) {
17932: for (var j=0; j<total; j++) {
1.171 raeburn 17933: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17934: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17935: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 17936: }
1.150 raeburn 17937: }
17938: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 17939: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17940: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 17941: if (insttypes[k] != '_LC_external') {
1.171 raeburn 17942: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17943: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 17944: }
17945: }
17946: return;
17947: }
17948:
1.171 raeburn 17949: function checkOffloads(item,balnum,type) {
1.150 raeburn 17950: var alltargets = new Array('$alltargets');
17951: var offloadtypes = new Array('primary','default');
17952: if (item.checked) {
17953: var total = alltargets.length - 1;
17954: var other;
17955: if (type == offloadtypes[0]) {
1.151 raeburn 17956: other = offloadtypes[1];
1.150 raeburn 17957: } else {
1.151 raeburn 17958: other = offloadtypes[0];
1.150 raeburn 17959: }
17960: for (var i=0; i<total; i++) {
1.171 raeburn 17961: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 17962: if (server == item.value) {
1.171 raeburn 17963: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17964: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 17965: }
17966: }
17967: }
17968: }
17969: return;
17970: }
17971:
1.171 raeburn 17972: function singleServerToggle(balnum,type) {
17973: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 17974: if (offloadtoSelIdx == 0) {
1.171 raeburn 17975: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17976: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17977:
17978: } else {
1.171 raeburn 17979: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17980: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 17981: }
17982: return;
17983: }
17984:
1.171 raeburn 17985: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 17986: if (type == '_LC_external') {
1.171 raeburn 17987: return;
1.150 raeburn 17988: }
1.171 raeburn 17989: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 17990: for (var i=0; i<typesRules.length; i++) {
17991: if (formname.elements[typesRules[i]].checked) {
17992: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 17993: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17994: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17995: } else {
1.171 raeburn 17996: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17997: }
17998: }
17999: }
18000: return;
18001: }
18002:
18003: function balancerDeleteChange(balnum) {
18004: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
18005: var baltotal = document.getElementById('loadbalancing_total').value;
18006: var addtarget;
18007: var removetarget;
18008: var action = 'delete';
18009: if (document.getElementById('loadbalancing_delete_'+balnum)) {
18010: var lonhost = hostitem.value;
18011: var currIdx = currBalancers.indexOf(lonhost);
18012: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
18013: if (currIdx != -1) {
18014: currBalancers.splice(currIdx,1);
18015: }
18016: addtarget = lonhost;
18017: } else {
18018: if (currIdx == -1) {
18019: currBalancers.push(lonhost);
18020: }
18021: removetarget = lonhost;
18022: action = 'undelete';
18023: }
18024: balancerChange(balnum,baltotal,action,addtarget,removetarget);
18025: }
18026: return;
18027: }
18028:
18029: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
18030: if (baltotal > 1) {
18031: var offloadtypes = new Array('primary','default');
18032: var alltargets = new Array('$alltargets');
18033: var insttypes = new Array('$allinsttypes');
18034: for (var i=0; i<baltotal; i++) {
18035: if (i != balnum) {
18036: for (var j=0; j<offloadtypes.length; j++) {
18037: var total = alltargets.length - 1;
18038: for (var k=0; k<total; k++) {
18039: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
18040: var server = serveritem.value;
18041: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
18042: if (server == addtarget) {
18043: serveritem.disabled = '';
18044: }
18045: }
18046: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
18047: if (server == removetarget) {
18048: serveritem.disabled = 'disabled';
18049: serveritem.checked = false;
18050: }
18051: }
18052: }
18053: }
18054: for (var j=0; j<insttypes.length; j++) {
18055: if (insttypes[j] != '_LC_external') {
18056: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
18057: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
18058: var currSel = singleserver.selectedIndex;
18059: var currVal = singleserver.options[currSel].value;
18060: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
18061: var numoptions = singleserver.options.length;
18062: var needsnew = 1;
18063: for (var k=0; k<numoptions; k++) {
18064: if (singleserver.options[k] == addtarget) {
18065: needsnew = 0;
18066: break;
18067: }
18068: }
18069: if (needsnew == 1) {
18070: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
18071: }
18072: }
18073: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
18074: singleserver.options.length = 0;
18075: if ((currVal) && (currVal != removetarget)) {
18076: singleserver.options[0] = new Option("","",false,false);
18077: } else {
18078: singleserver.options[0] = new Option("","",true,true);
18079: }
18080: var idx = 0;
18081: for (var m=0; m<alltargets.length; m++) {
18082: if (currBalancers.indexOf(alltargets[m]) == -1) {
18083: idx ++;
18084: if (currVal == alltargets[m]) {
18085: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
18086: } else {
18087: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
18088: }
18089: }
18090: }
18091: }
18092: }
18093: }
18094: }
1.150 raeburn 18095: }
18096: }
18097: }
18098: return;
18099: }
18100:
1.152 raeburn 18101: // ]]>
18102: </script>
18103:
18104: END
18105: }
18106:
18107: sub new_spares_js {
18108: my @sparestypes = ('primary','default');
18109: my $types = join("','",@sparestypes);
18110: my $select = &mt('Select');
18111: return <<"END";
18112:
18113: <script type="text/javascript">
18114: // <![CDATA[
18115:
18116: function updateNewSpares(formname,lonhost) {
18117: var types = new Array('$types');
18118: var include = new Array();
18119: var exclude = new Array();
18120: for (var i=0; i<types.length; i++) {
18121: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
18122: for (var j=0; j<spareboxes.length; j++) {
18123: if (formname.elements[spareboxes[j]].checked) {
18124: exclude.push(formname.elements[spareboxes[j]].value);
18125: } else {
18126: include.push(formname.elements[spareboxes[j]].value);
18127: }
18128: }
18129: }
18130: for (var i=0; i<types.length; i++) {
18131: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
18132: var selIdx = newSpare.selectedIndex;
18133: var currnew = newSpare.options[selIdx].value;
18134: var okSpares = new Array();
18135: for (var j=0; j<newSpare.options.length; j++) {
18136: var possible = newSpare.options[j].value;
18137: if (possible != '') {
18138: if (exclude.indexOf(possible) == -1) {
18139: okSpares.push(possible);
18140: } else {
18141: if (currnew == possible) {
18142: selIdx = 0;
18143: }
18144: }
18145: }
18146: }
18147: for (var k=0; k<include.length; k++) {
18148: if (okSpares.indexOf(include[k]) == -1) {
18149: okSpares.push(include[k]);
18150: }
18151: }
18152: okSpares.sort();
18153: newSpare.options.length = 0;
18154: if (selIdx == 0) {
18155: newSpare.options[0] = new Option("$select","",true,true);
18156: } else {
18157: newSpare.options[0] = new Option("$select","",false,false);
18158: }
18159: for (var m=0; m<okSpares.length; m++) {
18160: var idx = m+1;
18161: var selThis = 0;
18162: if (selIdx != 0) {
18163: if (okSpares[m] == currnew) {
18164: selThis = 1;
18165: }
18166: }
18167: if (selThis == 1) {
18168: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
18169: } else {
18170: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
18171: }
18172: }
18173: }
18174: return;
18175: }
18176:
18177: function checkNewSpares(lonhost,type) {
18178: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
18179: var chosen = newSpare.options[newSpare.selectedIndex].value;
18180: if (chosen != '') {
18181: var othertype;
18182: var othernewSpare;
18183: if (type == 'primary') {
18184: othernewSpare = document.getElementById('newspare_default_'+lonhost);
18185: }
18186: if (type == 'default') {
18187: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
18188: }
18189: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
18190: othernewSpare.selectedIndex = 0;
18191: }
18192: }
18193: return;
18194: }
18195:
18196: // ]]>
18197: </script>
18198:
18199: END
18200:
18201: }
18202:
18203: sub common_domprefs_js {
18204: return <<"END";
18205:
18206: <script type="text/javascript">
18207: // <![CDATA[
18208:
1.150 raeburn 18209: function getIndicesByName(formname,item) {
1.152 raeburn 18210: var group = new Array();
1.150 raeburn 18211: for (var i=0;i<formname.elements.length;i++) {
18212: if (formname.elements[i].name == item) {
1.152 raeburn 18213: group.push(formname.elements[i].id);
1.150 raeburn 18214: }
18215: }
1.152 raeburn 18216: return group;
1.150 raeburn 18217: }
18218:
18219: // ]]>
18220: </script>
18221:
18222: END
1.152 raeburn 18223:
1.150 raeburn 18224: }
18225:
1.165 raeburn 18226: sub recaptcha_js {
18227: my %lt = &captcha_phrases();
18228: return <<"END";
18229:
18230: <script type="text/javascript">
18231: // <![CDATA[
18232:
18233: function updateCaptcha(caller,context) {
18234: var privitem;
18235: var pubitem;
18236: var privtext;
18237: var pubtext;
1.269 raeburn 18238: var versionitem;
18239: var versiontext;
1.165 raeburn 18240: if (document.getElementById(context+'_recaptchapub')) {
18241: pubitem = document.getElementById(context+'_recaptchapub');
18242: } else {
18243: return;
18244: }
18245: if (document.getElementById(context+'_recaptchapriv')) {
18246: privitem = document.getElementById(context+'_recaptchapriv');
18247: } else {
18248: return;
18249: }
18250: if (document.getElementById(context+'_recaptchapubtxt')) {
18251: pubtext = document.getElementById(context+'_recaptchapubtxt');
18252: } else {
18253: return;
18254: }
18255: if (document.getElementById(context+'_recaptchaprivtxt')) {
18256: privtext = document.getElementById(context+'_recaptchaprivtxt');
18257: } else {
18258: return;
18259: }
1.269 raeburn 18260: if (document.getElementById(context+'_recaptchaversion')) {
18261: versionitem = document.getElementById(context+'_recaptchaversion');
18262: } else {
18263: return;
18264: }
18265: if (document.getElementById(context+'_recaptchavertxt')) {
18266: versiontext = document.getElementById(context+'_recaptchavertxt');
18267: } else {
18268: return;
18269: }
1.165 raeburn 18270: if (caller.checked) {
18271: if (caller.value == 'recaptcha') {
18272: pubitem.type = 'text';
18273: privitem.type = 'text';
18274: pubitem.size = '40';
18275: privitem.size = '40';
18276: pubtext.innerHTML = "$lt{'pub'}";
18277: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 18278: versionitem.type = 'text';
18279: versionitem.size = '3';
1.289 raeburn 18280: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 18281: } else {
18282: pubitem.type = 'hidden';
18283: privitem.type = 'hidden';
1.269 raeburn 18284: versionitem.type = 'hidden';
1.165 raeburn 18285: pubtext.innerHTML = '';
18286: privtext.innerHTML = '';
1.269 raeburn 18287: versiontext.innerHTML = '';
1.165 raeburn 18288: }
18289: }
18290: return;
18291: }
18292:
18293: // ]]>
18294: </script>
18295:
18296: END
18297:
18298: }
18299:
1.236 raeburn 18300: sub toggle_display_js {
1.192 raeburn 18301: return <<"END";
18302:
18303: <script type="text/javascript">
18304: // <![CDATA[
18305:
1.236 raeburn 18306: function toggleDisplay(domForm,caller) {
18307: if (document.getElementById(caller)) {
18308: var divitem = document.getElementById(caller);
18309: var optionsElement = domForm.coursecredits;
1.264 raeburn 18310: var checkval = 1;
18311: var dispval = 'block';
1.303 raeburn 18312: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 18313: if (caller == 'emailoptions') {
18314: optionsElement = domForm.cancreate_email;
18315: }
1.257 raeburn 18316: if (caller == 'studentsubmission') {
18317: optionsElement = domForm.postsubmit;
18318: }
1.264 raeburn 18319: if (caller == 'cloneinstcode') {
18320: optionsElement = domForm.canclone;
18321: checkval = 'instcode';
18322: }
1.303 raeburn 18323: if (selfcreateRegExp.test(caller)) {
18324: optionsElement = domForm.elements[caller];
18325: checkval = 'other';
18326: dispval = 'inline'
18327: }
1.236 raeburn 18328: if (optionsElement.length) {
1.192 raeburn 18329: var currval;
1.236 raeburn 18330: for (var i=0; i<optionsElement.length; i++) {
18331: if (optionsElement[i].checked) {
18332: currval = optionsElement[i].value;
1.192 raeburn 18333: }
18334: }
1.264 raeburn 18335: if (currval == checkval) {
18336: divitem.style.display = dispval;
1.192 raeburn 18337: } else {
1.236 raeburn 18338: divitem.style.display = 'none';
1.192 raeburn 18339: }
18340: }
18341: }
18342: return;
18343: }
18344:
18345: // ]]>
18346: </script>
18347:
18348: END
18349:
18350: }
18351:
1.165 raeburn 18352: sub captcha_phrases {
18353: return &Apache::lonlocal::texthash (
18354: priv => 'Private key',
18355: pub => 'Public key',
18356: original => 'original (CAPTCHA)',
18357: recaptcha => 'successor (ReCAPTCHA)',
18358: notused => 'unused',
1.289 raeburn 18359: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 18360: );
18361: }
18362:
1.205 raeburn 18363: sub devalidate_remote_domconfs {
1.212 raeburn 18364: my ($dom,$cachekeys) = @_;
18365: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 18366: my %servers = &Apache::lonnet::internet_dom_servers($dom);
18367: my %thismachine;
18368: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 18369: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 18370: if (keys(%servers)) {
1.205 raeburn 18371: foreach my $server (keys(%servers)) {
18372: next if ($thismachine{$server});
1.212 raeburn 18373: my @cached;
18374: foreach my $name (@posscached) {
18375: if ($cachekeys->{$name}) {
18376: push(@cached,&escape($name).':'.&escape($dom));
18377: }
18378: }
18379: if (@cached) {
18380: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
18381: }
1.205 raeburn 18382: }
18383: }
18384: return;
18385: }
18386:
1.3 raeburn 18387: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>