Annotation of loncom/interface/domainprefs.pm, revision 1.349
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.349 ! raeburn 4: # $Id: domainprefs.pm,v 1.348 2019/01/31 17:44:07 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 = (
5275: anonsurvey_threshold => 10,
5276: uploadquota => 500,
1.257 raeburn 5277: postsubmit => 60,
1.276 raeburn 5278: mysqltables => 172800,
1.198 raeburn 5279: );
1.139 raeburn 5280: if ($position eq 'top') {
1.257 raeburn 5281: %defaultchecked = (
5282: 'canuse_pdfforms' => 'off',
5283: 'uselcmath' => 'on',
5284: 'usejsme' => 'on',
1.289 raeburn 5285: 'canclone' => 'none',
1.257 raeburn 5286: );
5287: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349 ! raeburn 5288: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 5289: if (ref($settings) eq 'HASH') {
5290: if ($settings->{'texengine'}) {
5291: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5292: $deftex = $settings->{'texengine'};
5293: }
5294: }
5295: }
5296: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5297: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5298: '<span class="LC_nobreak">'.$choices{'texengine'}.
5299: '</span></td><td class="LC_right_item">'.
5300: '<select name="texengine">'."\n";
5301: my %texoptions = (
5302: MathJax => 'MathJax',
5303: mimetex => &mt('Convert to Images'),
5304: tth => &mt('TeX to HTML'),
5305: );
5306: foreach my $renderer ('MathJax','mimetex','tth') {
5307: my $selected = '';
5308: if ($renderer eq $deftex) {
5309: $selected = ' selected="selected"';
5310: }
5311: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5312: }
5313: $mathdisp .= '</select></td></tr>'."\n";
5314: $itemcount ++;
1.139 raeburn 5315: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 5316: \%choices,$itemcount);
1.314 raeburn 5317: $datatable = $mathdisp.$datatable;
1.264 raeburn 5318: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5319: $datatable .=
1.306 raeburn 5320: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 5321: '<span class="LC_nobreak">'.$choices{'canclone'}.
5322: '</span></td><td class="LC_left_item">';
5323: my $currcanclone = 'none';
5324: my $onclick;
5325: my @cloneoptions = ('none','domain');
5326: my %clonetitles = (
5327: none => 'No additional course requesters',
5328: domain => "Any course requester in course's domain",
5329: instcode => 'Course requests for official courses ...',
5330: );
5331: my (%codedefaults,@code_order,@posscodes);
5332: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5333: \@code_order) eq 'ok') {
5334: if (@code_order > 0) {
5335: push(@cloneoptions,'instcode');
5336: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5337: }
5338: }
5339: if (ref($settings) eq 'HASH') {
5340: if ($settings->{'canclone'}) {
5341: if (ref($settings->{'canclone'}) eq 'HASH') {
5342: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5343: if (@code_order > 0) {
5344: $currcanclone = 'instcode';
5345: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5346: }
5347: }
5348: } elsif ($settings->{'canclone'} eq 'domain') {
5349: $currcanclone = $settings->{'canclone'};
5350: }
5351: }
1.289 raeburn 5352: }
1.264 raeburn 5353: foreach my $option (@cloneoptions) {
5354: my ($checked,$additional);
5355: if ($currcanclone eq $option) {
5356: $checked = ' checked="checked"';
5357: }
5358: if ($option eq 'instcode') {
5359: if (@code_order) {
5360: my $show = 'none';
5361: if ($checked) {
5362: $show = 'block';
5363: }
1.317 raeburn 5364: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 5365: &mt('Institutional codes for new and cloned course have identical:').
5366: '<br />';
5367: foreach my $item (@code_order) {
5368: my $codechk;
5369: if ($checked) {
5370: if (grep(/^\Q$item\E$/,@posscodes)) {
5371: $codechk = ' checked="checked"';
5372: }
5373: }
5374: $additional .= '<label>'.
5375: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5376: $item.'</label>';
5377: }
5378: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5379: }
5380: }
5381: $datatable .=
5382: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5383: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5384: '</label> '.$additional.'</span><br />';
5385: }
5386: $datatable .= '</td>'.
5387: '</tr>';
5388: $itemcount ++;
1.139 raeburn 5389: } else {
5390: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 5391: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 5392: my $currusecredits = 0;
1.257 raeburn 5393: my $postsubmitclient = 1;
1.271 raeburn 5394: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 5395: if (ref($settings) eq 'HASH') {
5396: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 5397: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5398: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5399: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5400: }
5401: }
1.192 raeburn 5402: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 5403: foreach my $type (@types) {
5404: next if ($type eq 'community');
5405: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5406: if ($defcredits{$type} ne '') {
5407: $currusecredits = 1;
5408: }
5409: }
5410: }
5411: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5412: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5413: $postsubmitclient = 0;
5414: foreach my $type (@types) {
5415: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5416: }
5417: } else {
5418: foreach my $type (@types) {
5419: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5420: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 5421: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 5422: } else {
5423: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5424: }
5425: } else {
5426: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5427: }
5428: }
5429: }
5430: } else {
5431: foreach my $type (@types) {
5432: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 5433: }
5434: }
1.276 raeburn 5435: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5436: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5437: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5438: }
5439: } else {
5440: foreach my $type (@types) {
5441: $currmysql{$type} = $staticdefaults{'mysqltables'};
5442: }
5443: }
1.258 raeburn 5444: } else {
5445: foreach my $type (@types) {
5446: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5447: }
1.139 raeburn 5448: }
5449: if (!$currdefresponder) {
1.198 raeburn 5450: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5451: } elsif ($currdefresponder < 1) {
5452: $currdefresponder = 1;
5453: }
1.198 raeburn 5454: foreach my $type (@types) {
5455: if ($curruploadquota{$type} eq '') {
5456: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5457: }
5458: }
1.139 raeburn 5459: $datatable .=
1.192 raeburn 5460: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5461: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5462: '</span></td>'.
5463: '<td class="LC_right_item"><span class="LC_nobreak">'.
5464: '<input type="text" name="anonsurvey_threshold"'.
5465: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5466: '</td></tr>'."\n";
5467: $itemcount ++;
5468: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5469: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5470: $choices{'uploadquota'}.
5471: '</span></td>'.
1.306 raeburn 5472: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5473: '<table><tr>';
1.198 raeburn 5474: foreach my $type (@types) {
1.306 raeburn 5475: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5476: '<input type="text" name="uploadquota_'.$type.'"'.
5477: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5478: }
5479: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5480: $itemcount ++;
1.236 raeburn 5481: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5482: my $display = 'none';
1.192 raeburn 5483: if ($currusecredits) {
5484: $display = 'block';
5485: }
5486: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5487: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5488: foreach my $type (@types) {
5489: next if ($type eq 'community');
1.306 raeburn 5490: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5491: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5492: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5493: }
5494: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5495: %defaultchecked = ('coursecredits' => 'off');
5496: @toggles = ('coursecredits');
5497: my $current = {
5498: 'coursecredits' => $currusecredits,
5499: };
5500: (my $table,$itemcount) =
5501: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5502: \%choices,$itemcount,$onclick,$additional,'left');
5503: $datatable .= $table;
5504: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5505: my $display = 'none';
5506: if ($postsubmitclient) {
5507: $display = 'block';
5508: }
5509: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5510: &mt('Number of seconds submit is disabled').'<br />'.
5511: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5512: '<table><tr>';
1.257 raeburn 5513: foreach my $type (@types) {
1.306 raeburn 5514: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5515: '<input type="text" name="'.$type.'_timeout" value="'.
5516: $deftimeout{$type}.'" size="5" /></td>';
5517: }
5518: $additional .= '</tr></table></div>'."\n";
5519: %defaultchecked = ('postsubmit' => 'on');
5520: @toggles = ('postsubmit');
1.280 raeburn 5521: $current = {
5522: 'postsubmit' => $postsubmitclient,
5523: };
1.257 raeburn 5524: ($table,$itemcount) =
5525: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5526: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5527: $datatable .= $table;
1.276 raeburn 5528: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5529: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5530: $choices{'mysqltables'}.
5531: '</span></td>'.
1.306 raeburn 5532: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5533: '<table><tr>';
5534: foreach my $type (@types) {
1.306 raeburn 5535: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5536: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5537: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5538: }
5539: $datatable .= '</tr></table></td></tr>'."\n";
5540: $itemcount ++;
5541:
1.139 raeburn 5542: }
1.192 raeburn 5543: $$rowtotal += $itemcount;
1.121 raeburn 5544: return $datatable;
1.118 jms 5545: }
5546:
1.231 raeburn 5547: sub print_selfenrollment {
5548: my ($position,$dom,$settings,$rowtotal) = @_;
5549: my ($css_class,$datatable);
5550: my $itemcount = 1;
1.271 raeburn 5551: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5552: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5553: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5554: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5555: my @rows;
5556: my $key;
5557: if ($position eq 'top') {
5558: $key = 'admin';
5559: if (ref($rowsref) eq 'ARRAY') {
5560: @rows = @{$rowsref};
5561: }
5562: } elsif ($position eq 'middle') {
5563: $key = 'default';
5564: @rows = ('types','registered','approval','limit');
5565: }
5566: foreach my $row (@rows) {
5567: if (defined($titlesref->{$row})) {
5568: $itemcount ++;
5569: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5570: $datatable .= '<tr'.$css_class.'>'.
5571: '<td>'.$titlesref->{$row}.'</td>'.
5572: '<td class="LC_left_item">'.
5573: '<table><tr>';
5574: my (%current,%currentcap);
5575: if (ref($settings) eq 'HASH') {
5576: if (ref($settings->{$key}) eq 'HASH') {
5577: foreach my $type (@types) {
5578: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5579: $current{$type} = $settings->{$key}->{$type}->{$row};
5580: }
5581: if (($row eq 'limit') && ($key eq 'default')) {
5582: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5583: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5584: }
5585: }
5586: }
5587: }
5588: }
5589: my %roles = (
5590: '0' => &Apache::lonnet::plaintext('dc'),
5591: );
5592:
5593: foreach my $type (@types) {
5594: unless (($row eq 'registered') && ($key eq 'default')) {
5595: $datatable .= '<th>'.&mt($type).'</th>';
5596: }
5597: }
5598: unless (($row eq 'registered') && ($key eq 'default')) {
5599: $datatable .= '</tr><tr>';
5600: }
5601: foreach my $type (@types) {
5602: if ($type eq 'community') {
5603: $roles{'1'} = &mt('Community personnel');
5604: } else {
5605: $roles{'1'} = &mt('Course personnel');
5606: }
5607: $datatable .= '<td style="vertical-align: top">';
5608: if ($position eq 'top') {
5609: my %checked;
5610: if ($current{$type} eq '0') {
5611: $checked{'0'} = ' checked="checked"';
5612: } else {
5613: $checked{'1'} = ' checked="checked"';
5614: }
5615: foreach my $role ('1','0') {
5616: $datatable .= '<span class="LC_nobreak"><label>'.
5617: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5618: 'value="'.$role.'"'.$checked{$role}.' />'.
5619: $roles{$role}.'</label></span> ';
5620: }
5621: } else {
5622: if ($row eq 'types') {
5623: my %checked;
5624: if ($current{$type} =~ /^(all|dom)$/) {
5625: $checked{$1} = ' checked="checked"';
5626: } else {
5627: $checked{''} = ' checked="checked"';
5628: }
5629: foreach my $val ('','dom','all') {
5630: $datatable .= '<span class="LC_nobreak"><label>'.
5631: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5632: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5633: }
5634: } elsif ($row eq 'registered') {
5635: my %checked;
5636: if ($current{$type} eq '1') {
5637: $checked{'1'} = ' checked="checked"';
5638: } else {
5639: $checked{'0'} = ' checked="checked"';
5640: }
5641: foreach my $val ('0','1') {
5642: $datatable .= '<span class="LC_nobreak"><label>'.
5643: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5644: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5645: }
5646: } elsif ($row eq 'approval') {
5647: my %checked;
5648: if ($current{$type} =~ /^([12])$/) {
5649: $checked{$1} = ' checked="checked"';
5650: } else {
5651: $checked{'0'} = ' checked="checked"';
5652: }
5653: for my $val (0..2) {
5654: $datatable .= '<span class="LC_nobreak"><label>'.
5655: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5656: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5657: }
5658: } elsif ($row eq 'limit') {
5659: my %checked;
5660: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5661: $checked{$1} = ' checked="checked"';
5662: } else {
5663: $checked{'none'} = ' checked="checked"';
5664: }
5665: my $cap;
5666: if ($currentcap{$type} =~ /^\d+$/) {
5667: $cap = $currentcap{$type};
5668: }
5669: foreach my $val ('none','allstudents','selfenrolled') {
5670: $datatable .= '<span class="LC_nobreak"><label>'.
5671: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5672: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5673: }
5674: $datatable .= '<br />'.
5675: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5676: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5677: '</span>';
5678: }
5679: }
5680: $datatable .= '</td>';
5681: }
5682: $datatable .= '</tr>';
5683: }
5684: $datatable .= '</table></td></tr>';
5685: }
5686: } elsif ($position eq 'bottom') {
1.235 raeburn 5687: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5688: }
5689: $$rowtotal += $itemcount;
5690: return $datatable;
5691: }
5692:
5693: sub print_validation_rows {
5694: my ($caller,$dom,$settings,$rowtotal) = @_;
5695: my ($itemsref,$namesref,$fieldsref);
5696: if ($caller eq 'selfenroll') {
5697: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5698: } elsif ($caller eq 'requestcourses') {
5699: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5700: }
5701: my %currvalidation;
5702: if (ref($settings) eq 'HASH') {
5703: if (ref($settings->{'validation'}) eq 'HASH') {
5704: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5705: }
1.235 raeburn 5706: }
5707: my $datatable;
5708: my $itemcount = 0;
5709: foreach my $item (@{$itemsref}) {
5710: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5711: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5712: $namesref->{$item}.
5713: '</span></td>'.
5714: '<td class="LC_left_item">';
5715: if (($item eq 'url') || ($item eq 'button')) {
5716: $datatable .= '<span class="LC_nobreak">'.
5717: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5718: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5719: } elsif ($item eq 'fields') {
5720: my @currfields;
5721: if (ref($currvalidation{$item}) eq 'ARRAY') {
5722: @currfields = @{$currvalidation{$item}};
5723: }
5724: foreach my $field (@{$fieldsref}) {
5725: my $check = '';
5726: if (grep(/^\Q$field\E$/,@currfields)) {
5727: $check = ' checked="checked"';
5728: }
5729: $datatable .= '<span class="LC_nobreak"><label>'.
5730: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5731: ' value="'.$field.'"'.$check.' />'.$field.
5732: '</label></span> ';
5733: }
5734: } elsif ($item eq 'markup') {
1.334 raeburn 5735: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 5736: $currvalidation{$item}.
1.231 raeburn 5737: '</textarea>';
1.235 raeburn 5738: }
5739: $datatable .= '</td></tr>'."\n";
5740: if (ref($rowtotal)) {
1.231 raeburn 5741: $itemcount ++;
5742: }
5743: }
1.235 raeburn 5744: if ($caller eq 'requestcourses') {
5745: my %currhash;
1.248 raeburn 5746: if (ref($settings) eq 'HASH') {
5747: if (ref($settings->{'validation'}) eq 'HASH') {
5748: if ($settings->{'validation'}{'dc'} ne '') {
5749: $currhash{$settings->{'validation'}{'dc'}} = 1;
5750: }
1.235 raeburn 5751: }
5752: }
5753: my $numinrow = 2;
5754: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5755: 'validationdc',%currhash);
1.247 raeburn 5756: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 5757: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 5758: if ($numdc > 1) {
1.247 raeburn 5759: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5760: } else {
1.247 raeburn 5761: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5762: }
1.247 raeburn 5763: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5764: $itemcount ++;
5765: }
5766: if (ref($rowtotal)) {
5767: $$rowtotal += $itemcount;
5768: }
1.231 raeburn 5769: return $datatable;
5770: }
5771:
1.137 raeburn 5772: sub print_usersessions {
5773: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 5774: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 5775: my (%by_ip,%by_location,@intdoms,@instdoms);
5776: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 5777:
5778: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5779: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5780: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5781: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5782: if ($position eq 'top') {
1.152 raeburn 5783: if (keys(%serverhomes) > 1) {
1.145 raeburn 5784: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 5785: my $curroffloadnow;
5786: if (ref($settings) eq 'HASH') {
5787: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5788: $curroffloadnow = $settings->{'offloadnow'};
5789: }
5790: }
5791: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 5792: } else {
1.140 raeburn 5793: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 5794: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
5795: '</td></tr>';
1.140 raeburn 5796: }
1.137 raeburn 5797: } else {
1.279 raeburn 5798: my %titles = &usersession_titles();
5799: my ($prefix,@types);
5800: if ($position eq 'bottom') {
5801: $prefix = 'remote';
5802: @types = ('version','excludedomain','includedomain');
1.145 raeburn 5803: } else {
1.279 raeburn 5804: $prefix = 'hosted';
5805: @types = ('excludedomain','includedomain');
5806: }
5807: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5808: }
5809: $$rowtotal += $itemcount;
5810: return $datatable;
5811: }
5812:
5813: sub rules_by_location {
5814: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
5815: my ($datatable,$itemcount,$css_class);
5816: if (keys(%{$by_location}) == 0) {
5817: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5818: $datatable = '<tr'.$css_class.'><td colspan="2">'.
5819: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
5820: '</td></tr>';
5821: $itemcount = 1;
5822: } else {
5823: $itemcount = 0;
5824: my $numinrow = 5;
5825: my (%current,%checkedon,%checkedoff);
5826: my @locations = sort(keys(%{$by_location}));
5827: foreach my $type (@{$types}) {
5828: $checkedon{$type} = '';
5829: $checkedoff{$type} = ' checked="checked"';
5830: }
5831: if (ref($settings) eq 'HASH') {
5832: if (ref($settings->{$prefix}) eq 'HASH') {
5833: foreach my $key (keys(%{$settings->{$prefix}})) {
5834: $current{$key} = $settings->{$prefix}{$key};
5835: if ($key eq 'version') {
5836: if ($current{$key} ne '') {
1.145 raeburn 5837: $checkedon{$key} = ' checked="checked"';
5838: $checkedoff{$key} = '';
5839: }
1.279 raeburn 5840: } elsif (ref($current{$key}) eq 'ARRAY') {
5841: $checkedon{$key} = ' checked="checked"';
5842: $checkedoff{$key} = '';
1.137 raeburn 5843: }
5844: }
5845: }
1.279 raeburn 5846: }
5847: foreach my $type (@{$types}) {
5848: next if ($type ne 'version' && !@locations);
5849: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5850: $datatable .= '<tr'.$css_class.'>
5851: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
5852: <span class="LC_nobreak">
5853: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5854: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5855: if ($type eq 'version') {
5856: my @lcversions = &Apache::lonnet::all_loncaparevs();
5857: my $selector = '<select name="'.$prefix.'_version">';
5858: foreach my $version (@lcversions) {
5859: my $selected = '';
5860: if ($current{'version'} eq $version) {
5861: $selected = ' selected="selected"';
1.145 raeburn 5862: }
1.279 raeburn 5863: $selector .= ' <option value="'.$version.'"'.
5864: $selected.'>'.$version.'</option>';
5865: }
5866: $selector .= '</select> ';
5867: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5868: } else {
5869: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5870: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5871: ' />'.(' 'x2).
5872: '<input type="button" value="'.&mt('uncheck all').'" '.
5873: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5874: "\n".
5875: '</div><div><table>';
5876: my $rem;
5877: for (my $i=0; $i<@locations; $i++) {
5878: my ($showloc,$value,$checkedtype);
5879: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
5880: my $ip = $by_location->{$locations[$i]}->[0];
5881: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5882: $value = join(':',@{$by_ip->{$ip}});
5883: $showloc = join(', ',@{$by_ip->{$ip}});
5884: if (ref($current{$type}) eq 'ARRAY') {
5885: foreach my $loc (@{$by_ip->{$ip}}) {
5886: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5887: $checkedtype = ' checked="checked"';
5888: last;
1.145 raeburn 5889: }
1.138 raeburn 5890: }
5891: }
5892: }
1.137 raeburn 5893: }
1.279 raeburn 5894: $rem = $i%($numinrow);
5895: if ($rem == 0) {
5896: if ($i > 0) {
5897: $datatable .= '</tr>';
5898: }
5899: $datatable .= '<tr>';
5900: }
5901: $datatable .= '<td class="LC_left_item">'.
5902: '<span class="LC_nobreak"><label>'.
5903: '<input type="checkbox" name="'.$prefix.'_'.$type.
5904: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5905: '</label></span></td>';
5906: }
5907: $rem = @locations%($numinrow);
5908: my $colsleft = $numinrow - $rem;
5909: if ($colsleft > 1 ) {
5910: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5911: ' </td>';
5912: } elsif ($colsleft == 1) {
5913: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5914: }
1.279 raeburn 5915: $datatable .= '</tr></table>';
1.137 raeburn 5916: }
1.279 raeburn 5917: $datatable .= '</td></tr>';
5918: $itemcount ++;
1.137 raeburn 5919: }
5920: }
1.279 raeburn 5921: return ($datatable,$itemcount);
1.137 raeburn 5922: }
5923:
1.275 raeburn 5924: sub print_ssl {
5925: my ($position,$dom,$settings,$rowtotal) = @_;
5926: my ($css_class,$datatable);
5927: my $itemcount = 1;
5928: if ($position eq 'top') {
1.281 raeburn 5929: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5930: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5931: my $same_institution;
5932: if ($intdom ne '') {
5933: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
5934: if (ref($internet_names) eq 'ARRAY') {
5935: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5936: $same_institution = 1;
5937: }
5938: }
5939: }
1.275 raeburn 5940: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 5941: $datatable = '<tr'.$css_class.'><td colspan="2">';
5942: if ($same_institution) {
5943: my %domservers = &Apache::lonnet::get_servers($dom);
5944: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
5945: } else {
5946: $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.");
5947: }
5948: $datatable .= '</td></tr>';
1.275 raeburn 5949: $itemcount ++;
5950: } else {
5951: my %titles = &ssl_titles();
5952: my (%by_ip,%by_location,@intdoms,@instdoms);
5953: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5954: my @alldoms = &Apache::lonnet::all_domains();
5955: my %serverhomes = %Apache::lonnet::serverhomeIDs;
5956: my @domservers = &Apache::lonnet::get_servers($dom);
5957: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5958: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 5959: if (($position eq 'connto') || ($position eq 'connfrom')) {
5960: my $legacy;
5961: unless (ref($settings) eq 'HASH') {
5962: my $name;
5963: if ($position eq 'connto') {
5964: $name = 'loncAllowInsecure';
5965: } else {
5966: $name = 'londAllowInsecure';
5967: }
5968: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
5969: my @ids=&Apache::lonnet::current_machine_ids();
5970: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
5971: my %what = (
5972: $name => 1,
5973: );
5974: my ($result,$returnhash) =
5975: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
5976: if ($result eq 'ok') {
5977: if (ref($returnhash) eq 'HASH') {
5978: $legacy = $returnhash->{$name};
5979: }
5980: }
5981: } else {
5982: $legacy = $Apache::lonnet::perlvar{$name};
5983: }
5984: }
1.275 raeburn 5985: foreach my $type ('dom','intdom','other') {
5986: my %checked;
5987: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5988: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
5989: '<td class="LC_right_item">';
5990: my $skip;
5991: if ($type eq 'dom') {
5992: unless (keys(%servers) > 1) {
5993: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
5994: $skip = 1;
5995: }
5996: }
5997: if ($type eq 'intdom') {
5998: unless (@instdoms > 1) {
5999: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
6000: $skip = 1;
6001: }
6002: } elsif ($type eq 'other') {
6003: if (keys(%by_location) == 0) {
6004: $datatable .= &mt('Nothing to set here, as there are no other institutions');
6005: $skip = 1;
6006: }
6007: }
6008: unless ($skip) {
6009: $checked{'yes'} = ' checked="checked"';
6010: if (ref($settings) eq 'HASH') {
1.293 raeburn 6011: if (ref($settings->{$position}) eq 'HASH') {
6012: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 6013: $checked{$1} = $checked{'yes'};
6014: delete($checked{'yes'});
6015: }
6016: }
1.293 raeburn 6017: } else {
6018: if ($legacy == 0) {
6019: $checked{'req'} = $checked{'yes'};
6020: delete($checked{'yes'});
6021: }
1.275 raeburn 6022: }
6023: foreach my $option ('no','yes','req') {
6024: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 6025: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 6026: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
6027: '</label></span>'.(' 'x2);
6028: }
6029: }
6030: $datatable .= '</td></tr>';
6031: $itemcount ++;
6032: }
6033: } else {
6034: my $prefix = 'replication';
6035: my @types = ('certreq','nocertreq');
1.279 raeburn 6036: if (keys(%by_location) == 0) {
6037: $datatable .= '<tr'.$css_class.'><td>'.
6038: &mt('Nothing to set here, as there are no other institutions').
6039: '</td></tr>';
6040: $itemcount ++;
1.275 raeburn 6041: } else {
1.279 raeburn 6042: ($datatable,$itemcount) =
6043: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 6044: }
6045: }
6046: }
6047: $$rowtotal += $itemcount;
6048: return $datatable;
6049: }
6050:
6051: sub ssl_titles {
6052: return &Apache::lonlocal::texthash (
6053: dom => 'LON-CAPA servers/VMs from same domain',
6054: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
6055: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 6056: connto => 'Connections to other servers',
6057: connfrom => 'Connections from other servers',
1.275 raeburn 6058: replication => 'Replicating content to other institutions',
6059: certreq => 'Client certificate required, but specific domains exempt',
6060: nocertreq => 'No client certificate required, except for specific domains',
6061: no => 'SSL not used',
6062: yes => 'SSL Optional (used if available)',
6063: req => 'SSL Required',
6064: );
1.279 raeburn 6065: }
6066:
6067: sub print_trust {
6068: my ($prefix,$dom,$settings,$rowtotal) = @_;
6069: my ($css_class,$datatable,%checked,%choices);
6070: my (%by_ip,%by_location,@intdoms,@instdoms);
6071: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6072: my $itemcount = 1;
6073: my %titles = &trust_titles();
6074: my @types = ('exc','inc');
6075: if ($prefix eq 'top') {
6076: $prefix = 'content';
6077: } elsif ($prefix eq 'bottom') {
6078: $prefix = 'msg';
6079: }
6080: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
6081: $$rowtotal += $itemcount;
6082: return $datatable;
6083: }
6084:
6085: sub trust_titles {
6086: return &Apache::lonlocal::texthash(
6087: content => "Access to this domain's content by others",
6088: shared => "Access to other domain's content by this domain",
6089: enroll => "Enrollment in this domain's courses by others",
6090: othcoau => "Co-author roles in this domain for others",
6091: coaurem => "Co-author roles for this domain's users elsewhere",
6092: domroles => "Domain roles in this domain assignable to others",
6093: catalog => "Course Catalog for this domain displayed elsewhere",
6094: reqcrs => "Requests for creation of courses in this domain by others",
6095: msg => "Users in other domains can send messages to this domain",
6096: exc => "Allow all, but exclude specific domains",
6097: inc => "Deny all, but include specific domains",
6098: );
1.275 raeburn 6099: }
6100:
1.138 raeburn 6101: sub build_location_hashes {
1.275 raeburn 6102: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 6103: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 6104: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 6105: my %iphost = &Apache::lonnet::get_iphost();
6106: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
6107: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
6108: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
6109: foreach my $id (@{$iphost{$primary_ip}}) {
6110: my $intdom = &Apache::lonnet::internet_dom($id);
6111: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
6112: push(@{$intdoms},$intdom);
6113: }
6114: }
6115: }
6116: foreach my $ip (keys(%iphost)) {
6117: if (ref($iphost{$ip}) eq 'ARRAY') {
6118: foreach my $id (@{$iphost{$ip}}) {
6119: my $location = &Apache::lonnet::internet_dom($id);
6120: if ($location) {
1.275 raeburn 6121: if (grep(/^\Q$location\E$/,@{$intdoms})) {
6122: my $dom = &Apache::lonnet::host_domain($id);
6123: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
6124: push(@{$instdoms},$dom);
6125: }
6126: next;
6127: }
1.138 raeburn 6128: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6129: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
6130: push(@{$by_ip->{$ip}},$location);
6131: }
6132: } else {
6133: $by_ip->{$ip} = [$location];
6134: }
6135: }
6136: }
6137: }
6138: }
6139: foreach my $ip (sort(keys(%{$by_ip}))) {
6140: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6141: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
6142: my $first = $by_ip->{$ip}->[0];
6143: if (ref($by_location->{$first}) eq 'ARRAY') {
6144: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
6145: push(@{$by_location->{$first}},$ip);
6146: }
6147: } else {
6148: $by_location->{$first} = [$ip];
6149: }
6150: }
6151: }
6152: return;
6153: }
6154:
1.145 raeburn 6155: sub current_offloads_to {
6156: my ($dom,$settings,$servers) = @_;
6157: my (%spareid,%otherdomconfigs);
1.152 raeburn 6158: if (ref($servers) eq 'HASH') {
1.145 raeburn 6159: foreach my $lonhost (sort(keys(%{$servers}))) {
6160: my $gotspares;
1.152 raeburn 6161: if (ref($settings) eq 'HASH') {
6162: if (ref($settings->{'spares'}) eq 'HASH') {
6163: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
6164: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
6165: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
6166: $gotspares = 1;
6167: }
1.145 raeburn 6168: }
6169: }
6170: unless ($gotspares) {
6171: my $gotspares;
6172: my $serverhomeID =
6173: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
6174: my $serverhomedom =
6175: &Apache::lonnet::host_domain($serverhomeID);
6176: if ($serverhomedom ne $dom) {
6177: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
6178: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6179: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6180: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6181: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6182: $gotspares = 1;
6183: }
6184: }
6185: } else {
6186: $otherdomconfigs{$serverhomedom} =
6187: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
6188: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
6189: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6190: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6191: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
6192: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6193: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6194: $gotspares = 1;
6195: }
6196: }
6197: }
6198: }
6199: }
6200: }
6201: }
6202: unless ($gotspares) {
6203: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6204: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6205: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6206: } else {
6207: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6208: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6209: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6210: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6211: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6212: } else {
1.150 raeburn 6213: my %what = (
6214: spareid => 1,
6215: );
6216: my ($result,$returnhash) =
6217: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6218: if ($result eq 'ok') {
6219: if (ref($returnhash) eq 'HASH') {
6220: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6221: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6222: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6223: }
6224: }
1.145 raeburn 6225: }
6226: }
6227: }
6228: }
6229: }
6230: }
6231: return %spareid;
6232: }
6233:
6234: sub spares_row {
1.261 raeburn 6235: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 6236: my $css_class;
6237: my $numinrow = 4;
6238: my $itemcount = 1;
6239: my $datatable;
1.152 raeburn 6240: my %typetitles = &sparestype_titles();
6241: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6242: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6243: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6244: my ($othercontrol,$serverdom);
6245: if ($serverhome ne $server) {
6246: $serverdom = &Apache::lonnet::host_domain($serverhome);
6247: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6248: } else {
6249: $serverdom = &Apache::lonnet::host_domain($server);
6250: if ($serverdom ne $dom) {
6251: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6252: }
6253: }
6254: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 6255: my $checkednow;
6256: if (ref($curroffloadnow) eq 'HASH') {
6257: if ($curroffloadnow->{$server}) {
6258: $checkednow = ' checked="checked"';
6259: }
6260: }
1.145 raeburn 6261: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6262: $datatable .= '<tr'.$css_class.'>
6263: <td rowspan="2">
1.183 bisitz 6264: <span class="LC_nobreak">'.
6265: &mt('[_1] when busy, offloads to:'
1.261 raeburn 6266: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 6267: '<span class="LC_nobreak">'."\n".
1.261 raeburn 6268: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
6269: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 6270: "\n";
1.145 raeburn 6271: my (%current,%canselect);
1.152 raeburn 6272: my @choices =
6273: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6274: foreach my $type ('primary','default') {
6275: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6276: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6277: my @spares = @{$spareid->{$server}{$type}};
6278: if (@spares > 0) {
1.152 raeburn 6279: if ($othercontrol) {
6280: $current{$type} = join(', ',@spares);
6281: } else {
6282: $current{$type} .= '<table>';
6283: my $numspares = scalar(@spares);
6284: for (my $i=0; $i<@spares; $i++) {
6285: my $rem = $i%($numinrow);
6286: if ($rem == 0) {
6287: if ($i > 0) {
6288: $current{$type} .= '</tr>';
6289: }
6290: $current{$type} .= '<tr>';
1.145 raeburn 6291: }
1.152 raeburn 6292: $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'".');" /> '.
6293: $spareid->{$server}{$type}[$i].
6294: '</label></td>'."\n";
6295: }
6296: my $rem = @spares%($numinrow);
6297: my $colsleft = $numinrow - $rem;
6298: if ($colsleft > 1 ) {
6299: $current{$type} .= '<td colspan="'.$colsleft.
6300: '" class="LC_left_item">'.
6301: ' </td>';
6302: } elsif ($colsleft == 1) {
6303: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6304: }
1.152 raeburn 6305: $current{$type} .= '</tr></table>';
1.150 raeburn 6306: }
1.145 raeburn 6307: }
6308: }
6309: if ($current{$type} eq '') {
6310: $current{$type} = &mt('None specified');
6311: }
1.152 raeburn 6312: if ($othercontrol) {
6313: if ($type eq 'primary') {
6314: $canselect{$type} = $othercontrol;
6315: }
6316: } else {
6317: $canselect{$type} =
6318: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6319: '<select name="newspare_'.$type.'_'.$server.'" '.
6320: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6321: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6322: if (@choices > 0) {
6323: foreach my $lonhost (@choices) {
6324: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6325: }
6326: }
6327: $canselect{$type} .= '</select>'."\n";
6328: }
6329: } else {
6330: $current{$type} = &mt('Could not be determined');
6331: if ($type eq 'primary') {
6332: $canselect{$type} = $othercontrol;
6333: }
1.145 raeburn 6334: }
1.152 raeburn 6335: if ($type eq 'default') {
6336: $datatable .= '<tr'.$css_class.'>';
6337: }
6338: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6339: '<td>'.$current{$type}.'</td>'."\n".
6340: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6341: }
6342: $itemcount ++;
6343: }
6344: }
6345: $$rowtotal += $itemcount;
6346: return $datatable;
6347: }
6348:
1.152 raeburn 6349: sub possible_newspares {
6350: my ($server,$currspares,$serverhomes,$altids) = @_;
6351: my $serverhostname = &Apache::lonnet::hostname($server);
6352: my %excluded;
6353: if ($serverhostname ne '') {
6354: %excluded = (
6355: $serverhostname => 1,
6356: );
6357: }
6358: if (ref($currspares) eq 'HASH') {
6359: foreach my $type (keys(%{$currspares})) {
6360: if (ref($currspares->{$type}) eq 'ARRAY') {
6361: if (@{$currspares->{$type}} > 0) {
6362: foreach my $curr (@{$currspares->{$type}}) {
6363: my $hostname = &Apache::lonnet::hostname($curr);
6364: $excluded{$hostname} = 1;
6365: }
6366: }
6367: }
6368: }
6369: }
6370: my @choices;
6371: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6372: if (keys(%{$serverhomes}) > 1) {
6373: foreach my $name (sort(keys(%{$serverhomes}))) {
6374: unless ($excluded{$name}) {
6375: if (exists($altids->{$serverhomes->{$name}})) {
6376: push(@choices,$altids->{$serverhomes->{$name}});
6377: } else {
6378: push(@choices,$serverhomes->{$name});
1.145 raeburn 6379: }
6380: }
6381: }
6382: }
6383: }
1.152 raeburn 6384: return sort(@choices);
1.145 raeburn 6385: }
6386:
1.150 raeburn 6387: sub print_loadbalancing {
6388: my ($dom,$settings,$rowtotal) = @_;
6389: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6390: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6391: my $numinrow = 1;
6392: my $datatable;
6393: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 6394: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 6395: if (ref($settings) eq 'HASH') {
6396: %existing = %{$settings};
6397: }
6398: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6399: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 6400: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 6401: } else {
6402: return;
6403: }
6404: my ($othertitle,$usertypes,$types) =
6405: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 6406: my $rownum = 8;
1.150 raeburn 6407: if (ref($types) eq 'ARRAY') {
6408: $rownum += scalar(@{$types});
6409: }
1.171 raeburn 6410: my @css_class = ('LC_odd_row','LC_even_row');
6411: my $balnum = 0;
6412: my $islast;
6413: my (@toshow,$disabledtext);
6414: if (keys(%currbalancer) > 0) {
6415: @toshow = sort(keys(%currbalancer));
6416: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6417: push(@toshow,'');
6418: }
6419: } else {
6420: @toshow = ('');
6421: $disabledtext = &mt('No existing load balancer');
6422: }
6423: foreach my $lonhost (@toshow) {
6424: if ($balnum == scalar(@toshow)-1) {
6425: $islast = 1;
6426: } else {
6427: $islast = 0;
6428: }
6429: my $cssidx = $balnum%2;
6430: my $targets_div_style = 'display: none';
6431: my $disabled_div_style = 'display: block';
6432: my $homedom_div_style = 'display: none';
6433: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 6434: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6435: '<p>';
6436: if ($lonhost eq '') {
1.210 raeburn 6437: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 6438: if (keys(%currbalancer) > 0) {
6439: $datatable .= &mt('Add balancer:');
6440: } else {
6441: $datatable .= &mt('Enable balancer:');
6442: }
6443: $datatable .= ' '.
6444: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6445: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6446: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6447: '<option value="" selected="selected">'.&mt('None').
6448: '</option>'."\n";
6449: foreach my $server (sort(keys(%servers))) {
6450: next if ($currbalancer{$server});
6451: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6452: }
1.210 raeburn 6453: $datatable .=
1.171 raeburn 6454: '</select>'."\n".
6455: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6456: } else {
6457: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6458: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6459: &mt('Stop balancing').'</label>'.
6460: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6461: $targets_div_style = 'display: block';
6462: $disabled_div_style = 'display: none';
6463: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6464: $homedom_div_style = 'display: block';
6465: }
6466: }
1.306 raeburn 6467: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6468: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6469: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6470: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6471: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6472: my @sparestypes = ('primary','default');
6473: my %typetitles = &sparestype_titles();
1.284 raeburn 6474: my %hostherechecked = (
6475: no => ' checked="checked"',
6476: );
1.342 raeburn 6477: my %balcookiechecked = (
6478: no => ' checked="checked"',
6479: );
1.171 raeburn 6480: foreach my $sparetype (@sparestypes) {
6481: my $targettable;
6482: for (my $i=0; $i<$numspares; $i++) {
6483: my $checked;
6484: if (ref($currtargets{$lonhost}) eq 'HASH') {
6485: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6486: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6487: $checked = ' checked="checked"';
6488: }
6489: }
6490: }
6491: my ($chkboxval,$disabled);
6492: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6493: $chkboxval = $spares[$i];
6494: }
6495: if (exists($currbalancer{$spares[$i]})) {
6496: $disabled = ' disabled="disabled"';
6497: }
1.210 raeburn 6498: $targettable .=
1.253 raeburn 6499: '<td><span class="LC_nobreak"><label>'.
6500: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 6501: $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 6502: '</span></label></span></td>';
1.171 raeburn 6503: my $rem = $i%($numinrow);
6504: if ($rem == 0) {
6505: if (($i > 0) && ($i < $numspares-1)) {
6506: $targettable .= '</tr>';
6507: }
6508: if ($i < $numspares-1) {
6509: $targettable .= '<tr>';
1.150 raeburn 6510: }
6511: }
6512: }
1.171 raeburn 6513: if ($targettable ne '') {
6514: my $rem = $numspares%($numinrow);
6515: my $colsleft = $numinrow - $rem;
6516: if ($colsleft > 1 ) {
6517: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6518: ' </td>';
6519: } elsif ($colsleft == 1) {
6520: $targettable .= '<td class="LC_left_item"> </td>';
6521: }
6522: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6523: '<table><tr>'.$targettable.'</tr></table><br />';
6524: }
1.284 raeburn 6525: $hostherechecked{$sparetype} = '';
6526: if (ref($currtargets{$lonhost}) eq 'HASH') {
6527: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6528: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6529: $hostherechecked{$sparetype} = ' checked="checked"';
6530: $hostherechecked{'no'} = '';
6531: }
6532: }
6533: }
6534: }
1.342 raeburn 6535: if ($currcookies{$lonhost}) {
6536: %balcookiechecked = (
6537: yes => ' checked="checked"',
6538: );
6539: }
1.284 raeburn 6540: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6541: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6542: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6543: foreach my $sparetype (@sparestypes) {
6544: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6545: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6546: '</i></label><br />';
1.171 raeburn 6547: }
1.342 raeburn 6548: $datatable .= &mt('Use balancer cookie').'<br />'.
6549: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
6550: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
6551: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
6552: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
6553: '</div></td></tr>'.
1.171 raeburn 6554: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6555: $othertitle,$usertypes,$types,\%servers,
6556: \%currbalancer,$lonhost,
6557: $targets_div_style,$homedom_div_style,
6558: $css_class[$cssidx],$balnum,$islast);
6559: $$rowtotal += $rownum;
6560: $balnum ++;
6561: }
6562: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6563: return $datatable;
6564: }
6565:
6566: sub get_loadbalancers_config {
1.342 raeburn 6567: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 6568: return unless ((ref($servers) eq 'HASH') &&
6569: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 6570: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
6571: (ref($currcookies) eq 'HASH'));
1.171 raeburn 6572: if (keys(%{$existing}) > 0) {
6573: my $oldlonhost;
6574: foreach my $key (sort(keys(%{$existing}))) {
6575: if ($key eq 'lonhost') {
6576: $oldlonhost = $existing->{'lonhost'};
6577: $currbalancer->{$oldlonhost} = 1;
6578: } elsif ($key eq 'targets') {
6579: if ($oldlonhost) {
6580: $currtargets->{$oldlonhost} = $existing->{'targets'};
6581: }
6582: } elsif ($key eq 'rules') {
6583: if ($oldlonhost) {
6584: $currrules->{$oldlonhost} = $existing->{'rules'};
6585: }
6586: } elsif (ref($existing->{$key}) eq 'HASH') {
6587: $currbalancer->{$key} = 1;
6588: $currtargets->{$key} = $existing->{$key}{'targets'};
6589: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 6590: if ($existing->{$key}{'cookie'}) {
6591: $currcookies->{$key} = 1;
6592: }
1.150 raeburn 6593: }
6594: }
1.171 raeburn 6595: } else {
6596: my ($balancerref,$targetsref) =
6597: &Apache::lonnet::get_lonbalancer_config($servers);
6598: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6599: foreach my $server (sort(keys(%{$balancerref}))) {
6600: $currbalancer->{$server} = 1;
6601: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6602: }
6603: }
6604: }
1.171 raeburn 6605: return;
1.150 raeburn 6606: }
6607:
6608: sub loadbalancing_rules {
6609: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 6610: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6611: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6612: my $output;
1.171 raeburn 6613: my $num = 0;
1.210 raeburn 6614: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6615: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6616: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6617: foreach my $type (@{$alltypes}) {
1.171 raeburn 6618: $num ++;
1.150 raeburn 6619: my $current;
6620: if (ref($currrules) eq 'HASH') {
6621: $current = $currrules->{$type};
6622: }
1.253 raeburn 6623: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 6624: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6625: $current = '';
6626: }
6627: }
6628: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 6629: $servers,$currbalancer,$lonhost,$dom,
6630: $targets_div_style,$homedom_div_style,
6631: $css_class,$balnum,$num,$islast);
1.150 raeburn 6632: }
6633: }
6634: return $output;
6635: }
6636:
6637: sub loadbalancing_titles {
6638: my ($dom,$intdom,$usertypes,$types) = @_;
6639: my %othertypes = (
6640: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6641: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6642: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6643: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 6644: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6645: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6646: );
1.209 raeburn 6647: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 6648: my @available;
1.150 raeburn 6649: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6650: @available = @{$types};
1.150 raeburn 6651: }
1.302 raeburn 6652: unless (grep(/^default$/,@available)) {
6653: push(@available,'default');
6654: }
6655: unshift(@alltypes,@available);
1.150 raeburn 6656: my %titles;
6657: foreach my $type (@alltypes) {
6658: if ($type =~ /^_LC_/) {
6659: $titles{$type} = $othertypes{$type};
6660: } elsif ($type eq 'default') {
6661: $titles{$type} = &mt('All users from [_1]',$dom);
6662: if (ref($types) eq 'ARRAY') {
6663: if (@{$types} > 0) {
6664: $titles{$type} = &mt('Other users from [_1]',$dom);
6665: }
6666: }
6667: } elsif (ref($usertypes) eq 'HASH') {
6668: $titles{$type} = $usertypes->{$type};
6669: }
6670: }
6671: return (\@alltypes,\%othertypes,\%titles);
6672: }
6673:
6674: sub loadbalance_rule_row {
1.171 raeburn 6675: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6676: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 6677: my @rulenames;
1.150 raeburn 6678: my %ruletitles = &offloadtype_text();
1.209 raeburn 6679: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 6680: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6681: } else {
1.209 raeburn 6682: @rulenames = ('default','homeserver');
6683: if ($type eq '_LC_external') {
6684: push(@rulenames,'externalbalancer');
6685: } else {
6686: push(@rulenames,'specific');
6687: }
6688: push(@rulenames,'none');
1.150 raeburn 6689: }
6690: my $style = $targets_div_style;
1.253 raeburn 6691: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6692: $style = $homedom_div_style;
6693: }
1.171 raeburn 6694: my $space;
6695: if ($islast && $num == 1) {
1.317 raeburn 6696: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 6697: }
1.210 raeburn 6698: my $output =
1.306 raeburn 6699: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 6700: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6701: '<td valaign="top">'.$space.
6702: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6703: for (my $i=0; $i<@rulenames; $i++) {
6704: my $rule = $rulenames[$i];
6705: my ($checked,$extra);
6706: if ($rulenames[$i] eq 'default') {
6707: $rule = '';
6708: }
6709: if ($rulenames[$i] eq 'specific') {
6710: if (ref($servers) eq 'HASH') {
6711: my $default;
6712: if (($current ne '') && (exists($servers->{$current}))) {
6713: $checked = ' checked="checked"';
6714: }
6715: unless ($checked) {
6716: $default = ' selected="selected"';
6717: }
1.210 raeburn 6718: $extra =
1.171 raeburn 6719: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6720: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6721: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6722: '<option value=""'.$default.'></option>'."\n";
6723: foreach my $server (sort(keys(%{$servers}))) {
6724: if (ref($currbalancer) eq 'HASH') {
6725: next if (exists($currbalancer->{$server}));
6726: }
1.150 raeburn 6727: my $selected;
1.171 raeburn 6728: if ($server eq $current) {
1.150 raeburn 6729: $selected = ' selected="selected"';
6730: }
1.171 raeburn 6731: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6732: }
6733: $extra .= '</select>';
6734: }
6735: } elsif ($rule eq $current) {
6736: $checked = ' checked="checked"';
6737: }
6738: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 6739: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6740: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6741: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 6742: ')"'.$checked.' /> ';
6743: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
6744: $output .= $ruletitles{'particular'};
6745: } else {
6746: $output .= $ruletitles{$rulenames[$i]};
6747: }
6748: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6749: }
6750: $output .= '</div></td></tr>'."\n";
6751: return $output;
6752: }
6753:
6754: sub offloadtype_text {
6755: my %ruletitles = &Apache::lonlocal::texthash (
6756: 'default' => 'Offloads to default destinations',
6757: 'homeserver' => "Offloads to user's home server",
6758: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6759: 'specific' => 'Offloads to specific server',
1.161 raeburn 6760: 'none' => 'No offload',
1.209 raeburn 6761: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6762: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 6763: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6764: );
6765: return %ruletitles;
6766: }
6767:
6768: sub sparestype_titles {
6769: my %typestitles = &Apache::lonlocal::texthash (
6770: 'primary' => 'primary',
6771: 'default' => 'default',
6772: );
6773: return %typestitles;
6774: }
6775:
1.28 raeburn 6776: sub contact_titles {
6777: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 6778: 'supportemail' => 'Support E-mail address',
6779: 'adminemail' => 'Default Server Admin E-mail address',
6780: 'errormail' => 'Error reports to be e-mailed to',
6781: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 6782: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6783: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 6784: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6785: 'requestsmail' => 'E-mail from course requests requiring approval',
6786: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 6787: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.340 raeburn 6788: 'errorthreshold' => 'Error/warning threshold for status e-mail',
6789: 'errorsysmail' => 'Error threshold for e-mail to core group',
6790: 'errorweights' => 'Weights used to compute error count',
6791: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 6792: );
6793: my %short_titles = &Apache::lonlocal::texthash (
6794: adminemail => 'Admin E-mail address',
6795: supportemail => 'Support E-mail',
6796: );
6797: return (\%titles,\%short_titles);
6798: }
6799:
1.286 raeburn 6800: sub helpform_fields {
6801: my %titles = &Apache::lonlocal::texthash (
6802: 'username' => 'Name',
6803: 'user' => 'Username/domain',
6804: 'phone' => 'Phone',
6805: 'cc' => 'Cc e-mail',
6806: 'course' => 'Course Details',
6807: 'section' => 'Sections',
1.289 raeburn 6808: 'screenshot' => 'File upload',
1.286 raeburn 6809: );
6810: my @fields = ('username','phone','user','course','section','cc','screenshot');
6811: my %possoptions = (
6812: username => ['yes','no','req'],
1.289 raeburn 6813: phone => ['yes','no','req'],
1.286 raeburn 6814: user => ['yes','no'],
1.289 raeburn 6815: cc => ['yes','no'],
1.286 raeburn 6816: course => ['yes','no'],
6817: section => ['yes','no'],
6818: screenshot => ['yes','no'],
6819: );
6820: my %fieldoptions = &Apache::lonlocal::texthash (
6821: 'yes' => 'Optional',
6822: 'req' => 'Required',
6823: 'no' => "Not shown",
6824: );
6825: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6826: }
6827:
1.72 raeburn 6828: sub tool_titles {
6829: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 6830: aboutme => 'Personal web page',
1.86 raeburn 6831: blog => 'Blog',
1.162 raeburn 6832: webdav => 'WebDAV',
1.86 raeburn 6833: portfolio => 'Portfolio',
1.88 bisitz 6834: official => 'Official courses (with institutional codes)',
6835: unofficial => 'Unofficial courses',
1.98 raeburn 6836: community => 'Communities',
1.216 raeburn 6837: textbook => 'Textbook courses',
1.271 raeburn 6838: placement => 'Placement tests',
1.86 raeburn 6839: );
1.72 raeburn 6840: return %titles;
6841: }
6842:
1.101 raeburn 6843: sub courserequest_titles {
6844: my %titles = &Apache::lonlocal::texthash (
6845: official => 'Official',
6846: unofficial => 'Unofficial',
6847: community => 'Communities',
1.216 raeburn 6848: textbook => 'Textbook',
1.271 raeburn 6849: placement => 'Placement tests',
1.325 raeburn 6850: lti => 'LTI Provider',
1.101 raeburn 6851: norequest => 'Not allowed',
1.325 raeburn 6852: approval => 'Approval by DC',
1.101 raeburn 6853: validate => 'With validation',
6854: autolimit => 'Numerical limit',
1.103 raeburn 6855: unlimited => '(blank for unlimited)',
1.101 raeburn 6856: );
6857: return %titles;
6858: }
6859:
1.163 raeburn 6860: sub authorrequest_titles {
6861: my %titles = &Apache::lonlocal::texthash (
6862: norequest => 'Not allowed',
6863: approval => 'Approval by Dom. Coord.',
6864: automatic => 'Automatic approval',
6865: );
6866: return %titles;
1.210 raeburn 6867: }
1.163 raeburn 6868:
1.101 raeburn 6869: sub courserequest_conditions {
6870: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6871: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 6872: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6873: );
6874: return %conditions;
6875: }
6876:
6877:
1.27 raeburn 6878: sub print_usercreation {
1.30 raeburn 6879: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6880: my $numinrow = 4;
1.28 raeburn 6881: my $datatable;
6882: if ($position eq 'top') {
1.30 raeburn 6883: $$rowtotal ++;
1.34 raeburn 6884: my $rowcount = 0;
1.32 raeburn 6885: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6886: if (ref($rules) eq 'HASH') {
6887: if (keys(%{$rules}) > 0) {
1.32 raeburn 6888: $datatable .= &user_formats_row('username',$settings,$rules,
6889: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6890: $$rowtotal ++;
1.32 raeburn 6891: $rowcount ++;
6892: }
6893: }
6894: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6895: if (ref($idrules) eq 'HASH') {
6896: if (keys(%{$idrules}) > 0) {
6897: $datatable .= &user_formats_row('id',$settings,$idrules,
6898: $idruleorder,$numinrow,$rowcount);
6899: $$rowtotal ++;
6900: $rowcount ++;
1.28 raeburn 6901: }
6902: }
1.39 raeburn 6903: if ($rowcount == 0) {
6904: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6905: $$rowtotal ++;
6906: $rowcount ++;
6907: }
1.34 raeburn 6908: } elsif ($position eq 'middle') {
1.224 raeburn 6909: my @creators = ('author','course','requestcrs');
1.37 raeburn 6910: my ($rules,$ruleorder) =
6911: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6912: my %lt = &usercreation_types();
6913: my %checked;
6914: if (ref($settings) eq 'HASH') {
6915: if (ref($settings->{'cancreate'}) eq 'HASH') {
6916: foreach my $item (@creators) {
6917: $checked{$item} = $settings->{'cancreate'}{$item};
6918: }
6919: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6920: foreach my $item (@creators) {
6921: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6922: $checked{$item} = 'none';
6923: }
6924: }
6925: }
6926: }
6927: my $rownum = 0;
6928: foreach my $item (@creators) {
6929: $rownum ++;
1.224 raeburn 6930: if ($checked{$item} eq '') {
6931: $checked{$item} = 'any';
1.34 raeburn 6932: }
6933: my $css_class;
6934: if ($rownum%2) {
6935: $css_class = '';
6936: } else {
6937: $css_class = ' class="LC_odd_row" ';
6938: }
6939: $datatable .= '<tr'.$css_class.'>'.
6940: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 6941: '</span></td><td style="text-align: right">';
1.224 raeburn 6942: my @options = ('any');
6943: if (ref($rules) eq 'HASH') {
6944: if (keys(%{$rules}) > 0) {
6945: push(@options,('official','unofficial'));
1.37 raeburn 6946: }
6947: }
1.224 raeburn 6948: push(@options,'none');
1.37 raeburn 6949: foreach my $option (@options) {
1.50 raeburn 6950: my $type = 'radio';
1.34 raeburn 6951: my $check = ' ';
1.224 raeburn 6952: if ($checked{$item} eq $option) {
6953: $check = ' checked="checked" ';
1.34 raeburn 6954: }
6955: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6956: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6957: $item.'" value="'.$option.'"'.$check.'/> '.
6958: $lt{$option}.'</label> </span>';
6959: }
6960: $datatable .= '</td></tr>';
6961: }
1.28 raeburn 6962: } else {
6963: my @contexts = ('author','course','domain');
1.325 raeburn 6964: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 6965: my %checked;
6966: if (ref($settings) eq 'HASH') {
6967: if (ref($settings->{'authtypes'}) eq 'HASH') {
6968: foreach my $item (@contexts) {
6969: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6970: foreach my $auth (@authtypes) {
6971: if ($settings->{'authtypes'}{$item}{$auth}) {
6972: $checked{$item}{$auth} = ' checked="checked" ';
6973: }
6974: }
6975: }
6976: }
1.27 raeburn 6977: }
1.35 raeburn 6978: } else {
6979: foreach my $item (@contexts) {
1.36 raeburn 6980: foreach my $auth (@authtypes) {
1.35 raeburn 6981: $checked{$item}{$auth} = ' checked="checked" ';
6982: }
6983: }
1.27 raeburn 6984: }
1.28 raeburn 6985: my %title = &context_names();
6986: my %authname = &authtype_names();
6987: my $rownum = 0;
6988: my $css_class;
6989: foreach my $item (@contexts) {
6990: if ($rownum%2) {
6991: $css_class = '';
6992: } else {
6993: $css_class = ' class="LC_odd_row" ';
6994: }
1.30 raeburn 6995: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6996: '<td>'.$title{$item}.
6997: '</td><td class="LC_left_item">'.
6998: '<span class="LC_nobreak">';
6999: foreach my $auth (@authtypes) {
7000: $datatable .= '<label>'.
7001: '<input type="checkbox" name="'.$item.'_auth" '.
7002: $checked{$item}{$auth}.' value="'.$auth.'" />'.
7003: $authname{$auth}.'</label> ';
7004: }
7005: $datatable .= '</span></td></tr>';
7006: $rownum ++;
1.27 raeburn 7007: }
1.30 raeburn 7008: $$rowtotal += $rownum;
1.27 raeburn 7009: }
7010: return $datatable;
7011: }
7012:
1.224 raeburn 7013: sub print_selfcreation {
7014: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 7015: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
7016: $emaildomain,$datatable);
1.224 raeburn 7017: if (ref($settings) eq 'HASH') {
7018: if (ref($settings->{'cancreate'}) eq 'HASH') {
7019: $createsettings = $settings->{'cancreate'};
1.236 raeburn 7020: if (ref($createsettings) eq 'HASH') {
7021: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
7022: @selfcreate = @{$createsettings->{'selfcreate'}};
7023: } elsif ($createsettings->{'selfcreate'} ne '') {
7024: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
7025: @selfcreate = ('email','login','sso');
7026: } elsif ($createsettings->{'selfcreate'} ne 'none') {
7027: @selfcreate = ($createsettings->{'selfcreate'});
7028: }
7029: }
7030: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
7031: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 7032: }
1.305 raeburn 7033: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
7034: $emailoptions = $createsettings->{'emailoptions'};
7035: }
1.303 raeburn 7036: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
7037: $emailverified = $createsettings->{'emailverified'};
7038: }
7039: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
7040: $emaildomain = $createsettings->{'emaildomain'};
7041: }
1.224 raeburn 7042: }
7043: }
7044: }
7045: my %radiohash;
7046: my $numinrow = 4;
7047: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 7048: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 7049: if ($position eq 'top') {
7050: my %choices = &Apache::lonlocal::texthash (
7051: cancreate_login => 'Institutional Login',
7052: cancreate_sso => 'Institutional Single Sign On',
7053: );
7054: my @toggles = sort(keys(%choices));
7055: my %defaultchecked = (
7056: 'cancreate_login' => 'off',
7057: 'cancreate_sso' => 'off',
7058: );
1.228 raeburn 7059: my ($onclick,$itemcount);
1.224 raeburn 7060: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7061: \%choices,$itemcount,$onclick);
1.228 raeburn 7062: $$rowtotal += $itemcount;
7063:
1.224 raeburn 7064: if (ref($usertypes) eq 'HASH') {
7065: if (keys(%{$usertypes}) > 0) {
7066: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
7067: $dom,$numinrow,$othertitle,
1.305 raeburn 7068: 'statustocreate',$rowtotal);
1.224 raeburn 7069: $$rowtotal ++;
7070: }
7071: }
1.240 raeburn 7072: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
7073: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7074: $fieldtitles{'inststatus'} = &mt('Institutional status');
7075: my $rem;
7076: my $numperrow = 2;
7077: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
7078: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 7079: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 7080: '<td class="LC_left_item">'."\n".
1.334 raeburn 7081: '<table>'."\n";
1.240 raeburn 7082: for (my $i=0; $i<@fields; $i++) {
7083: $rem = $i%($numperrow);
7084: if ($rem == 0) {
7085: if ($i > 0) {
7086: $datatable .= '</tr>';
7087: }
7088: $datatable .= '<tr>';
7089: }
7090: my $currval;
1.248 raeburn 7091: if (ref($createsettings) eq 'HASH') {
7092: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
7093: $currval = $createsettings->{'shibenv'}{$fields[$i]};
7094: }
1.240 raeburn 7095: }
7096: $datatable .= '<td class="LC_left_item">'.
7097: '<span class="LC_nobreak">'.
7098: '<input type="text" name="shibenv_'.$fields[$i].'" '.
7099: 'value="'.$currval.'" size="10" /> '.
7100: $fieldtitles{$fields[$i]}.'</span></td>';
7101: }
7102: my $colsleft = $numperrow - $rem;
7103: if ($colsleft > 1 ) {
7104: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7105: ' </td>';
7106: } elsif ($colsleft == 1) {
7107: $datatable .= '<td class="LC_left_item"> </td>';
7108: }
7109: $datatable .= '</tr></table></td></tr>';
7110: $$rowtotal ++;
1.224 raeburn 7111: } elsif ($position eq 'middle') {
7112: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 7113: my @posstypes;
1.224 raeburn 7114: if (ref($types) eq 'ARRAY') {
1.302 raeburn 7115: @posstypes = @{$types};
7116: }
7117: unless (grep(/^default$/,@posstypes)) {
7118: push(@posstypes,'default');
7119: }
7120: my %usertypeshash;
7121: if (ref($usertypes) eq 'HASH') {
7122: %usertypeshash = %{$usertypes};
7123: }
7124: $usertypeshash{'default'} = $othertitle;
7125: foreach my $status (@posstypes) {
7126: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
7127: $numinrow,$$rowtotal,\%usertypeshash);
7128: $$rowtotal ++;
1.224 raeburn 7129: }
7130: } else {
1.236 raeburn 7131: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 7132: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 7133: );
7134: my @toggles = sort(keys(%choices));
7135: my %defaultchecked = (
7136: 'cancreate_email' => 'off',
7137: );
1.305 raeburn 7138: my $customclass = 'LC_selfcreate_email';
7139: my $classprefix = 'LC_canmodify_emailusername_';
7140: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 7141: my $display = 'none';
1.305 raeburn 7142: my $rowstyle = 'display:none';
1.236 raeburn 7143: if (grep(/^\Qemail\E$/,@selfcreate)) {
7144: $display = 'block';
1.305 raeburn 7145: $rowstyle = 'display:table-row';
1.236 raeburn 7146: }
1.305 raeburn 7147: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
7148: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7149: \%choices,$$rowtotal,$onclick);
7150: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
7151: $rowstyle);
7152: $$rowtotal ++;
7153: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
7154: $rowstyle);
7155: $$rowtotal ++;
7156: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 7157: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 7158: my ($emailrules,$emailruleorder) =
7159: &Apache::lonnet::inst_userrules($dom,'email');
7160: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7161: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7162: if (ref($types) eq 'ARRAY') {
7163: @posstypes = @{$types};
7164: }
7165: if (@posstypes) {
7166: unless (grep(/^default$/,@posstypes)) {
7167: push(@posstypes,'default');
1.302 raeburn 7168: }
7169: if (ref($usertypes) eq 'HASH') {
7170: %usertypeshash = %{$usertypes};
7171: }
1.305 raeburn 7172: my $currassign;
7173: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
7174: $currassign = {
7175: selfassign => $domdefaults{'inststatusguest'},
7176: };
7177: @ordered = @{$domdefaults{'inststatusguest'}};
7178: } else {
7179: $currassign = { selfassign => [] };
7180: }
7181: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
7182: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
7183: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
7184: $numinrow,$othertitle,'selfassign',
7185: $rowtotal,$onclicktypes,$customclass,
7186: $rowstyle);
7187: $$rowtotal ++;
1.302 raeburn 7188: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7189: foreach my $status (@posstypes) {
7190: my $css_class;
7191: if ($$rowtotal%2) {
7192: $css_class = 'LC_odd_row ';
7193: }
7194: $css_class .= $customclass;
7195: my $rowid = $optionsprefix.$status;
7196: my $hidden = 1;
7197: my $currstyle = 'display:none';
7198: if (grep(/^\Q$status\E$/,@ordered)) {
7199: $currstyle = $rowstyle;
7200: $hidden = 0;
7201: }
7202: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7203: $emailrules,$emailruleorder,$settings,$status,$rowid,
7204: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7205: unless ($hidden) {
7206: $$rowtotal ++;
7207: }
1.224 raeburn 7208: }
1.302 raeburn 7209: } else {
1.305 raeburn 7210: my $css_class;
7211: if ($$rowtotal%2) {
7212: $css_class = 'LC_odd_row ';
7213: }
7214: $css_class .= $customclass;
1.302 raeburn 7215: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7216: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7217: $emailrules,$emailruleorder,$settings,'default','',
7218: $othertitle,$css_class,$rowstyle,$intdom);
7219: $$rowtotal ++;
1.224 raeburn 7220: }
7221: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 7222: $numinrow = 1;
1.305 raeburn 7223: if (@posstypes) {
7224: foreach my $status (@posstypes) {
7225: my $rowid = $classprefix.$status;
7226: my $datarowstyle = 'display:none';
7227: if (grep(/^\Q$status\E$/,@ordered)) {
7228: $datarowstyle = $rowstyle;
7229: }
7230: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7231: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7232: $infotitles,$rowid,$customclass,$datarowstyle);
7233: unless ($datarowstyle eq 'display:none') {
7234: $$rowtotal ++;
7235: }
1.224 raeburn 7236: }
1.305 raeburn 7237: } else {
7238: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7239: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7240: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 7241: }
7242: }
7243: return $datatable;
7244: }
7245:
1.305 raeburn 7246: sub selfcreate_javascript {
7247: return <<"ENDSCRIPT";
7248:
7249: <script type="text/javascript">
7250: // <![CDATA[
7251:
7252: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7253: var x = document.getElementsByClassName(target);
7254: var insttypes = 0;
7255: var insttypeRegExp = new RegExp(prefix);
7256: if ((x.length != undefined) && (x.length > 0)) {
7257: if (form.elements[radio].length != undefined) {
7258: for (var i=0; i<form.elements[radio].length; i++) {
7259: if (form.elements[radio][i].checked) {
7260: if (form.elements[radio][i].value == 1) {
7261: for (var j=0; j<x.length; j++) {
7262: if (x[j].id == 'undefined') {
7263: x[j].style.display = 'table-row';
7264: } else if (insttypeRegExp.test(x[j].id)) {
7265: insttypes ++;
7266: } else {
7267: x[j].style.display = 'table-row';
7268: }
7269: }
7270: } else {
7271: for (var j=0; j<x.length; j++) {
7272: x[j].style.display = 'none';
7273: }
1.236 raeburn 7274: }
1.305 raeburn 7275: break;
7276: }
7277: }
7278: if (insttypes > 0) {
7279: toggleDataRow(form,checkbox,target,altprefix);
7280: toggleDataRow(form,checkbox,target,prefix,1);
7281: }
7282: }
7283: }
7284: return;
7285: }
7286:
7287: function toggleDataRow(form,checkbox,target,prefix,docount) {
7288: if (form.elements[checkbox].length != undefined) {
7289: var count = 0;
7290: if (docount) {
7291: for (var i=0; i<form.elements[checkbox].length; i++) {
7292: if (form.elements[checkbox][i].checked) {
7293: count ++;
1.236 raeburn 7294: }
1.305 raeburn 7295: }
7296: }
7297: for (var i=0; i<form.elements[checkbox].length; i++) {
7298: var type = form.elements[checkbox][i].value;
7299: if (document.getElementById(prefix+type)) {
7300: if (form.elements[checkbox][i].checked) {
7301: document.getElementById(prefix+type).style.display = 'table-row';
7302: if (count % 2 == 1) {
7303: document.getElementById(prefix+type).className = target+' LC_odd_row';
7304: } else {
7305: document.getElementById(prefix+type).className = target;
1.236 raeburn 7306: }
1.305 raeburn 7307: count ++;
1.236 raeburn 7308: } else {
1.305 raeburn 7309: document.getElementById(prefix+type).style.display = 'none';
7310: }
7311: }
7312: }
7313: }
7314: return;
7315: }
7316:
7317: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7318: var caller = radio+'_'+status;
7319: if (form.elements[caller].length != undefined) {
7320: for (var i=0; i<form.elements[caller].length; i++) {
7321: if (form.elements[caller][i].checked) {
7322: if (document.getElementById(altprefix+'_inst_'+status)) {
7323: var curr = form.elements[caller][i].value;
7324: if (prefix) {
7325: document.getElementById(prefix+'_'+status).style.display = 'none';
7326: }
7327: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7328: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7329: if (curr == 'custom') {
7330: if (prefix) {
7331: document.getElementById(prefix+'_'+status).style.display = 'inline';
7332: }
7333: } else if (curr == 'inst') {
7334: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7335: } else if (curr == 'noninst') {
7336: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 7337: }
1.305 raeburn 7338: break;
1.236 raeburn 7339: }
7340: }
7341: }
7342: }
7343: }
7344:
1.305 raeburn 7345: // ]]>
7346: </script>
7347:
7348: ENDSCRIPT
7349: }
7350:
7351: sub noninst_users {
7352: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7353: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7354: my $class = 'LC_left_item';
7355: if ($css_class) {
7356: $css_class = ' class="'.$css_class.'"';
7357: }
7358: if ($rowid) {
7359: $rowid = ' id="'.$rowid.'"';
7360: }
7361: if ($rowstyle) {
7362: $rowstyle = ' style="'.$rowstyle.'"';
7363: }
7364: my ($output,$description);
7365: if ($type eq 'default') {
7366: $description = &mt('Requests for: [_1]',$typetitle);
7367: } else {
7368: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7369: }
7370: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7371: "<td>$description</td>\n".
7372: '<td class="'.$class.'" colspan="2">'.
7373: '<table><tr>';
7374: my %headers = &Apache::lonlocal::texthash(
7375: approve => 'Processing',
7376: email => 'E-mail',
7377: username => 'Username',
7378: );
7379: foreach my $item ('approve','email','username') {
7380: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 7381: }
1.305 raeburn 7382: $output .= '</tr><tr>';
7383: foreach my $item ('approve','email','username') {
1.306 raeburn 7384: $output .= '<td style="vertical-align: top">';
1.305 raeburn 7385: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7386: if ($item eq 'approve') {
7387: %choices = &Apache::lonlocal::texthash (
7388: automatic => 'Automatically approved',
7389: approval => 'Queued for approval',
7390: );
7391: @options = ('automatic','approval');
7392: $hashref = $processing;
7393: $defoption = 'automatic';
7394: $name = 'cancreate_emailprocess_'.$type;
7395: } elsif ($item eq 'email') {
7396: %choices = &Apache::lonlocal::texthash (
7397: any => 'Any e-mail',
7398: inst => 'Institutional only',
7399: noninst => 'Non-institutional only',
7400: custom => 'Custom restrictions',
7401: );
7402: @options = ('any','inst','noninst');
7403: my $showcustom;
7404: if (ref($emailrules) eq 'HASH') {
7405: if (keys(%{$emailrules}) > 0) {
7406: push(@options,'custom');
7407: $showcustom = 'cancreate_emailrule';
7408: if (ref($settings) eq 'HASH') {
7409: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7410: foreach my $rule (@{$settings->{'email_rule'}}) {
7411: if (exists($emailrules->{$rule})) {
7412: $hascustom ++;
7413: }
7414: }
7415: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7416: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7417: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7418: if (exists($emailrules->{$rule})) {
7419: $hascustom ++;
7420: }
7421: }
7422: }
7423: }
7424: }
7425: }
7426: }
7427: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7428: "'cancreate_emaildomain','$type'".');"';
7429: $hashref = $emailoptions;
7430: $defoption = 'any';
7431: $name = 'cancreate_emailoptions_'.$type;
7432: } elsif ($item eq 'username') {
7433: %choices = &Apache::lonlocal::texthash (
7434: all => 'Same as e-mail',
7435: first => 'Omit @domain',
7436: free => 'Free to choose',
7437: );
7438: @options = ('all','first','free');
7439: $hashref = $emailverified;
7440: $defoption = 'all';
7441: $name = 'cancreate_usernameoptions_'.$type;
7442: }
7443: foreach my $option (@options) {
7444: my $checked;
7445: if (ref($hashref) eq 'HASH') {
7446: if ($type eq '') {
7447: if (!exists($hashref->{'default'})) {
7448: if ($option eq $defoption) {
7449: $checked = ' checked="checked"';
7450: }
7451: } else {
7452: if ($hashref->{'default'} eq $option) {
7453: $checked = ' checked="checked"';
7454: }
1.303 raeburn 7455: }
7456: } else {
1.305 raeburn 7457: if (!exists($hashref->{$type})) {
7458: if ($option eq $defoption) {
7459: $checked = ' checked="checked"';
7460: }
7461: } else {
7462: if ($hashref->{$type} eq $option) {
7463: $checked = ' checked="checked"';
7464: }
1.303 raeburn 7465: }
7466: }
1.305 raeburn 7467: } elsif (($item eq 'email') && ($hascustom)) {
7468: if ($option eq 'custom') {
7469: $checked = ' checked="checked"';
7470: }
7471: } elsif ($option eq $defoption) {
7472: $checked = ' checked="checked"';
7473: }
7474: $output .= '<span class="LC_nobreak"><label>'.
7475: '<input type="radio" name="'.$name.'"'.
7476: $checked.' value="'.$option.'"'.$onclick.' />'.
7477: $choices{$option}.'</label></span><br />';
7478: if ($item eq 'email') {
7479: if ($option eq 'custom') {
7480: my $id = 'cancreate_emailrule_'.$type;
7481: my $display = 'none';
7482: if ($checked) {
7483: $display = 'inline';
1.303 raeburn 7484: }
1.305 raeburn 7485: my $numinrow = 2;
7486: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7487: '<legend>'.&mt('Disallow').'</legend><table>'.
7488: &user_formats_row('email',$settings,$emailrules,
7489: $emailruleorder,$numinrow,'',$type);
7490: '</table></fieldset>';
7491: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7492: my %text = &Apache::lonlocal::texthash (
7493: inst => 'must end:',
7494: noninst => 'cannot end:',
7495: );
7496: my $value;
7497: if (ref($emaildomain) eq 'HASH') {
7498: if (ref($emaildomain->{$type}) eq 'HASH') {
7499: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 7500: }
7501: }
1.305 raeburn 7502: if ($value eq '') {
7503: $value = '@'.$intdom;
7504: }
7505: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7506: my $display = 'none';
7507: if ($checked) {
7508: $display = 'inline';
7509: }
7510: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7511: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7512: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7513: '</div>';
1.303 raeburn 7514: }
7515: }
7516: }
1.305 raeburn 7517: $output .= '</td>'."\n";
1.303 raeburn 7518: }
1.305 raeburn 7519: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 7520: return $output;
7521: }
7522:
1.165 raeburn 7523: sub captcha_choice {
1.305 raeburn 7524: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 7525: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7526: $vertext,$currver);
1.165 raeburn 7527: my %lt = &captcha_phrases();
7528: $keyentry = 'hidden';
7529: if ($context eq 'cancreate') {
1.224 raeburn 7530: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 7531: } elsif ($context eq 'login') {
7532: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 7533: }
7534: if (ref($settings) eq 'HASH') {
7535: if ($settings->{'captcha'}) {
7536: $checked{$settings->{'captcha'}} = ' checked="checked"';
7537: } else {
7538: $checked{'original'} = ' checked="checked"';
7539: }
7540: if ($settings->{'captcha'} eq 'recaptcha') {
7541: $pubtext = $lt{'pub'};
7542: $privtext = $lt{'priv'};
7543: $keyentry = 'text';
1.269 raeburn 7544: $vertext = $lt{'ver'};
7545: $currver = $settings->{'recaptchaversion'};
7546: if ($currver ne '2') {
7547: $currver = 1;
7548: }
1.165 raeburn 7549: }
7550: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7551: $currpub = $settings->{'recaptchakeys'}{'public'};
7552: $currpriv = $settings->{'recaptchakeys'}{'private'};
7553: }
7554: } else {
7555: $checked{'original'} = ' checked="checked"';
7556: }
1.305 raeburn 7557: my $css_class;
7558: if ($itemcount%2) {
7559: $css_class = 'LC_odd_row';
7560: }
7561: if ($customcss) {
7562: $css_class .= " $customcss";
7563: }
7564: $css_class =~ s/^\s+//;
7565: if ($css_class) {
7566: $css_class = ' class="'.$css_class.'"';
7567: }
7568: if ($rowstyle) {
7569: $css_class .= ' style="'.$rowstyle.'"';
7570: }
1.169 raeburn 7571: my $output = '<tr'.$css_class.'>'.
7572: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 7573: '<table><tr><td>'."\n";
7574: foreach my $option ('original','recaptcha','notused') {
7575: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7576: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7577: $lt{$option}.'</label></span>';
7578: unless ($option eq 'notused') {
7579: $output .= (' 'x2)."\n";
7580: }
7581: }
7582: #
7583: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7584: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 7585: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 7586: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 7587: #
1.165 raeburn 7588: $output .= '</td></tr>'."\n".
1.305 raeburn 7589: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 7590: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7591: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7592: $currpub.'" size="40" /></span><br />'."\n".
7593: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7594: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 7595: $currpriv.'" size="40" /></span><br />'.
7596: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7597: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7598: $currver.'" size="3" /></span><br />'.
7599: '</td></tr></table>'."\n".
1.165 raeburn 7600: '</td></tr>';
7601: return $output;
7602: }
7603:
1.32 raeburn 7604: sub user_formats_row {
1.305 raeburn 7605: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7606: my $output;
7607: my %text = (
7608: 'username' => 'new usernames',
7609: 'id' => 'IDs',
7610: );
1.305 raeburn 7611: unless ($type eq 'email') {
7612: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7613: $output = '<tr '.$css_class.'>'.
7614: '<td><span class="LC_nobreak">'.
7615: &mt("Format rules to check for $text{$type}: ").
7616: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7617: }
1.27 raeburn 7618: my $rem;
7619: if (ref($ruleorder) eq 'ARRAY') {
7620: for (my $i=0; $i<@{$ruleorder}; $i++) {
7621: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7622: my $rem = $i%($numinrow);
7623: if ($rem == 0) {
7624: if ($i > 0) {
7625: $output .= '</tr>';
7626: }
7627: $output .= '<tr>';
7628: }
7629: my $check = ' ';
1.39 raeburn 7630: if (ref($settings) eq 'HASH') {
7631: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7632: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7633: $check = ' checked="checked" ';
7634: }
1.305 raeburn 7635: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7636: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7637: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7638: $check = ' checked="checked" ';
7639: }
7640: }
1.27 raeburn 7641: }
7642: }
1.305 raeburn 7643: my $name = $type.'_rule';
7644: if ($type eq 'email') {
7645: $name .= '_'.$status;
7646: }
1.27 raeburn 7647: $output .= '<td class="LC_left_item">'.
7648: '<span class="LC_nobreak"><label>'.
1.311 raeburn 7649: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7650: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7651: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7652: }
7653: }
7654: $rem = @{$ruleorder}%($numinrow);
7655: }
1.305 raeburn 7656: my $colsleft;
7657: if ($rem) {
7658: $colsleft = $numinrow - $rem;
7659: }
1.27 raeburn 7660: if ($colsleft > 1 ) {
7661: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7662: ' </td>';
7663: } elsif ($colsleft == 1) {
7664: $output .= '<td class="LC_left_item"> </td>';
7665: }
1.305 raeburn 7666: $output .= '</tr></table>';
7667: unless ($type eq 'email') {
7668: $output .= '</td></tr>';
7669: }
1.27 raeburn 7670: return $output;
7671: }
7672:
1.34 raeburn 7673: sub usercreation_types {
7674: my %lt = &Apache::lonlocal::texthash (
7675: author => 'When adding a co-author',
7676: course => 'When adding a user to a course',
1.100 raeburn 7677: requestcrs => 'When requesting a course',
1.34 raeburn 7678: any => 'Any',
7679: official => 'Institutional only ',
7680: unofficial => 'Non-institutional only',
7681: none => 'None',
7682: );
7683: return %lt;
1.48 raeburn 7684: }
1.34 raeburn 7685:
1.224 raeburn 7686: sub selfcreation_types {
7687: my %lt = &Apache::lonlocal::texthash (
7688: selfcreate => 'User creates own account',
7689: any => 'Any',
7690: official => 'Institutional only ',
7691: unofficial => 'Non-institutional only',
7692: email => 'E-mail address',
7693: login => 'Institutional Login',
7694: sso => 'SSO',
7695: );
7696: }
7697:
1.28 raeburn 7698: sub authtype_names {
7699: my %lt = &Apache::lonlocal::texthash(
7700: int => 'Internal',
7701: krb4 => 'Kerberos 4',
7702: krb5 => 'Kerberos 5',
7703: loc => 'Local',
1.325 raeburn 7704: lti => 'LTI',
1.28 raeburn 7705: );
7706: return %lt;
7707: }
7708:
7709: sub context_names {
7710: my %context_title = &Apache::lonlocal::texthash(
7711: author => 'Creating users when an Author',
7712: course => 'Creating users when in a course',
7713: domain => 'Creating users when a Domain Coordinator',
7714: );
7715: return %context_title;
7716: }
7717:
1.33 raeburn 7718: sub print_usermodification {
7719: my ($position,$dom,$settings,$rowtotal) = @_;
7720: my $numinrow = 4;
7721: my ($context,$datatable,$rowcount);
7722: if ($position eq 'top') {
7723: $rowcount = 0;
7724: $context = 'author';
7725: foreach my $role ('ca','aa') {
7726: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7727: $numinrow,$rowcount);
7728: $$rowtotal ++;
7729: $rowcount ++;
7730: }
1.230 raeburn 7731: } elsif ($position eq 'bottom') {
1.33 raeburn 7732: $context = 'course';
7733: $rowcount = 0;
7734: foreach my $role ('st','ep','ta','in','cr') {
7735: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7736: $numinrow,$rowcount);
7737: $$rowtotal ++;
7738: $rowcount ++;
7739: }
7740: }
7741: return $datatable;
7742: }
7743:
1.43 raeburn 7744: sub print_defaults {
1.236 raeburn 7745: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7746: my $rownum = 0;
1.294 raeburn 7747: my ($datatable,$css_class,$titles);
7748: unless ($position eq 'bottom') {
7749: $titles = &defaults_titles($dom);
7750: }
1.236 raeburn 7751: if ($position eq 'top') {
7752: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7753: 'datelocale_def','portal_def');
7754: my %defaults;
7755: if (ref($settings) eq 'HASH') {
7756: %defaults = %{$settings};
1.43 raeburn 7757: } else {
1.236 raeburn 7758: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7759: foreach my $item (@items) {
7760: $defaults{$item} = $domdefaults{$item};
7761: }
1.43 raeburn 7762: }
1.236 raeburn 7763: foreach my $item (@items) {
7764: if ($rownum%2) {
7765: $css_class = '';
7766: } else {
7767: $css_class = ' class="LC_odd_row" ';
7768: }
7769: $datatable .= '<tr'.$css_class.'>'.
7770: '<td><span class="LC_nobreak">'.$titles->{$item}.
7771: '</span></td><td class="LC_right_item" colspan="3">';
7772: if ($item eq 'auth_def') {
1.325 raeburn 7773: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 7774: my %shortauth = (
7775: internal => 'int',
7776: krb4 => 'krb4',
7777: krb5 => 'krb5',
1.325 raeburn 7778: localauth => 'loc',
7779: lti => 'lti',
1.236 raeburn 7780: );
7781: my %authnames = &authtype_names();
7782: foreach my $auth (@authtypes) {
7783: my $checked = ' ';
7784: if ($defaults{$item} eq $auth) {
7785: $checked = ' checked="checked" ';
7786: }
7787: $datatable .= '<label><input type="radio" name="'.$item.
7788: '" value="'.$auth.'"'.$checked.'/>'.
7789: $authnames{$shortauth{$auth}}.'</label> ';
7790: }
7791: } elsif ($item eq 'timezone_def') {
7792: my $includeempty = 1;
7793: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7794: } elsif ($item eq 'datelocale_def') {
7795: my $includeempty = 1;
7796: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7797: } elsif ($item eq 'lang_def') {
1.263 raeburn 7798: my $includeempty = 1;
7799: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 7800: } else {
7801: my $size;
7802: if ($item eq 'portal_def') {
7803: $size = ' size="25"';
7804: }
7805: $datatable .= '<input type="text" name="'.$item.'" value="'.
7806: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 7807: }
1.236 raeburn 7808: $datatable .= '</td></tr>';
7809: $rownum ++;
7810: }
1.294 raeburn 7811: } elsif ($position eq 'middle') {
7812: my @items = ('intauth_cost','intauth_check','intauth_switch');
7813: my %defaults;
7814: if (ref($settings) eq 'HASH') {
7815: %defaults = %{$settings};
7816: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7817: $defaults{'intauth_cost'} = 10;
7818: }
7819: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7820: $defaults{'intauth_check'} = 0;
7821: }
7822: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7823: $defaults{'intauth_switch'} = 0;
7824: }
7825: } else {
7826: %defaults = (
7827: 'intauth_cost' => 10,
7828: 'intauth_check' => 0,
7829: 'intauth_switch' => 0,
7830: );
7831: }
7832: foreach my $item (@items) {
7833: if ($rownum%2) {
7834: $css_class = '';
7835: } else {
7836: $css_class = ' class="LC_odd_row" ';
7837: }
7838: $datatable .= '<tr'.$css_class.'>'.
7839: '<td><span class="LC_nobreak">'.$titles->{$item}.
7840: '</span></td><td class="LC_left_item" colspan="3">';
7841: if ($item eq 'intauth_switch') {
7842: my @options = (0,1,2);
7843: my %optiondesc = &Apache::lonlocal::texthash (
7844: 0 => 'No',
7845: 1 => 'Yes',
7846: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7847: );
7848: $datatable .= '<table width="100%">';
7849: foreach my $option (@options) {
7850: my $checked = ' ';
7851: if ($defaults{$item} eq $option) {
7852: $checked = ' checked="checked"';
7853: }
7854: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7855: '<label><input type="radio" name="'.$item.
7856: '" value="'.$option.'"'.$checked.' />'.
7857: $optiondesc{$option}.'</label></span></td></tr>';
7858: }
7859: $datatable .= '</table>';
7860: } elsif ($item eq 'intauth_check') {
7861: my @options = (0,1,2);
7862: my %optiondesc = &Apache::lonlocal::texthash (
7863: 0 => 'No',
7864: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7865: 2 => 'Yes, disallow login if stored cost is less than domain default',
7866: );
1.332 raeburn 7867: $datatable .= '<table width="100%">';
1.294 raeburn 7868: foreach my $option (@options) {
7869: my $checked = ' ';
7870: my $onclick;
7871: if ($defaults{$item} eq $option) {
7872: $checked = ' checked="checked"';
7873: }
7874: if ($option == 2) {
7875: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7876: }
7877: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7878: '<label><input type="radio" name="'.$item.
7879: '" value="'.$option.'"'.$checked.$onclick.' />'.
7880: $optiondesc{$option}.'</label></span></td></tr>';
7881: }
7882: $datatable .= '</table>';
7883: } else {
7884: $datatable .= '<input type="text" name="'.$item.'" value="'.
7885: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7886: }
7887: $datatable .= '</td></tr>';
7888: $rownum ++;
7889: }
1.236 raeburn 7890: } else {
1.294 raeburn 7891: my %defaults;
1.236 raeburn 7892: if (ref($settings) eq 'HASH') {
1.305 raeburn 7893: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.236 raeburn 7894: my $maxnum = @{$settings->{'inststatusorder'}};
7895: for (my $i=0; $i<$maxnum; $i++) {
7896: $css_class = $rownum%2?' class="LC_odd_row"':'';
7897: my $item = $settings->{'inststatusorder'}->[$i];
7898: my $title = $settings->{'inststatustypes'}->{$item};
7899: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7900: $datatable .= '<tr'.$css_class.'>'.
7901: '<td><span class="LC_nobreak">'.
7902: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7903: for (my $k=0; $k<=$maxnum; $k++) {
7904: my $vpos = $k+1;
7905: my $selstr;
7906: if ($k == $i) {
7907: $selstr = ' selected="selected" ';
7908: }
7909: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7910: }
7911: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7912: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7913: &mt('delete').'</span></td>'.
1.305 raeburn 7914: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.236 raeburn 7915: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.305 raeburn 7916: '</span></td></tr>';
1.236 raeburn 7917: }
7918: $css_class = $rownum%2?' class="LC_odd_row"':'';
7919: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7920: $datatable .= '<tr '.$css_class.'>'.
7921: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7922: for (my $k=0; $k<=$maxnum; $k++) {
7923: my $vpos = $k+1;
7924: my $selstr;
7925: if ($k == $maxnum) {
7926: $selstr = ' selected="selected" ';
7927: }
7928: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7929: }
7930: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 7931: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 7932: ' '.&mt('(new)').
1.305 raeburn 7933: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.236 raeburn 7934: &mt('Name displayed:').
7935: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7936: '</tr>'."\n";
7937: $rownum ++;
1.141 raeburn 7938: }
1.43 raeburn 7939: }
7940: }
7941: $$rowtotal += $rownum;
7942: return $datatable;
7943: }
7944:
1.168 raeburn 7945: sub get_languages_hash {
7946: my %langchoices;
7947: foreach my $id (&Apache::loncommon::languageids()) {
7948: my $code = &Apache::loncommon::supportedlanguagecode($id);
7949: if ($code ne '') {
7950: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7951: }
7952: }
7953: return %langchoices;
7954: }
7955:
1.43 raeburn 7956: sub defaults_titles {
1.141 raeburn 7957: my ($dom) = @_;
1.43 raeburn 7958: my %titles = &Apache::lonlocal::texthash (
7959: 'auth_def' => 'Default authentication type',
7960: 'auth_arg_def' => 'Default authentication argument',
7961: 'lang_def' => 'Default language',
1.54 raeburn 7962: 'timezone_def' => 'Default timezone',
1.68 raeburn 7963: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7964: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 7965: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7966: 'intauth_check' => 'Check bcrypt cost if authenticated',
7967: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7968: );
1.141 raeburn 7969: if ($dom) {
7970: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7971: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7972: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7973: $protocol = 'http' if ($protocol ne 'https');
7974: if ($uint_dom) {
7975: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7976: $uint_dom);
7977: }
7978: }
1.43 raeburn 7979: return (\%titles);
7980: }
7981:
1.346 raeburn 7982: sub print_scantron {
7983: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
7984: if ($position eq 'top') {
7985: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
7986: } else {
7987: return &print_scantronconfig($dom,$settings,\$rowtotal);
7988: }
7989: }
7990:
7991: sub scantron_javascript {
7992: return <<"ENDSCRIPT";
7993:
7994: <script type="text/javascript">
7995: // <![CDATA[
7996:
7997: function toggleScantron(form) {
1.347 raeburn 7998: var csvfieldset = new Array();
1.346 raeburn 7999: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 8000: csvfieldset.push(document.getElementById('scantroncsv_cols'));
8001: }
8002: if (document.getElementById('scantroncsv_options')) {
8003: csvfieldset.push(document.getElementById('scantroncsv_options'));
8004: }
8005: if (csvfieldset.length) {
1.346 raeburn 8006: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 8007: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 8008: if (scantroncsv.checked) {
1.347 raeburn 8009: for (var i=0; i<csvfieldset.length; i++) {
8010: csvfieldset[i].style.display = 'block';
8011: }
1.346 raeburn 8012: } else {
1.347 raeburn 8013: for (var i=0; i<csvfieldset.length; i++) {
8014: csvfieldset[i].style.display = 'none';
8015: }
1.346 raeburn 8016: var csvselects = document.getElementsByClassName('scantronconfig_csv');
8017: if (csvselects.length) {
8018: for (var j=0; j<csvselects.length; j++) {
8019: csvselects[j].selectedIndex = 0;
8020: }
8021: }
8022: }
8023: }
8024: }
8025: return;
8026: }
8027: // ]]>
8028: </script>
8029:
8030: ENDSCRIPT
8031:
8032: }
8033:
1.46 raeburn 8034: sub print_scantronformat {
8035: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
8036: my $itemcount = 1;
1.60 raeburn 8037: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
8038: %confhash);
1.46 raeburn 8039: my $switchserver = &check_switchserver($dom,$confname);
8040: my %lt = &Apache::lonlocal::texthash (
1.95 www 8041: default => 'Default bubblesheet format file error',
8042: custom => 'Custom bubblesheet format file error',
1.46 raeburn 8043: );
8044: my %scantronfiles = (
8045: default => 'default.tab',
8046: custom => 'custom.tab',
8047: );
8048: foreach my $key (keys(%scantronfiles)) {
8049: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
8050: .$scantronfiles{$key};
8051: }
8052: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
8053: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
8054: if (!$switchserver) {
8055: my $servadm = $r->dir_config('lonAdmEMail');
8056: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
8057: if ($configuserok eq 'ok') {
8058: if ($author_ok eq 'ok') {
8059: my %legacyfile = (
1.346 raeburn 8060: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
8061: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 8062: );
8063: my %md5chk;
8064: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 8065: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
8066: chomp($md5chk{$type});
1.46 raeburn 8067: }
8068: if ($md5chk{'default'} ne $md5chk{'custom'}) {
8069: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 8070: ($scantronurls{$type},my $error) =
1.46 raeburn 8071: &legacy_scantronformat($r,$dom,$confname,
8072: $type,$legacyfile{$type},
8073: $scantronurls{$type},
8074: $scantronfiles{$type});
1.60 raeburn 8075: if ($error ne '') {
8076: $error{$type} = $error;
8077: }
8078: }
8079: if (keys(%error) == 0) {
8080: $is_custom = 1;
1.346 raeburn 8081: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 8082: $scantronurls{'custom'};
1.346 raeburn 8083: my $putresult =
1.60 raeburn 8084: &Apache::lonnet::put_dom('configuration',
8085: \%confhash,$dom);
8086: if ($putresult ne 'ok') {
1.346 raeburn 8087: $error{'custom'} =
1.60 raeburn 8088: '<span class="LC_error">'.
8089: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8090: }
1.46 raeburn 8091: }
8092: } else {
1.60 raeburn 8093: ($scantronurls{'default'},my $error) =
1.46 raeburn 8094: &legacy_scantronformat($r,$dom,$confname,
8095: 'default',$legacyfile{'default'},
8096: $scantronurls{'default'},
8097: $scantronfiles{'default'});
1.60 raeburn 8098: if ($error eq '') {
8099: $confhash{'scantron'}{'scantronformat'} = '';
8100: my $putresult =
8101: &Apache::lonnet::put_dom('configuration',
8102: \%confhash,$dom);
8103: if ($putresult ne 'ok') {
8104: $error{'default'} =
8105: '<span class="LC_error">'.
8106: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8107: }
8108: } else {
8109: $error{'default'} = $error;
8110: }
1.46 raeburn 8111: }
8112: }
8113: }
8114: } else {
1.95 www 8115: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 8116: }
8117: }
8118: if (ref($settings) eq 'HASH') {
8119: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
8120: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
8121: if ((!@info) || ($info[0] eq 'no_such_dir')) {
8122: $scantronurl = '';
8123: } else {
8124: $scantronurl = $settings->{'scantronformat'};
8125: }
8126: $is_custom = 1;
8127: } else {
8128: $scantronurl = $scantronurls{'default'};
8129: }
8130: } else {
1.60 raeburn 8131: if ($is_custom) {
8132: $scantronurl = $scantronurls{'custom'};
8133: } else {
8134: $scantronurl = $scantronurls{'default'};
8135: }
1.46 raeburn 8136: }
8137: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8138: $datatable .= '<tr'.$css_class.'>';
8139: if (!$is_custom) {
1.65 raeburn 8140: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
8141: '<span class="LC_nobreak">';
1.46 raeburn 8142: if ($scantronurl) {
1.199 raeburn 8143: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
8144: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 8145: } else {
8146: $datatable = &mt('File unavailable for display');
8147: }
1.65 raeburn 8148: $datatable .= '</span></td>';
1.60 raeburn 8149: if (keys(%error) == 0) {
1.306 raeburn 8150: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 8151: if (!$switchserver) {
8152: $datatable .= &mt('Upload:').'<br />';
8153: }
8154: } else {
8155: my $errorstr;
8156: foreach my $key (sort(keys(%error))) {
8157: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8158: }
8159: $datatable .= '<td>'.$errorstr;
8160: }
1.46 raeburn 8161: } else {
8162: if (keys(%error) > 0) {
8163: my $errorstr;
8164: foreach my $key (sort(keys(%error))) {
8165: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8166: }
1.60 raeburn 8167: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 8168: } elsif ($scantronurl) {
1.199 raeburn 8169: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
8170: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 8171: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 8172: $link.
8173: '<label><input type="checkbox" name="scantronformat_del"'.
8174: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 8175: '<td><span class="LC_nobreak"> '.
8176: &mt('Replace:').'</span><br />';
1.46 raeburn 8177: }
8178: }
8179: if (keys(%error) == 0) {
8180: if ($switchserver) {
8181: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
8182: } else {
1.65 raeburn 8183: $datatable .='<span class="LC_nobreak"> '.
8184: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 8185: }
8186: }
8187: $datatable .= '</td></tr>';
8188: $$rowtotal ++;
8189: return $datatable;
8190: }
8191:
8192: sub legacy_scantronformat {
8193: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
8194: my ($url,$error);
8195: my @statinfo = &Apache::lonnet::stat_file($newurl);
8196: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
8197: (my $result,$url) =
8198: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
8199: '','',$newfile);
8200: if ($result ne 'ok') {
1.130 raeburn 8201: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 8202: }
8203: }
8204: return ($url,$error);
8205: }
1.43 raeburn 8206:
1.346 raeburn 8207: sub print_scantronconfig {
8208: my ($dom,$settings,$rowtotal) = @_;
8209: my $itemcount = 2;
8210: my $is_checked = ' checked="checked"';
1.347 raeburn 8211: my %optionson = (
8212: hdr => ' checked="checked"',
8213: pad => ' checked="checked"',
8214: rem => ' checked="checked"',
8215: );
8216: my %optionsoff = (
8217: hdr => '',
8218: pad => '',
8219: rem => '',
8220: );
1.346 raeburn 8221: my $currcsvsty = 'none';
1.347 raeburn 8222: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 8223: my @fields = &scantroncsv_fields();
8224: my %titles = &scantronconfig_titles();
8225: if (ref($settings) eq 'HASH') {
8226: if (ref($settings->{config}) eq 'HASH') {
8227: if ($settings->{config}->{dat}) {
8228: $checked{'dat'} = $is_checked;
8229: }
8230: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 8231: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
8232: %csvfields = %{$settings->{config}->{csv}->{fields}};
8233: if (keys(%csvfields) > 0) {
8234: $checked{'csv'} = $is_checked;
8235: $currcsvsty = 'block';
8236: }
8237: }
8238: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
8239: %csvoptions = %{$settings->{config}->{csv}->{options}};
8240: foreach my $option (keys(%optionson)) {
8241: unless ($csvoptions{$option}) {
8242: $optionsoff{$option} = $optionson{$option};
8243: $optionson{$option} = '';
8244: }
8245: }
1.346 raeburn 8246: }
8247: }
8248: } else {
8249: $checked{'dat'} = $is_checked;
8250: }
8251: } else {
8252: $checked{'dat'} = $is_checked;
8253: }
8254: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8255: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8256: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8257: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8258: foreach my $item ('dat','csv') {
8259: my $id;
8260: if ($item eq 'csv') {
8261: $id = 'id="scantronconfcsv" ';
1.347 raeburn 8262: }
1.346 raeburn 8263: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8264: $titles{$item}.'</label>'.(' 'x3);
8265: if ($item eq 'csv') {
8266: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8267: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8268: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8269: foreach my $col (@fields) {
8270: my $selnone;
8271: if ($csvfields{$col} eq '') {
8272: $selnone = ' selected="selected"';
8273: }
8274: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8275: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8276: '<option value=""'.$selnone.'></option>';
8277: for (my $i=0; $i<20; $i++) {
8278: my $shown = $i+1;
8279: my $sel;
8280: unless ($selnone) {
8281: if (exists($csvfields{$col})) {
8282: if ($csvfields{$col} == $i) {
8283: $sel = ' selected="selected"';
8284: }
8285: }
8286: }
8287: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8288: }
8289: $datatable .= '</select></td></tr>';
8290: }
1.347 raeburn 8291: $datatable .= '</table></fieldset>'.
8292: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
8293: '<legend>'.&mt('CSV Options').'</legend>';
8294: foreach my $option ('hdr','pad','rem') {
8295: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
8296: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
8297: &mt('Yes').'</label>'.(' 'x2)."\n".
8298: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
8299: }
8300: $datatable .= '</fieldset>';
1.346 raeburn 8301: $itemcount ++;
8302: }
8303: }
8304: $datatable .= '</td></tr>';
8305: $$rowtotal ++;
8306: return $datatable;
8307: }
8308:
8309: sub scantronconfig_titles {
8310: return &Apache::lonlocal::texthash(
8311: dat => 'Standard format (.dat)',
8312: csv => 'Comma separated values (.csv)',
1.347 raeburn 8313: hdr => 'Remove first line in file (contains column titles)',
8314: pad => 'Prepend 0s to PaperID',
1.348 raeburn 8315: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 8316: CODE => 'CODE',
8317: ID => 'Student ID',
8318: PaperID => 'Paper ID',
8319: FirstName => 'First Name',
8320: LastName => 'Last Name',
8321: FirstQuestion => 'First Question Response',
8322: Section => 'Section',
8323: );
8324: }
8325:
8326: sub scantroncsv_fields {
8327: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
8328: }
8329:
1.49 raeburn 8330: sub print_coursecategories {
1.57 raeburn 8331: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8332: my $datatable;
8333: if ($position eq 'top') {
1.238 raeburn 8334: my (%checked);
8335: my @catitems = ('unauth','auth');
8336: my @cattypes = ('std','domonly','codesrch','none');
8337: $checked{'unauth'} = 'std';
8338: $checked{'auth'} = 'std';
8339: if (ref($settings) eq 'HASH') {
8340: foreach my $type (@cattypes) {
8341: if ($type eq $settings->{'unauth'}) {
8342: $checked{'unauth'} = $type;
8343: }
8344: if ($type eq $settings->{'auth'}) {
8345: $checked{'auth'} = $type;
8346: }
8347: }
8348: }
8349: my %lt = &Apache::lonlocal::texthash (
8350: unauth => 'Catalog type for unauthenticated users',
8351: auth => 'Catalog type for authenticated users',
8352: none => 'No catalog',
8353: std => 'Standard catalog',
8354: domonly => 'Domain-only catalog',
8355: codesrch => "Code search form",
8356: );
8357: my $itemcount = 0;
8358: foreach my $item (@catitems) {
8359: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8360: $datatable .= '<tr '.$css_class.'>'.
8361: '<td>'.$lt{$item}.'</td>'.
8362: '<td class="LC_right_item"><span class="LC_nobreak">';
8363: foreach my $type (@cattypes) {
8364: my $ischecked;
8365: if ($checked{$item} eq $type) {
8366: $ischecked=' checked="checked"';
8367: }
8368: $datatable .= '<label>'.
8369: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8370: ' />'.$lt{$type}.'</label> ';
8371: }
1.327 raeburn 8372: $datatable .= '</span></td></tr>';
1.238 raeburn 8373: $itemcount ++;
8374: }
8375: $$rowtotal += $itemcount;
8376: } elsif ($position eq 'middle') {
1.57 raeburn 8377: my $toggle_cats_crs = ' ';
8378: my $toggle_cats_dom = ' checked="checked" ';
8379: my $can_cat_crs = ' ';
8380: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8381: my $toggle_catscomm_comm = ' ';
8382: my $toggle_catscomm_dom = ' checked="checked" ';
8383: my $can_catcomm_comm = ' ';
8384: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 8385: my $toggle_catsplace_place = ' ';
8386: my $toggle_catsplace_dom = ' checked="checked" ';
8387: my $can_catplace_place = ' ';
8388: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 8389:
1.57 raeburn 8390: if (ref($settings) eq 'HASH') {
8391: if ($settings->{'togglecats'} eq 'crs') {
8392: $toggle_cats_crs = $toggle_cats_dom;
8393: $toggle_cats_dom = ' ';
8394: }
8395: if ($settings->{'categorize'} eq 'crs') {
8396: $can_cat_crs = $can_cat_dom;
8397: $can_cat_dom = ' ';
8398: }
1.120 raeburn 8399: if ($settings->{'togglecatscomm'} eq 'comm') {
8400: $toggle_catscomm_comm = $toggle_catscomm_dom;
8401: $toggle_catscomm_dom = ' ';
8402: }
8403: if ($settings->{'categorizecomm'} eq 'comm') {
8404: $can_catcomm_comm = $can_catcomm_dom;
8405: $can_catcomm_dom = ' ';
8406: }
1.272 raeburn 8407: if ($settings->{'togglecatsplace'} eq 'place') {
8408: $toggle_catsplace_place = $toggle_catsplace_dom;
8409: $toggle_catsplace_dom = ' ';
8410: }
8411: if ($settings->{'categorizeplace'} eq 'place') {
8412: $can_catplace_place = $can_catplace_dom;
8413: $can_catplace_dom = ' ';
8414: }
1.57 raeburn 8415: }
8416: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 8417: togglecats => 'Show/Hide a course in catalog',
8418: togglecatscomm => 'Show/Hide a community in catalog',
8419: togglecatsplace => 'Show/Hide a placement test in catalog',
8420: categorize => 'Assign a category to a course',
8421: categorizecomm => 'Assign a category to a community',
8422: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 8423: );
8424: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 8425: dom => 'Set in Domain',
8426: crs => 'Set in Course',
8427: comm => 'Set in Community',
8428: place => 'Set in Placement Test',
1.57 raeburn 8429: );
8430: $datatable = '<tr class="LC_odd_row">'.
8431: '<td>'.$title{'togglecats'}.'</td>'.
8432: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8433: '<input type="radio" name="togglecats"'.
8434: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8435: '<label><input type="radio" name="togglecats"'.
8436: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8437: '</tr><tr>'.
8438: '<td>'.$title{'categorize'}.'</td>'.
8439: '<td class="LC_right_item"><span class="LC_nobreak">'.
8440: '<label><input type="radio" name="categorize"'.
8441: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8442: '<label><input type="radio" name="categorize"'.
8443: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8444: '</tr><tr class="LC_odd_row">'.
8445: '<td>'.$title{'togglecatscomm'}.'</td>'.
8446: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8447: '<input type="radio" name="togglecatscomm"'.
8448: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8449: '<label><input type="radio" name="togglecatscomm"'.
8450: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8451: '</tr><tr>'.
8452: '<td>'.$title{'categorizecomm'}.'</td>'.
8453: '<td class="LC_right_item"><span class="LC_nobreak">'.
8454: '<label><input type="radio" name="categorizecomm"'.
8455: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8456: '<label><input type="radio" name="categorizecomm"'.
8457: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 8458: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 8459: '<td>'.$title{'togglecatsplace'}.'</td>'.
8460: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8461: '<input type="radio" name="togglecatsplace"'.
8462: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8463: '<label><input type="radio" name="togglecatscomm"'.
8464: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
8465: '</tr><tr>'.
8466: '<td>'.$title{'categorizeplace'}.'</td>'.
8467: '<td class="LC_right_item"><span class="LC_nobreak">'.
8468: '<label><input type="radio" name="categorizeplace"'.
8469: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8470: '<label><input type="radio" name="categorizeplace"'.
8471: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 8472: '</tr>';
1.272 raeburn 8473: $$rowtotal += 6;
1.57 raeburn 8474: } else {
8475: my $css_class;
8476: my $itemcount = 1;
8477: my $cathash;
8478: if (ref($settings) eq 'HASH') {
8479: $cathash = $settings->{'cats'};
8480: }
8481: if (ref($cathash) eq 'HASH') {
8482: my (@cats,@trails,%allitems,%idx,@jsarray);
8483: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8484: \%allitems,\%idx,\@jsarray);
8485: my $maxdepth = scalar(@cats);
8486: my $colattrib = '';
8487: if ($maxdepth > 2) {
8488: $colattrib = ' colspan="2" ';
8489: }
8490: my @path;
8491: if (@cats > 0) {
8492: if (ref($cats[0]) eq 'ARRAY') {
8493: my $numtop = @{$cats[0]};
8494: my $maxnum = $numtop;
1.120 raeburn 8495: my %default_names = (
8496: instcode => &mt('Official courses'),
8497: communities => &mt('Communities'),
1.272 raeburn 8498: placement => &mt('Placement Tests'),
1.120 raeburn 8499: );
8500:
8501: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8502: ($cathash->{'instcode::0'} eq '') ||
8503: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 8504: ($cathash->{'communities::0'} eq '') ||
8505: (!grep(/^placement$/,@{$cats[0]})) ||
8506: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 8507: $maxnum ++;
8508: }
8509: my $lastidx;
8510: for (my $i=0; $i<$numtop; $i++) {
8511: my $parent = $cats[0][$i];
8512: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8513: my $item = &escape($parent).'::0';
8514: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8515: $lastidx = $idx{$item};
8516: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8517: .'<select name="'.$item.'"'.$chgstr.'>';
8518: for (my $k=0; $k<=$maxnum; $k++) {
8519: my $vpos = $k+1;
8520: my $selstr;
8521: if ($k == $i) {
8522: $selstr = ' selected="selected" ';
8523: }
8524: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8525: }
1.214 raeburn 8526: $datatable .= '</select></span></td><td>';
1.272 raeburn 8527: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 8528: $datatable .= '<span class="LC_nobreak">'
8529: .$default_names{$parent}.'</span>';
8530: if ($parent eq 'instcode') {
8531: $datatable .= '<br /><span class="LC_nobreak">('
8532: .&mt('with institutional codes')
8533: .')</span></td><td'.$colattrib.'>';
8534: } else {
8535: $datatable .= '<table><tr><td>';
8536: }
8537: $datatable .= '<span class="LC_nobreak">'
8538: .'<label><input type="radio" name="'
8539: .$parent.'" value="1" checked="checked" />'
8540: .&mt('Display').'</label>';
8541: if ($parent eq 'instcode') {
8542: $datatable .= ' ';
8543: } else {
8544: $datatable .= '</span></td></tr><tr><td>'
8545: .'<span class="LC_nobreak">';
8546: }
8547: $datatable .= '<label><input type="radio" name="'
8548: .$parent.'" value="0" />'
8549: .&mt('Do not display').'</label></span>';
1.272 raeburn 8550: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 8551: $datatable .= '</td></tr></table>';
8552: }
8553: $datatable .= '</td>';
1.57 raeburn 8554: } else {
8555: $datatable .= $parent
1.214 raeburn 8556: .' <span class="LC_nobreak"><label>'
8557: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8558: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8559: }
8560: my $depth = 1;
8561: push(@path,$parent);
8562: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8563: pop(@path);
8564: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8565: $itemcount ++;
8566: }
1.48 raeburn 8567: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8568: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8569: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8570: for (my $k=0; $k<=$maxnum; $k++) {
8571: my $vpos = $k+1;
8572: my $selstr;
1.57 raeburn 8573: if ($k == $numtop) {
1.48 raeburn 8574: $selstr = ' selected="selected" ';
8575: }
8576: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8577: }
1.59 bisitz 8578: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8579: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8580: .'</tr>'."\n";
1.48 raeburn 8581: $itemcount ++;
1.272 raeburn 8582: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8583: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8584: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8585: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8586: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8587: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8588: for (my $k=0; $k<=$maxnum; $k++) {
8589: my $vpos = $k+1;
8590: my $selstr;
8591: if ($k == $maxnum) {
8592: $selstr = ' selected="selected" ';
8593: }
8594: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8595: }
1.120 raeburn 8596: $datatable .= '</select></span></td>'.
8597: '<td><span class="LC_nobreak">'.
8598: $default_names{$default}.'</span>';
8599: if ($default eq 'instcode') {
8600: $datatable .= '<br /><span class="LC_nobreak">('
8601: .&mt('with institutional codes').')</span>';
8602: }
8603: $datatable .= '</td>'
8604: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8605: .&mt('Display').'</label> '
8606: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8607: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8608: }
8609: }
8610: }
1.57 raeburn 8611: } else {
8612: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8613: }
8614: } else {
1.327 raeburn 8615: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 8616: .&initialize_categories($itemcount);
1.48 raeburn 8617: }
1.57 raeburn 8618: $$rowtotal += $itemcount;
1.48 raeburn 8619: }
8620: return $datatable;
8621: }
8622:
1.69 raeburn 8623: sub print_serverstatuses {
8624: my ($dom,$settings,$rowtotal) = @_;
8625: my $datatable;
8626: my @pages = &serverstatus_pages();
8627: my (%namedaccess,%machineaccess);
8628: foreach my $type (@pages) {
8629: $namedaccess{$type} = '';
8630: $machineaccess{$type}= '';
8631: }
8632: if (ref($settings) eq 'HASH') {
8633: foreach my $type (@pages) {
8634: if (exists($settings->{$type})) {
8635: if (ref($settings->{$type}) eq 'HASH') {
8636: foreach my $key (keys(%{$settings->{$type}})) {
8637: if ($key eq 'namedusers') {
8638: $namedaccess{$type} = $settings->{$type}->{$key};
8639: } elsif ($key eq 'machines') {
8640: $machineaccess{$type} = $settings->{$type}->{$key};
8641: }
8642: }
8643: }
8644: }
8645: }
8646: }
1.81 raeburn 8647: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8648: my $rownum = 0;
8649: my $css_class;
8650: foreach my $type (@pages) {
8651: $rownum ++;
8652: $css_class = $rownum%2?' class="LC_odd_row"':'';
8653: $datatable .= '<tr'.$css_class.'>'.
8654: '<td><span class="LC_nobreak">'.
8655: $titles->{$type}.'</span></td>'.
8656: '<td class="LC_left_item">'.
8657: '<input type="text" name="'.$type.'_namedusers" '.
8658: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8659: '<td class="LC_right_item">'.
8660: '<span class="LC_nobreak">'.
8661: '<input type="text" name="'.$type.'_machines" '.
8662: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 8663: '</span></td></tr>'."\n";
1.69 raeburn 8664: }
8665: $$rowtotal += $rownum;
8666: return $datatable;
8667: }
8668:
8669: sub serverstatus_pages {
8670: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 8671: 'checksums','clusterstatus','certstatus','metadata_keywords',
8672: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
8673: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8674: }
8675:
1.236 raeburn 8676: sub defaults_javascript {
8677: my ($settings) = @_;
1.294 raeburn 8678: 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.');
8679: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
8680: &js_escape(\$intauthcheck);
8681: &js_escape(\$intauthcost);
8682: my $intauthjs = <<"ENDSCRIPT";
8683:
8684: function warnIntAuth(field) {
8685: if (field.name == 'intauth_check') {
8686: if (field.value == '2') {
8687: alert('$intauthcheck');
8688: }
8689: }
8690: if (field.name == 'intauth_cost') {
8691: field.value.replace(/\s/g,'');
8692: if (field.value != '') {
8693: var regexdigit=/^\\d+\$/;
8694: if (!regexdigit.test(field.value)) {
8695: alert('$intauthcost');
8696: }
8697: }
8698: }
8699: return;
8700: }
8701:
8702: ENDSCRIPT
8703:
8704: if (ref($settings) ne 'HASH') {
8705: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8706: }
1.236 raeburn 8707: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8708: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8709: if ($maxnum eq '') {
8710: $maxnum = 0;
8711: }
8712: $maxnum ++;
1.249 raeburn 8713: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 8714: return <<"ENDSCRIPT";
8715: <script type="text/javascript">
8716: // <![CDATA[
8717: function reorderTypes(form,caller) {
8718: var changedVal;
8719: $jstext
8720: var newpos = 'addinststatus_pos';
8721: var current = new Array;
8722: var maxh = $maxnum;
8723: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8724: var oldVal;
8725: if (caller == newpos) {
8726: changedVal = newitemVal;
8727: } else {
8728: var curritem = 'inststatus_pos_'+caller;
8729: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8730: current[newitemVal] = newpos;
8731: }
8732: for (var i=0; i<inststatuses.length; i++) {
8733: if (inststatuses[i] != caller) {
8734: var elementName = 'inststatus_pos_'+inststatuses[i];
8735: if (form.elements[elementName]) {
8736: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8737: current[currVal] = elementName;
8738: }
8739: }
8740: }
8741: for (var j=0; j<maxh; j++) {
8742: if (current[j] == undefined) {
8743: oldVal = j;
8744: }
8745: }
8746: if (oldVal < changedVal) {
8747: for (var k=oldVal+1; k<=changedVal ; k++) {
8748: var elementName = current[k];
8749: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8750: }
8751: } else {
8752: for (var k=changedVal; k<oldVal; k++) {
8753: var elementName = current[k];
8754: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8755: }
8756: }
8757: return;
8758: }
8759:
1.294 raeburn 8760: $intauthjs
8761:
1.236 raeburn 8762: // ]]>
8763: </script>
8764:
8765: ENDSCRIPT
1.294 raeburn 8766: } else {
8767: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 8768: }
8769: }
8770:
1.49 raeburn 8771: sub coursecategories_javascript {
8772: my ($settings) = @_;
1.57 raeburn 8773: my ($output,$jstext,$cathash);
1.49 raeburn 8774: if (ref($settings) eq 'HASH') {
1.57 raeburn 8775: $cathash = $settings->{'cats'};
8776: }
8777: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8778: my (@cats,@jsarray,%idx);
1.57 raeburn 8779: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8780: if (@jsarray > 0) {
8781: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8782: for (my $i=0; $i<@jsarray; $i++) {
8783: if (ref($jsarray[$i]) eq 'ARRAY') {
8784: my $catstr = join('","',@{$jsarray[$i]});
8785: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8786: }
8787: }
8788: }
8789: } else {
8790: $jstext = ' var categories = Array(1);'."\n".
8791: ' categories[0] = Array("instcode_pos");'."\n";
8792: }
1.237 bisitz 8793: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8794: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 8795: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 8796: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8797: &js_escape(\$instcode_reserved);
8798: &js_escape(\$communities_reserved);
1.272 raeburn 8799: &js_escape(\$placement_reserved);
1.265 damieng 8800: &js_escape(\$choose_again);
1.49 raeburn 8801: $output = <<"ENDSCRIPT";
8802: <script type="text/javascript">
1.109 raeburn 8803: // <![CDATA[
1.49 raeburn 8804: function reorderCats(form,parent,item,idx) {
8805: var changedVal;
8806: $jstext
8807: var newpos = 'addcategory_pos';
8808: if (parent == '') {
8809: var has_instcode = 0;
8810: var maxtop = categories[idx].length;
8811: for (var j=0; j<maxtop; j++) {
8812: if (categories[idx][j] == 'instcode::0') {
8813: has_instcode == 1;
8814: }
8815: }
8816: if (has_instcode == 0) {
8817: categories[idx][maxtop] = 'instcode_pos';
8818: }
8819: } else {
8820: newpos += '_'+parent;
8821: }
8822: var maxh = 1 + categories[idx].length;
8823: var current = new Array;
8824: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8825: if (item == newpos) {
8826: changedVal = newitemVal;
8827: } else {
8828: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8829: current[newitemVal] = newpos;
8830: }
8831: for (var i=0; i<categories[idx].length; i++) {
8832: var elementName = categories[idx][i];
8833: if (elementName != item) {
8834: if (form.elements[elementName]) {
8835: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8836: current[currVal] = elementName;
8837: }
8838: }
8839: }
8840: var oldVal;
8841: for (var j=0; j<maxh; j++) {
8842: if (current[j] == undefined) {
8843: oldVal = j;
8844: }
8845: }
8846: if (oldVal < changedVal) {
8847: for (var k=oldVal+1; k<=changedVal ; k++) {
8848: var elementName = current[k];
8849: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8850: }
8851: } else {
8852: for (var k=changedVal; k<oldVal; k++) {
8853: var elementName = current[k];
8854: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8855: }
8856: }
8857: return;
8858: }
1.120 raeburn 8859:
8860: function categoryCheck(form) {
8861: if (form.elements['addcategory_name'].value == 'instcode') {
8862: alert('$instcode_reserved\\n$choose_again');
8863: return false;
8864: }
8865: if (form.elements['addcategory_name'].value == 'communities') {
8866: alert('$communities_reserved\\n$choose_again');
8867: return false;
8868: }
1.272 raeburn 8869: if (form.elements['addcategory_name'].value == 'placement') {
8870: alert('$placement_reserved\\n$choose_again');
8871: return false;
8872: }
1.120 raeburn 8873: return true;
8874: }
8875:
1.109 raeburn 8876: // ]]>
1.49 raeburn 8877: </script>
8878:
8879: ENDSCRIPT
8880: return $output;
8881: }
8882:
1.48 raeburn 8883: sub initialize_categories {
8884: my ($itemcount) = @_;
1.120 raeburn 8885: my ($datatable,$css_class,$chgstr);
8886: my %default_names = (
8887: instcode => 'Official courses (with institutional codes)',
8888: communities => 'Communities',
1.272 raeburn 8889: placement => 'Placement Tests',
1.120 raeburn 8890: );
1.328 raeburn 8891: my %selnum = (
8892: instcode => '0',
8893: communities => '1',
8894: placement => '2',
8895: );
8896: my %selected;
1.272 raeburn 8897: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8898: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 8899: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 8900: map { $selected{$selnum{$_}} = '' } keys(%selnum);
8901: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 8902: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 8903: .'<select name="'.$default.'_pos"'.$chgstr.'>'
8904: .'<option value="0"'.$selected{'0'}.'>1</option>'
8905: .'<option value="1"'.$selected{'1'}.'>2</option>'
8906: .'<option value="2"'.$selected{'2'}.'>3</option>'
8907: .'<option value="3">4</option></select> '
1.120 raeburn 8908: .$default_names{$default}
8909: .'</span></td><td><span class="LC_nobreak">'
8910: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8911: .&mt('Display').'</label> <label>'
8912: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8913: .'</label></span></td></tr>';
1.120 raeburn 8914: $itemcount ++;
8915: }
1.48 raeburn 8916: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8917: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8918: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8919: .'<select name="addcategory_pos"'.$chgstr.'>'
8920: .'<option value="0">1</option>'
8921: .'<option value="1">2</option>'
1.328 raeburn 8922: .'<option value="2">3</option>'
8923: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 8924: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
8925: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8926: .'</td></tr>';
1.48 raeburn 8927: return $datatable;
8928: }
8929:
8930: sub build_category_rows {
1.49 raeburn 8931: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8932: my ($text,$name,$item,$chgstr);
1.48 raeburn 8933: if (ref($cats) eq 'ARRAY') {
8934: my $maxdepth = scalar(@{$cats});
8935: if (ref($cats->[$depth]) eq 'HASH') {
8936: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8937: my $numchildren = @{$cats->[$depth]{$parent}};
8938: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 8939: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8940: my ($idxnum,$parent_name,$parent_item);
8941: my $higher = $depth - 1;
8942: if ($higher == 0) {
8943: $parent_name = &escape($parent).'::'.$higher;
8944: } else {
8945: if (ref($path) eq 'ARRAY') {
8946: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8947: }
8948: }
8949: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8950: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8951: if ($j < $numchildren) {
1.48 raeburn 8952: $name = $cats->[$depth]{$parent}[$j];
8953: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8954: $idxnum = $idx->{$item};
8955: } else {
8956: $name = $parent_name;
8957: $item = $parent_item;
1.48 raeburn 8958: }
1.49 raeburn 8959: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8960: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8961: for (my $i=0; $i<=$numchildren; $i++) {
8962: my $vpos = $i+1;
8963: my $selstr;
8964: if ($j == $i) {
8965: $selstr = ' selected="selected" ';
8966: }
8967: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8968: }
8969: $text .= '</select> ';
8970: if ($j < $numchildren) {
8971: my $deeper = $depth+1;
8972: $text .= $name.' '
8973: .'<label><input type="checkbox" name="deletecategory" value="'
8974: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8975: if(ref($path) eq 'ARRAY') {
8976: push(@{$path},$name);
1.49 raeburn 8977: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8978: pop(@{$path});
8979: }
8980: } else {
1.330 raeburn 8981: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 8982: if ($j == $numchildren) {
8983: $text .= $name;
8984: } else {
8985: $text .= $item;
8986: }
8987: $text .= '" value="" />';
8988: }
8989: $text .= '</td></tr>';
8990: }
8991: $text .= '</table></td>';
8992: } else {
8993: my $higher = $depth-1;
8994: if ($higher == 0) {
8995: $name = &escape($parent).'::'.$higher;
8996: } else {
8997: if (ref($path) eq 'ARRAY') {
8998: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8999: }
9000: }
9001: my $colspan;
9002: if ($parent ne 'instcode') {
9003: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 9004: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 9005: }
9006: }
9007: }
9008: }
9009: return $text;
9010: }
9011:
1.33 raeburn 9012: sub modifiable_userdata_row {
1.305 raeburn 9013: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
9014: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 9015: my ($role,$rolename,$statustype);
9016: $role = $item;
1.224 raeburn 9017: if ($context eq 'cancreate') {
1.305 raeburn 9018: if ($item =~ /^(emailusername)_(.+)$/) {
9019: $role = $1;
9020: $statustype = $2;
1.228 raeburn 9021: if (ref($usertypes) eq 'HASH') {
9022: if ($usertypes->{$statustype}) {
9023: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
9024: } else {
9025: $rolename = &mt('Data provided by user');
9026: }
9027: }
1.224 raeburn 9028: }
9029: } elsif ($context eq 'selfcreate') {
1.63 raeburn 9030: if (ref($usertypes) eq 'HASH') {
9031: $rolename = $usertypes->{$role};
9032: } else {
9033: $rolename = $role;
9034: }
1.325 raeburn 9035: } elsif ($context eq 'lti') {
9036: $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 9037: } else {
1.63 raeburn 9038: if ($role eq 'cr') {
9039: $rolename = &mt('Custom role');
9040: } else {
9041: $rolename = &Apache::lonnet::plaintext($role);
9042: }
1.33 raeburn 9043: }
1.224 raeburn 9044: my (@fields,%fieldtitles);
9045: if (ref($fieldsref) eq 'ARRAY') {
9046: @fields = @{$fieldsref};
9047: } else {
9048: @fields = ('lastname','firstname','middlename','generation',
9049: 'permanentemail','id');
9050: }
9051: if ((ref($titlesref) eq 'HASH')) {
9052: %fieldtitles = %{$titlesref};
9053: } else {
9054: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9055: }
1.33 raeburn 9056: my $output;
1.305 raeburn 9057: my $css_class;
9058: if ($rowcount%2) {
9059: $css_class = 'LC_odd_row';
9060: }
9061: if ($customcss) {
9062: $css_class .= " $customcss";
9063: }
9064: $css_class =~ s/^\s+//;
9065: if ($css_class) {
9066: $css_class = ' class="'.$css_class.'"';
9067: }
9068: if ($rowstyle) {
9069: $css_class .= ' style="'.$rowstyle.'"';
9070: }
9071: if ($rowid) {
9072: $rowid = ' id="'.$rowid.'"';
9073: }
9074: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 9075: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
9076: '<td class="LC_left_item" colspan="2"><table>';
9077: my $rem;
9078: my %checks;
1.325 raeburn 9079: my %current;
1.33 raeburn 9080: if (ref($settings) eq 'HASH') {
1.325 raeburn 9081: my $hashref;
9082: if ($context eq 'lti') {
9083: if (ref($settings) eq 'HASH') {
9084: $hashref = $settings->{'instdata'};
9085: }
9086: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 9087: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 9088: $hashref = $settings->{'lti_instdata'};
9089: }
9090: if ($role eq 'emailusername') {
9091: if ($statustype) {
9092: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
9093: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 9094: }
1.325 raeburn 9095: }
9096: }
9097: }
9098: if (ref($hashref) eq 'HASH') {
9099: foreach my $field (@fields) {
9100: if ($hashref->{$field}) {
9101: if ($role eq 'emailusername') {
9102: $checks{$field} = $hashref->{$field};
9103: } else {
9104: $checks{$field} = ' checked="checked" ';
1.33 raeburn 9105: }
9106: }
9107: }
9108: }
9109: }
1.305 raeburn 9110:
9111: my $total = scalar(@fields);
9112: for (my $i=0; $i<$total; $i++) {
9113: $rem = $i%($numinrow);
1.33 raeburn 9114: if ($rem == 0) {
9115: if ($i > 0) {
9116: $output .= '</tr>';
9117: }
9118: $output .= '<tr>';
9119: }
9120: my $check = ' ';
1.228 raeburn 9121: unless ($role eq 'emailusername') {
9122: if (exists($checks{$fields[$i]})) {
9123: $check = $checks{$fields[$i]}
1.325 raeburn 9124: } elsif ($context ne 'lti') {
1.228 raeburn 9125: if ($role eq 'st') {
9126: if (ref($settings) ne 'HASH') {
9127: $check = ' checked="checked" ';
9128: }
1.33 raeburn 9129: }
9130: }
9131: }
9132: $output .= '<td class="LC_left_item">'.
1.228 raeburn 9133: '<span class="LC_nobreak">';
1.325 raeburn 9134: my $prefix = 'canmodify';
1.228 raeburn 9135: if ($role eq 'emailusername') {
9136: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
9137: $checks{$fields[$i]} = 'omit';
9138: }
9139: foreach my $option ('required','optional','omit') {
9140: my $checked='';
9141: if ($checks{$fields[$i]} eq $option) {
9142: $checked='checked="checked" ';
9143: }
9144: $output .= '<label>'.
1.325 raeburn 9145: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 9146: &mt($option).'</label>'.(' ' x2);
9147: }
9148: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
9149: } else {
1.325 raeburn 9150: if ($context eq 'lti') {
9151: $prefix = 'lti';
9152: }
1.228 raeburn 9153: $output .= '<label>'.
1.325 raeburn 9154: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 9155: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
9156: '</label>';
9157: }
9158: $output .= '</span></td>';
1.33 raeburn 9159: }
1.305 raeburn 9160: $rem = $total%$numinrow;
9161: my $colsleft;
9162: if ($rem) {
9163: $colsleft = $numinrow - $rem;
9164: }
9165: if ($colsleft > 1) {
1.33 raeburn 9166: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9167: ' </td>';
9168: } elsif ($colsleft == 1) {
9169: $output .= '<td class="LC_left_item"> </td>';
9170: }
9171: $output .= '</tr></table></td></tr>';
9172: return $output;
9173: }
1.28 raeburn 9174:
1.93 raeburn 9175: sub insttypes_row {
1.305 raeburn 9176: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
9177: $customcss,$rowstyle) = @_;
1.93 raeburn 9178: my %lt = &Apache::lonlocal::texthash (
9179: cansearch => 'Users allowed to search',
9180: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 9181: lockablenames => 'User preference to lock name',
1.305 raeburn 9182: selfassign => 'Self-reportable affiliations',
1.315 raeburn 9183: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 9184: );
9185: my $showdom;
9186: if ($context eq 'cansearch') {
9187: $showdom = ' ('.$dom.')';
9188: }
1.165 raeburn 9189: my $class = 'LC_left_item';
9190: if ($context eq 'statustocreate') {
9191: $class = 'LC_right_item';
9192: }
1.305 raeburn 9193: my $css_class;
9194: if ($$rowtotal%2) {
9195: $css_class = 'LC_odd_row';
9196: }
9197: if ($customcss) {
9198: $css_class .= ' '.$customcss;
9199: }
9200: $css_class =~ s/^\s+//;
9201: if ($css_class) {
9202: $css_class = ' class="'.$css_class.'"';
9203: }
9204: if ($rowstyle) {
9205: $css_class .= ' style="'.$rowstyle.'"';
9206: }
9207: if ($onclick) {
9208: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 9209: }
9210: my $output = '<tr'.$css_class.'>'.
9211: '<td>'.$lt{$context}.$showdom.
9212: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 9213: my $rem;
9214: if (ref($types) eq 'ARRAY') {
9215: for (my $i=0; $i<@{$types}; $i++) {
9216: if (defined($usertypes->{$types->[$i]})) {
9217: my $rem = $i%($numinrow);
9218: if ($rem == 0) {
9219: if ($i > 0) {
9220: $output .= '</tr>';
9221: }
9222: $output .= '<tr>';
1.23 raeburn 9223: }
1.26 raeburn 9224: my $check = ' ';
1.99 raeburn 9225: if (ref($settings) eq 'HASH') {
9226: if (ref($settings->{$context}) eq 'ARRAY') {
9227: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
9228: $check = ' checked="checked" ';
9229: }
1.315 raeburn 9230: } elsif (ref($settings->{$context}) eq 'HASH') {
9231: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
9232: $check = ' checked="checked" ';
9233: }
1.99 raeburn 9234: } elsif ($context eq 'statustocreate') {
1.26 raeburn 9235: $check = ' checked="checked" ';
9236: }
1.23 raeburn 9237: }
1.26 raeburn 9238: $output .= '<td class="LC_left_item">'.
9239: '<span class="LC_nobreak"><label>'.
1.93 raeburn 9240: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 9241: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 9242: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 9243: }
9244: }
1.26 raeburn 9245: $rem = @{$types}%($numinrow);
1.23 raeburn 9246: }
9247: my $colsleft = $numinrow - $rem;
1.315 raeburn 9248: if ($context eq 'overrides') {
9249: if ($colsleft > 1) {
9250: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9251: } else {
9252: $output .= '<td class="LC_left_item">';
9253: }
9254: $output .= ' ';
1.23 raeburn 9255: } else {
1.334 raeburn 9256: if ($rem == 0) {
1.315 raeburn 9257: $output .= '<tr>';
9258: }
9259: if ($colsleft > 1) {
9260: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9261: } else {
9262: $output .= '<td class="LC_left_item">';
9263: }
9264: my $defcheck = ' ';
9265: if (ref($settings) eq 'HASH') {
9266: if (ref($settings->{$context}) eq 'ARRAY') {
9267: if (grep(/^default$/,@{$settings->{$context}})) {
9268: $defcheck = ' checked="checked" ';
9269: }
9270: } elsif ($context eq 'statustocreate') {
1.99 raeburn 9271: $defcheck = ' checked="checked" ';
9272: }
1.26 raeburn 9273: }
1.315 raeburn 9274: $output .= '<span class="LC_nobreak"><label>'.
9275: '<input type="checkbox" name="'.$context.'" '.
9276: 'value="default"'.$defcheck.$onclick.' />'.
9277: $othertitle.'</label></span>';
1.23 raeburn 9278: }
1.315 raeburn 9279: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 9280: return $output;
1.23 raeburn 9281: }
9282:
9283: sub sorted_searchtitles {
9284: my %searchtitles = &Apache::lonlocal::texthash(
9285: 'uname' => 'username',
9286: 'lastname' => 'last name',
9287: 'lastfirst' => 'last name, first name',
9288: );
9289: my @titleorder = ('uname','lastname','lastfirst');
9290: return (\%searchtitles,\@titleorder);
9291: }
9292:
1.25 raeburn 9293: sub sorted_searchtypes {
9294: my %srchtypes_desc = (
9295: exact => 'is exact match',
9296: contains => 'contains ..',
9297: begins => 'begins with ..',
9298: );
9299: my @srchtypeorder = ('exact','begins','contains');
9300: return (\%srchtypes_desc,\@srchtypeorder);
9301: }
9302:
1.3 raeburn 9303: sub usertype_update_row {
9304: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9305: my $datatable;
9306: my $numinrow = 4;
9307: foreach my $type (@{$types}) {
9308: if (defined($usertypes->{$type})) {
9309: $$rownums ++;
9310: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9311: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9312: '</td><td class="LC_left_item"><table>';
9313: for (my $i=0; $i<@{$fields}; $i++) {
9314: my $rem = $i%($numinrow);
9315: if ($rem == 0) {
9316: if ($i > 0) {
9317: $datatable .= '</tr>';
9318: }
9319: $datatable .= '<tr>';
9320: }
9321: my $check = ' ';
1.39 raeburn 9322: if (ref($settings) eq 'HASH') {
9323: if (ref($settings->{'fields'}) eq 'HASH') {
9324: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9325: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9326: $check = ' checked="checked" ';
9327: }
1.3 raeburn 9328: }
9329: }
9330: }
9331:
9332: if ($i == @{$fields}-1) {
9333: my $colsleft = $numinrow - $rem;
9334: if ($colsleft > 1) {
9335: $datatable .= '<td colspan="'.$colsleft.'">';
9336: } else {
9337: $datatable .= '<td>';
9338: }
9339: } else {
9340: $datatable .= '<td>';
9341: }
1.8 raeburn 9342: $datatable .= '<span class="LC_nobreak"><label>'.
9343: '<input type="checkbox" name="updateable_'.$type.
9344: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9345: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 9346: }
9347: $datatable .= '</tr></table></td></tr>';
9348: }
9349: }
9350: return $datatable;
1.1 raeburn 9351: }
9352:
9353: sub modify_login {
1.205 raeburn 9354: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 9355: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
9356: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
9357: %title = ( coursecatalog => 'Display course catalog',
9358: adminmail => 'Display administrator E-mail address',
1.188 raeburn 9359: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 9360: newuser => 'Link for visitors to create a user account',
9361: loginheader => 'Log-in box header');
9362: @offon = ('off','on');
1.112 raeburn 9363: if (ref($domconfig{login}) eq 'HASH') {
9364: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9365: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9366: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9367: }
9368: }
9369: }
1.9 raeburn 9370: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9371: \%domconfig,\%loginhash);
1.188 raeburn 9372: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9373: foreach my $item (@toggles) {
9374: $loginhash{login}{$item} = $env{'form.'.$item};
9375: }
1.41 raeburn 9376: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 9377: if (ref($colchanges{'login'}) eq 'HASH') {
9378: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9379: \%loginhash);
9380: }
1.110 raeburn 9381:
1.149 raeburn 9382: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 9383: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 9384: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 9385: if (keys(%servers) > 1) {
9386: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 9387: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9388: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9389: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9390: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9391: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9392: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9393: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9394: $changes{'loginvia'}{$lonhost} = 1;
9395: } else {
9396: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9397: $changes{'loginvia'}{$lonhost} = 1;
9398: }
9399: } else {
9400: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9401: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9402: $changes{'loginvia'}{$lonhost} = 1;
9403: }
9404: }
9405: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9406: foreach my $item (@loginvia_attribs) {
9407: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9408: }
9409: } else {
9410: foreach my $item (@loginvia_attribs) {
9411: my $new = $env{'form.'.$lonhost.'_'.$item};
9412: if (($item eq 'serverpath') && ($new eq 'custom')) {
9413: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9414: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9415: $new = '/';
9416: }
9417: }
9418: if (($item eq 'custompath') &&
9419: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9420: $new = '';
9421: }
9422: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9423: $changes{'loginvia'}{$lonhost} = 1;
9424: }
9425: if ($item eq 'exempt') {
1.256 raeburn 9426: $new = &check_exempt_addresses($new);
1.128 raeburn 9427: }
9428: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9429: }
9430: }
1.112 raeburn 9431: } else {
1.128 raeburn 9432: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9433: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9434: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9435: foreach my $item (@loginvia_attribs) {
9436: my $new = $env{'form.'.$lonhost.'_'.$item};
9437: if (($item eq 'serverpath') && ($new eq 'custom')) {
9438: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9439: $new = '/';
9440: }
9441: }
9442: if (($item eq 'custompath') &&
9443: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9444: $new = '';
9445: }
9446: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9447: }
1.110 raeburn 9448: }
9449: }
9450: }
9451: }
1.119 raeburn 9452:
1.168 raeburn 9453: my $servadm = $r->dir_config('lonAdmEMail');
9454: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9455: if (ref($domconfig{'login'}) eq 'HASH') {
9456: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9457: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9458: if ($lang eq 'nolang') {
9459: push(@currlangs,$lang);
9460: } elsif (defined($langchoices{$lang})) {
9461: push(@currlangs,$lang);
9462: } else {
9463: next;
9464: }
9465: }
9466: }
9467: }
9468: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9469: if (@currlangs > 0) {
9470: foreach my $lang (@currlangs) {
9471: if (grep(/^\Q$lang\E$/,@delurls)) {
9472: $changes{'helpurl'}{$lang} = 1;
9473: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9474: $changes{'helpurl'}{$lang} = 1;
9475: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9476: push(@newlangs,$lang);
9477: } else {
9478: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9479: }
9480: }
9481: }
9482: unless (grep(/^nolang$/,@currlangs)) {
9483: if ($env{'form.loginhelpurl_nolang.filename'}) {
9484: $changes{'helpurl'}{'nolang'} = 1;
9485: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9486: push(@newlangs,'nolang');
9487: }
9488: }
9489: if ($env{'form.loginhelpurl_add_lang'}) {
9490: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9491: ($env{'form.loginhelpurl_add_file.filename'})) {
9492: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9493: $addedfile = $env{'form.loginhelpurl_add_lang'};
9494: }
9495: }
9496: if ((@newlangs > 0) || ($addedfile)) {
9497: my $error;
9498: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9499: if ($configuserok eq 'ok') {
9500: if ($switchserver) {
9501: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9502: } elsif ($author_ok eq 'ok') {
9503: my @allnew = @newlangs;
9504: if ($addedfile ne '') {
9505: push(@allnew,$addedfile);
9506: }
9507: foreach my $lang (@allnew) {
9508: my $formelem = 'loginhelpurl_'.$lang;
9509: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9510: $formelem = 'loginhelpurl_add_file';
9511: }
9512: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9513: "help/$lang",'','',$newfile{$lang});
9514: if ($result eq 'ok') {
9515: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9516: $changes{'helpurl'}{$lang} = 1;
9517: } else {
9518: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9519: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 9520: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 9521: (!grep(/^\Q$lang\E$/,@delurls))) {
9522: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9523: }
9524: }
9525: }
9526: } else {
9527: $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);
9528: }
9529: } else {
9530: $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);
9531: }
9532: if ($error) {
9533: &Apache::lonnet::logthis($error);
9534: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9535: }
9536: }
1.256 raeburn 9537:
9538: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9539: if (ref($domconfig{'login'}) eq 'HASH') {
9540: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9541: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9542: if ($domservers{$lonhost}) {
9543: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9544: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 9545: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 9546: }
9547: }
9548: }
9549: }
9550: }
9551: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9552: foreach my $lonhost (sort(keys(%domservers))) {
9553: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9554: $changes{'headtag'}{$lonhost} = 1;
9555: } else {
9556: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9557: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9558: }
9559: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9560: push(@newhosts,$lonhost);
9561: } elsif ($currheadtagurls{$lonhost}) {
9562: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9563: if ($currexempt{$lonhost}) {
1.289 raeburn 9564: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 9565: $changes{'headtag'}{$lonhost} = 1;
9566: }
9567: } elsif ($possexempt{$lonhost}) {
9568: $changes{'headtag'}{$lonhost} = 1;
9569: }
9570: if ($possexempt{$lonhost}) {
9571: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9572: }
9573: }
9574: }
9575: }
9576: if (@newhosts) {
9577: my $error;
9578: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9579: if ($configuserok eq 'ok') {
9580: if ($switchserver) {
9581: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9582: } elsif ($author_ok eq 'ok') {
9583: foreach my $lonhost (@newhosts) {
9584: my $formelem = 'loginheadtag_'.$lonhost;
9585: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9586: "login/headtag/$lonhost",'','',
9587: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9588: if ($result eq 'ok') {
9589: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9590: $changes{'headtag'}{$lonhost} = 1;
9591: if ($possexempt{$lonhost}) {
9592: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9593: }
9594: } else {
9595: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9596: $newheadtagurls{$lonhost},$result);
9597: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9598: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9599: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9600: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9601: }
9602: }
9603: }
9604: } else {
9605: $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);
9606: }
9607: } else {
9608: $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);
9609: }
9610: if ($error) {
9611: &Apache::lonnet::logthis($error);
9612: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9613: }
9614: }
1.169 raeburn 9615: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 9616:
9617: my $defaulthelpfile = '/adm/loginproblems.html';
9618: my $defaulttext = &mt('Default in use');
9619:
1.1 raeburn 9620: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9621: $dom);
9622: if ($putresult eq 'ok') {
1.188 raeburn 9623: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9624: my %defaultchecked = (
9625: 'coursecatalog' => 'on',
1.188 raeburn 9626: 'helpdesk' => 'on',
1.42 raeburn 9627: 'adminmail' => 'off',
1.43 raeburn 9628: 'newuser' => 'off',
1.42 raeburn 9629: );
1.55 raeburn 9630: if (ref($domconfig{'login'}) eq 'HASH') {
9631: foreach my $item (@toggles) {
9632: if ($defaultchecked{$item} eq 'on') {
9633: if (($domconfig{'login'}{$item} eq '0') &&
9634: ($env{'form.'.$item} eq '1')) {
9635: $changes{$item} = 1;
9636: } elsif (($domconfig{'login'}{$item} eq '' ||
9637: $domconfig{'login'}{$item} eq '1') &&
9638: ($env{'form.'.$item} eq '0')) {
9639: $changes{$item} = 1;
9640: }
9641: } elsif ($defaultchecked{$item} eq 'off') {
9642: if (($domconfig{'login'}{$item} eq '1') &&
9643: ($env{'form.'.$item} eq '0')) {
9644: $changes{$item} = 1;
9645: } elsif (($domconfig{'login'}{$item} eq '' ||
9646: $domconfig{'login'}{$item} eq '0') &&
9647: ($env{'form.'.$item} eq '1')) {
9648: $changes{$item} = 1;
9649: }
1.42 raeburn 9650: }
9651: }
1.41 raeburn 9652: }
1.6 raeburn 9653: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9654: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9655: if (ref($lastactref) eq 'HASH') {
9656: $lastactref->{'domainconfig'} = 1;
9657: }
1.1 raeburn 9658: $resulttext = &mt('Changes made:').'<ul>';
9659: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9660: if ($item eq 'loginvia') {
1.112 raeburn 9661: if (ref($changes{$item}) eq 'HASH') {
9662: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9663: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9664: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9665: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9666: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9667: $protocol = 'http' if ($protocol ne 'https');
9668: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9669:
9670: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9671: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9672: } else {
9673: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9674: }
9675: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9676: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9677: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9678: }
9679: $resulttext .= '</li>';
9680: } else {
9681: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9682: }
1.112 raeburn 9683: } else {
1.128 raeburn 9684: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9685: }
9686: }
1.128 raeburn 9687: $resulttext .= '</ul></li>';
1.112 raeburn 9688: }
1.168 raeburn 9689: } elsif ($item eq 'helpurl') {
9690: if (ref($changes{$item}) eq 'HASH') {
9691: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9692: if (grep(/^\Q$lang\E$/,@delurls)) {
9693: my ($chg,$link);
9694: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9695: if ($lang eq 'nolang') {
9696: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9697: } else {
9698: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9699: }
9700: $resulttext .= '<li>'.$chg.'</li>';
9701: } else {
9702: my $chg;
9703: if ($lang eq 'nolang') {
9704: $chg = &mt('custom log-in help file for no preferred language');
9705: } else {
9706: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9707: }
9708: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9709: $loginhash{'login'}{'helpurl'}{$lang}.
9710: '?inhibitmenu=yes',$chg,600,500).
9711: '</li>';
9712: }
9713: }
9714: }
1.256 raeburn 9715: } elsif ($item eq 'headtag') {
9716: if (ref($changes{$item}) eq 'HASH') {
9717: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9718: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9719: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9720: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9721: $resulttext .= '<li><a href="'.
9722: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9723: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9724: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9725: if ($possexempt{$lonhost}) {
9726: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9727: } else {
9728: $resulttext .= &mt('included for any client IP');
9729: }
9730: $resulttext .= '</li>';
9731: }
9732: }
9733: }
1.169 raeburn 9734: } elsif ($item eq 'captcha') {
9735: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 9736: my $chgtxt;
1.169 raeburn 9737: if ($loginhash{'login'}{$item} eq 'notused') {
9738: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9739: } else {
9740: my %captchas = &captcha_phrases();
9741: if ($captchas{$loginhash{'login'}{$item}}) {
9742: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9743: } else {
9744: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9745: }
9746: }
9747: $resulttext .= '<li>'.$chgtxt.'</li>';
9748: }
9749: } elsif ($item eq 'recaptchakeys') {
9750: if (ref($loginhash{'login'}) eq 'HASH') {
9751: my ($privkey,$pubkey);
9752: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9753: $pubkey = $loginhash{'login'}{$item}{'public'};
9754: $privkey = $loginhash{'login'}{$item}{'private'};
9755: }
9756: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9757: if (!$pubkey) {
9758: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9759: } else {
9760: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9761: }
9762: if (!$privkey) {
9763: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9764: } else {
1.251 raeburn 9765: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 9766: }
9767: $chgtxt .= '</ul>';
9768: $resulttext .= '<li>'.$chgtxt.'</li>';
9769: }
1.269 raeburn 9770: } elsif ($item eq 'recaptchaversion') {
9771: if (ref($loginhash{'login'}) eq 'HASH') {
9772: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 9773: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 9774: '</li>';
9775: }
9776: }
1.41 raeburn 9777: } else {
9778: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9779: }
1.1 raeburn 9780: }
1.6 raeburn 9781: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9782: } else {
9783: $resulttext = &mt('No changes made to log-in page settings');
9784: }
9785: } else {
1.11 albertel 9786: $resulttext = '<span class="LC_error">'.
9787: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9788: }
1.6 raeburn 9789: if ($errors) {
1.9 raeburn 9790: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9791: $errors.'</ul>';
9792: }
9793: return $resulttext;
9794: }
9795:
1.256 raeburn 9796: sub check_exempt_addresses {
9797: my ($iplist) = @_;
9798: $iplist =~ s/^\s+//;
9799: $iplist =~ s/\s+$//;
9800: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9801: my (@okips,$new);
9802: foreach my $ip (@poss_ips) {
9803: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9804: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9805: push(@okips,$ip);
9806: }
9807: }
9808: }
9809: if (@okips > 0) {
9810: $new = join(',',@okips);
9811: } else {
9812: $new = '';
9813: }
9814: return $new;
9815: }
9816:
1.6 raeburn 9817: sub color_font_choices {
9818: my %choices =
9819: &Apache::lonlocal::texthash (
9820: img => "Header",
9821: bgs => "Background colors",
9822: links => "Link colors",
1.55 raeburn 9823: images => "Images",
1.6 raeburn 9824: font => "Font color",
1.201 raeburn 9825: fontmenu => "Font menu",
1.76 raeburn 9826: pgbg => "Page",
1.6 raeburn 9827: tabbg => "Header",
9828: sidebg => "Border",
9829: link => "Link",
9830: alink => "Active link",
9831: vlink => "Visited link",
9832: );
9833: return %choices;
9834: }
9835:
9836: sub modify_rolecolors {
1.205 raeburn 9837: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9838: my ($resulttext,%rolehash);
9839: $rolehash{'rolecolors'} = {};
1.55 raeburn 9840: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9841: if ($domconfig{'rolecolors'} eq '') {
9842: $domconfig{'rolecolors'} = {};
9843: }
9844: }
1.9 raeburn 9845: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9846: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9847: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9848: $dom);
9849: if ($putresult eq 'ok') {
9850: if (keys(%changes) > 0) {
1.41 raeburn 9851: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9852: if (ref($lastactref) eq 'HASH') {
9853: $lastactref->{'domainconfig'} = 1;
9854: }
1.6 raeburn 9855: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9856: $rolehash{'rolecolors'});
9857: } else {
9858: $resulttext = &mt('No changes made to default color schemes');
9859: }
9860: } else {
1.11 albertel 9861: $resulttext = '<span class="LC_error">'.
9862: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9863: }
9864: if ($errors) {
9865: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9866: $errors.'</ul>';
9867: }
9868: return $resulttext;
9869: }
9870:
9871: sub modify_colors {
1.9 raeburn 9872: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9873: my (%changes,%choices);
1.51 raeburn 9874: my @bgs;
1.6 raeburn 9875: my @links = ('link','alink','vlink');
1.41 raeburn 9876: my @logintext;
1.6 raeburn 9877: my @images;
9878: my $servadm = $r->dir_config('lonAdmEMail');
9879: my $errors;
1.200 raeburn 9880: my %defaults;
1.6 raeburn 9881: foreach my $role (@{$roles}) {
9882: if ($role eq 'login') {
1.12 raeburn 9883: %choices = &login_choices();
1.41 raeburn 9884: @logintext = ('textcol','bgcol');
1.12 raeburn 9885: } else {
9886: %choices = &color_font_choices();
9887: }
9888: if ($role eq 'login') {
1.41 raeburn 9889: @images = ('img','logo','domlogo','login');
1.51 raeburn 9890: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9891: } else {
9892: @images = ('img');
1.200 raeburn 9893: @bgs = ('pgbg','tabbg','sidebg');
9894: }
9895: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9896: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9897: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9898: }
9899: if ($role eq 'login') {
9900: foreach my $item (@logintext) {
1.234 raeburn 9901: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9902: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9903: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9904: }
9905: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 9906: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9907: }
9908: }
9909: } else {
1.234 raeburn 9910: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9911: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9912: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9913: }
9914: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 9915: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9916: }
1.6 raeburn 9917: }
1.200 raeburn 9918: foreach my $item (@bgs) {
1.234 raeburn 9919: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9920: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9921: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9922: }
9923: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 9924: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9925: }
9926: }
9927: foreach my $item (@links) {
1.234 raeburn 9928: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9929: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9930: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9931: }
9932: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 9933: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9934: }
1.6 raeburn 9935: }
1.46 raeburn 9936: my ($configuserok,$author_ok,$switchserver) =
9937: &config_check($dom,$confname,$servadm);
1.9 raeburn 9938: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 9939: if (ref($domconfig->{$role}) ne 'HASH') {
9940: $domconfig->{$role} = {};
9941: }
1.8 raeburn 9942: foreach my $img (@images) {
1.70 raeburn 9943: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9944: if (defined($env{'form.login_showlogo_'.$img})) {
9945: $confhash->{$role}{'showlogo'}{$img} = 1;
9946: } else {
9947: $confhash->{$role}{'showlogo'}{$img} = 0;
9948: }
9949: }
1.18 albertel 9950: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9951: && !defined($domconfig->{$role}{$img})
9952: && !$env{'form.'.$role.'_del_'.$img}
9953: && $env{'form.'.$role.'_import_'.$img}) {
9954: # import the old configured image from the .tab setting
9955: # if they haven't provided a new one
9956: $domconfig->{$role}{$img} =
9957: $env{'form.'.$role.'_import_'.$img};
9958: }
1.6 raeburn 9959: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9960: my $error;
1.6 raeburn 9961: if ($configuserok eq 'ok') {
1.9 raeburn 9962: if ($switchserver) {
1.12 raeburn 9963: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9964: } else {
9965: if ($author_ok eq 'ok') {
9966: my ($result,$logourl) =
9967: &publishlogo($r,'upload',$role.'_'.$img,
9968: $dom,$confname,$img,$width,$height);
9969: if ($result eq 'ok') {
9970: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9971: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9972: } else {
1.12 raeburn 9973: $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 9974: }
9975: } else {
1.46 raeburn 9976: $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 9977: }
9978: }
9979: } else {
1.46 raeburn 9980: $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 9981: }
9982: if ($error) {
1.8 raeburn 9983: &Apache::lonnet::logthis($error);
1.11 albertel 9984: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9985: }
9986: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9987: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9988: my $error;
9989: if ($configuserok eq 'ok') {
9990: # is confname an author?
9991: if ($switchserver eq '') {
9992: if ($author_ok eq 'ok') {
9993: my ($result,$logourl) =
9994: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9995: $dom,$confname,$img,$width,$height);
9996: if ($result eq 'ok') {
9997: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9998: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9999: }
10000: }
10001: }
10002: }
1.6 raeburn 10003: }
10004: }
10005: }
10006: if (ref($domconfig) eq 'HASH') {
10007: if (ref($domconfig->{$role}) eq 'HASH') {
10008: foreach my $img (@images) {
10009: if ($domconfig->{$role}{$img} ne '') {
10010: if ($env{'form.'.$role.'_del_'.$img}) {
10011: $confhash->{$role}{$img} = '';
1.12 raeburn 10012: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10013: } else {
1.9 raeburn 10014: if ($confhash->{$role}{$img} eq '') {
10015: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
10016: }
1.6 raeburn 10017: }
10018: } else {
10019: if ($env{'form.'.$role.'_del_'.$img}) {
10020: $confhash->{$role}{$img} = '';
1.12 raeburn 10021: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10022: }
10023: }
1.70 raeburn 10024: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
10025: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
10026: if ($confhash->{$role}{'showlogo'}{$img} ne
10027: $domconfig->{$role}{'showlogo'}{$img}) {
10028: $changes{$role}{'showlogo'}{$img} = 1;
10029: }
10030: } else {
10031: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10032: $changes{$role}{'showlogo'}{$img} = 1;
10033: }
10034: }
10035: }
10036: }
1.6 raeburn 10037: if ($domconfig->{$role}{'font'} ne '') {
10038: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
10039: $changes{$role}{'font'} = 1;
10040: }
10041: } else {
10042: if ($confhash->{$role}{'font'}) {
10043: $changes{$role}{'font'} = 1;
10044: }
10045: }
1.107 raeburn 10046: if ($role ne 'login') {
10047: if ($domconfig->{$role}{'fontmenu'} ne '') {
10048: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
10049: $changes{$role}{'fontmenu'} = 1;
10050: }
10051: } else {
10052: if ($confhash->{$role}{'fontmenu'}) {
10053: $changes{$role}{'fontmenu'} = 1;
10054: }
1.97 tempelho 10055: }
10056: }
1.6 raeburn 10057: foreach my $item (@bgs) {
10058: if ($domconfig->{$role}{$item} ne '') {
10059: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10060: $changes{$role}{'bgs'}{$item} = 1;
10061: }
10062: } else {
10063: if ($confhash->{$role}{$item}) {
10064: $changes{$role}{'bgs'}{$item} = 1;
10065: }
10066: }
10067: }
10068: foreach my $item (@links) {
10069: if ($domconfig->{$role}{$item} ne '') {
10070: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10071: $changes{$role}{'links'}{$item} = 1;
10072: }
10073: } else {
10074: if ($confhash->{$role}{$item}) {
10075: $changes{$role}{'links'}{$item} = 1;
10076: }
10077: }
10078: }
1.41 raeburn 10079: foreach my $item (@logintext) {
10080: if ($domconfig->{$role}{$item} ne '') {
10081: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10082: $changes{$role}{'logintext'}{$item} = 1;
10083: }
10084: } else {
10085: if ($confhash->{$role}{$item}) {
10086: $changes{$role}{'logintext'}{$item} = 1;
10087: }
10088: }
10089: }
1.6 raeburn 10090: } else {
10091: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10092: \@logintext,$confhash,\%changes);
1.6 raeburn 10093: }
10094: } else {
10095: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10096: \@logintext,$confhash,\%changes);
1.6 raeburn 10097: }
10098: }
10099: return ($errors,%changes);
10100: }
10101:
1.46 raeburn 10102: sub config_check {
10103: my ($dom,$confname,$servadm) = @_;
10104: my ($configuserok,$author_ok,$switchserver,%currroles);
10105: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
10106: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
10107: $confname,$servadm);
10108: if ($configuserok eq 'ok') {
10109: $switchserver = &check_switchserver($dom,$confname);
10110: if ($switchserver eq '') {
10111: $author_ok = &check_authorstatus($dom,$confname,%currroles);
10112: }
10113: }
10114: return ($configuserok,$author_ok,$switchserver);
10115: }
10116:
1.6 raeburn 10117: sub default_change_checker {
1.41 raeburn 10118: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 10119: foreach my $item (@{$links}) {
10120: if ($confhash->{$role}{$item}) {
10121: $changes->{$role}{'links'}{$item} = 1;
10122: }
10123: }
10124: foreach my $item (@{$bgs}) {
10125: if ($confhash->{$role}{$item}) {
10126: $changes->{$role}{'bgs'}{$item} = 1;
10127: }
10128: }
1.41 raeburn 10129: foreach my $item (@{$logintext}) {
10130: if ($confhash->{$role}{$item}) {
10131: $changes->{$role}{'logintext'}{$item} = 1;
10132: }
10133: }
1.6 raeburn 10134: foreach my $img (@{$images}) {
10135: if ($env{'form.'.$role.'_del_'.$img}) {
10136: $confhash->{$role}{$img} = '';
1.12 raeburn 10137: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 10138: }
1.70 raeburn 10139: if ($role eq 'login') {
10140: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10141: $changes->{$role}{'showlogo'}{$img} = 1;
10142: }
10143: }
1.6 raeburn 10144: }
10145: if ($confhash->{$role}{'font'}) {
10146: $changes->{$role}{'font'} = 1;
10147: }
1.48 raeburn 10148: }
1.6 raeburn 10149:
10150: sub display_colorchgs {
10151: my ($dom,$changes,$roles,$confhash) = @_;
10152: my (%choices,$resulttext);
10153: if (!grep(/^login$/,@{$roles})) {
10154: $resulttext = &mt('Changes made:').'<br />';
10155: }
10156: foreach my $role (@{$roles}) {
10157: if ($role eq 'login') {
10158: %choices = &login_choices();
10159: } else {
10160: %choices = &color_font_choices();
10161: }
10162: if (ref($changes->{$role}) eq 'HASH') {
10163: if ($role ne 'login') {
10164: $resulttext .= '<h4>'.&mt($role).'</h4>';
10165: }
10166: foreach my $key (sort(keys(%{$changes->{$role}}))) {
10167: if ($role ne 'login') {
10168: $resulttext .= '<ul>';
10169: }
10170: if (ref($changes->{$role}{$key}) eq 'HASH') {
10171: if ($role ne 'login') {
10172: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
10173: }
10174: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 10175: if (($role eq 'login') && ($key eq 'showlogo')) {
10176: if ($confhash->{$role}{$key}{$item}) {
10177: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
10178: } else {
10179: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
10180: }
10181: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 10182: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
10183: } else {
1.12 raeburn 10184: my $newitem = $confhash->{$role}{$item};
10185: if ($key eq 'images') {
1.306 raeburn 10186: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 10187: }
10188: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 10189: }
10190: }
10191: if ($role ne 'login') {
10192: $resulttext .= '</ul></li>';
10193: }
10194: } else {
10195: if ($confhash->{$role}{$key} eq '') {
10196: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
10197: } else {
10198: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
10199: }
10200: }
10201: if ($role ne 'login') {
10202: $resulttext .= '</ul>';
10203: }
10204: }
10205: }
10206: }
1.3 raeburn 10207: return $resulttext;
1.1 raeburn 10208: }
10209:
1.9 raeburn 10210: sub thumb_dimensions {
10211: return ('200','50');
10212: }
10213:
1.16 raeburn 10214: sub check_dimensions {
10215: my ($inputfile) = @_;
10216: my ($fullwidth,$fullheight);
10217: if ($inputfile =~ m|^[/\w.\-]+$|) {
10218: if (open(PIPE,"identify $inputfile 2>&1 |")) {
10219: my $imageinfo = <PIPE>;
10220: if (!close(PIPE)) {
10221: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
10222: }
10223: chomp($imageinfo);
10224: my ($fullsize) =
1.21 raeburn 10225: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 10226: if ($fullsize) {
10227: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10228: }
10229: }
10230: }
10231: return ($fullwidth,$fullheight);
10232: }
10233:
1.9 raeburn 10234: sub check_configuser {
10235: my ($uhome,$dom,$confname,$servadm) = @_;
10236: my ($configuserok,%currroles);
10237: if ($uhome eq 'no_host') {
10238: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
10239: my $configpass = &LONCAPA::Enrollment::create_password();
10240: $configuserok =
10241: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10242: $configpass,'','','','','',undef,$servadm);
10243: } else {
10244: $configuserok = 'ok';
10245: %currroles =
10246: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10247: }
10248: return ($configuserok,%currroles);
10249: }
10250:
10251: sub check_authorstatus {
10252: my ($dom,$confname,%currroles) = @_;
10253: my $author_ok;
1.40 raeburn 10254: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 10255: my $start = time;
10256: my $end = 0;
10257: $author_ok =
10258: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 10259: 'au',$end,$start,'','','domconfig');
1.9 raeburn 10260: } else {
10261: $author_ok = 'ok';
10262: }
10263: return $author_ok;
10264: }
10265:
10266: sub publishlogo {
1.46 raeburn 10267: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 10268: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 10269: if ($action eq 'upload') {
10270: $fname=$env{'form.'.$formname.'.filename'};
10271: chop($env{'form.'.$formname});
10272: } else {
10273: ($fname) = ($formname =~ /([^\/]+)$/);
10274: }
1.46 raeburn 10275: if ($savefileas ne '') {
10276: $fname = $savefileas;
10277: }
1.9 raeburn 10278: $fname=&Apache::lonnet::clean_filename($fname);
10279: # See if there is anything left
10280: unless ($fname) { return ('error: no uploaded file'); }
10281: $fname="$subdir/$fname";
1.210 raeburn 10282: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 10283: my $filepath="$docroot/priv";
10284: my $relpath = "$dom/$confname";
1.9 raeburn 10285: my ($fnamepath,$file,$fetchthumb);
10286: $file=$fname;
10287: if ($fname=~m|/|) {
10288: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
10289: }
1.164 raeburn 10290: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 10291: my $count;
1.164 raeburn 10292: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 10293: $filepath.="/$parts[$count]";
10294: if ((-e $filepath)!=1) {
10295: mkdir($filepath,02770);
10296: }
10297: }
10298: # Check for bad extension and disallow upload
10299: if ($file=~/\.(\w+)$/ &&
10300: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
10301: $output =
1.207 bisitz 10302: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 10303: } elsif ($file=~/\.(\w+)$/ &&
10304: !defined(&Apache::loncommon::fileembstyle($1))) {
10305: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
10306: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 10307: $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 10308: } elsif (-d "$filepath/$file") {
1.195 bisitz 10309: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 10310: } else {
10311: my $source = $filepath.'/'.$file;
10312: my $logfile;
1.316 raeburn 10313: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 10314: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 10315: }
10316: print $logfile
10317: "\n================= Publish ".localtime()." ================\n".
10318: $env{'user.name'}.':'.$env{'user.domain'}."\n";
10319: # Save the file
1.316 raeburn 10320: if (!open(FH,">",$source)) {
1.9 raeburn 10321: &Apache::lonnet::logthis('Failed to create '.$source);
10322: return (&mt('Failed to create file'));
10323: }
10324: if ($action eq 'upload') {
10325: if (!print FH ($env{'form.'.$formname})) {
10326: &Apache::lonnet::logthis('Failed to write to '.$source);
10327: return (&mt('Failed to write file'));
10328: }
10329: } else {
10330: my $original = &Apache::lonnet::filelocation('',$formname);
10331: if(!copy($original,$source)) {
10332: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
10333: return (&mt('Failed to write file'));
10334: }
10335: }
10336: close(FH);
10337: chmod(0660, $source); # Permissions to rw-rw---.
10338:
10339: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
10340: my $copyfile=$targetdir.'/'.$file;
10341:
10342: my @parts=split(/\//,$targetdir);
10343: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
10344: for (my $count=5;$count<=$#parts;$count++) {
10345: $path.="/$parts[$count]";
10346: if (!-e $path) {
10347: print $logfile "\nCreating directory ".$path;
10348: mkdir($path,02770);
10349: }
10350: }
10351: my $versionresult;
10352: if (-e $copyfile) {
10353: $versionresult = &logo_versioning($targetdir,$file,$logfile);
10354: } else {
10355: $versionresult = 'ok';
10356: }
10357: if ($versionresult eq 'ok') {
10358: if (copy($source,$copyfile)) {
10359: print $logfile "\nCopied original source to ".$copyfile."\n";
10360: $output = 'ok';
10361: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 10362: push(@{$modified_urls},[$copyfile,$source]);
10363: my $metaoutput =
10364: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
10365: unless ($registered_cleanup) {
10366: my $handlers = $r->get_handlers('PerlCleanupHandler');
10367: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10368: $registered_cleanup=1;
10369: }
1.9 raeburn 10370: } else {
10371: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
10372: $output = &mt('Failed to copy file to RES space').", $!";
10373: }
10374: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
10375: my $inputfile = $filepath.'/'.$file;
10376: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 10377: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
10378: if ($fullwidth ne '' && $fullheight ne '') {
10379: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
10380: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 10381: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
10382: system({$args[0]} @args);
1.16 raeburn 10383: chmod(0660, $filepath.'/tn-'.$file);
10384: if (-e $outfile) {
10385: my $copyfile=$targetdir.'/tn-'.$file;
10386: if (copy($outfile,$copyfile)) {
10387: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 10388: my $thumb_metaoutput =
10389: &write_metadata($dom,$confname,$formname,
10390: $targetdir,'tn-'.$file,$logfile);
10391: push(@{$modified_urls},[$copyfile,$outfile]);
10392: unless ($registered_cleanup) {
10393: my $handlers = $r->get_handlers('PerlCleanupHandler');
10394: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10395: $registered_cleanup=1;
10396: }
1.267 raeburn 10397: $madethumb = 1;
1.16 raeburn 10398: } else {
10399: print $logfile "\nUnable to write ".$copyfile.
10400: ':'.$!."\n";
10401: }
10402: }
1.9 raeburn 10403: }
10404: }
10405: }
10406: } else {
10407: $output = $versionresult;
10408: }
10409: }
1.267 raeburn 10410: return ($output,$logourl,$madethumb);
1.9 raeburn 10411: }
10412:
10413: sub logo_versioning {
10414: my ($targetdir,$file,$logfile) = @_;
10415: my $target = $targetdir.'/'.$file;
10416: my ($maxversion,$fn,$extn,$output);
10417: $maxversion = 0;
10418: if ($file =~ /^(.+)\.(\w+)$/) {
10419: $fn=$1;
10420: $extn=$2;
10421: }
10422: opendir(DIR,$targetdir);
10423: while (my $filename=readdir(DIR)) {
10424: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10425: $maxversion=($1>$maxversion)?$1:$maxversion;
10426: }
10427: }
10428: $maxversion++;
10429: print $logfile "\nCreating old version ".$maxversion."\n";
10430: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10431: if (copy($target,$copyfile)) {
10432: print $logfile "Copied old target to ".$copyfile."\n";
10433: $copyfile=$copyfile.'.meta';
10434: if (copy($target.'.meta',$copyfile)) {
10435: print $logfile "Copied old target metadata to ".$copyfile."\n";
10436: $output = 'ok';
10437: } else {
10438: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10439: $output = &mt('Failed to copy old meta').", $!, ";
10440: }
10441: } else {
10442: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10443: $output = &mt('Failed to copy old target').", $!, ";
10444: }
10445: return $output;
10446: }
10447:
10448: sub write_metadata {
10449: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10450: my (%metadatafields,%metadatakeys,$output);
10451: $metadatafields{'title'}=$formname;
10452: $metadatafields{'creationdate'}=time;
10453: $metadatafields{'lastrevisiondate'}=time;
10454: $metadatafields{'copyright'}='public';
10455: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10456: $env{'user.domain'};
10457: $metadatafields{'authorspace'}=$confname.':'.$dom;
10458: $metadatafields{'domain'}=$dom;
10459: {
10460: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10461: my $mfh;
1.316 raeburn 10462: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 10463: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10464: unless ($_=~/\./) {
10465: my $unikey=$_;
10466: $unikey=~/^([A-Za-z]+)/;
10467: my $tag=$1;
10468: $tag=~tr/A-Z/a-z/;
10469: print $mfh "\n\<$tag";
10470: foreach (split(/\,/,$metadatakeys{$unikey})) {
10471: my $value=$metadatafields{$unikey.'.'.$_};
10472: $value=~s/\"/\'\'/g;
10473: print $mfh ' '.$_.'="'.$value.'"';
10474: }
10475: print $mfh '>'.
10476: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10477: .'</'.$tag.'>';
10478: }
10479: }
10480: $output = 'ok';
10481: print $logfile "\nWrote metadata";
10482: close($mfh);
10483: } else {
10484: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10485: $output = &mt('Could not write metadata');
10486: }
10487: }
1.155 raeburn 10488: return $output;
10489: }
10490:
10491: sub notifysubscribed {
10492: foreach my $targetsource (@{$modified_urls}){
10493: next unless (ref($targetsource) eq 'ARRAY');
10494: my ($target,$source)=@{$targetsource};
10495: if ($source ne '') {
1.316 raeburn 10496: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10497: print $logfh "\nCleanup phase: Notifications\n";
10498: my @subscribed=&subscribed_hosts($target);
10499: foreach my $subhost (@subscribed) {
10500: print $logfh "\nNotifying host ".$subhost.':';
10501: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10502: print $logfh $reply;
10503: }
10504: my @subscribedmeta=&subscribed_hosts("$target.meta");
10505: foreach my $subhost (@subscribedmeta) {
10506: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10507: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10508: $subhost);
10509: print $logfh $reply;
10510: }
10511: print $logfh "\n============ Done ============\n";
1.160 raeburn 10512: close($logfh);
1.155 raeburn 10513: }
10514: }
10515: }
10516: return OK;
10517: }
10518:
10519: sub subscribed_hosts {
10520: my ($target) = @_;
10521: my @subscribed;
1.316 raeburn 10522: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10523: while (my $subline=<$fh>) {
10524: if ($subline =~ /^($match_lonid):/) {
10525: my $host = $1;
10526: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10527: unless (grep(/^\Q$host\E$/,@subscribed)) {
10528: push(@subscribed,$host);
10529: }
10530: }
10531: }
10532: }
10533: }
10534: return @subscribed;
1.9 raeburn 10535: }
10536:
10537: sub check_switchserver {
10538: my ($dom,$confname) = @_;
10539: my ($allowed,$switchserver);
10540: my $home = &Apache::lonnet::homeserver($confname,$dom);
10541: if ($home eq 'no_host') {
10542: $home = &Apache::lonnet::domain($dom,'primary');
10543: }
10544: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10545: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10546: if (!$allowed) {
1.180 raeburn 10547: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10548: }
10549: return $switchserver;
10550: }
10551:
1.1 raeburn 10552: sub modify_quotas {
1.216 raeburn 10553: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10554: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 10555: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 10556: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10557: $validationfieldsref);
1.86 raeburn 10558: if ($action eq 'quotas') {
10559: $context = 'tools';
1.163 raeburn 10560: } else {
1.86 raeburn 10561: $context = $action;
10562: }
10563: if ($context eq 'requestcourses') {
1.325 raeburn 10564: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 10565: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10566: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10567: %titles = &courserequest_titles();
10568: $toolregexp = join('|',@usertools);
10569: %conditions = &courserequest_conditions();
1.216 raeburn 10570: $confname = $dom.'-domainconfig';
10571: my $servadm = $r->dir_config('lonAdmEMail');
10572: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 10573: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10574: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 10575: } elsif ($context eq 'requestauthor') {
10576: @usertools = ('author');
10577: %titles = &authorrequest_titles();
1.86 raeburn 10578: } else {
1.162 raeburn 10579: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10580: %titles = &tool_titles();
1.86 raeburn 10581: }
1.212 raeburn 10582: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10583: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10584: foreach my $key (keys(%env)) {
1.101 raeburn 10585: if ($context eq 'requestcourses') {
10586: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10587: my $item = $1;
10588: my $type = $2;
10589: if ($type =~ /^limit_(.+)/) {
10590: $limithash{$item}{$1} = $env{$key};
10591: } else {
10592: $confhash{$item}{$type} = $env{$key};
10593: }
10594: }
1.163 raeburn 10595: } elsif ($context eq 'requestauthor') {
10596: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10597: $confhash{$1} = $env{$key};
10598: }
1.101 raeburn 10599: } else {
1.86 raeburn 10600: if ($key =~ /^form\.quota_(.+)$/) {
10601: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 10602: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10603: $confhash{'authorquota'}{$1} = $env{$key};
10604: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10605: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10606: }
1.72 raeburn 10607: }
10608: }
1.163 raeburn 10609: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 10610: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10611: @approvalnotify = sort(@approvalnotify);
10612: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 10613: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 10614: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10615: foreach my $type (@hasuniquecode) {
10616: if (grep(/^\Q$type\E$/,@crstypes)) {
10617: $confhash{'uniquecode'}{$type} = 1;
10618: }
1.216 raeburn 10619: }
1.242 raeburn 10620: my (%newbook,%allpos);
1.216 raeburn 10621: if ($context eq 'requestcourses') {
1.242 raeburn 10622: foreach my $type ('textbooks','templates') {
10623: @{$allpos{$type}} = ();
10624: my $invalid;
10625: if ($type eq 'textbooks') {
10626: $invalid = &mt('Invalid LON-CAPA course for textbook');
10627: } else {
10628: $invalid = &mt('Invalid LON-CAPA course for template');
10629: }
10630: if ($env{'form.'.$type.'_addbook'}) {
10631: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10632: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10633: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10634: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10635: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10636: } else {
10637: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10638: my $position = $env{'form.'.$type.'_addbook_pos'};
10639: $position =~ s/\D+//g;
10640: if ($position ne '') {
10641: $allpos{$type}[$position] = $newbook{$type};
10642: }
1.216 raeburn 10643: }
1.242 raeburn 10644: } else {
10645: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 10646: }
10647: }
1.242 raeburn 10648: }
1.216 raeburn 10649: }
1.102 raeburn 10650: if (ref($domconfig{$action}) eq 'HASH') {
10651: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10652: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10653: $changes{'notify'}{'approval'} = 1;
10654: }
10655: } else {
1.144 raeburn 10656: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10657: $changes{'notify'}{'approval'} = 1;
10658: }
10659: }
1.218 raeburn 10660: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10661: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10662: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10663: unless ($confhash{'uniquecode'}{$crstype}) {
10664: $changes{'uniquecode'} = 1;
10665: }
10666: }
10667: unless ($changes{'uniquecode'}) {
10668: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10669: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10670: $changes{'uniquecode'} = 1;
10671: }
10672: }
10673: }
10674: } else {
10675: $changes{'uniquecode'} = 1;
10676: }
10677: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10678: $changes{'uniquecode'} = 1;
1.216 raeburn 10679: }
10680: if ($context eq 'requestcourses') {
1.242 raeburn 10681: foreach my $type ('textbooks','templates') {
10682: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10683: my %deletions;
10684: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10685: if (@todelete) {
10686: map { $deletions{$_} = 1; } @todelete;
10687: }
10688: my %imgdeletions;
10689: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10690: if (@todeleteimages) {
10691: map { $imgdeletions{$_} = 1; } @todeleteimages;
10692: }
10693: my $maxnum = $env{'form.'.$type.'_maxnum'};
10694: for (my $i=0; $i<=$maxnum; $i++) {
10695: my $itemid = $env{'form.'.$type.'_id_'.$i};
10696: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10697: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10698: if ($deletions{$key}) {
10699: if ($domconfig{$action}{$type}{$key}{'image'}) {
10700: #FIXME need to obsolete item in RES space
10701: }
10702: next;
10703: } else {
10704: my $newpos = $env{'form.'.$itemid};
10705: $newpos =~ s/\D+//g;
1.243 raeburn 10706: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 10707: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 10708: ($type eq 'templates'));
1.242 raeburn 10709: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10710: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10711: $changes{$type}{$key} = 1;
10712: }
10713: }
10714: $allpos{$type}[$newpos] = $key;
10715: }
10716: if ($imgdeletions{$key}) {
10717: $changes{$type}{$key} = 1;
1.216 raeburn 10718: #FIXME need to obsolete item in RES space
1.242 raeburn 10719: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10720: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 10721: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10722: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10723: } else {
10724: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10725: $cdom,$cnum,$type,$configuserok,
10726: $switchserver,$author_ok);
10727: if ($imgurl) {
10728: $confhash{$type}{$key}{'image'} = $imgurl;
10729: $changes{$type}{$key} = 1;
10730: }
10731: if ($error) {
10732: &Apache::lonnet::logthis($error);
10733: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10734: }
10735: }
1.242 raeburn 10736: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10737: $confhash{$type}{$key}{'image'} =
10738: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 10739: }
10740: }
10741: }
10742: }
10743: }
10744: }
1.102 raeburn 10745: } else {
1.144 raeburn 10746: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10747: $changes{'notify'}{'approval'} = 1;
10748: }
1.218 raeburn 10749: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 10750: $changes{'uniquecode'} = 1;
10751: }
10752: }
10753: if ($context eq 'requestcourses') {
1.242 raeburn 10754: foreach my $type ('textbooks','templates') {
10755: if ($newbook{$type}) {
10756: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 10757: foreach my $item ('subject','title','publisher','author') {
10758: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10759: ($type eq 'template'));
1.242 raeburn 10760: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10761: if ($env{'form.'.$type.'_addbook_'.$item}) {
10762: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10763: }
10764: }
10765: if ($type eq 'textbooks') {
10766: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10767: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 10768: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10769: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10770: } else {
10771: my ($imageurl,$error) =
10772: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10773: $configuserok,$switchserver,$author_ok);
10774: if ($imageurl) {
10775: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10776: }
10777: if ($error) {
10778: &Apache::lonnet::logthis($error);
10779: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10780: }
1.242 raeburn 10781: }
10782: }
1.216 raeburn 10783: }
10784: }
1.242 raeburn 10785: if (@{$allpos{$type}} > 0) {
10786: my $idx = 0;
10787: foreach my $item (@{$allpos{$type}}) {
10788: if ($item ne '') {
10789: $confhash{$type}{$item}{'order'} = $idx;
10790: if (ref($domconfig{$action}) eq 'HASH') {
10791: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10792: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10793: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10794: $changes{$type}{$item} = 1;
10795: }
1.216 raeburn 10796: }
10797: }
10798: }
1.242 raeburn 10799: $idx ++;
1.216 raeburn 10800: }
10801: }
10802: }
10803: }
1.235 raeburn 10804: if (ref($validationitemsref) eq 'ARRAY') {
10805: foreach my $item (@{$validationitemsref}) {
10806: if ($item eq 'fields') {
10807: my @changed;
10808: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10809: if (@{$confhash{'validation'}{$item}} > 0) {
10810: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10811: }
1.266 raeburn 10812: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10813: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10814: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10815: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10816: $domconfig{'requestcourses'}{'validation'}{$item});
10817: } else {
10818: @changed = @{$confhash{'validation'}{$item}};
10819: }
1.235 raeburn 10820: } else {
10821: @changed = @{$confhash{'validation'}{$item}};
10822: }
10823: } else {
10824: @changed = @{$confhash{'validation'}{$item}};
10825: }
10826: if (@changed) {
10827: if ($confhash{'validation'}{$item}) {
10828: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10829: } else {
10830: $changes{'validation'}{$item} = &mt('None');
10831: }
10832: }
10833: } else {
10834: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10835: if ($item eq 'markup') {
10836: if ($env{'form.requestcourses_validation_'.$item}) {
10837: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10838: }
10839: }
1.266 raeburn 10840: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10841: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10842: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10843: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10844: }
10845: } else {
10846: if ($confhash{'validation'}{$item} ne '') {
10847: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10848: }
1.235 raeburn 10849: }
10850: } else {
10851: if ($confhash{'validation'}{$item} ne '') {
10852: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10853: }
10854: }
10855: }
10856: }
10857: }
10858: if ($env{'form.validationdc'}) {
10859: my $newval = $env{'form.validationdc'};
1.285 raeburn 10860: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 10861: if (exists($domcoords{$newval})) {
10862: $confhash{'validation'}{'dc'} = $newval;
10863: }
10864: }
10865: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 10866: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10867: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10868: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10869: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10870: if ($confhash{'validation'}{'dc'} eq '') {
10871: $changes{'validation'}{'dc'} = &mt('None');
10872: } else {
10873: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10874: }
1.235 raeburn 10875: }
1.266 raeburn 10876: } elsif ($confhash{'validation'}{'dc'} ne '') {
10877: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 10878: }
10879: } elsif ($confhash{'validation'}{'dc'} ne '') {
10880: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10881: }
10882: } elsif ($confhash{'validation'}{'dc'} ne '') {
10883: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 10884: }
1.266 raeburn 10885: } else {
10886: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10887: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10888: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10889: $changes{'validation'}{'dc'} = &mt('None');
10890: }
10891: }
1.235 raeburn 10892: }
10893: }
1.102 raeburn 10894: }
10895: } else {
1.86 raeburn 10896: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 10897: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10898: }
1.72 raeburn 10899: foreach my $item (@usertools) {
10900: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10901: my $unset;
1.101 raeburn 10902: if ($context eq 'requestcourses') {
1.104 raeburn 10903: $unset = '0';
10904: if ($type eq '_LC_adv') {
10905: $unset = '';
10906: }
1.101 raeburn 10907: if ($confhash{$item}{$type} eq 'autolimit') {
10908: $confhash{$item}{$type} .= '=';
10909: unless ($limithash{$item}{$type} =~ /\D/) {
10910: $confhash{$item}{$type} .= $limithash{$item}{$type};
10911: }
10912: }
1.163 raeburn 10913: } elsif ($context eq 'requestauthor') {
10914: $unset = '0';
10915: if ($type eq '_LC_adv') {
10916: $unset = '';
10917: }
1.72 raeburn 10918: } else {
1.101 raeburn 10919: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10920: $confhash{$item}{$type} = 1;
10921: } else {
10922: $confhash{$item}{$type} = 0;
10923: }
1.72 raeburn 10924: }
1.86 raeburn 10925: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 10926: if ($action eq 'requestauthor') {
10927: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10928: $changes{$type} = 1;
10929: }
10930: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10931: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10932: $changes{$item}{$type} = 1;
10933: }
10934: } else {
10935: if ($context eq 'requestcourses') {
1.104 raeburn 10936: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 10937: $changes{$item}{$type} = 1;
10938: }
10939: } else {
10940: if (!$confhash{$item}{$type}) {
10941: $changes{$item}{$type} = 1;
10942: }
10943: }
10944: }
10945: } else {
10946: if ($context eq 'requestcourses') {
1.104 raeburn 10947: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10948: $changes{$item}{$type} = 1;
10949: }
1.163 raeburn 10950: } elsif ($context eq 'requestauthor') {
10951: if ($confhash{$type} ne $unset) {
10952: $changes{$type} = 1;
10953: }
1.72 raeburn 10954: } else {
10955: if (!$confhash{$item}{$type}) {
10956: $changes{$item}{$type} = 1;
10957: }
10958: }
10959: }
1.1 raeburn 10960: }
10961: }
1.163 raeburn 10962: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10963: if (ref($domconfig{'quotas'}) eq 'HASH') {
10964: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10965: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10966: if (exists($confhash{'defaultquota'}{$key})) {
10967: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10968: $changes{'defaultquota'}{$key} = 1;
10969: }
10970: } else {
10971: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10972: }
10973: }
1.86 raeburn 10974: } else {
10975: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10976: if (exists($confhash{'defaultquota'}{$key})) {
10977: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10978: $changes{'defaultquota'}{$key} = 1;
10979: }
10980: } else {
10981: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10982: }
1.1 raeburn 10983: }
10984: }
1.197 raeburn 10985: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10986: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10987: if (exists($confhash{'authorquota'}{$key})) {
10988: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10989: $changes{'authorquota'}{$key} = 1;
10990: }
10991: } else {
10992: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10993: }
10994: }
10995: }
1.1 raeburn 10996: }
1.86 raeburn 10997: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10998: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10999: if (ref($domconfig{'quotas'}) eq 'HASH') {
11000: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11001: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
11002: $changes{'defaultquota'}{$key} = 1;
11003: }
11004: } else {
11005: if (!exists($domconfig{'quotas'}{$key})) {
11006: $changes{'defaultquota'}{$key} = 1;
11007: }
1.72 raeburn 11008: }
11009: } else {
1.86 raeburn 11010: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 11011: }
1.1 raeburn 11012: }
11013: }
1.197 raeburn 11014: if (ref($confhash{'authorquota'}) eq 'HASH') {
11015: foreach my $key (keys(%{$confhash{'authorquota'}})) {
11016: if (ref($domconfig{'quotas'}) eq 'HASH') {
11017: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11018: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
11019: $changes{'authorquota'}{$key} = 1;
11020: }
11021: } else {
11022: $changes{'authorquota'}{$key} = 1;
11023: }
11024: } else {
11025: $changes{'authorquota'}{$key} = 1;
11026: }
11027: }
11028: }
1.1 raeburn 11029: }
1.72 raeburn 11030:
1.163 raeburn 11031: if ($context eq 'requestauthor') {
11032: $domdefaults{'requestauthor'} = \%confhash;
11033: } else {
11034: foreach my $key (keys(%confhash)) {
1.242 raeburn 11035: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 11036: $domdefaults{$key} = $confhash{$key};
11037: }
1.163 raeburn 11038: }
1.72 raeburn 11039: }
1.163 raeburn 11040:
1.1 raeburn 11041: my %quotahash = (
1.86 raeburn 11042: $action => { %confhash }
1.1 raeburn 11043: );
11044: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
11045: $dom);
11046: if ($putresult eq 'ok') {
11047: if (keys(%changes) > 0) {
1.72 raeburn 11048: my $cachetime = 24*60*60;
11049: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11050: if (ref($lastactref) eq 'HASH') {
11051: $lastactref->{'domdefaults'} = 1;
11052: }
1.1 raeburn 11053: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 11054: unless (($context eq 'requestcourses') ||
1.163 raeburn 11055: ($context eq 'requestauthor')) {
1.86 raeburn 11056: if (ref($changes{'defaultquota'}) eq 'HASH') {
11057: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
11058: foreach my $type (@{$types},'default') {
11059: if (defined($changes{'defaultquota'}{$type})) {
11060: my $typetitle = $usertypes->{$type};
11061: if ($type eq 'default') {
11062: $typetitle = $othertitle;
11063: }
1.213 raeburn 11064: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 11065: }
11066: }
1.86 raeburn 11067: $resulttext .= '</ul></li>';
1.72 raeburn 11068: }
1.197 raeburn 11069: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 11070: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 11071: foreach my $type (@{$types},'default') {
11072: if (defined($changes{'authorquota'}{$type})) {
11073: my $typetitle = $usertypes->{$type};
11074: if ($type eq 'default') {
11075: $typetitle = $othertitle;
11076: }
1.213 raeburn 11077: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 11078: }
11079: }
11080: $resulttext .= '</ul></li>';
11081: }
1.72 raeburn 11082: }
1.80 raeburn 11083: my %newenv;
1.72 raeburn 11084: foreach my $item (@usertools) {
1.163 raeburn 11085: my (%haschgs,%inconf);
11086: if ($context eq 'requestauthor') {
11087: %haschgs = %changes;
1.210 raeburn 11088: %inconf = %confhash;
1.163 raeburn 11089: } else {
11090: if (ref($changes{$item}) eq 'HASH') {
11091: %haschgs = %{$changes{$item}};
11092: }
11093: if (ref($confhash{$item}) eq 'HASH') {
11094: %inconf = %{$confhash{$item}};
11095: }
11096: }
11097: if (keys(%haschgs) > 0) {
1.80 raeburn 11098: my $newacc =
11099: &Apache::lonnet::usertools_access($env{'user.name'},
11100: $env{'user.domain'},
1.86 raeburn 11101: $item,'reload',$context);
1.210 raeburn 11102: if (($context eq 'requestcourses') ||
1.163 raeburn 11103: ($context eq 'requestauthor')) {
1.108 raeburn 11104: if ($env{'environment.canrequest.'.$item} ne $newacc) {
11105: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 11106: }
11107: } else {
11108: if ($env{'environment.availabletools.'.$item} ne $newacc) {
11109: $newenv{'environment.availabletools.'.$item} = $newacc;
11110: }
1.80 raeburn 11111: }
1.163 raeburn 11112: unless ($context eq 'requestauthor') {
11113: $resulttext .= '<li>'.$titles{$item}.'<ul>';
11114: }
1.72 raeburn 11115: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 11116: if ($haschgs{$type}) {
1.72 raeburn 11117: my $typetitle = $usertypes->{$type};
11118: if ($type eq 'default') {
11119: $typetitle = $othertitle;
11120: } elsif ($type eq '_LC_adv') {
11121: $typetitle = 'LON-CAPA Advanced Users';
11122: }
1.163 raeburn 11123: if ($inconf{$type}) {
1.101 raeburn 11124: if ($context eq 'requestcourses') {
11125: my $cond;
1.163 raeburn 11126: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 11127: if ($1 eq '') {
11128: $cond = &mt('(Automatic processing of any request).');
11129: } else {
11130: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
11131: }
11132: } else {
1.163 raeburn 11133: $cond = $conditions{$inconf{$type}};
1.101 raeburn 11134: }
11135: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 11136: } elsif ($context eq 'requestauthor') {
11137: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
11138: $titles{$inconf{$type}},$typetitle);
11139:
1.101 raeburn 11140: } else {
11141: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
11142: }
1.72 raeburn 11143: } else {
1.104 raeburn 11144: if ($type eq '_LC_adv') {
1.163 raeburn 11145: if ($inconf{$type} eq '0') {
1.104 raeburn 11146: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11147: } else {
11148: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
11149: }
11150: } else {
11151: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11152: }
1.72 raeburn 11153: }
11154: }
1.26 raeburn 11155: }
1.163 raeburn 11156: unless ($context eq 'requestauthor') {
11157: $resulttext .= '</ul></li>';
11158: }
1.26 raeburn 11159: }
1.1 raeburn 11160: }
1.163 raeburn 11161: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 11162: if (ref($changes{'notify'}) eq 'HASH') {
11163: if ($changes{'notify'}{'approval'}) {
11164: if (ref($confhash{'notify'}) eq 'HASH') {
11165: if ($confhash{'notify'}{'approval'}) {
11166: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
11167: } else {
1.163 raeburn 11168: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 11169: }
11170: }
11171: }
11172: }
11173: }
1.216 raeburn 11174: if ($action eq 'requestcourses') {
11175: my @offon = ('off','on');
11176: if ($changes{'uniquecode'}) {
1.218 raeburn 11177: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11178: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
11179: $resulttext .= '<li>'.
11180: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
11181: '</li>';
11182: } else {
11183: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
11184: '</li>';
11185: }
1.216 raeburn 11186: }
1.242 raeburn 11187: foreach my $type ('textbooks','templates') {
11188: if (ref($changes{$type}) eq 'HASH') {
11189: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
11190: foreach my $key (sort(keys(%{$changes{$type}}))) {
11191: my %coursehash = &Apache::lonnet::coursedescription($key);
11192: my $coursetitle = $coursehash{'description'};
11193: my $position = $confhash{$type}{$key}{'order'} + 1;
11194: $resulttext .= '<li>';
1.243 raeburn 11195: foreach my $item ('subject','title','publisher','author') {
11196: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11197: ($type eq 'templates'));
1.242 raeburn 11198: my $name = $item.':';
11199: $name =~ s/^(\w)/\U$1/;
11200: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
11201: }
11202: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
11203: if ($type eq 'textbooks') {
11204: if ($confhash{$type}{$key}{'image'}) {
11205: $resulttext .= ' '.&mt('Image: [_1]',
11206: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
11207: ' alt="Textbook cover" />').'<br />';
11208: }
11209: }
11210: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 11211: }
1.242 raeburn 11212: $resulttext .= '</ul></li>';
1.216 raeburn 11213: }
11214: }
1.235 raeburn 11215: if (ref($changes{'validation'}) eq 'HASH') {
11216: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
11217: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
11218: foreach my $item (@{$validationitemsref}) {
11219: if (exists($changes{'validation'}{$item})) {
11220: if ($item eq 'markup') {
11221: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11222: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
11223: } else {
11224: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11225: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
11226: }
11227: }
11228: }
11229: if (exists($changes{'validation'}{'dc'})) {
11230: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11231: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11232: }
11233: }
11234: }
1.216 raeburn 11235: }
1.1 raeburn 11236: $resulttext .= '</ul>';
1.80 raeburn 11237: if (keys(%newenv)) {
11238: &Apache::lonnet::appenv(\%newenv);
11239: }
1.1 raeburn 11240: } else {
1.86 raeburn 11241: if ($context eq 'requestcourses') {
11242: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 11243: } elsif ($context eq 'requestauthor') {
11244: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 11245: } else {
1.90 weissno 11246: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 11247: }
1.1 raeburn 11248: }
11249: } else {
1.11 albertel 11250: $resulttext = '<span class="LC_error">'.
11251: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11252: }
1.216 raeburn 11253: if ($errors) {
11254: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
11255: '<ul>'.$errors.'</ul></p>';
11256: }
1.3 raeburn 11257: return $resulttext;
1.1 raeburn 11258: }
11259:
1.216 raeburn 11260: sub process_textbook_image {
1.242 raeburn 11261: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 11262: my $filename = $env{'form.'.$caller.'.filename'};
11263: my ($error,$url);
11264: my ($width,$height) = (50,50);
11265: if ($configuserok eq 'ok') {
11266: if ($switchserver) {
11267: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
11268: $switchserver);
11269: } elsif ($author_ok eq 'ok') {
11270: my ($result,$imageurl) =
11271: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 11272: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 11273: if ($result eq 'ok') {
11274: $url = $imageurl;
11275: } else {
11276: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11277: }
11278: } else {
11279: $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);
11280: }
11281: } else {
11282: $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);
11283: }
11284: return ($url,$error);
11285: }
11286:
1.267 raeburn 11287: sub modify_ltitools {
11288: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11289: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 11290: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 11291: my $confname = $dom.'-domainconfig';
11292: my $servadm = $r->dir_config('lonAdmEMail');
11293: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11294: my (%posslti,%possfield);
11295: my @courseroles = ('cc','in','ta','ep','st');
11296: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
11297: map { $posslti{$_} = 1; } @ltiroles;
11298: my @allfields = ('fullname','firstname','lastname','email','user','roles');
11299: map { $possfield{$_} = 1; } @allfields;
11300: my %lt = <itools_names();
11301: if ($env{'form.ltitools_add'}) {
11302: my $title = $env{'form.ltitools_add_title'};
11303: $title =~ s/(`)/'/g;
11304: ($newid,my $error) = &get_ltitools_id($dom,$title);
11305: if ($newid) {
11306: my $position = $env{'form.ltitools_add_pos'};
11307: $position =~ s/\D+//g;
11308: if ($position ne '') {
11309: $allpos[$position] = $newid;
11310: }
11311: $changes{$newid} = 1;
1.322 raeburn 11312: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 11313: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 11314: if ($item eq 'lifetime') {
11315: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
11316: }
1.267 raeburn 11317: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 11318: if (($item eq 'key') || ($item eq 'secret')) {
11319: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11320: } else {
11321: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11322: }
1.267 raeburn 11323: }
11324: }
11325: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
11326: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
11327: }
11328: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
11329: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
11330: }
1.323 raeburn 11331: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
11332: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
11333: } else {
11334: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
11335: }
1.296 raeburn 11336: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 11337: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
11338: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 11339: if (($item eq 'width') || ($item eq 'height')) {
11340: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
11341: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11342: }
11343: } else {
11344: if ($env{'form.ltitools_add_'.$item} ne '') {
11345: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11346: }
1.267 raeburn 11347: }
11348: }
11349: if ($env{'form.ltitools_add_target'} eq 'window') {
11350: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 11351: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
11352: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 11353: } else {
11354: $confhash{$newid}{'display'}{'target'} = 'iframe';
11355: }
11356: foreach my $item ('passback','roster') {
1.319 raeburn 11357: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 11358: $confhash{$newid}{$item} = 1;
1.319 raeburn 11359: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
11360: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
11361: $lifetime =~ s/^\s+|\s+$//g;
11362: if ($lifetime =~ /^\d+\.?\d*$/) {
11363: $confhash{$newid}{$item.'valid'} = $lifetime;
11364: }
11365: }
1.267 raeburn 11366: }
11367: }
11368: if ($env{'form.ltitools_add_image.filename'} ne '') {
11369: my ($imageurl,$error) =
1.307 raeburn 11370: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 11371: $configuserok,$switchserver,$author_ok);
11372: if ($imageurl) {
11373: $confhash{$newid}{'image'} = $imageurl;
11374: }
11375: if ($error) {
11376: &Apache::lonnet::logthis($error);
11377: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11378: }
11379: }
11380: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
11381: foreach my $field (@fields) {
11382: if ($possfield{$field}) {
11383: if ($field eq 'roles') {
11384: foreach my $role (@courseroles) {
11385: my $choice = $env{'form.ltitools_add_roles_'.$role};
11386: if (($choice ne '') && ($posslti{$choice})) {
11387: $confhash{$newid}{'roles'}{$role} = $choice;
11388: if ($role eq 'cc') {
11389: $confhash{$newid}{'roles'}{'co'} = $choice;
11390: }
11391: }
11392: }
11393: } else {
11394: $confhash{$newid}{'fields'}{$field} = 1;
11395: }
11396: }
11397: }
1.324 raeburn 11398: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
11399: if ($confhash{$newid}{'fields'}{'user'}) {
11400: if ($env{'form.ltitools_userincdom_add'}) {
11401: $confhash{$newid}{'incdom'} = 1;
11402: }
11403: }
11404: }
1.273 raeburn 11405: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
11406: foreach my $item (@courseconfig) {
11407: $confhash{$newid}{'crsconf'}{$item} = 1;
11408: }
1.267 raeburn 11409: if ($env{'form.ltitools_add_custom'}) {
11410: my $name = $env{'form.ltitools_add_custom_name'};
11411: my $value = $env{'form.ltitools_add_custom_value'};
11412: $value =~ s/(`)/'/g;
11413: $name =~ s/(`)/'/g;
11414: $confhash{$newid}{'custom'}{$name} = $value;
11415: }
11416: } else {
11417: my $error = &mt('Failed to acquire unique ID for new external tool');
11418: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11419: }
11420: }
11421: if (ref($domconfig{$action}) eq 'HASH') {
11422: my %deletions;
11423: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
11424: if (@todelete) {
11425: map { $deletions{$_} = 1; } @todelete;
11426: }
11427: my %customadds;
11428: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
11429: if (@newcustom) {
11430: map { $customadds{$_} = 1; } @newcustom;
11431: }
11432: my %imgdeletions;
11433: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
11434: if (@todeleteimages) {
11435: map { $imgdeletions{$_} = 1; } @todeleteimages;
11436: }
11437: my $maxnum = $env{'form.ltitools_maxnum'};
11438: for (my $i=0; $i<=$maxnum; $i++) {
11439: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 11440: $itemid =~ s/\D+//g;
1.267 raeburn 11441: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11442: if ($deletions{$itemid}) {
11443: if ($domconfig{$action}{$itemid}{'image'}) {
11444: #FIXME need to obsolete item in RES space
11445: }
11446: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
11447: next;
11448: } else {
11449: my $newpos = $env{'form.ltitools_'.$itemid};
11450: $newpos =~ s/\D+//g;
1.322 raeburn 11451: foreach my $item ('title','url','lifetime') {
1.267 raeburn 11452: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11453: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11454: $changes{$itemid} = 1;
11455: }
11456: }
1.297 raeburn 11457: foreach my $item ('key','secret') {
11458: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11459: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
11460: $changes{$itemid} = 1;
11461: }
11462: }
1.267 raeburn 11463: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
11464: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
11465: }
11466: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
11467: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
11468: }
1.323 raeburn 11469: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
11470: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
11471: } else {
11472: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
11473: }
11474: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
11475: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
11476: $changes{$itemid} = 1;
11477: }
11478: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
11479: $changes{$itemid} = 1;
11480: }
1.267 raeburn 11481: foreach my $size ('width','height') {
11482: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
11483: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
11484: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
11485: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
11486: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11487: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
11488: $changes{$itemid} = 1;
11489: }
11490: } else {
11491: $changes{$itemid} = 1;
11492: }
1.296 raeburn 11493: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11494: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
11495: $changes{$itemid} = 1;
11496: }
11497: }
11498: }
11499: foreach my $item ('linktext','explanation') {
11500: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
11501: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
11502: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
11503: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11504: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11505: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
11506: $changes{$itemid} = 1;
11507: }
11508: } else {
11509: $changes{$itemid} = 1;
11510: }
11511: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11512: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
11513: $changes{$itemid} = 1;
11514: }
1.267 raeburn 11515: }
11516: }
11517: if ($env{'form.ltitools_target_'.$i} eq 'window') {
11518: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 11519: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
11520: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 11521: } else {
11522: $confhash{$itemid}{'display'}{'target'} = 'iframe';
11523: }
11524: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11525: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
11526: $changes{$itemid} = 1;
11527: }
11528: } else {
11529: $changes{$itemid} = 1;
11530: }
11531: foreach my $extra ('passback','roster') {
11532: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
11533: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 11534: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 11535: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 11536: $lifetime =~ s/^\s+|\s+$//g;
11537: if ($lifetime =~ /^\d+\.?\d*$/) {
11538: $confhash{$itemid}{$extra.'valid'} = $lifetime;
11539: }
11540: }
1.267 raeburn 11541: }
11542: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
11543: $changes{$itemid} = 1;
11544: }
1.319 raeburn 11545: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
11546: $changes{$itemid} = 1;
11547: }
1.267 raeburn 11548: }
1.273 raeburn 11549: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 11550: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 11551: if (grep(/^\Q$item\E$/,@courseconfig)) {
11552: $confhash{$itemid}{'crsconf'}{$item} = 1;
11553: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
11554: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
11555: $changes{$itemid} = 1;
11556: }
11557: } else {
11558: $changes{$itemid} = 1;
11559: }
11560: }
11561: }
1.267 raeburn 11562: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
11563: foreach my $field (@fields) {
11564: if ($possfield{$field}) {
11565: if ($field eq 'roles') {
11566: foreach my $role (@courseroles) {
11567: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
11568: if (($choice ne '') && ($posslti{$choice})) {
11569: $confhash{$itemid}{'roles'}{$role} = $choice;
11570: if ($role eq 'cc') {
11571: $confhash{$itemid}{'roles'}{'co'} = $choice;
11572: }
11573: }
11574: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
11575: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
11576: $changes{$itemid} = 1;
11577: }
11578: } elsif ($confhash{$itemid}{'roles'}{$role}) {
11579: $changes{$itemid} = 1;
11580: }
11581: }
11582: } else {
11583: $confhash{$itemid}{'fields'}{$field} = 1;
11584: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
11585: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
11586: $changes{$itemid} = 1;
11587: }
11588: } else {
11589: $changes{$itemid} = 1;
11590: }
11591: }
11592: }
11593: }
1.324 raeburn 11594: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11595: if ($confhash{$itemid}{'fields'}{'user'}) {
11596: if ($env{'form.ltitools_userincdom_'.$i}) {
11597: $confhash{$itemid}{'incdom'} = 1;
11598: }
11599: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
11600: $changes{$itemid} = 1;
11601: }
11602: }
11603: }
1.267 raeburn 11604: $allpos[$newpos] = $itemid;
11605: }
11606: if ($imgdeletions{$itemid}) {
11607: $changes{$itemid} = 1;
11608: #FIXME need to obsolete item in RES space
11609: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
11610: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
11611: $itemid,$configuserok,$switchserver,
11612: $author_ok);
11613: if ($imgurl) {
11614: $confhash{$itemid}{'image'} = $imgurl;
11615: $changes{$itemid} = 1;
11616: }
11617: if ($error) {
11618: &Apache::lonnet::logthis($error);
11619: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11620: }
11621: } elsif ($domconfig{$action}{$itemid}{'image'}) {
11622: $confhash{$itemid}{'image'} =
11623: $domconfig{$action}{$itemid}{'image'};
11624: }
11625: if ($customadds{$i}) {
11626: my $name = $env{'form.ltitools_custom_name_'.$i};
11627: $name =~ s/(`)/'/g;
11628: $name =~ s/^\s+//;
11629: $name =~ s/\s+$//;
11630: my $value = $env{'form.ltitools_custom_value_'.$i};
11631: $value =~ s/(`)/'/g;
11632: $value =~ s/^\s+//;
11633: $value =~ s/\s+$//;
11634: if ($name ne '') {
11635: $confhash{$itemid}{'custom'}{$name} = $value;
11636: $changes{$itemid} = 1;
11637: }
11638: }
11639: my %customdels;
11640: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
11641: if (@customdeletions) {
11642: $changes{$itemid} = 1;
11643: }
11644: map { $customdels{$_} = 1; } @customdeletions;
11645: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
11646: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
11647: unless ($customdels{$key}) {
11648: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
11649: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
11650: }
11651: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
11652: $changes{$itemid} = 1;
11653: }
11654: }
11655: }
11656: }
11657: unless ($changes{$itemid}) {
11658: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
11659: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
11660: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
11661: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
11662: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
11663: $changes{$itemid} = 1;
11664: last;
11665: }
11666: }
11667: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
11668: $changes{$itemid} = 1;
11669: }
11670: }
11671: last if ($changes{$itemid});
11672: }
11673: }
11674: }
11675: }
11676: }
11677: if (@allpos > 0) {
11678: my $idx = 0;
11679: foreach my $itemid (@allpos) {
11680: if ($itemid ne '') {
11681: $confhash{$itemid}{'order'} = $idx;
11682: if (ref($domconfig{$action}) eq 'HASH') {
11683: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11684: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11685: $changes{$itemid} = 1;
11686: }
11687: }
11688: }
11689: $idx ++;
11690: }
11691: }
11692: }
11693: my %ltitoolshash = (
11694: $action => { %confhash }
11695: );
11696: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
11697: $dom);
11698: if ($putresult eq 'ok') {
1.297 raeburn 11699: my %ltienchash = (
11700: $action => { %encconfig }
11701: );
11702: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 11703: if (keys(%changes) > 0) {
11704: my $cachetime = 24*60*60;
1.297 raeburn 11705: my %ltiall = %confhash;
11706: foreach my $id (keys(%ltiall)) {
11707: if (ref($encconfig{$id}) eq 'HASH') {
11708: foreach my $item ('key','secret') {
11709: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11710: }
11711: }
11712: }
11713: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 11714: if (ref($lastactref) eq 'HASH') {
11715: $lastactref->{'ltitools'} = 1;
11716: }
11717: $resulttext = &mt('Changes made:').'<ul>';
11718: my %bynum;
11719: foreach my $itemid (sort(keys(%changes))) {
11720: my $position = $confhash{$itemid}{'order'};
11721: $bynum{$position} = $itemid;
11722: }
11723: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11724: my $itemid = $bynum{$pos};
11725: if (ref($confhash{$itemid}) ne 'HASH') {
11726: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11727: } else {
11728: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
11729: if ($confhash{$itemid}{'image'}) {
11730: $resulttext .= ' '.
11731: '<img src="'.$confhash{$itemid}{'image'}.'"'.
11732: ' alt="'.&mt('Tool Provider icon').'" />';
11733: }
11734: $resulttext .= '</li><ul>';
11735: my $position = $pos + 1;
11736: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 11737: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 11738: if ($confhash{$itemid}{$item} ne '') {
11739: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11740: }
11741: }
1.297 raeburn 11742: if ($encconfig{$itemid}{'key'} ne '') {
11743: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11744: }
11745: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 11746: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 11747: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 11748: $resulttext .= ('*'x$num).'</li>';
11749: }
1.273 raeburn 11750: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 11751: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 11752: my $numconfig = 0;
11753: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
11754: foreach my $item (@possconfig) {
11755: if ($confhash{$itemid}{'crsconf'}{$item}) {
11756: $numconfig ++;
1.296 raeburn 11757: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 11758: }
11759: }
11760: }
11761: if (!$numconfig) {
11762: $resulttext .= &mt('None');
11763: }
11764: $resulttext .= '</li>';
1.267 raeburn 11765: foreach my $item ('passback','roster') {
11766: $resulttext .= '<li>'.$lt{$item}.' ';
11767: if ($confhash{$itemid}{$item}) {
11768: $resulttext .= &mt('Yes');
1.319 raeburn 11769: if ($confhash{$itemid}{$item.'valid'}) {
11770: if ($item eq 'passback') {
11771: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
11772: $confhash{$itemid}{$item.'valid'});
11773: } else {
11774: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
11775: $confhash{$itemid}{$item.'valid'});
11776: }
11777: }
1.267 raeburn 11778: } else {
11779: $resulttext .= &mt('No');
11780: }
11781: $resulttext .= '</li>';
11782: }
11783: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11784: my $displaylist;
11785: if ($confhash{$itemid}{'display'}{'target'}) {
11786: $displaylist = &mt('Display target').': '.
11787: $confhash{$itemid}{'display'}{'target'}.',';
11788: }
11789: foreach my $size ('width','height') {
11790: if ($confhash{$itemid}{'display'}{$size}) {
11791: $displaylist .= (' 'x2).$lt{$size}.': '.
11792: $confhash{$itemid}{'display'}{$size}.',';
11793: }
11794: }
11795: if ($displaylist) {
11796: $displaylist =~ s/,$//;
11797: $resulttext .= '<li>'.$displaylist.'</li>';
11798: }
1.296 raeburn 11799: foreach my $item ('linktext','explanation') {
11800: if ($confhash{$itemid}{'display'}{$item}) {
11801: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11802: }
11803: }
11804: }
1.267 raeburn 11805: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11806: my $fieldlist;
11807: foreach my $field (@allfields) {
11808: if ($confhash{$itemid}{'fields'}{$field}) {
11809: $fieldlist .= (' 'x2).$lt{$field}.',';
11810: }
11811: }
11812: if ($fieldlist) {
11813: $fieldlist =~ s/,$//;
1.324 raeburn 11814: if ($confhash{$itemid}{'fields'}{'user'}) {
11815: if ($confhash{$itemid}{'incdom'}) {
11816: $fieldlist .= ' ('.&mt('username:domain').')';
11817: } else {
11818: $fieldlist .= ' ('.&mt('username').')';
11819: }
11820: }
1.267 raeburn 11821: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11822: }
11823: }
11824: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11825: my $rolemaps;
11826: foreach my $role (@courseroles) {
11827: if ($confhash{$itemid}{'roles'}{$role}) {
11828: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11829: $confhash{$itemid}{'roles'}{$role}.',';
11830: }
11831: }
11832: if ($rolemaps) {
11833: $rolemaps =~ s/,$//;
11834: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11835: }
11836: }
11837: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11838: my $customlist;
11839: if (keys(%{$confhash{$itemid}{'custom'}})) {
11840: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11841: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11842: }
11843: }
11844: if ($customlist) {
1.317 raeburn 11845: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 11846: }
11847: }
11848: $resulttext .= '</ul></li>';
11849: }
11850: }
11851: $resulttext .= '</ul>';
11852: } else {
11853: $resulttext = &mt('No changes made.');
11854: }
11855: } else {
11856: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11857: }
11858: if ($errors) {
11859: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11860: $errors.'</ul>';
11861: }
11862: return $resulttext;
11863: }
11864:
11865: sub process_ltitools_image {
11866: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11867: my $filename = $env{'form.'.$caller.'.filename'};
11868: my ($error,$url);
11869: my ($width,$height) = (21,21);
11870: if ($configuserok eq 'ok') {
11871: if ($switchserver) {
11872: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11873: $switchserver);
11874: } elsif ($author_ok eq 'ok') {
11875: my ($result,$imageurl,$madethumb) =
11876: &publishlogo($r,'upload',$caller,$dom,$confname,
11877: "ltitools/$itemid/icon",$width,$height);
11878: if ($result eq 'ok') {
11879: if ($madethumb) {
11880: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11881: my $imagethumb = "$path/tn-".$imagefile;
11882: $url = $imagethumb;
11883: } else {
11884: $url = $imageurl;
11885: }
11886: } else {
11887: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11888: }
11889: } else {
11890: $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);
11891: }
11892: } else {
11893: $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);
11894: }
11895: return ($url,$error);
11896: }
11897:
11898: sub get_ltitools_id {
11899: my ($cdom,$title) = @_;
11900: # get lock on ltitools db
11901: my $lockhash = {
11902: lock => $env{'user.name'}.
11903: ':'.$env{'user.domain'},
11904: };
11905: my $tries = 0;
11906: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11907: my ($id,$error);
11908:
11909: while (($gotlock ne 'ok') && ($tries<10)) {
11910: $tries ++;
11911: sleep (0.1);
11912: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11913: }
11914: if ($gotlock eq 'ok') {
11915: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11916: if ($currids{'lock'}) {
11917: delete($currids{'lock'});
11918: if (keys(%currids)) {
11919: my @curr = sort { $a <=> $b } keys(%currids);
11920: if ($curr[-1] =~ /^\d+$/) {
11921: $id = 1 + $curr[-1];
11922: }
11923: } else {
11924: $id = 1;
11925: }
11926: if ($id) {
11927: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11928: $error = 'nostore';
11929: }
11930: } else {
11931: $error = 'nonumber';
11932: }
11933: }
11934: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11935: } else {
11936: $error = 'nolock';
11937: }
11938: return ($id,$error);
11939: }
11940:
1.320 raeburn 11941: sub modify_lti {
11942: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11943: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11944: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
11945: my (%posslti,%posslticrs,%posscrstype);
11946: my @courseroles = ('cc','in','ta','ep','st');
11947: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
11948: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
11949: my @coursetypes = ('official','unofficial','community','textbook','placement');
11950: my %coursetypetitles = &Apache::lonlocal::texthash (
11951: official => 'Official',
11952: unofficial => 'Unofficial',
11953: community => 'Community',
11954: textbook => 'Textbook',
11955: placement => 'Placement Test',
11956: );
1.325 raeburn 11957: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 11958: my %lt = <i_names();
11959: map { $posslti{$_} = 1; } @ltiroles;
11960: map { $posslticrs{$_} = 1; } @lticourseroles;
11961: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 11962:
1.326 raeburn 11963: my %menutitles = <imenu_titles();
11964:
1.320 raeburn 11965: my (@items,%deletions,%itemids);
11966: if ($env{'form.lti_add'}) {
11967: my $consumer = $env{'form.lti_consumer_add'};
11968: $consumer =~ s/(`)/'/g;
11969: ($newid,my $error) = &get_lti_id($dom,$consumer);
11970: if ($newid) {
11971: $itemids{'add'} = $newid;
11972: push(@items,'add');
11973: $changes{$newid} = 1;
11974: } else {
11975: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
11976: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11977: }
11978: }
11979: if (ref($domconfig{$action}) eq 'HASH') {
11980: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
11981: if (@todelete) {
11982: map { $deletions{$_} = 1; } @todelete;
11983: }
11984: my $maxnum = $env{'form.lti_maxnum'};
11985: for (my $i=0; $i<=$maxnum; $i++) {
11986: my $itemid = $env{'form.lti_id_'.$i};
11987: $itemid =~ s/\D+//g;
11988: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11989: if ($deletions{$itemid}) {
11990: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
11991: } else {
11992: push(@items,$i);
11993: $itemids{$i} = $itemid;
11994: }
11995: }
11996: }
11997: }
11998: foreach my $idx (@items) {
11999: my $itemid = $itemids{$idx};
12000: next unless ($itemid);
12001: my $position = $env{'form.lti_pos_'.$idx};
12002: $position =~ s/\D+//g;
12003: if ($position ne '') {
12004: $allpos[$position] = $itemid;
12005: }
1.345 raeburn 12006: foreach my $item ('consumer','key','secret','lifetime','requser') {
1.320 raeburn 12007: my $formitem = 'form.lti_'.$item.'_'.$idx;
12008: $env{$formitem} =~ s/(`)/'/g;
12009: if ($item eq 'lifetime') {
12010: $env{$formitem} =~ s/[^\d.]//g;
12011: }
12012: if ($env{$formitem} ne '') {
12013: if (($item eq 'key') || ($item eq 'secret')) {
12014: $encconfig{$itemid}{$item} = $env{$formitem};
12015: } else {
12016: $confhash{$itemid}{$item} = $env{$formitem};
12017: unless (($idx eq 'add') || ($changes{$itemid})) {
12018: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
12019: $changes{$itemid} = 1;
12020: }
12021: }
12022: }
12023: }
12024: }
12025: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
12026: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
12027: }
1.345 raeburn 12028: if ($confhash{$itemid}{'requser'}) {
12029: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
12030: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
12031: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
12032: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
12033: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
12034: my $mapuser = $env{'form.lti_customuser_'.$idx};
12035: $mapuser =~ s/(`)/'/g;
12036: $mapuser =~ s/^\s+|\s+$//g;
12037: $confhash{$itemid}{'mapuser'} = $mapuser;
12038: }
12039: foreach my $ltirole (@lticourseroles) {
12040: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
12041: if (grep(/^\Q$possrole\E$/,@courseroles)) {
12042: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
12043: }
12044: }
12045: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
12046: my @makeuser;
12047: foreach my $ltirole (sort(@possmakeuser)) {
12048: if ($posslti{$ltirole}) {
12049: push(@makeuser,$ltirole);
12050: }
12051: }
12052: $confhash{$itemid}{'makeuser'} = \@makeuser;
12053: if (@makeuser) {
12054: my $lcauth = $env{'form.lti_lcauth_'.$idx};
12055: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
12056: $confhash{$itemid}{'lcauth'} = $lcauth;
12057: if ($lcauth ne 'internal') {
12058: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
12059: $lcauthparm =~ s/^(\s+|\s+)$//g;
12060: $lcauthparm =~ s/`//g;
12061: if ($lcauthparm ne '') {
12062: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
12063: }
12064: }
12065: } else {
12066: $confhash{$itemid}{'lcauth'} = 'lti';
12067: }
1.320 raeburn 12068: }
1.345 raeburn 12069: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
12070: if (@possinstdata) {
12071: foreach my $field (@possinstdata) {
12072: if (exists($fieldtitles{$field})) {
12073: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 12074: }
12075: }
12076: }
1.345 raeburn 12077: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
12078: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
12079: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
12080: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
12081: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
12082: $mapcrs =~ s/(`)/'/g;
12083: $mapcrs =~ s/^\s+|\s+$//g;
12084: $confhash{$itemid}{'mapcrs'} = $mapcrs;
12085: }
12086: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
12087: my @crstypes;
12088: foreach my $type (sort(@posstypes)) {
12089: if ($posscrstype{$type}) {
12090: push(@crstypes,$type);
1.325 raeburn 12091: }
12092: }
1.345 raeburn 12093: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
12094: if ($env{'form.lti_makecrs_'.$idx}) {
12095: $confhash{$itemid}{'makecrs'} = 1;
1.320 raeburn 12096: }
1.345 raeburn 12097: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
12098: my @selfenroll;
12099: foreach my $type (sort(@possenroll)) {
12100: if ($posslticrs{$type}) {
12101: push(@selfenroll,$type);
12102: }
1.320 raeburn 12103: }
1.345 raeburn 12104: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
12105: if ($env{'form.lti_crssec_'.$idx}) {
12106: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
12107: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
12108: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
12109: my $section = $env{'form.lti_customsection_'.$idx};
12110: $section =~ s/(`)/'/g;
12111: $section =~ s/^\s+|\s+$//g;
12112: if ($section ne '') {
12113: $confhash{$itemid}{'section'} = $section;
12114: }
1.320 raeburn 12115: }
12116: }
1.345 raeburn 12117: foreach my $field ('passback','roster','topmenu','inlinemenu') {
12118: if ($env{'form.lti_'.$field.'_'.$idx}) {
12119: $confhash{$itemid}{$field} = 1;
12120: }
1.320 raeburn 12121: }
1.345 raeburn 12122: if ($env{'form.lti_passback_'.$idx}) {
12123: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
12124: $confhash{$itemid}{'passbackformat'} = '1.0';
12125: } else {
12126: $confhash{$itemid}{'passbackformat'} = '1.1';
12127: }
1.337 raeburn 12128: }
1.345 raeburn 12129: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
12130: $confhash{$itemid}{lcmenu} = [];
12131: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
12132: foreach my $field (@possmenu) {
12133: if (exists($menutitles{$field})) {
12134: if ($field eq 'grades') {
12135: next unless ($env{'form.lti_inlinemenu_'.$idx});
12136: }
12137: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 12138: }
12139: }
12140: }
1.345 raeburn 12141: unless (($idx eq 'add') || ($changes{$itemid})) {
12142: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu') {
12143: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.337 raeburn 12144: $changes{$itemid} = 1;
12145: }
12146: }
1.320 raeburn 12147: unless ($changes{$itemid}) {
1.345 raeburn 12148: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
12149: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 12150: $changes{$itemid} = 1;
12151: }
1.345 raeburn 12152: }
1.320 raeburn 12153: }
1.345 raeburn 12154: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
12155: unless ($changes{$itemid}) {
12156: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
12157: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
12158: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
12159: $confhash{$itemid}{$field});
12160: if (@diffs) {
12161: $changes{$itemid} = 1;
12162: }
12163: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
12164: $changes{$itemid} = 1;
12165: }
12166: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
12167: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 12168: $changes{$itemid} = 1;
12169: }
12170: }
1.345 raeburn 12171: }
12172: }
12173: unless ($changes{$itemid}) {
12174: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
12175: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12176: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
12177: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
12178: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.320 raeburn 12179: $changes{$itemid} = 1;
12180: last;
12181: }
12182: }
1.345 raeburn 12183: unless ($changes{$itemid}) {
12184: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
12185: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
12186: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
12187: $changes{$itemid} = 1;
12188: last;
12189: }
12190: }
12191: }
12192: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
12193: $changes{$itemid} = 1;
1.320 raeburn 12194: }
1.345 raeburn 12195: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12196: unless ($changes{$itemid}) {
12197: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
12198: $changes{$itemid} = 1;
12199: }
1.320 raeburn 12200: }
12201: }
12202: }
12203: }
12204: }
12205: }
12206: if (@allpos > 0) {
12207: my $idx = 0;
12208: foreach my $itemid (@allpos) {
12209: if ($itemid ne '') {
12210: $confhash{$itemid}{'order'} = $idx;
12211: if (ref($domconfig{$action}) eq 'HASH') {
12212: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12213: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12214: $changes{$itemid} = 1;
12215: }
12216: }
12217: }
12218: $idx ++;
12219: }
12220: }
12221: }
12222: my %ltihash = (
12223: $action => { %confhash }
12224: );
12225: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
12226: $dom);
12227: if ($putresult eq 'ok') {
12228: my %ltienchash = (
12229: $action => { %encconfig }
12230: );
12231: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
12232: if (keys(%changes) > 0) {
12233: my $cachetime = 24*60*60;
12234: my %ltiall = %confhash;
12235: foreach my $id (keys(%ltiall)) {
12236: if (ref($encconfig{$id}) eq 'HASH') {
12237: foreach my $item ('key','secret') {
12238: $ltiall{$id}{$item} = $encconfig{$id}{$item};
12239: }
12240: }
12241: }
12242: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
12243: if (ref($lastactref) eq 'HASH') {
12244: $lastactref->{'lti'} = 1;
12245: }
12246: $resulttext = &mt('Changes made:').'<ul>';
12247: my %bynum;
12248: foreach my $itemid (sort(keys(%changes))) {
12249: my $position = $confhash{$itemid}{'order'};
12250: $bynum{$position} = $itemid;
12251: }
12252: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12253: my $itemid = $bynum{$pos};
12254: if (ref($confhash{$itemid}) ne 'HASH') {
12255: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12256: } else {
12257: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
12258: my $position = $pos + 1;
12259: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12260: foreach my $item ('version','lifetime') {
12261: if ($confhash{$itemid}{$item} ne '') {
12262: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12263: }
12264: }
12265: if ($encconfig{$itemid}{'key'} ne '') {
12266: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12267: }
12268: if ($encconfig{$itemid}{'secret'} ne '') {
12269: $resulttext .= '<li>'.$lt{'secret'}.': ';
12270: my $num = length($encconfig{$itemid}{'secret'});
12271: $resulttext .= ('*'x$num).'</li>';
12272: }
1.345 raeburn 12273: if ($confhash{$itemid}{'requser'}) {
12274: if ($confhash{$itemid}{'mapuser'}) {
12275: my $shownmapuser;
12276: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
12277: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
12278: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
12279: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
12280: } else {
12281: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 12282: }
1.345 raeburn 12283: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 12284: }
1.345 raeburn 12285: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12286: my $rolemaps;
12287: foreach my $role (@ltiroles) {
12288: if ($confhash{$itemid}{'maproles'}{$role}) {
12289: $rolemaps .= (' 'x2).$role.'='.
12290: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
12291: 'Course').',';
12292: }
12293: }
12294: if ($rolemaps) {
12295: $rolemaps =~ s/,$//;
12296: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12297: }
12298: }
12299: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
12300: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
12301: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
12302: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
12303: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
12304: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
12305: } else {
12306: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
12307: $confhash{$itemid}{'lcauth'});
12308: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
12309: $resulttext .= '; '.&mt('a randomly generated password will be created');
12310: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
12311: if ($confhash{$itemid}{'lcauthparm'} ne '') {
12312: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
12313: }
12314: } else {
12315: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
12316: }
12317: }
12318: $resulttext .= '</li>';
12319: } else {
12320: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
12321: }
1.320 raeburn 12322: }
1.345 raeburn 12323: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
12324: if (@{$confhash{$itemid}{'instdata'}} > 0) {
12325: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
12326: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 12327: } else {
1.345 raeburn 12328: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 12329: }
1.320 raeburn 12330: }
1.345 raeburn 12331: if ($confhash{$itemid}{'mapcrs'}) {
12332: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
12333: }
12334: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
12335: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
12336: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
12337: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
12338: '</li>';
12339: } else {
12340: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
12341: }
1.325 raeburn 12342: }
1.345 raeburn 12343: if ($confhash{$itemid}{'makecrs'}) {
12344: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
1.320 raeburn 12345: } else {
1.345 raeburn 12346: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
1.320 raeburn 12347: }
1.345 raeburn 12348: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
12349: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
12350: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
12351: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
12352: '</li>';
12353: } else {
12354: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
12355: }
1.320 raeburn 12356: }
1.345 raeburn 12357: if ($confhash{$itemid}{'section'}) {
12358: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
12359: $resulttext .= '<li>'.&mt('User section from standard field:').
12360: ' (course_section_sourcedid)'.'</li>';
12361: } else {
12362: $resulttext .= '<li>'.&mt('User section from:').' '.
12363: $confhash{$itemid}{'section'}.'</li>';
12364: }
1.320 raeburn 12365: } else {
1.345 raeburn 12366: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
1.320 raeburn 12367: }
1.345 raeburn 12368: foreach my $item ('passback','roster','topmenu','inlinemenu') {
12369: $resulttext .= '<li>'.$lt{$item}.': ';
12370: if ($confhash{$itemid}{$item}) {
12371: $resulttext .= &mt('Yes');
12372: if ($item eq 'passback') {
12373: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
12374: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
12375: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
12376: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
12377: }
1.337 raeburn 12378: }
1.345 raeburn 12379: } else {
12380: $resulttext .= &mt('No');
1.337 raeburn 12381: }
1.345 raeburn 12382: $resulttext .= '</li>';
1.320 raeburn 12383: }
1.345 raeburn 12384: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
12385: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
12386: $resulttext .= '<li>'.&mt('Menu items:').' '.
12387: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
12388: } else {
12389: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
12390: }
1.326 raeburn 12391: }
12392: }
1.320 raeburn 12393: $resulttext .= '</ul></li>';
12394: }
12395: }
12396: $resulttext .= '</ul>';
12397: } else {
12398: $resulttext = &mt('No changes made.');
12399: }
12400: } else {
12401: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12402: }
12403: if ($errors) {
12404: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12405: $errors.'</ul>';
12406: }
12407: return $resulttext;
12408: }
12409:
12410: sub get_lti_id {
12411: my ($domain,$consumer) = @_;
12412: # get lock on lti db
12413: my $lockhash = {
12414: lock => $env{'user.name'}.
12415: ':'.$env{'user.domain'},
12416: };
12417: my $tries = 0;
12418: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12419: my ($id,$error);
12420:
12421: while (($gotlock ne 'ok') && ($tries<10)) {
12422: $tries ++;
12423: sleep (0.1);
12424: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12425: }
12426: if ($gotlock eq 'ok') {
12427: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
12428: if ($currids{'lock'}) {
12429: delete($currids{'lock'});
12430: if (keys(%currids)) {
12431: my @curr = sort { $a <=> $b } keys(%currids);
12432: if ($curr[-1] =~ /^\d+$/) {
12433: $id = 1 + $curr[-1];
12434: }
12435: } else {
12436: $id = 1;
12437: }
12438: if ($id) {
12439: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
12440: $error = 'nostore';
12441: }
12442: } else {
12443: $error = 'nonumber';
12444: }
12445: }
12446: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
12447: } else {
12448: $error = 'nolock';
12449: }
12450: return ($id,$error);
12451: }
12452:
1.3 raeburn 12453: sub modify_autoenroll {
1.205 raeburn 12454: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 12455: my ($resulttext,%changes);
12456: my %currautoenroll;
12457: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
12458: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
12459: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
12460: }
12461: }
12462: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
12463: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 12464: sender => 'Sender for notification messages',
1.274 raeburn 12465: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
12466: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 12467: my @offon = ('off','on');
1.17 raeburn 12468: my $sender_uname = $env{'form.sender_uname'};
12469: my $sender_domain = $env{'form.sender_domain'};
12470: if ($sender_domain eq '') {
12471: $sender_uname = '';
12472: } elsif ($sender_uname eq '') {
12473: $sender_domain = '';
12474: }
1.129 raeburn 12475: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 12476: my $failsafe = $env{'form.autoenroll_failsafe'};
12477: $failsafe =~ s{^\s+|\s+$}{}g;
12478: if ($failsafe =~ /\D/) {
12479: undef($failsafe);
12480: }
1.1 raeburn 12481: my %autoenrollhash = (
1.129 raeburn 12482: autoenroll => { 'run' => $env{'form.autoenroll_run'},
12483: 'sender_uname' => $sender_uname,
12484: 'sender_domain' => $sender_domain,
12485: 'co-owners' => $coowners,
1.274 raeburn 12486: 'autofailsafe' => $failsafe,
1.1 raeburn 12487: }
12488: );
1.4 raeburn 12489: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
12490: $dom);
1.1 raeburn 12491: if ($putresult eq 'ok') {
12492: if (exists($currautoenroll{'run'})) {
12493: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
12494: $changes{'run'} = 1;
12495: }
12496: } elsif ($autorun) {
12497: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 12498: $changes{'run'} = 1;
1.1 raeburn 12499: }
12500: }
1.17 raeburn 12501: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 12502: $changes{'sender'} = 1;
12503: }
1.17 raeburn 12504: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 12505: $changes{'sender'} = 1;
12506: }
1.129 raeburn 12507: if ($currautoenroll{'co-owners'} ne '') {
12508: if ($currautoenroll{'co-owners'} ne $coowners) {
12509: $changes{'coowners'} = 1;
12510: }
12511: } elsif ($coowners) {
12512: $changes{'coowners'} = 1;
1.274 raeburn 12513: }
12514: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
12515: $changes{'autofailsafe'} = 1;
12516: }
1.1 raeburn 12517: if (keys(%changes) > 0) {
12518: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 12519: if ($changes{'run'}) {
1.1 raeburn 12520: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
12521: }
12522: if ($changes{'sender'}) {
1.17 raeburn 12523: if ($sender_uname eq '' || $sender_domain eq '') {
12524: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
12525: } else {
12526: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
12527: }
1.1 raeburn 12528: }
1.129 raeburn 12529: if ($changes{'coowners'}) {
12530: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
12531: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12532: if (ref($lastactref) eq 'HASH') {
12533: $lastactref->{'domainconfig'} = 1;
12534: }
1.129 raeburn 12535: }
1.274 raeburn 12536: if ($changes{'autofailsafe'}) {
12537: if ($failsafe ne '') {
1.299 raeburn 12538: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 12539: } else {
1.299 raeburn 12540: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 12541: }
12542: &Apache::lonnet::get_domain_defaults($dom,1);
12543: if (ref($lastactref) eq 'HASH') {
12544: $lastactref->{'domdefaults'} = 1;
12545: }
12546: }
1.1 raeburn 12547: $resulttext .= '</ul>';
12548: } else {
12549: $resulttext = &mt('No changes made to auto-enrollment settings');
12550: }
12551: } else {
1.11 albertel 12552: $resulttext = '<span class="LC_error">'.
12553: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12554: }
1.3 raeburn 12555: return $resulttext;
1.1 raeburn 12556: }
12557:
12558: sub modify_autoupdate {
1.3 raeburn 12559: my ($dom,%domconfig) = @_;
1.1 raeburn 12560: my ($resulttext,%currautoupdate,%fields,%changes);
12561: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
12562: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
12563: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
12564: }
12565: }
12566: my @offon = ('off','on');
12567: my %title = &Apache::lonlocal::texthash (
12568: run => 'Auto-update:',
12569: classlists => 'Updates to user information in classlists?'
12570: );
1.44 raeburn 12571: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12572: my %fieldtitles = &Apache::lonlocal::texthash (
12573: id => 'Student/Employee ID',
1.20 raeburn 12574: permanentemail => 'E-mail address',
1.1 raeburn 12575: lastname => 'Last Name',
12576: firstname => 'First Name',
12577: middlename => 'Middle Name',
1.132 raeburn 12578: generation => 'Generation',
1.1 raeburn 12579: );
1.142 raeburn 12580: $othertitle = &mt('All users');
1.1 raeburn 12581: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 12582: $othertitle = &mt('Other users');
1.1 raeburn 12583: }
12584: foreach my $key (keys(%env)) {
12585: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 12586: my ($usertype,$item) = ($1,$2);
12587: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
12588: if ($usertype eq 'default') {
12589: push(@{$fields{$1}},$2);
12590: } elsif (ref($types) eq 'ARRAY') {
12591: if (grep(/^\Q$usertype\E$/,@{$types})) {
12592: push(@{$fields{$1}},$2);
12593: }
12594: }
12595: }
1.1 raeburn 12596: }
12597: }
1.131 raeburn 12598: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
12599: @lockablenames = sort(@lockablenames);
12600: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
12601: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12602: if (@changed) {
12603: $changes{'lockablenames'} = 1;
12604: }
12605: } else {
12606: if (@lockablenames) {
12607: $changes{'lockablenames'} = 1;
12608: }
12609: }
1.1 raeburn 12610: my %updatehash = (
12611: autoupdate => { run => $env{'form.autoupdate_run'},
12612: classlists => $env{'form.classlists'},
12613: fields => {%fields},
1.131 raeburn 12614: lockablenames => \@lockablenames,
1.1 raeburn 12615: }
12616: );
12617: foreach my $key (keys(%currautoupdate)) {
12618: if (($key eq 'run') || ($key eq 'classlists')) {
12619: if (exists($updatehash{autoupdate}{$key})) {
12620: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
12621: $changes{$key} = 1;
12622: }
12623: }
12624: } elsif ($key eq 'fields') {
12625: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 12626: foreach my $item (@{$types},'default') {
1.1 raeburn 12627: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
12628: my $change = 0;
12629: foreach my $type (@{$currautoupdate{$key}{$item}}) {
12630: if (!exists($fields{$item})) {
12631: $change = 1;
1.132 raeburn 12632: last;
1.1 raeburn 12633: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 12634: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 12635: $change = 1;
1.132 raeburn 12636: last;
1.1 raeburn 12637: }
12638: }
12639: }
12640: if ($change) {
12641: push(@{$changes{$key}},$item);
12642: }
1.26 raeburn 12643: }
1.1 raeburn 12644: }
12645: }
1.131 raeburn 12646: } elsif ($key eq 'lockablenames') {
12647: if (ref($currautoupdate{$key}) eq 'ARRAY') {
12648: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12649: if (@changed) {
12650: $changes{'lockablenames'} = 1;
12651: }
12652: } else {
12653: if (@lockablenames) {
12654: $changes{'lockablenames'} = 1;
12655: }
12656: }
12657: }
12658: }
12659: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
12660: if (@lockablenames) {
12661: $changes{'lockablenames'} = 1;
1.1 raeburn 12662: }
12663: }
1.26 raeburn 12664: foreach my $item (@{$types},'default') {
12665: if (defined($fields{$item})) {
12666: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 12667: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
12668: my $change = 0;
12669: if (ref($fields{$item}) eq 'ARRAY') {
12670: foreach my $type (@{$fields{$item}}) {
12671: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
12672: $change = 1;
12673: last;
12674: }
12675: }
12676: }
12677: if ($change) {
12678: push(@{$changes{'fields'}},$item);
12679: }
12680: } else {
1.26 raeburn 12681: push(@{$changes{'fields'}},$item);
12682: }
12683: } else {
12684: push(@{$changes{'fields'}},$item);
1.1 raeburn 12685: }
12686: }
12687: }
12688: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
12689: $dom);
12690: if ($putresult eq 'ok') {
12691: if (keys(%changes) > 0) {
12692: $resulttext = &mt('Changes made:').'<ul>';
12693: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 12694: if ($key eq 'lockablenames') {
12695: $resulttext .= '<li>';
12696: if (@lockablenames) {
12697: $usertypes->{'default'} = $othertitle;
12698: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
12699: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
12700: } else {
12701: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
12702: }
12703: $resulttext .= '</li>';
12704: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 12705: foreach my $item (@{$changes{$key}}) {
12706: my @newvalues;
12707: foreach my $type (@{$fields{$item}}) {
12708: push(@newvalues,$fieldtitles{$type});
12709: }
1.3 raeburn 12710: my $newvaluestr;
12711: if (@newvalues > 0) {
12712: $newvaluestr = join(', ',@newvalues);
12713: } else {
12714: $newvaluestr = &mt('none');
1.6 raeburn 12715: }
1.1 raeburn 12716: if ($item eq 'default') {
1.26 raeburn 12717: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 12718: } else {
1.26 raeburn 12719: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 12720: }
12721: }
12722: } else {
12723: my $newvalue;
12724: if ($key eq 'run') {
12725: $newvalue = $offon[$env{'form.autoupdate_run'}];
12726: } else {
12727: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 12728: }
1.1 raeburn 12729: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
12730: }
12731: }
12732: $resulttext .= '</ul>';
12733: } else {
1.3 raeburn 12734: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 12735: }
12736: } else {
1.11 albertel 12737: $resulttext = '<span class="LC_error">'.
12738: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12739: }
1.3 raeburn 12740: return $resulttext;
1.1 raeburn 12741: }
12742:
1.125 raeburn 12743: sub modify_autocreate {
12744: my ($dom,%domconfig) = @_;
12745: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
12746: if (ref($domconfig{'autocreate'}) eq 'HASH') {
12747: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
12748: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
12749: }
12750: }
12751: my %title= ( xml => 'Auto-creation of courses in XML course description files',
12752: req => 'Auto-creation of validated requests for official courses',
12753: xmldc => 'Identity of course creator of courses from XML files',
12754: );
12755: my @types = ('xml','req');
12756: foreach my $item (@types) {
12757: $newvals{$item} = $env{'form.autocreate_'.$item};
12758: $newvals{$item} =~ s/\D//g;
12759: $newvals{$item} = 0 if ($newvals{$item} eq '');
12760: }
12761: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 12762: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 12763: unless (exists($domcoords{$newvals{'xmldc'}})) {
12764: $newvals{'xmldc'} = '';
12765: }
12766: %autocreatehash = (
12767: autocreate => { xml => $newvals{'xml'},
12768: req => $newvals{'req'},
12769: }
12770: );
12771: if ($newvals{'xmldc'} ne '') {
12772: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
12773: }
12774: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
12775: $dom);
12776: if ($putresult eq 'ok') {
12777: my @items = @types;
12778: if ($newvals{'xml'}) {
12779: push(@items,'xmldc');
12780: }
12781: foreach my $item (@items) {
12782: if (exists($currautocreate{$item})) {
12783: if ($currautocreate{$item} ne $newvals{$item}) {
12784: $changes{$item} = 1;
12785: }
12786: } elsif ($newvals{$item}) {
12787: $changes{$item} = 1;
12788: }
12789: }
12790: if (keys(%changes) > 0) {
12791: my @offon = ('off','on');
12792: $resulttext = &mt('Changes made:').'<ul>';
12793: foreach my $item (@types) {
12794: if ($changes{$item}) {
12795: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 12796: $resulttext .= '<li>'.
12797: &mt("$title{$item} set to [_1]$newtxt [_2]",
12798: '<b>','</b>').
12799: '</li>';
1.125 raeburn 12800: }
12801: }
12802: if ($changes{'xmldc'}) {
12803: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
12804: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 12805: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 12806: }
12807: $resulttext .= '</ul>';
12808: } else {
12809: $resulttext = &mt('No changes made to auto-creation settings');
12810: }
12811: } else {
12812: $resulttext = '<span class="LC_error">'.
12813: &mt('An error occurred: [_1]',$putresult).'</span>';
12814: }
12815: return $resulttext;
12816: }
12817:
1.23 raeburn 12818: sub modify_directorysrch {
1.295 raeburn 12819: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 12820: my ($resulttext,%changes);
12821: my %currdirsrch;
12822: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
12823: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
12824: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
12825: }
12826: }
1.277 raeburn 12827: my %title = ( available => 'Institutional directory search available',
12828: localonly => 'Other domains can search institution',
12829: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 12830: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 12831: searchby => 'Search types',
12832: searchtypes => 'Search latitude');
12833: my @offon = ('off','on');
1.24 raeburn 12834: my @otherdoms = ('Yes','No');
1.23 raeburn 12835:
1.25 raeburn 12836: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 12837: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
12838: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
12839:
1.44 raeburn 12840: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 12841: if (keys(%{$usertypes}) == 0) {
12842: @cansearch = ('default');
12843: } else {
12844: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
12845: foreach my $type (@{$currdirsrch{'cansearch'}}) {
12846: if (!grep(/^\Q$type\E$/,@cansearch)) {
12847: push(@{$changes{'cansearch'}},$type);
12848: }
1.23 raeburn 12849: }
1.26 raeburn 12850: foreach my $type (@cansearch) {
12851: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
12852: push(@{$changes{'cansearch'}},$type);
12853: }
1.23 raeburn 12854: }
1.26 raeburn 12855: } else {
12856: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 12857: }
12858: }
12859:
12860: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
12861: foreach my $by (@{$currdirsrch{'searchby'}}) {
12862: if (!grep(/^\Q$by\E$/,@searchby)) {
12863: push(@{$changes{'searchby'}},$by);
12864: }
12865: }
12866: foreach my $by (@searchby) {
12867: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
12868: push(@{$changes{'searchby'}},$by);
12869: }
12870: }
12871: } else {
12872: push(@{$changes{'searchby'}},@searchby);
12873: }
1.25 raeburn 12874:
12875: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
12876: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
12877: if (!grep(/^\Q$type\E$/,@searchtypes)) {
12878: push(@{$changes{'searchtypes'}},$type);
12879: }
12880: }
12881: foreach my $type (@searchtypes) {
12882: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
12883: push(@{$changes{'searchtypes'}},$type);
12884: }
12885: }
12886: } else {
12887: if (exists($currdirsrch{'searchtypes'})) {
12888: foreach my $type (@searchtypes) {
12889: if ($type ne $currdirsrch{'searchtypes'}) {
12890: push(@{$changes{'searchtypes'}},$type);
12891: }
12892: }
12893: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
12894: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12895: }
12896: } else {
12897: push(@{$changes{'searchtypes'}},@searchtypes);
12898: }
12899: }
12900:
1.23 raeburn 12901: my %dirsrch_hash = (
12902: directorysrch => { available => $env{'form.dirsrch_available'},
12903: cansearch => \@cansearch,
1.277 raeburn 12904: localonly => $env{'form.dirsrch_instlocalonly'},
12905: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12906: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 12907: searchby => \@searchby,
1.25 raeburn 12908: searchtypes => \@searchtypes,
1.23 raeburn 12909: }
12910: );
12911: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12912: $dom);
12913: if ($putresult eq 'ok') {
12914: if (exists($currdirsrch{'available'})) {
12915: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12916: $changes{'available'} = 1;
12917: }
12918: } else {
12919: if ($env{'form.dirsrch_available'} eq '1') {
12920: $changes{'available'} = 1;
12921: }
12922: }
1.277 raeburn 12923: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 12924: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12925: $changes{'lcavailable'} = 1;
12926: }
1.277 raeburn 12927: } else {
12928: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12929: $changes{'lcavailable'} = 1;
12930: }
12931: }
1.24 raeburn 12932: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 12933: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
12934: $changes{'localonly'} = 1;
12935: }
1.24 raeburn 12936: } else {
1.277 raeburn 12937: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 12938: $changes{'localonly'} = 1;
12939: }
12940: }
1.277 raeburn 12941: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 12942: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12943: $changes{'lclocalonly'} = 1;
12944: }
1.277 raeburn 12945: } else {
12946: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12947: $changes{'lclocalonly'} = 1;
12948: }
12949: }
1.23 raeburn 12950: if (keys(%changes) > 0) {
12951: $resulttext = &mt('Changes made:').'<ul>';
12952: if ($changes{'available'}) {
12953: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12954: }
1.277 raeburn 12955: if ($changes{'lcavailable'}) {
12956: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12957: }
1.24 raeburn 12958: if ($changes{'localonly'}) {
1.277 raeburn 12959: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 12960: }
1.277 raeburn 12961: if ($changes{'lclocalonly'}) {
12962: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 12963: }
1.23 raeburn 12964: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12965: my $chgtext;
1.26 raeburn 12966: if (ref($usertypes) eq 'HASH') {
12967: if (keys(%{$usertypes}) > 0) {
12968: foreach my $type (@{$types}) {
12969: if (grep(/^\Q$type\E$/,@cansearch)) {
12970: $chgtext .= $usertypes->{$type}.'; ';
12971: }
12972: }
12973: if (grep(/^default$/,@cansearch)) {
12974: $chgtext .= $othertitle;
12975: } else {
12976: $chgtext =~ s/\; $//;
12977: }
1.210 raeburn 12978: $resulttext .=
1.178 raeburn 12979: '<li>'.
12980: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12981: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12982: '</li>';
1.23 raeburn 12983: }
12984: }
12985: }
12986: if (ref($changes{'searchby'}) eq 'ARRAY') {
12987: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12988: my $chgtext;
12989: foreach my $type (@{$titleorder}) {
12990: if (grep(/^\Q$type\E$/,@searchby)) {
12991: if (defined($searchtitles->{$type})) {
12992: $chgtext .= $searchtitles->{$type}.'; ';
12993: }
12994: }
12995: }
12996: $chgtext =~ s/\; $//;
12997: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12998: }
1.25 raeburn 12999: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
13000: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
13001: my $chgtext;
13002: foreach my $type (@{$srchtypeorder}) {
13003: if (grep(/^\Q$type\E$/,@searchtypes)) {
13004: if (defined($srchtypes_desc->{$type})) {
13005: $chgtext .= $srchtypes_desc->{$type}.'; ';
13006: }
13007: }
13008: }
13009: $chgtext =~ s/\; $//;
1.178 raeburn 13010: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 13011: }
13012: $resulttext .= '</ul>';
1.295 raeburn 13013: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
13014: if (ref($lastactref) eq 'HASH') {
13015: $lastactref->{'directorysrch'} = 1;
13016: }
1.23 raeburn 13017: } else {
1.277 raeburn 13018: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 13019: }
13020: } else {
13021: $resulttext = '<span class="LC_error">'.
1.27 raeburn 13022: &mt('An error occurred: [_1]',$putresult).'</span>';
13023: }
13024: return $resulttext;
13025: }
13026:
1.28 raeburn 13027: sub modify_contacts {
1.205 raeburn 13028: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 13029: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
13030: if (ref($domconfig{'contacts'}) eq 'HASH') {
13031: foreach my $key (keys(%{$domconfig{'contacts'}})) {
13032: $currsetting{$key} = $domconfig{'contacts'}{$key};
13033: }
13034: }
1.286 raeburn 13035: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 13036: my @contacts = ('supportemail','adminemail');
1.286 raeburn 13037: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
13038: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.340 raeburn 13039: my @toggles = ('reporterrors','reportupdates','reportstatus');
13040: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 13041: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 13042: foreach my $type (@mailings) {
13043: @{$newsetting{$type}} =
13044: &Apache::loncommon::get_env_multiple('form.'.$type);
13045: foreach my $item (@contacts) {
13046: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
13047: $contacts_hash{contacts}{$type}{$item} = 1;
13048: } else {
13049: $contacts_hash{contacts}{$type}{$item} = 0;
13050: }
1.289 raeburn 13051: }
1.28 raeburn 13052: $others{$type} = $env{'form.'.$type.'_others'};
13053: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 13054: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13055: $bcc{$type} = $env{'form.'.$type.'_bcc'};
13056: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 13057: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
13058: $includestr{$type} = $env{'form.'.$type.'_includestr'};
13059: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
13060: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13061: }
1.134 raeburn 13062: }
1.28 raeburn 13063: }
13064: foreach my $item (@contacts) {
13065: $to{$item} = $env{'form.'.$item};
13066: $contacts_hash{'contacts'}{$item} = $to{$item};
13067: }
1.203 raeburn 13068: foreach my $item (@toggles) {
13069: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13070: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
13071: }
13072: }
1.340 raeburn 13073: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
13074: foreach my $item (@lonstatus) {
13075: if ($item eq 'excluded') {
13076: my (%serverhomes,@excluded);
13077: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
13078: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
13079: if (@possexcluded) {
13080: foreach my $id (sort(@possexcluded)) {
13081: if ($serverhomes{$id}) {
13082: push(@excluded,$id);
13083: }
13084: }
13085: }
13086: if (@excluded) {
13087: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
13088: }
13089: } elsif ($item eq 'weights') {
13090: foreach my $type ('E','W','N') {
13091: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
13092: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
13093: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
13094: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
13095: $env{'form.error'.$item.'_'.$type};
13096: }
13097: }
13098: }
13099: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
13100: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
13101: if ($env{'form.error'.$item} =~ /^\d+$/) {
13102: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
13103: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
13104: }
13105: }
13106: }
13107: }
1.286 raeburn 13108: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
13109: foreach my $field (@{$fields}) {
13110: if (ref($possoptions->{$field}) eq 'ARRAY') {
13111: my $value = $env{'form.helpform_'.$field};
13112: $value =~ s/^\s+|\s+$//g;
13113: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 13114: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 13115: if ($field eq 'screenshot') {
13116: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
13117: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 13118: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 13119: }
13120: }
13121: }
13122: }
13123: }
13124: }
1.315 raeburn 13125: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13126: my (@statuses,%usertypeshash,@overrides);
13127: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
13128: @statuses = @{$types};
13129: if (ref($usertypes) eq 'HASH') {
13130: %usertypeshash = %{$usertypes};
13131: }
13132: }
13133: if (@statuses) {
13134: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
13135: foreach my $type (@possoverrides) {
13136: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
13137: push(@overrides,$type);
13138: }
13139: }
13140: if (@overrides) {
13141: foreach my $type (@overrides) {
13142: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
13143: foreach my $item (@contacts) {
13144: if (grep(/^\Q$item\E$/,@standard)) {
13145: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
13146: $newsetting{'override_'.$type}{$item} = 1;
13147: } else {
13148: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
13149: $newsetting{'override_'.$type}{$item} = 0;
13150: }
13151: }
13152: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
13153: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13154: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
13155: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13156: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
13157: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
13158: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
13159: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13160: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
13161: }
13162: }
13163: }
13164: }
1.28 raeburn 13165: if (keys(%currsetting) > 0) {
13166: foreach my $item (@contacts) {
13167: if ($to{$item} ne $currsetting{$item}) {
13168: $changes{$item} = 1;
13169: }
13170: }
13171: foreach my $type (@mailings) {
13172: foreach my $item (@contacts) {
13173: if (ref($currsetting{$type}) eq 'HASH') {
13174: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
13175: push(@{$changes{$type}},$item);
13176: }
13177: } else {
13178: push(@{$changes{$type}},@{$newsetting{$type}});
13179: }
13180: }
13181: if ($others{$type} ne $currsetting{$type}{'others'}) {
13182: push(@{$changes{$type}},'others');
13183: }
1.289 raeburn 13184: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13185: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
13186: push(@{$changes{$type}},'bcc');
13187: }
1.286 raeburn 13188: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
13189: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
13190: push(@{$changes{$type}},'include');
13191: }
13192: }
13193: }
13194: if (ref($fields) eq 'ARRAY') {
13195: if (ref($currsetting{'helpform'}) eq 'HASH') {
13196: foreach my $field (@{$fields}) {
13197: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
13198: push(@{$changes{'helpform'}},$field);
13199: }
13200: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13201: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
13202: push(@{$changes{'helpform'}},'maxsize');
13203: }
13204: }
13205: }
13206: } else {
13207: foreach my $field (@{$fields}) {
13208: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13209: push(@{$changes{'helpform'}},$field);
13210: }
13211: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13212: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13213: push(@{$changes{'helpform'}},'maxsize');
13214: }
13215: }
13216: }
1.134 raeburn 13217: }
1.28 raeburn 13218: }
1.315 raeburn 13219: if (@statuses) {
13220: if (ref($currsetting{'overrides'}) eq 'HASH') {
13221: foreach my $key (keys(%{$currsetting{'overrides'}})) {
13222: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
13223: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
13224: foreach my $item (@contacts,'bcc','others','include') {
13225: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
13226: push(@{$changes{'overrides'}},$key);
13227: last;
13228: }
13229: }
13230: } else {
13231: push(@{$changes{'overrides'}},$key);
13232: }
13233: }
13234: }
13235: foreach my $key (@overrides) {
13236: unless (exists($currsetting{'overrides'}{$key})) {
13237: push(@{$changes{'overrides'}},$key);
13238: }
13239: }
13240: } else {
13241: foreach my $key (@overrides) {
13242: push(@{$changes{'overrides'}},$key);
13243: }
13244: }
13245: }
1.340 raeburn 13246: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
13247: foreach my $key ('excluded','weights','threshold','sysmail') {
13248: if ($key eq 'excluded') {
13249: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13250: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
13251: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13252: (@{$currsetting{'lonstatus'}{$key}})) {
13253: my @diffs =
13254: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
13255: $currsetting{'lonstatus'}{$key});
13256: if (@diffs) {
13257: push(@{$changes{'lonstatus'}},$key);
13258: }
13259: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
13260: push(@{$changes{'lonstatus'}},$key);
13261: }
13262: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13263: (@{$currsetting{'lonstatus'}{$key}})) {
13264: push(@{$changes{'lonstatus'}},$key);
13265: }
13266: } elsif ($key eq 'weights') {
13267: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13268: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
13269: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13270: foreach my $type ('E','W','N','U') {
1.340 raeburn 13271: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
13272: $currsetting{'lonstatus'}{$key}{$type}) {
13273: push(@{$changes{'lonstatus'}},$key);
13274: last;
13275: }
13276: }
13277: } else {
1.341 raeburn 13278: foreach my $type ('E','W','N','U') {
1.340 raeburn 13279: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
13280: push(@{$changes{'lonstatus'}},$key);
13281: last;
13282: }
13283: }
13284: }
13285: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13286: foreach my $type ('E','W','N','U') {
1.340 raeburn 13287: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
13288: push(@{$changes{'lonstatus'}},$key);
13289: last;
13290: }
13291: }
13292: }
13293: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
13294: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13295: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13296: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
13297: push(@{$changes{'lonstatus'}},$key);
13298: }
13299: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
13300: push(@{$changes{'lonstatus'}},$key);
13301: }
13302: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13303: push(@{$changes{'lonstatus'}},$key);
13304: }
13305: }
13306: }
13307: } else {
13308: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13309: foreach my $key ('excluded','weights','threshold','sysmail') {
13310: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13311: push(@{$changes{'lonstatus'}},$key);
13312: }
13313: }
13314: }
13315: }
1.28 raeburn 13316: } else {
13317: my %default;
13318: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
13319: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
13320: $default{'errormail'} = 'adminemail';
13321: $default{'packagesmail'} = 'adminemail';
13322: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 13323: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 13324: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 13325: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 13326: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 13327: foreach my $item (@contacts) {
13328: if ($to{$item} ne $default{$item}) {
1.286 raeburn 13329: $changes{$item} = 1;
1.203 raeburn 13330: }
1.28 raeburn 13331: }
13332: foreach my $type (@mailings) {
13333: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
13334: push(@{$changes{$type}},@{$newsetting{$type}});
13335: }
13336: if ($others{$type} ne '') {
13337: push(@{$changes{$type}},'others');
1.134 raeburn 13338: }
1.286 raeburn 13339: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13340: if ($bcc{$type} ne '') {
13341: push(@{$changes{$type}},'bcc');
13342: }
1.286 raeburn 13343: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
13344: push(@{$changes{$type}},'include');
13345: }
1.134 raeburn 13346: }
1.28 raeburn 13347: }
1.286 raeburn 13348: if (ref($fields) eq 'ARRAY') {
13349: foreach my $field (@{$fields}) {
13350: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13351: push(@{$changes{'helpform'}},$field);
13352: }
13353: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13354: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13355: push(@{$changes{'helpform'}},'maxsize');
13356: }
13357: }
13358: }
1.289 raeburn 13359: }
1.340 raeburn 13360: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13361: foreach my $key ('excluded','weights','threshold','sysmail') {
13362: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13363: push(@{$changes{'lonstatus'}},$key);
13364: }
13365: }
13366: }
1.28 raeburn 13367: }
1.203 raeburn 13368: foreach my $item (@toggles) {
13369: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
13370: $changes{$item} = 1;
13371: } elsif ((!$env{'form.'.$item}) &&
13372: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
13373: $changes{$item} = 1;
13374: }
13375: }
1.28 raeburn 13376: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
13377: $dom);
13378: if ($putresult eq 'ok') {
13379: if (keys(%changes) > 0) {
1.205 raeburn 13380: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13381: if (ref($lastactref) eq 'HASH') {
13382: $lastactref->{'domainconfig'} = 1;
13383: }
1.28 raeburn 13384: my ($titles,$short_titles) = &contact_titles();
13385: $resulttext = &mt('Changes made:').'<ul>';
13386: foreach my $item (@contacts) {
13387: if ($changes{$item}) {
13388: $resulttext .= '<li>'.$titles->{$item}.
13389: &mt(' set to: ').
13390: '<span class="LC_cusr_emph">'.
13391: $to{$item}.'</span></li>';
13392: }
13393: }
13394: foreach my $type (@mailings) {
13395: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 13396: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 13397: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 13398: } else {
13399: $resulttext .= '<li>'.$titles->{$type}.': ';
13400: }
1.28 raeburn 13401: my @text;
13402: foreach my $item (@{$newsetting{$type}}) {
13403: push(@text,$short_titles->{$item});
13404: }
13405: if ($others{$type} ne '') {
13406: push(@text,$others{$type});
13407: }
1.286 raeburn 13408: if (@text) {
13409: $resulttext .= '<span class="LC_cusr_emph">'.
13410: join(', ',@text).'</span>';
13411: }
13412: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13413: if ($bcc{$type} ne '') {
1.286 raeburn 13414: my $bcctext;
13415: if (@text) {
1.289 raeburn 13416: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 13417: } else {
13418: $bcctext = '(Bcc)';
13419: }
13420: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
13421: } elsif (!@text) {
13422: $resulttext .= &mt('No one');
13423: }
1.289 raeburn 13424: if ($includestr{$type} ne '') {
1.286 raeburn 13425: if ($includeloc{$type} eq 'b') {
13426: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
13427: } elsif ($includeloc{$type} eq 's') {
13428: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
13429: }
1.134 raeburn 13430: }
1.286 raeburn 13431: } elsif (!@text) {
13432: $resulttext .= &mt('No recipients');
1.134 raeburn 13433: }
13434: $resulttext .= '</li>';
1.28 raeburn 13435: }
13436: }
1.315 raeburn 13437: if (ref($changes{'overrides'}) eq 'ARRAY') {
13438: my @deletions;
13439: foreach my $type (@{$changes{'overrides'}}) {
13440: if ($usertypeshash{$type}) {
13441: if (grep(/^\Q$type\E/,@overrides)) {
13442: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
13443: $usertypeshash{$type}).'<ul><li>';
13444: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
13445: my @text;
13446: foreach my $item (@contacts) {
13447: if ($newsetting{'override_'.$type}{$item}) {
13448: push(@text,$short_titles->{$item});
13449: }
13450: }
13451: if ($newsetting{'override_'.$type}{'others'} ne '') {
13452: push(@text,$newsetting{'override_'.$type}{'others'});
13453: }
13454:
13455: if (@text) {
13456: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
13457: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
13458: }
13459: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
13460: my $bcctext;
13461: if (@text) {
13462: $bcctext = ' '.&mt('with Bcc to');
13463: } else {
13464: $bcctext = '(Bcc)';
13465: }
13466: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
13467: } elsif (!@text) {
13468: $resulttext .= &mt('Helpdesk e-mail sent to no one');
13469: }
13470: $resulttext .= '</li>';
13471: if ($newsetting{'override_'.$type}{'include'} ne '') {
13472: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
13473: if ($loc eq 'b') {
13474: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
13475: } elsif ($loc eq 's') {
13476: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
13477: }
13478: }
13479: }
13480: $resulttext .= '</li></ul></li>';
13481: } else {
13482: push(@deletions,$usertypeshash{$type});
13483: }
13484: }
13485: }
13486: if (@deletions) {
13487: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
13488: join(', ',@deletions)).'</li>';
13489: }
13490: }
1.203 raeburn 13491: my @offon = ('off','on');
1.340 raeburn 13492: my $corelink = &core_link_msu();
1.203 raeburn 13493: if ($changes{'reporterrors'}) {
13494: $resulttext .= '<li>'.
13495: &mt('E-mail error reports to [_1] set to "'.
13496: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 13497: $corelink).
1.203 raeburn 13498: '</li>';
13499: }
13500: if ($changes{'reportupdates'}) {
13501: $resulttext .= '<li>'.
13502: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
13503: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 13504: $corelink).
1.203 raeburn 13505: '</li>';
13506: }
1.340 raeburn 13507: if ($changes{'reportstatus'}) {
13508: $resulttext .= '<li>'.
13509: &mt('E-mail status if errors above threshold to [_1] set to "'.
13510: $offon[$env{'form.reportstatus'}].'".',
13511: $corelink).
13512: '</li>';
13513: }
13514: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
13515: $resulttext .= '<li>'.
13516: &mt('Nightly status check e-mail settings').':<ul>';
13517: my (%defval,%use_def,%shown);
13518: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
13519: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
13520: $defval{'weights'} =
1.341 raeburn 13521: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 13522: $defval{'excluded'} = &mt('None');
13523: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
13524: foreach my $item ('threshold','sysmail','weights','excluded') {
13525: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
13526: if (($item eq 'threshold') || ($item eq 'sysmail')) {
13527: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
13528: } elsif ($item eq 'weights') {
13529: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 13530: foreach my $type ('E','W','N','U') {
1.340 raeburn 13531: $shown{$item} .= $lonstatus_names->{$type}.'=';
13532: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
13533: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
13534: } else {
13535: $shown{$item} .= $lonstatus_defs->{$type};
13536: }
13537: $shown{$item} .= ', ';
13538: }
13539: $shown{$item} =~ s/, $//;
13540: } else {
13541: $shown{$item} = $defval{$item};
13542: }
13543: } elsif ($item eq 'excluded') {
13544: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
13545: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
13546: } else {
13547: $shown{$item} = $defval{$item};
13548: }
13549: }
13550: } else {
13551: $shown{$item} = $defval{$item};
13552: }
13553: }
13554: } else {
13555: foreach my $item ('threshold','weights','excluded','sysmail') {
13556: $shown{$item} = $defval{$item};
13557: }
13558: }
13559: foreach my $item ('threshold','weights','excluded','sysmail') {
13560: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
13561: $shown{$item}).'</li>';
13562: }
13563: $resulttext .= '</ul></li>';
13564: }
1.286 raeburn 13565: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
13566: my (@optional,@required,@unused,$maxsizechg);
13567: foreach my $field (@{$changes{'helpform'}}) {
13568: if ($field eq 'maxsize') {
13569: $maxsizechg = 1;
13570: next;
13571: }
13572: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 13573: push(@optional,$field);
1.286 raeburn 13574: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
13575: push(@unused,$field);
13576: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 13577: push(@required,$field);
1.286 raeburn 13578: }
13579: }
13580: if (@optional) {
13581: $resulttext .= '<li>'.
13582: &mt('Help form fields changed to "Optional": [_1].',
13583: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
13584: '</li>';
13585: }
13586: if (@required) {
13587: $resulttext .= '<li>'.
13588: &mt('Help form fields changed to "Required": [_1].',
13589: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
13590: '</li>';
13591: }
13592: if (@unused) {
13593: $resulttext .= '<li>'.
13594: &mt('Help form fields changed to "Not shown": [_1].',
13595: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
13596: '</li>';
13597: }
13598: if ($maxsizechg) {
13599: $resulttext .= '<li>'.
13600: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
13601: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
13602: '</li>';
13603: }
13604: }
1.28 raeburn 13605: $resulttext .= '</ul>';
13606: } else {
1.288 raeburn 13607: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 13608: }
13609: } else {
13610: $resulttext = '<span class="LC_error">'.
13611: &mt('An error occurred: [_1].',$putresult).'</span>';
13612: }
13613: return $resulttext;
13614: }
13615:
13616: sub modify_usercreation {
1.27 raeburn 13617: my ($dom,%domconfig) = @_;
1.224 raeburn 13618: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 13619: my $warningmsg;
1.27 raeburn 13620: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13621: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 13622: if ($key eq 'cancreate') {
13623: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13624: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 13625: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
13626: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13627: } else {
1.224 raeburn 13628: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13629: }
13630: }
13631: }
13632: } elsif ($key eq 'email_rule') {
13633: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13634: } else {
13635: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13636: }
1.27 raeburn 13637: }
13638: }
13639: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 13640: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 13641: my @contexts = ('author','course','requestcrs');
1.34 raeburn 13642: foreach my $item(@contexts) {
1.224 raeburn 13643: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 13644: }
1.34 raeburn 13645: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13646: foreach my $item (@contexts) {
1.224 raeburn 13647: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
13648: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 13649: }
1.27 raeburn 13650: }
1.34 raeburn 13651: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
13652: foreach my $item (@contexts) {
1.43 raeburn 13653: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 13654: if ($cancreate{$item} ne 'any') {
13655: push(@{$changes{'cancreate'}},$item);
13656: }
13657: } else {
13658: if ($cancreate{$item} ne 'none') {
13659: push(@{$changes{'cancreate'}},$item);
13660: }
1.27 raeburn 13661: }
13662: }
13663: } else {
1.43 raeburn 13664: foreach my $item (@contexts) {
1.34 raeburn 13665: push(@{$changes{'cancreate'}},$item);
13666: }
1.27 raeburn 13667: }
1.34 raeburn 13668:
1.27 raeburn 13669: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
13670: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
13671: if (!grep(/^\Q$type\E$/,@username_rule)) {
13672: push(@{$changes{'username_rule'}},$type);
13673: }
13674: }
13675: foreach my $type (@username_rule) {
13676: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
13677: push(@{$changes{'username_rule'}},$type);
13678: }
13679: }
13680: } else {
13681: push(@{$changes{'username_rule'}},@username_rule);
13682: }
13683:
1.32 raeburn 13684: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
13685: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
13686: if (!grep(/^\Q$type\E$/,@id_rule)) {
13687: push(@{$changes{'id_rule'}},$type);
13688: }
13689: }
13690: foreach my $type (@id_rule) {
13691: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
13692: push(@{$changes{'id_rule'}},$type);
13693: }
13694: }
13695: } else {
13696: push(@{$changes{'id_rule'}},@id_rule);
13697: }
13698:
1.43 raeburn 13699: my @authen_contexts = ('author','course','domain');
1.325 raeburn 13700: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 13701: my %authhash;
1.43 raeburn 13702: foreach my $item (@authen_contexts) {
1.28 raeburn 13703: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
13704: foreach my $auth (@authtypes) {
13705: if (grep(/^\Q$auth\E$/,@authallowed)) {
13706: $authhash{$item}{$auth} = 1;
13707: } else {
13708: $authhash{$item}{$auth} = 0;
13709: }
13710: }
13711: }
13712: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 13713: foreach my $item (@authen_contexts) {
1.28 raeburn 13714: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
13715: foreach my $auth (@authtypes) {
13716: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
13717: push(@{$changes{'authtypes'}},$item);
13718: last;
13719: }
13720: }
13721: }
13722: }
13723: } else {
1.43 raeburn 13724: foreach my $item (@authen_contexts) {
1.28 raeburn 13725: push(@{$changes{'authtypes'}},$item);
13726: }
13727: }
13728:
1.224 raeburn 13729: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13730: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13731: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13732: $save_usercreate{'id_rule'} = \@id_rule;
13733: $save_usercreate{'username_rule'} = \@username_rule,
13734: $save_usercreate{'authtypes'} = \%authhash;
13735:
1.27 raeburn 13736: my %usercreation_hash = (
1.224 raeburn 13737: usercreation => \%save_usercreate,
13738: );
1.27 raeburn 13739:
13740: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13741: $dom);
1.50 raeburn 13742:
1.224 raeburn 13743: if ($putresult eq 'ok') {
13744: if (keys(%changes) > 0) {
13745: $resulttext = &mt('Changes made:').'<ul>';
13746: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13747: my %lt = &usercreation_types();
13748: foreach my $type (@{$changes{'cancreate'}}) {
13749: my $chgtext = $lt{$type}.', ';
13750: if ($cancreate{$type} eq 'none') {
13751: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13752: } elsif ($cancreate{$type} eq 'any') {
13753: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13754: } elsif ($cancreate{$type} eq 'official') {
13755: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13756: } elsif ($cancreate{$type} eq 'unofficial') {
13757: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13758: }
13759: $resulttext .= '<li>'.$chgtext.'</li>';
13760: }
13761: }
13762: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13763: my ($rules,$ruleorder) =
13764: &Apache::lonnet::inst_userrules($dom,'username');
13765: my $chgtext = '<ul>';
13766: foreach my $type (@username_rule) {
13767: if (ref($rules->{$type}) eq 'HASH') {
13768: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13769: }
13770: }
13771: $chgtext .= '</ul>';
13772: if (@username_rule > 0) {
13773: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13774: } else {
13775: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13776: }
13777: }
13778: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13779: my ($idrules,$idruleorder) =
13780: &Apache::lonnet::inst_userrules($dom,'id');
13781: my $chgtext = '<ul>';
13782: foreach my $type (@id_rule) {
13783: if (ref($idrules->{$type}) eq 'HASH') {
13784: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13785: }
13786: }
13787: $chgtext .= '</ul>';
13788: if (@id_rule > 0) {
13789: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13790: } else {
13791: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13792: }
13793: }
13794: my %authname = &authtype_names();
13795: my %context_title = &context_names();
13796: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13797: my $chgtext = '<ul>';
13798: foreach my $type (@{$changes{'authtypes'}}) {
13799: my @allowed;
13800: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13801: foreach my $auth (@authtypes) {
13802: if ($authhash{$type}{$auth}) {
13803: push(@allowed,$authname{$auth});
13804: }
13805: }
13806: if (@allowed > 0) {
13807: $chgtext .= join(', ',@allowed).'</li>';
13808: } else {
13809: $chgtext .= &mt('none').'</li>';
13810: }
13811: }
13812: $chgtext .= '</ul>';
13813: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13814: $resulttext .= '</li>';
13815: }
13816: $resulttext .= '</ul>';
13817: } else {
13818: $resulttext = &mt('No changes made to user creation settings');
13819: }
13820: } else {
13821: $resulttext = '<span class="LC_error">'.
13822: &mt('An error occurred: [_1]',$putresult).'</span>';
13823: }
13824: if ($warningmsg ne '') {
13825: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13826: }
13827: return $resulttext;
13828: }
13829:
13830: sub modify_selfcreation {
1.305 raeburn 13831: my ($dom,$lastactref,%domconfig) = @_;
13832: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13833: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13834: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 13835: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13836: if (ref($typesref) eq 'ARRAY') {
13837: @types = @{$typesref};
13838: }
13839: if (ref($usertypesref) eq 'HASH') {
13840: %usertypes = %{$usertypesref};
1.228 raeburn 13841: }
1.303 raeburn 13842: $usertypes{'default'} = $othertitle;
1.224 raeburn 13843: #
13844: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13845: #
13846: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13847: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13848: if ($key eq 'cancreate') {
13849: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13850: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13851: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 13852: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13853: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13854: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13855: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 13856: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 13857: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13858: } else {
13859: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13860: }
13861: }
13862: }
13863: } elsif ($key eq 'email_rule') {
13864: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13865: } else {
13866: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13867: }
13868: }
13869: }
13870: #
13871: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13872: #
13873: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13874: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13875: if ($key eq 'selfcreate') {
13876: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13877: } else {
13878: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13879: }
13880: }
13881: }
1.305 raeburn 13882: #
13883: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13884: #
13885: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13886: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13887: if ($key eq 'inststatusguest') {
13888: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13889: } else {
13890: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13891: }
13892: }
13893: }
1.224 raeburn 13894:
13895: my @contexts = ('selfcreate');
13896: @{$cancreate{'selfcreate'}} = ();
13897: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 13898: if (@types) {
13899: @{$cancreate{'statustocreate'}} = ();
13900: }
1.236 raeburn 13901: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 13902: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 13903: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 13904: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 13905: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13906: my %selfcreatetypes = (
13907: sso => 'users authenticated by institutional single sign on',
13908: login => 'users authenticated by institutional log-in',
1.303 raeburn 13909: email => 'users verified by e-mail',
1.50 raeburn 13910: );
1.224 raeburn 13911: #
13912: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13913: # is permitted.
13914: #
1.305 raeburn 13915: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 13916:
1.305 raeburn 13917: my (@statuses,%email_rule);
1.228 raeburn 13918: foreach my $item ('login','sso','email') {
1.224 raeburn 13919: if ($item eq 'email') {
1.236 raeburn 13920: if ($env{'form.cancreate_email'}) {
1.305 raeburn 13921: if (@types) {
13922: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13923: foreach my $status (@poss_statuses) {
13924: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13925: push(@statuses,$status);
13926: }
13927: }
13928: $save_inststatus{'inststatusguest'} = \@statuses;
13929: } else {
13930: push(@statuses,'default');
13931: }
13932: if (@statuses) {
13933: my %curr_rule;
13934: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13935: foreach my $type (@statuses) {
13936: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 13937: }
1.305 raeburn 13938: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13939: foreach my $type (@statuses) {
13940: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13941: }
13942: }
13943: push(@{$cancreate{'selfcreate'}},'email');
13944: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13945: my %curremaildom;
13946: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13947: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13948: }
13949: foreach my $type (@statuses) {
13950: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13951: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13952: }
13953: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13954: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13955: }
13956: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13957: #
13958: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13959: #
13960: my $chosen = $1;
13961: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13962: my $emaildom;
13963: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13964: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13965: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13966: if (ref($curremaildom{$type}) eq 'HASH') {
13967: if (exists($curremaildom{$type}{$chosen})) {
13968: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13969: push(@{$changes{'cancreate'}},'emaildomain');
13970: }
13971: } elsif ($emaildom ne '') {
13972: push(@{$changes{'cancreate'}},'emaildomain');
13973: }
13974: } elsif ($emaildom ne '') {
13975: push(@{$changes{'cancreate'}},'emaildomain');
13976: }
13977: }
13978: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13979: } elsif ($chosen eq 'custom') {
13980: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13981: $email_rule{$type} = [];
13982: if (ref($emailrules) eq 'HASH') {
13983: foreach my $rule (@possemail_rules) {
13984: if (exists($emailrules->{$rule})) {
13985: push(@{$email_rule{$type}},$rule);
13986: }
13987: }
13988: }
13989: if (@{$email_rule{$type}}) {
13990: $cancreate{'emailoptions'}{$type} = 'custom';
13991: if (ref($curr_rule{$type}) eq 'ARRAY') {
13992: if (@{$curr_rule{$type}} > 0) {
13993: foreach my $rule (@{$curr_rule{$type}}) {
13994: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13995: push(@{$changes{'email_rule'}},$type);
13996: }
13997: }
13998: }
13999: foreach my $type (@{$email_rule{$type}}) {
14000: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
14001: push(@{$changes{'email_rule'}},$type);
14002: }
14003: }
14004: } else {
14005: push(@{$changes{'email_rule'}},$type);
14006: }
14007: }
14008: } else {
14009: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
14010: }
14011: }
14012: }
14013: if (@types) {
14014: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14015: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
14016: if (@changed) {
14017: push(@{$changes{'inststatus'}},'inststatusguest');
14018: }
14019: } else {
14020: push(@{$changes{'inststatus'}},'inststatusguest');
14021: }
14022: }
14023: } else {
14024: delete($env{'form.cancreate_email'});
14025: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14026: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
14027: push(@{$changes{'inststatus'}},'inststatusguest');
14028: }
14029: }
14030: }
14031: } else {
14032: $save_inststatus{'inststatusguest'} = [];
14033: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14034: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
14035: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 14036: }
14037: }
1.224 raeburn 14038: }
14039: } else {
14040: if ($env{'form.cancreate_'.$item}) {
14041: push(@{$cancreate{'selfcreate'}},$item);
14042: }
14043: }
14044: }
1.305 raeburn 14045: my (%userinfo,%savecaptcha);
1.224 raeburn 14046: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
14047: #
1.228 raeburn 14048: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
14049: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 14050: #
1.236 raeburn 14051:
1.244 raeburn 14052: if ($env{'form.cancreate_email'}) {
1.228 raeburn 14053: push(@contexts,'emailusername');
1.305 raeburn 14054: if (@statuses) {
14055: foreach my $type (@statuses) {
1.228 raeburn 14056: if (ref($infofields) eq 'ARRAY') {
14057: foreach my $field (@{$infofields}) {
14058: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
14059: $cancreate{'emailusername'}{$type}{$field} = $1;
14060: }
14061: }
1.224 raeburn 14062: }
14063: }
14064: }
14065: #
14066: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 14067: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 14068: #
14069:
14070: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
14071: @approvalnotify = sort(@approvalnotify);
14072: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
14073: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14074: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
14075: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
14076: push(@{$changes{'cancreate'}},'notify');
14077: }
14078: } else {
14079: if ($cancreate{'notify'}{'approval'}) {
14080: push(@{$changes{'cancreate'}},'notify');
14081: }
14082: }
14083: } elsif ($cancreate{'notify'}{'approval'}) {
14084: push(@{$changes{'cancreate'}},'notify');
14085: }
14086:
14087: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
14088: }
14089: #
1.236 raeburn 14090: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 14091: # institutional log-in.
14092: #
14093: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
14094: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
14095: ($domdefaults{'auth_def'} eq 'localauth'))) {
14096: $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.').' '.
14097: &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.');
14098: }
14099: }
14100: my @fields = ('lastname','firstname','middlename','generation',
14101: 'permanentemail','id');
1.240 raeburn 14102: my @shibfields = (@fields,'inststatus');
1.224 raeburn 14103: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14104: #
14105: # Where usernames may created for institutional log-in and/or institutional single sign on:
14106: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
14107: # may self-create accounts
14108: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
14109: # which the user may supply, if institutional data is unavailable.
14110: #
14111: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 14112: if (@types) {
1.305 raeburn 14113: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
14114: push(@contexts,'statustocreate');
1.303 raeburn 14115: foreach my $type (@types) {
1.224 raeburn 14116: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
14117: foreach my $field (@fields) {
14118: if (grep(/^\Q$field\E$/,@modifiable)) {
14119: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
14120: } else {
14121: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
14122: }
14123: }
14124: }
14125: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 14126: foreach my $type (@types) {
1.224 raeburn 14127: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
14128: foreach my $field (@fields) {
14129: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
14130: $curr_usermodify{'selfcreate'}{$type}{$field}) {
14131: push(@{$changes{'selfcreate'}},$type);
14132: last;
14133: }
14134: }
14135: }
14136: }
14137: } else {
1.303 raeburn 14138: foreach my $type (@types) {
1.224 raeburn 14139: push(@{$changes{'selfcreate'}},$type);
14140: }
14141: }
14142: }
1.240 raeburn 14143: foreach my $field (@shibfields) {
14144: if ($env{'form.shibenv_'.$field} ne '') {
14145: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
14146: }
14147: }
14148: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14149: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
14150: foreach my $field (@shibfields) {
14151: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
14152: push(@{$changes{'cancreate'}},'shibenv');
14153: }
14154: }
14155: } else {
14156: foreach my $field (@shibfields) {
14157: if ($env{'form.shibenv_'.$field}) {
14158: push(@{$changes{'cancreate'}},'shibenv');
14159: last;
14160: }
14161: }
14162: }
14163: }
1.224 raeburn 14164: }
14165: foreach my $item (@contexts) {
14166: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
14167: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
14168: if (ref($cancreate{$item}) eq 'ARRAY') {
14169: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
14170: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14171: push(@{$changes{'cancreate'}},$item);
14172: }
14173: }
14174: }
14175: }
14176: if (ref($cancreate{$item}) eq 'ARRAY') {
14177: foreach my $type (@{$cancreate{$item}}) {
14178: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
14179: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14180: push(@{$changes{'cancreate'}},$item);
14181: }
14182: }
14183: }
14184: }
14185: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
14186: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 14187: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
14188: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
14189: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
14190: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 14191: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14192: push(@{$changes{'cancreate'}},$item);
14193: }
14194: }
14195: }
1.305 raeburn 14196: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
14197: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 14198: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14199: push(@{$changes{'cancreate'}},$item);
14200: }
1.224 raeburn 14201: }
14202: }
14203: }
1.305 raeburn 14204: foreach my $type (keys(%{$cancreate{$item}})) {
14205: if (ref($cancreate{$item}{$type}) eq 'HASH') {
14206: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
14207: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
14208: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 14209: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14210: push(@{$changes{'cancreate'}},$item);
14211: }
14212: }
14213: } else {
14214: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14215: push(@{$changes{'cancreate'}},$item);
14216: }
14217: }
14218: }
1.305 raeburn 14219: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
14220: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 14221: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14222: push(@{$changes{'cancreate'}},$item);
14223: }
1.224 raeburn 14224: }
14225: }
14226: }
14227: }
14228: } elsif ($curr_usercreation{'cancreate'}{$item}) {
14229: if (ref($cancreate{$item}) eq 'ARRAY') {
14230: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
14231: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14232: push(@{$changes{'cancreate'}},$item);
14233: }
14234: }
1.305 raeburn 14235: }
14236: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
14237: if (ref($cancreate{$item}) eq 'HASH') {
14238: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14239: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 14240: }
14241: }
14242: } elsif ($item eq 'emailusername') {
1.228 raeburn 14243: if (ref($cancreate{$item}) eq 'HASH') {
14244: foreach my $type (keys(%{$cancreate{$item}})) {
14245: if (ref($cancreate{$item}{$type}) eq 'HASH') {
14246: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
14247: if ($cancreate{$item}{$type}{$field}) {
14248: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14249: push(@{$changes{'cancreate'}},$item);
14250: }
14251: last;
14252: }
14253: }
14254: }
14255: }
1.224 raeburn 14256: }
14257: }
14258: }
14259: #
14260: # Populate %save_usercreate hash with updates to self-creation configuration.
14261: #
14262: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
14263: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 14264: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 14265: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
14266: if (ref($cancreate{'notify'}) eq 'HASH') {
14267: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
14268: }
1.236 raeburn 14269: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
14270: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
14271: }
1.303 raeburn 14272: if (ref($cancreate{'emailverified'}) eq 'HASH') {
14273: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
14274: }
1.305 raeburn 14275: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
14276: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
14277: }
1.303 raeburn 14278: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
14279: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
14280: }
1.224 raeburn 14281: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
14282: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
14283: }
1.240 raeburn 14284: if (ref($cancreate{'shibenv'}) eq 'HASH') {
14285: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
14286: }
1.224 raeburn 14287: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 14288: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 14289:
14290: my %userconfig_hash = (
14291: usercreation => \%save_usercreate,
14292: usermodification => \%save_usermodify,
1.305 raeburn 14293: inststatus => \%save_inststatus,
1.224 raeburn 14294: );
1.305 raeburn 14295:
1.224 raeburn 14296: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
14297: $dom);
14298: #
1.305 raeburn 14299: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 14300: #
1.27 raeburn 14301: if ($putresult eq 'ok') {
14302: if (keys(%changes) > 0) {
14303: $resulttext = &mt('Changes made:').'<ul>';
14304: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 14305: my %lt = &selfcreation_types();
1.34 raeburn 14306: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 14307: my $chgtext = '';
1.45 raeburn 14308: if ($type eq 'selfcreate') {
1.50 raeburn 14309: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 14310: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 14311: } else {
1.224 raeburn 14312: $chgtext .= &mt('Self-creation of a new account is permitted for:').
14313: '<ul>';
1.50 raeburn 14314: foreach my $case (@{$cancreate{$type}}) {
14315: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
14316: }
14317: $chgtext .= '</ul>';
1.100 raeburn 14318: if (ref($cancreate{$type}) eq 'ARRAY') {
14319: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
14320: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
14321: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 14322: $chgtext .= '<span class="LC_warning">'.
14323: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
14324: '</span><br />';
14325: }
14326: }
14327: }
14328: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 14329: if (!@statuses) {
14330: $chgtext .= '<span class="LC_warning">'.
14331: &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.").
14332: '</span><br />';
1.303 raeburn 14333:
1.100 raeburn 14334: }
14335: }
14336: }
1.43 raeburn 14337: }
1.240 raeburn 14338: } elsif ($type eq 'shibenv') {
14339: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 14340: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 14341: } else {
14342: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
14343: '<ul>';
14344: foreach my $field (@shibfields) {
14345: next if ($cancreate{$type}{$field} eq '');
14346: if ($field eq 'inststatus') {
14347: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
14348: } else {
14349: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
14350: }
14351: }
14352: $chgtext .= '</ul>';
1.303 raeburn 14353: }
1.93 raeburn 14354: } elsif ($type eq 'statustocreate') {
1.96 raeburn 14355: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
14356: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
14357: if (@{$cancreate{'selfcreate'}} > 0) {
14358: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 14359: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 14360: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 14361: $chgtext .= '<br />'.
14362: '<span class="LC_warning">'.
14363: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
14364: '</span>';
14365: }
1.303 raeburn 14366: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 14367: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 14368: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
14369: } else {
14370: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
14371: }
14372: $chgtext .= '<ul>';
14373: foreach my $case (@{$cancreate{$type}}) {
14374: if ($case eq 'default') {
14375: $chgtext .= '<li>'.$othertitle.'</li>';
14376: } else {
1.303 raeburn 14377: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 14378: }
14379: }
1.100 raeburn 14380: $chgtext .= '</ul>';
14381: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 14382: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 14383: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
14384: '</span>';
1.100 raeburn 14385: }
14386: }
14387: } else {
14388: if (@{$cancreate{$type}} == 0) {
14389: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
14390: } else {
14391: $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 14392: }
14393: }
1.303 raeburn 14394: $chgtext .= '<br />';
1.93 raeburn 14395: }
1.236 raeburn 14396: } elsif ($type eq 'selfcreateprocessing') {
14397: my %choices = &Apache::lonlocal::texthash (
14398: automatic => 'Automatic approval',
14399: approval => 'Queued for approval',
14400: );
1.305 raeburn 14401: if (@types) {
14402: if (@statuses) {
1.303 raeburn 14403: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 14404: '<ul>';
1.305 raeburn 14405: foreach my $status (@statuses) {
14406: if ($status eq 'default') {
14407: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 14408: } else {
1.305 raeburn 14409: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 14410: }
14411: }
14412: $chgtext .= '</ul>';
14413: }
14414: } else {
14415: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
14416: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
14417: }
14418: } elsif ($type eq 'emailverified') {
14419: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 14420: all => 'Same as e-mail',
14421: first => 'Omit @domain',
14422: free => 'Free to choose',
1.303 raeburn 14423: );
1.305 raeburn 14424: if (@types) {
14425: if (@statuses) {
1.303 raeburn 14426: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
14427: '<ul>';
1.305 raeburn 14428: foreach my $status (@statuses) {
1.303 raeburn 14429: if ($type eq 'default') {
1.305 raeburn 14430: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 14431: } else {
1.305 raeburn 14432: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 14433: }
14434: }
14435: $chgtext .= '</ul>';
14436: }
14437: } else {
1.305 raeburn 14438: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 14439: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 14440: }
1.305 raeburn 14441: } elsif ($type eq 'emailoptions') {
14442: my %options = &Apache::lonlocal::texthash (
14443: any => 'Any e-mail',
14444: inst => 'Institutional only',
14445: noninst => 'Non-institutional only',
14446: custom => 'Custom restrictions',
14447: );
14448: if (@types) {
14449: if (@statuses) {
14450: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
14451: '<ul>';
14452: foreach my $status (@statuses) {
14453: if ($type eq 'default') {
14454: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
14455: } else {
14456: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 14457: }
14458: }
1.305 raeburn 14459: $chgtext .= '</ul>';
14460: }
14461: } else {
14462: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
14463: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
14464: } else {
14465: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
14466: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 14467: }
1.305 raeburn 14468: }
14469: } elsif ($type eq 'emaildomain') {
14470: my $output;
14471: if (@statuses) {
14472: foreach my $type (@statuses) {
14473: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
14474: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
14475: if ($type eq 'default') {
14476: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14477: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
14478: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
14479: } else {
14480: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
14481: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
14482: }
1.303 raeburn 14483: } else {
1.305 raeburn 14484: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14485: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
14486: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
14487: } else {
14488: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
14489: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
14490: }
1.303 raeburn 14491: }
1.305 raeburn 14492: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
14493: if ($type eq 'default') {
14494: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14495: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
14496: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
14497: } else {
14498: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
14499: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
14500: }
1.303 raeburn 14501: } else {
1.305 raeburn 14502: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14503: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
14504: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
14505: } else {
14506: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
14507: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
14508: }
1.303 raeburn 14509: }
14510: }
14511: }
14512: }
1.305 raeburn 14513: }
14514: if ($output ne '') {
14515: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
14516: '<ul>'.$output.'</ul>';
1.236 raeburn 14517: }
1.165 raeburn 14518: } elsif ($type eq 'captcha') {
1.224 raeburn 14519: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 14520: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
14521: } else {
14522: my %captchas = &captcha_phrases();
1.224 raeburn 14523: if ($captchas{$savecaptcha{$type}}) {
14524: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 14525: } else {
1.210 raeburn 14526: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 14527: }
14528: }
14529: } elsif ($type eq 'recaptchakeys') {
14530: my ($privkey,$pubkey);
1.224 raeburn 14531: if (ref($savecaptcha{$type}) eq 'HASH') {
14532: $pubkey = $savecaptcha{$type}{'public'};
14533: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 14534: }
14535: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
14536: if (!$pubkey) {
14537: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
14538: } else {
14539: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
14540: }
14541: if (!$privkey) {
14542: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
14543: } else {
14544: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
14545: }
14546: $chgtext .= '</ul>';
1.269 raeburn 14547: } elsif ($type eq 'recaptchaversion') {
14548: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 14549: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 14550: }
1.224 raeburn 14551: } elsif ($type eq 'emailusername') {
14552: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 14553: if (@statuses) {
14554: foreach my $type (@statuses) {
1.228 raeburn 14555: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
14556: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 14557: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 14558: '<ul>';
14559: foreach my $field (@{$infofields}) {
14560: if ($cancreate{'emailusername'}{$type}{$field}) {
14561: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
14562: }
14563: }
1.245 raeburn 14564: $chgtext .= '</ul>';
14565: } else {
1.303 raeburn 14566: $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 14567: }
14568: } else {
1.303 raeburn 14569: $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 14570: }
14571: }
14572: }
14573: }
14574: } elsif ($type eq 'notify') {
1.303 raeburn 14575: my $numapprove = 0;
1.224 raeburn 14576: if (ref($changes{'cancreate'}) eq 'ARRAY') {
14577: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
14578: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 14579: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
14580: $numapprove ++;
1.224 raeburn 14581: }
14582: }
1.43 raeburn 14583: }
1.303 raeburn 14584: unless ($numapprove) {
14585: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
14586: }
1.34 raeburn 14587: }
1.224 raeburn 14588: if ($chgtext) {
14589: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 14590: }
14591: }
14592: }
1.305 raeburn 14593: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 14594: my ($emailrules,$emailruleorder) =
14595: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 14596: foreach my $type (@{$changes{'email_rule'}}) {
14597: if (ref($email_rule{$type}) eq 'ARRAY') {
14598: my $chgtext = '<ul>';
14599: foreach my $rule (@{$email_rule{$type}}) {
14600: if (ref($emailrules->{$rule}) eq 'HASH') {
14601: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
14602: }
14603: }
14604: $chgtext .= '</ul>';
1.310 raeburn 14605: my $typename;
1.305 raeburn 14606: if (@types) {
14607: if ($type eq 'default') {
14608: $typename = $othertitle;
14609: } else {
14610: $typename = $usertypes{$type};
14611: }
14612: $chgtext .= &mt('(Affiliation: [_1])',$typename);
14613: }
14614: if (@{$email_rule{$type}} > 0) {
14615: $resulttext .= '<li>'.
14616: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
14617: $usertypes{$type}).
14618: $chgtext.
14619: '</li>';
14620: } else {
14621: $resulttext .= '<li>'.
1.310 raeburn 14622: &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 14623: '</li>'.
1.310 raeburn 14624: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 14625: }
1.43 raeburn 14626: }
14627: }
1.305 raeburn 14628: }
14629: if (ref($changes{'inststatus'}) eq 'ARRAY') {
14630: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
14631: if (@{$save_inststatus{'inststatusguest'}} > 0) {
14632: my $chgtext = '<ul>';
14633: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
14634: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
14635: }
14636: $chgtext .= '</ul>';
14637: $resulttext .= '<li>'.
14638: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
14639: $chgtext.
14640: '</li>';
14641: } else {
14642: $resulttext .= '<li>'.
14643: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
14644: '</li>';
14645: }
1.43 raeburn 14646: }
14647: }
1.224 raeburn 14648: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
14649: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
14650: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14651: foreach my $type (@{$changes{'selfcreate'}}) {
14652: my $typename = $type;
1.303 raeburn 14653: if (keys(%usertypes) > 0) {
14654: if ($usertypes{$type} ne '') {
14655: $typename = $usertypes{$type};
1.224 raeburn 14656: }
14657: }
14658: my @modifiable;
14659: $resulttext .= '<li>'.
14660: &mt('Self-creation of account by users with status: [_1]',
14661: '<span class="LC_cusr_emph">'.$typename.'</span>').
14662: ' - '.&mt('modifiable fields (if institutional data blank): ');
14663: foreach my $field (@fields) {
14664: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
14665: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 14666: }
14667: }
1.224 raeburn 14668: if (@modifiable > 0) {
14669: $resulttext .= join(', ',@modifiable);
1.43 raeburn 14670: } else {
1.224 raeburn 14671: $resulttext .= &mt('none');
1.43 raeburn 14672: }
1.224 raeburn 14673: $resulttext .= '</li>';
1.28 raeburn 14674: }
1.224 raeburn 14675: $resulttext .= '</ul></li>';
1.28 raeburn 14676: }
1.27 raeburn 14677: $resulttext .= '</ul>';
1.305 raeburn 14678: my $cachetime = 24*60*60;
14679: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
14680: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14681: if (ref($lastactref) eq 'HASH') {
14682: $lastactref->{'domdefaults'} = 1;
14683: }
1.27 raeburn 14684: } else {
1.224 raeburn 14685: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 14686: }
14687: } else {
14688: $resulttext = '<span class="LC_error">'.
1.23 raeburn 14689: &mt('An error occurred: [_1]',$putresult).'</span>';
14690: }
1.43 raeburn 14691: if ($warningmsg ne '') {
14692: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14693: }
1.23 raeburn 14694: return $resulttext;
14695: }
14696:
1.165 raeburn 14697: sub process_captcha {
14698: my ($container,$changes,$newsettings,$current) = @_;
14699: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
14700: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
14701: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
14702: $newsettings->{'captcha'} = 'original';
14703: }
14704: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 14705: if ($container eq 'cancreate') {
1.169 raeburn 14706: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14707: push(@{$changes->{'cancreate'}},'captcha');
14708: } elsif (!defined($changes->{'cancreate'})) {
14709: $changes->{'cancreate'} = ['captcha'];
14710: }
14711: } else {
14712: $changes->{'captcha'} = 1;
1.165 raeburn 14713: }
14714: }
1.269 raeburn 14715: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 14716: if ($newsettings->{'captcha'} eq 'recaptcha') {
14717: $newpub = $env{'form.'.$container.'_recaptchapub'};
14718: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 14719: $newpub =~ s/[^\w\-]//g;
14720: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 14721: $newsettings->{'recaptchakeys'} = {
14722: public => $newpub,
14723: private => $newpriv,
14724: };
1.269 raeburn 14725: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14726: $newversion =~ s/\D//g;
14727: if ($newversion ne '2') {
14728: $newversion = 1;
14729: }
14730: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 14731: }
14732: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
14733: $currpub = $current->{'recaptchakeys'}{'public'};
14734: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 14735: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14736: $newsettings->{'recaptchakeys'} = {
14737: public => '',
14738: private => '',
14739: }
14740: }
1.165 raeburn 14741: }
1.269 raeburn 14742: if ($current->{'captcha'} eq 'recaptcha') {
14743: $currversion = $current->{'recaptchaversion'};
14744: if ($currversion ne '2') {
14745: $currversion = 1;
14746: }
14747: }
14748: if ($currversion ne $newversion) {
14749: if ($container eq 'cancreate') {
14750: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14751: push(@{$changes->{'cancreate'}},'recaptchaversion');
14752: } elsif (!defined($changes->{'cancreate'})) {
14753: $changes->{'cancreate'} = ['recaptchaversion'];
14754: }
14755: } else {
14756: $changes->{'recaptchaversion'} = 1;
14757: }
14758: }
1.165 raeburn 14759: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 14760: if ($container eq 'cancreate') {
14761: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14762: push(@{$changes->{'cancreate'}},'recaptchakeys');
14763: } elsif (!defined($changes->{'cancreate'})) {
14764: $changes->{'cancreate'} = ['recaptchakeys'];
14765: }
14766: } else {
1.210 raeburn 14767: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 14768: }
14769: }
14770: return;
14771: }
14772:
1.33 raeburn 14773: sub modify_usermodification {
14774: my ($dom,%domconfig) = @_;
1.224 raeburn 14775: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14776: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14777: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 14778: if ($key eq 'selfcreate') {
14779: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14780: } else {
14781: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14782: }
1.33 raeburn 14783: }
14784: }
1.224 raeburn 14785: my @contexts = ('author','course');
1.33 raeburn 14786: my %context_title = (
14787: author => 'In author context',
14788: course => 'In course context',
14789: );
14790: my @fields = ('lastname','firstname','middlename','generation',
14791: 'permanentemail','id');
14792: my %roles = (
14793: author => ['ca','aa'],
14794: course => ['st','ep','ta','in','cr'],
14795: );
14796: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14797: foreach my $context (@contexts) {
14798: foreach my $role (@{$roles{$context}}) {
14799: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14800: foreach my $item (@fields) {
14801: if (grep(/^\Q$item\E$/,@modifiable)) {
14802: $modifyhash{$context}{$role}{$item} = 1;
14803: } else {
14804: $modifyhash{$context}{$role}{$item} = 0;
14805: }
14806: }
14807: }
14808: if (ref($curr_usermodification{$context}) eq 'HASH') {
14809: foreach my $role (@{$roles{$context}}) {
14810: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14811: foreach my $field (@fields) {
14812: if ($modifyhash{$context}{$role}{$field} ne
14813: $curr_usermodification{$context}{$role}{$field}) {
14814: push(@{$changes{$context}},$role);
14815: last;
14816: }
14817: }
14818: }
14819: }
14820: } else {
14821: foreach my $context (@contexts) {
14822: foreach my $role (@{$roles{$context}}) {
14823: push(@{$changes{$context}},$role);
14824: }
14825: }
14826: }
14827: }
14828: my %usermodification_hash = (
14829: usermodification => \%modifyhash,
14830: );
14831: my $putresult = &Apache::lonnet::put_dom('configuration',
14832: \%usermodification_hash,$dom);
14833: if ($putresult eq 'ok') {
14834: if (keys(%changes) > 0) {
14835: $resulttext = &mt('Changes made: ').'<ul>';
14836: foreach my $context (@contexts) {
14837: if (ref($changes{$context}) eq 'ARRAY') {
14838: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14839: if (ref($changes{$context}) eq 'ARRAY') {
14840: foreach my $role (@{$changes{$context}}) {
14841: my $rolename;
1.224 raeburn 14842: if ($role eq 'cr') {
14843: $rolename = &mt('Custom');
1.33 raeburn 14844: } else {
1.224 raeburn 14845: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14846: }
14847: my @modifiable;
1.224 raeburn 14848: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14849: foreach my $field (@fields) {
14850: if ($modifyhash{$context}{$role}{$field}) {
14851: push(@modifiable,$fieldtitles{$field});
14852: }
14853: }
14854: if (@modifiable > 0) {
14855: $resulttext .= join(', ',@modifiable);
14856: } else {
14857: $resulttext .= &mt('none');
14858: }
14859: $resulttext .= '</li>';
14860: }
14861: $resulttext .= '</ul></li>';
14862: }
14863: }
14864: }
14865: $resulttext .= '</ul>';
14866: } else {
14867: $resulttext = &mt('No changes made to user modification settings');
14868: }
14869: } else {
14870: $resulttext = '<span class="LC_error">'.
14871: &mt('An error occurred: [_1]',$putresult).'</span>';
14872: }
14873: return $resulttext;
14874: }
14875:
1.43 raeburn 14876: sub modify_defaults {
1.212 raeburn 14877: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14878: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 14879: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 14880: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
14881: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.325 raeburn 14882: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 14883: foreach my $item (@items) {
14884: $newvalues{$item} = $env{'form.'.$item};
14885: if ($item eq 'auth_def') {
14886: if ($newvalues{$item} ne '') {
14887: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14888: push(@errors,$item);
14889: }
14890: }
14891: } elsif ($item eq 'lang_def') {
14892: if ($newvalues{$item} ne '') {
14893: if ($newvalues{$item} =~ /^(\w+)/) {
14894: my $langcode = $1;
1.103 raeburn 14895: if ($langcode ne 'x_chef') {
14896: if (code2language($langcode) eq '') {
14897: push(@errors,$item);
14898: }
1.43 raeburn 14899: }
14900: } else {
14901: push(@errors,$item);
14902: }
14903: }
1.54 raeburn 14904: } elsif ($item eq 'timezone_def') {
14905: if ($newvalues{$item} ne '') {
1.62 raeburn 14906: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14907: push(@errors,$item);
14908: }
14909: }
1.68 raeburn 14910: } elsif ($item eq 'datelocale_def') {
14911: if ($newvalues{$item} ne '') {
14912: my @datelocale_ids = DateTime::Locale->ids();
14913: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14914: push(@errors,$item);
14915: }
14916: }
1.141 raeburn 14917: } elsif ($item eq 'portal_def') {
14918: if ($newvalues{$item} ne '') {
14919: 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])\/?$/) {
14920: push(@errors,$item);
14921: }
14922: }
1.294 raeburn 14923: } elsif ($item eq 'intauth_cost') {
14924: if ($newvalues{$item} ne '') {
14925: if ($newvalues{$item} =~ /\D/) {
14926: push(@errors,$item);
14927: }
14928: }
14929: } elsif ($item eq 'intauth_check') {
14930: if ($newvalues{$item} ne '') {
14931: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14932: push(@errors,$item);
14933: }
14934: }
14935: } elsif ($item eq 'intauth_switch') {
14936: if ($newvalues{$item} ne '') {
14937: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14938: push(@errors,$item);
14939: }
14940: }
1.43 raeburn 14941: }
14942: if (grep(/^\Q$item\E$/,@errors)) {
14943: $newvalues{$item} = $domdefaults{$item};
14944: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14945: $changes{$item} = 1;
14946: }
1.72 raeburn 14947: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14948: }
14949: my %defaults_hash = (
1.72 raeburn 14950: defaults => \%newvalues,
14951: );
1.43 raeburn 14952: my $title = &defaults_titles();
1.236 raeburn 14953:
14954: my $currinststatus;
14955: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14956: $currinststatus = $domconfig{'inststatus'};
14957: } else {
14958: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14959: $currinststatus = {
14960: inststatustypes => $usertypes,
14961: inststatusorder => $types,
14962: inststatusguest => [],
14963: };
14964: }
14965: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14966: my @allpos;
14967: my %alltypes;
1.305 raeburn 14968: my @inststatusguest;
14969: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14970: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14971: unless (grep(/^\Q$type\E$/,@todelete)) {
14972: push(@inststatusguest,$type);
14973: }
14974: }
14975: }
14976: my ($currtitles,$currorder);
1.236 raeburn 14977: if (ref($currinststatus) eq 'HASH') {
14978: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14979: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14980: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14981: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14982: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14983: }
14984: }
14985: unless (grep(/^\Q$type\E$/,@todelete)) {
14986: my $position = $env{'form.inststatus_pos_'.$type};
14987: $position =~ s/\D+//g;
14988: $allpos[$position] = $type;
14989: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14990: $alltypes{$type} =~ s/`//g;
14991: }
14992: }
14993: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14994: $currtitles =~ s/,$//;
14995: }
14996: }
14997: if ($env{'form.addinststatus'}) {
14998: my $newtype = $env{'form.addinststatus'};
14999: $newtype =~ s/\W//g;
15000: unless (exists($alltypes{$newtype})) {
15001: $alltypes{$newtype} = $env{'form.addinststatus_title'};
15002: $alltypes{$newtype} =~ s/`//g;
15003: my $position = $env{'form.addinststatus_pos'};
15004: $position =~ s/\D+//g;
15005: if ($position ne '') {
15006: $allpos[$position] = $newtype;
15007: }
15008: }
15009: }
1.305 raeburn 15010: my @orderedstatus;
1.236 raeburn 15011: foreach my $type (@allpos) {
15012: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
15013: push(@orderedstatus,$type);
15014: }
15015: }
15016: foreach my $type (keys(%alltypes)) {
15017: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
15018: delete($alltypes{$type});
15019: }
15020: }
15021: $defaults_hash{'inststatus'} = {
15022: inststatustypes => \%alltypes,
15023: inststatusorder => \@orderedstatus,
1.305 raeburn 15024: inststatusguest => \@inststatusguest,
1.236 raeburn 15025: };
15026: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
15027: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
15028: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
15029: }
15030: }
15031: if ($currorder ne join(',',@orderedstatus)) {
15032: $changes{'inststatus'}{'inststatusorder'} = 1;
15033: }
15034: my $newtitles;
15035: foreach my $item (@orderedstatus) {
15036: $newtitles .= $alltypes{$item}.',';
15037: }
15038: $newtitles =~ s/,$//;
15039: if ($currtitles ne $newtitles) {
15040: $changes{'inststatus'}{'inststatustypes'} = 1;
15041: }
1.43 raeburn 15042: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
15043: $dom);
15044: if ($putresult eq 'ok') {
15045: if (keys(%changes) > 0) {
15046: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 15047: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 15048: 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";
15049: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 15050: if ($item eq 'inststatus') {
15051: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 15052: if (@orderedstatus) {
1.236 raeburn 15053: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
15054: foreach my $type (@orderedstatus) {
15055: $resulttext .= $alltypes{$type}.', ';
15056: }
15057: $resulttext =~ s/, $//;
15058: $resulttext .= '</li>';
1.305 raeburn 15059: } else {
15060: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 15061: }
15062: }
15063: } else {
15064: my $value = $env{'form.'.$item};
15065: if ($value eq '') {
15066: $value = &mt('none');
15067: } elsif ($item eq 'auth_def') {
15068: my %authnames = &authtype_names();
15069: my %shortauth = (
15070: internal => 'int',
15071: krb4 => 'krb4',
15072: krb5 => 'krb5',
15073: localauth => 'loc',
1.325 raeburn 15074: lti => 'lti',
1.236 raeburn 15075: );
15076: $value = $authnames{$shortauth{$value}};
1.294 raeburn 15077: } elsif ($item eq 'intauth_switch') {
15078: my %optiondesc = &Apache::lonlocal::texthash (
15079: 0 => 'No',
15080: 1 => 'Yes',
15081: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
15082: );
15083: if ($value =~ /^(0|1|2)$/) {
15084: $value = $optiondesc{$value};
15085: } else {
15086: $value = &mt('none -- defaults to No');
15087: }
15088: } elsif ($item eq 'intauth_check') {
15089: my %optiondesc = &Apache::lonlocal::texthash (
15090: 0 => 'No',
15091: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
15092: 2 => 'Yes, disallow login if stored cost is less than domain default',
15093: );
15094: if ($value =~ /^(0|1|2)$/) {
15095: $value = $optiondesc{$value};
15096: } else {
15097: $value = &mt('none -- defaults to No');
15098: }
1.236 raeburn 15099: }
15100: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
15101: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 15102: }
15103: }
15104: $resulttext .= '</ul>';
15105: $mailmsgtext .= "\n";
15106: my $cachetime = 24*60*60;
1.72 raeburn 15107: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 15108: if (ref($lastactref) eq 'HASH') {
15109: $lastactref->{'domdefaults'} = 1;
15110: }
1.68 raeburn 15111: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 15112: my $notify = 1;
15113: if (ref($domconfig{'contacts'}) eq 'HASH') {
15114: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
15115: $notify = 0;
15116: }
15117: }
15118: if ($notify) {
15119: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
15120: "LON-CAPA Domain Settings Change - $dom",
15121: $mailmsgtext);
15122: }
1.54 raeburn 15123: }
1.43 raeburn 15124: } else {
1.54 raeburn 15125: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 15126: }
15127: } else {
15128: $resulttext = '<span class="LC_error">'.
15129: &mt('An error occurred: [_1]',$putresult).'</span>';
15130: }
15131: if (@errors > 0) {
15132: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
15133: foreach my $item (@errors) {
15134: $resulttext .= ' "'.$title->{$item}.'",';
15135: }
15136: $resulttext =~ s/,$//;
15137: }
15138: return $resulttext;
15139: }
15140:
1.46 raeburn 15141: sub modify_scantron {
1.205 raeburn 15142: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 15143: my ($resulttext,%confhash,%changes,$errors);
15144: my $custom = 'custom.tab';
15145: my $default = 'default.tab';
15146: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 15147: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 15148: &config_check($dom,$confname,$servadm);
15149: if ($env{'form.scantronformat.filename'} ne '') {
15150: my $error;
15151: if ($configuserok eq 'ok') {
15152: if ($switchserver) {
1.130 raeburn 15153: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 15154: } else {
15155: if ($author_ok eq 'ok') {
15156: my ($result,$scantronurl) =
15157: &publishlogo($r,'upload','scantronformat',$dom,
15158: $confname,'scantron','','',$custom);
15159: if ($result eq 'ok') {
15160: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 15161: $changes{'scantronformat'} = 1;
1.46 raeburn 15162: } else {
15163: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
15164: }
15165: } else {
15166: $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);
15167: }
15168: }
15169: } else {
15170: $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);
15171: }
15172: if ($error) {
15173: &Apache::lonnet::logthis($error);
15174: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15175: }
15176: }
1.48 raeburn 15177: if (ref($domconfig{'scantron'}) eq 'HASH') {
15178: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
15179: if ($env{'form.scantronformat_del'}) {
15180: $confhash{'scantron'}{'scantronformat'} = '';
15181: $changes{'scantronformat'} = 1;
1.347 raeburn 15182: } else {
15183: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 15184: }
15185: }
15186: }
1.347 raeburn 15187: my @options = ('hdr','pad','rem');
1.346 raeburn 15188: my @fields = &scantroncsv_fields();
15189: my %titles = &scantronconfig_titles();
1.347 raeburn 15190: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 15191: my ($newdat,$currdat,%newcol,%currcol);
15192: if (grep(/^dat$/,@formats)) {
15193: $confhash{'scantron'}{config}{dat} = 1;
15194: $newdat = 1;
15195: } else {
15196: $newdat = 0;
15197: }
15198: if (grep(/^csv$/,@formats)) {
15199: my %bynum;
15200: foreach my $field (@fields) {
15201: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
15202: my $posscol = $1;
15203: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 15204: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 15205: $bynum{$posscol} = $field;
15206: $newcol{$field} = $posscol;
15207: }
15208: }
15209: }
1.347 raeburn 15210: if (keys(%newcol)) {
15211: foreach my $option (@options) {
15212: if ($env{'form.scantroncsv_'.$option}) {
15213: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
15214: }
15215: }
15216: }
1.346 raeburn 15217: }
15218: $currdat = 1;
15219: if (ref($domconfig{'scantron'}) eq 'HASH') {
15220: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 15221: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 15222: $currdat = 0;
15223: }
15224: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 15225: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
15226: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
15227: }
1.346 raeburn 15228: }
15229: }
15230: }
15231: if ($currdat != $newdat) {
15232: $changes{'config'} = 1;
15233: } else {
15234: foreach my $field (@fields) {
15235: if ($currcol{$field} ne '') {
15236: if ($currcol{$field} ne $newcol{$field}) {
15237: $changes{'config'} = 1;
15238: last;
1.347 raeburn 15239: }
1.346 raeburn 15240: } elsif ($newcol{$field} ne '') {
15241: $changes{'config'} = 1;
15242: last;
15243: }
15244: }
15245: }
1.46 raeburn 15246: if (keys(%confhash) > 0) {
15247: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
15248: $dom);
15249: if ($putresult eq 'ok') {
15250: if (keys(%changes) > 0) {
1.48 raeburn 15251: if (ref($confhash{'scantron'}) eq 'HASH') {
15252: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 15253: if ($changes{'scantronformat'}) {
15254: if ($confhash{'scantron'}{'scantronformat'} eq '') {
15255: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
15256: } else {
15257: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
15258: }
15259: }
1.347 raeburn 15260: if ($changes{'config'}) {
1.346 raeburn 15261: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
15262: if ($confhash{'scantron'}{'config'}{'dat'}) {
15263: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
15264: }
15265: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 15266: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
15267: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
15268: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
15269: foreach my $field (@fields) {
15270: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
15271: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
15272: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
15273: }
15274: }
15275: $resulttext .= '</ul></li>';
15276: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
15277: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
15278: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
15279: foreach my $option (@options) {
15280: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
15281: $resulttext .= '<li>'.$titles{$option}.'</li>';
15282: }
15283: }
15284: $resulttext .= '</ul></li>';
15285: }
1.346 raeburn 15286: }
15287: }
15288: }
15289: }
15290: } else {
15291: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
15292: }
1.46 raeburn 15293: }
1.48 raeburn 15294: $resulttext .= '</ul>';
15295: } else {
1.130 raeburn 15296: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 15297: }
15298: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 15299: if (ref($lastactref) eq 'HASH') {
15300: $lastactref->{'domainconfig'} = 1;
15301: }
1.46 raeburn 15302: } else {
1.346 raeburn 15303: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 15304: }
15305: } else {
15306: $resulttext = '<span class="LC_error">'.
15307: &mt('An error occurred: [_1]',$putresult).'</span>';
15308: }
15309: } else {
1.130 raeburn 15310: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 15311: }
15312: if ($errors) {
15313: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15314: $errors.'</ul>';
15315: }
15316: return $resulttext;
15317: }
15318:
1.48 raeburn 15319: sub modify_coursecategories {
1.239 raeburn 15320: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 15321: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
15322: $cathash);
1.48 raeburn 15323: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 15324: my @catitems = ('unauth','auth');
15325: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 15326: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 15327: $cathash = $domconfig{'coursecategories'}{'cats'};
15328: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
15329: $changes{'togglecats'} = 1;
15330: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
15331: }
15332: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
15333: $changes{'categorize'} = 1;
15334: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
15335: }
1.120 raeburn 15336: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
15337: $changes{'togglecatscomm'} = 1;
15338: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
15339: }
15340: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
15341: $changes{'categorizecomm'} = 1;
15342: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 15343:
15344: }
15345: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
15346: $changes{'togglecatsplace'} = 1;
15347: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
15348: }
15349: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
15350: $changes{'categorizeplace'} = 1;
15351: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 15352: }
1.238 raeburn 15353: foreach my $item (@catitems) {
15354: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
15355: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
15356: $changes{$item} = 1;
15357: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
15358: }
15359: }
15360: }
1.57 raeburn 15361: } else {
15362: $changes{'togglecats'} = 1;
15363: $changes{'categorize'} = 1;
1.124 raeburn 15364: $changes{'togglecatscomm'} = 1;
15365: $changes{'categorizecomm'} = 1;
1.272 raeburn 15366: $changes{'togglecatsplace'} = 1;
15367: $changes{'categorizeplace'} = 1;
1.87 raeburn 15368: $domconfig{'coursecategories'} = {
15369: togglecats => $env{'form.togglecats'},
15370: categorize => $env{'form.categorize'},
1.124 raeburn 15371: togglecatscomm => $env{'form.togglecatscomm'},
15372: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 15373: togglecatsplace => $env{'form.togglecatsplace'},
15374: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 15375: };
1.238 raeburn 15376: foreach my $item (@catitems) {
15377: if ($env{'form.coursecat_'.$item} ne 'std') {
15378: $changes{$item} = 1;
15379: }
15380: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
15381: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
15382: }
15383: }
1.57 raeburn 15384: }
15385: if (ref($cathash) eq 'HASH') {
15386: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 15387: push (@deletecategory,'instcode::0');
15388: }
1.120 raeburn 15389: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
15390: push(@deletecategory,'communities::0');
15391: }
1.272 raeburn 15392: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
15393: push(@deletecategory,'placement::0');
15394: }
1.48 raeburn 15395: }
1.57 raeburn 15396: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
15397: if (ref($cathash) eq 'HASH') {
1.48 raeburn 15398: if (@deletecategory > 0) {
15399: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 15400: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 15401: foreach my $item (@deletecategory) {
1.57 raeburn 15402: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
15403: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 15404: $deletions{$item} = 1;
1.57 raeburn 15405: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 15406: }
15407: }
15408: }
1.57 raeburn 15409: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 15410: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 15411: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 15412: $reorderings{$item} = 1;
1.57 raeburn 15413: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 15414: }
15415: if ($env{'form.addcategory_name_'.$item} ne '') {
15416: my $newcat = $env{'form.addcategory_name_'.$item};
15417: my $newdepth = $depth+1;
15418: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 15419: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 15420: $adds{$newitem} = 1;
15421: }
15422: if ($env{'form.subcat_'.$item} ne '') {
15423: my $newcat = $env{'form.subcat_'.$item};
15424: my $newdepth = $depth+1;
15425: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 15426: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 15427: $adds{$newitem} = 1;
15428: }
15429: }
15430: }
15431: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 15432: if (ref($cathash) eq 'HASH') {
1.48 raeburn 15433: my $newitem = 'instcode::0';
1.57 raeburn 15434: if ($cathash->{$newitem} eq '') {
15435: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 15436: $adds{$newitem} = 1;
15437: }
15438: } else {
15439: my $newitem = 'instcode::0';
1.57 raeburn 15440: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 15441: $adds{$newitem} = 1;
15442: }
15443: }
1.120 raeburn 15444: if ($env{'form.communities'} eq '1') {
15445: if (ref($cathash) eq 'HASH') {
15446: my $newitem = 'communities::0';
15447: if ($cathash->{$newitem} eq '') {
15448: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
15449: $adds{$newitem} = 1;
15450: }
15451: } else {
15452: my $newitem = 'communities::0';
15453: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
15454: $adds{$newitem} = 1;
15455: }
15456: }
1.272 raeburn 15457: if ($env{'form.placement'} eq '1') {
15458: if (ref($cathash) eq 'HASH') {
15459: my $newitem = 'placement::0';
15460: if ($cathash->{$newitem} eq '') {
15461: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
15462: $adds{$newitem} = 1;
15463: }
15464: } else {
15465: my $newitem = 'placement::0';
15466: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
15467: $adds{$newitem} = 1;
15468: }
15469: }
1.48 raeburn 15470: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 15471: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 15472: ($env{'form.addcategory_name'} ne 'communities') &&
15473: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 15474: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
15475: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
15476: $adds{$newitem} = 1;
15477: }
1.48 raeburn 15478: }
1.57 raeburn 15479: my $putresult;
1.48 raeburn 15480: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15481: if (keys(%deletions) > 0) {
15482: foreach my $key (keys(%deletions)) {
15483: if ($predelallitems{$key} ne '') {
15484: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
15485: }
15486: }
15487: }
15488: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 15489: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 15490: if (ref($chkcats[0]) eq 'ARRAY') {
15491: my $depth = 0;
15492: my $chg = 0;
15493: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
15494: my $name = $chkcats[0][$i];
15495: my $item;
15496: if ($name eq '') {
15497: $chg ++;
15498: } else {
15499: $item = &escape($name).'::0';
15500: if ($chg) {
1.57 raeburn 15501: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 15502: }
15503: $depth ++;
1.57 raeburn 15504: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 15505: $depth --;
15506: }
15507: }
15508: }
1.57 raeburn 15509: }
15510: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15511: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 15512: if ($putresult eq 'ok') {
1.57 raeburn 15513: my %title = (
1.120 raeburn 15514: togglecats => 'Show/Hide a course in catalog',
15515: categorize => 'Assign a category to a course',
15516: togglecatscomm => 'Show/Hide a community in catalog',
15517: categorizecomm => 'Assign a category to a community',
1.57 raeburn 15518: );
15519: my %level = (
1.120 raeburn 15520: dom => 'set in Domain ("Modify Course/Community")',
15521: crs => 'set in Course ("Course Configuration")',
15522: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 15523: none => 'No catalog',
15524: std => 'Standard catalog',
15525: domonly => 'Domain-only catalog',
15526: codesrch => 'Code search form',
1.57 raeburn 15527: );
1.48 raeburn 15528: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 15529: if ($changes{'togglecats'}) {
15530: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
15531: }
15532: if ($changes{'categorize'}) {
15533: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 15534: }
1.120 raeburn 15535: if ($changes{'togglecatscomm'}) {
15536: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
15537: }
15538: if ($changes{'categorizecomm'}) {
15539: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
15540: }
1.238 raeburn 15541: if ($changes{'unauth'}) {
15542: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
15543: }
15544: if ($changes{'auth'}) {
15545: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
15546: }
1.57 raeburn 15547: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15548: my $cathash;
15549: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
15550: $cathash = $domconfig{'coursecategories'}{'cats'};
15551: } else {
15552: $cathash = {};
15553: }
15554: my (@cats,@trails,%allitems);
15555: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
15556: if (keys(%deletions) > 0) {
15557: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
15558: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
15559: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
15560: }
15561: $resulttext .= '</ul></li>';
15562: }
15563: if (keys(%reorderings) > 0) {
15564: my %sort_by_trail;
15565: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
15566: foreach my $key (keys(%reorderings)) {
15567: if ($allitems{$key} ne '') {
15568: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15569: }
1.48 raeburn 15570: }
1.57 raeburn 15571: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15572: $resulttext .= '<li>'.$trails[$trail].'</li>';
15573: }
15574: $resulttext .= '</ul></li>';
1.48 raeburn 15575: }
1.57 raeburn 15576: if (keys(%adds) > 0) {
15577: my %sort_by_trail;
15578: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
15579: foreach my $key (keys(%adds)) {
15580: if ($allitems{$key} ne '') {
15581: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15582: }
15583: }
15584: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15585: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 15586: }
1.57 raeburn 15587: $resulttext .= '</ul></li>';
1.48 raeburn 15588: }
15589: }
15590: $resulttext .= '</ul>';
1.239 raeburn 15591: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 15592: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15593: if ($changes{'auth'}) {
15594: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
15595: }
15596: if ($changes{'unauth'}) {
15597: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
15598: }
15599: my $cachetime = 24*60*60;
15600: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 15601: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 15602: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 15603: }
15604: }
1.48 raeburn 15605: } else {
15606: $resulttext = '<span class="LC_error">'.
1.57 raeburn 15607: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 15608: }
15609: } else {
1.120 raeburn 15610: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 15611: }
15612: return $resulttext;
15613: }
15614:
1.69 raeburn 15615: sub modify_serverstatuses {
15616: my ($dom,%domconfig) = @_;
15617: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
15618: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
15619: %currserverstatus = %{$domconfig{'serverstatuses'}};
15620: }
15621: my @pages = &serverstatus_pages();
15622: foreach my $type (@pages) {
15623: $newserverstatus{$type}{'namedusers'} = '';
15624: $newserverstatus{$type}{'machines'} = '';
15625: if (defined($env{'form.'.$type.'_namedusers'})) {
15626: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
15627: my @okusers;
15628: foreach my $user (@users) {
15629: my ($uname,$udom) = split(/:/,$user);
15630: if (($udom =~ /^$match_domain$/) &&
15631: (&Apache::lonnet::domain($udom)) &&
15632: ($uname =~ /^$match_username$/)) {
15633: if (!grep(/^\Q$user\E/,@okusers)) {
15634: push(@okusers,$user);
15635: }
15636: }
15637: }
15638: if (@okusers > 0) {
15639: @okusers = sort(@okusers);
15640: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
15641: }
15642: }
15643: if (defined($env{'form.'.$type.'_machines'})) {
15644: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
15645: my @okmachines;
15646: foreach my $ip (@machines) {
15647: my @parts = split(/\./,$ip);
15648: next if (@parts < 4);
15649: my $badip = 0;
15650: for (my $i=0; $i<4; $i++) {
15651: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
15652: $badip = 1;
15653: last;
15654: }
15655: }
15656: if (!$badip) {
15657: push(@okmachines,$ip);
15658: }
15659: }
15660: @okmachines = sort(@okmachines);
15661: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
15662: }
15663: }
15664: my %serverstatushash = (
15665: serverstatuses => \%newserverstatus,
15666: );
15667: foreach my $type (@pages) {
1.83 raeburn 15668: foreach my $setting ('namedusers','machines') {
1.84 raeburn 15669: my (@current,@new);
1.83 raeburn 15670: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 15671: if ($currserverstatus{$type}{$setting} ne '') {
15672: @current = split(/,/,$currserverstatus{$type}{$setting});
15673: }
15674: }
15675: if ($newserverstatus{$type}{$setting} ne '') {
15676: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 15677: }
15678: if (@current > 0) {
15679: if (@new > 0) {
15680: foreach my $item (@current) {
15681: if (!grep(/^\Q$item\E$/,@new)) {
15682: $changes{$type}{$setting} = 1;
1.82 raeburn 15683: last;
15684: }
15685: }
1.84 raeburn 15686: foreach my $item (@new) {
15687: if (!grep(/^\Q$item\E$/,@current)) {
15688: $changes{$type}{$setting} = 1;
15689: last;
1.82 raeburn 15690: }
15691: }
15692: } else {
1.83 raeburn 15693: $changes{$type}{$setting} = 1;
1.69 raeburn 15694: }
1.83 raeburn 15695: } elsif (@new > 0) {
15696: $changes{$type}{$setting} = 1;
1.69 raeburn 15697: }
15698: }
15699: }
15700: if (keys(%changes) > 0) {
1.81 raeburn 15701: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 15702: my $putresult = &Apache::lonnet::put_dom('configuration',
15703: \%serverstatushash,$dom);
15704: if ($putresult eq 'ok') {
15705: $resulttext .= &mt('Changes made:').'<ul>';
15706: foreach my $type (@pages) {
1.84 raeburn 15707: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 15708: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 15709: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 15710: if ($newserverstatus{$type}{'namedusers'} eq '') {
15711: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
15712: } else {
15713: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
15714: }
1.84 raeburn 15715: }
15716: if ($changes{$type}{'machines'}) {
1.69 raeburn 15717: if ($newserverstatus{$type}{'machines'} eq '') {
15718: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
15719: } else {
15720: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
15721: }
15722:
15723: }
15724: $resulttext .= '</ul></li>';
15725: }
15726: }
15727: $resulttext .= '</ul>';
15728: } else {
15729: $resulttext = '<span class="LC_error">'.
15730: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
15731:
15732: }
15733: } else {
15734: $resulttext = &mt('No changes made to access to server status pages');
15735: }
15736: return $resulttext;
15737: }
15738:
1.118 jms 15739: sub modify_helpsettings {
1.285 raeburn 15740: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 15741: my ($resulttext,$errors,%changes,%helphash);
15742: my %defaultchecked = ('submitbugs' => 'on');
15743: my @offon = ('off','on');
1.118 jms 15744: my @toggles = ('submitbugs');
1.285 raeburn 15745: my %current = ('submitbugs' => '',
15746: 'adhoc' => {},
15747: );
1.118 jms 15748: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 15749: %current = %{$domconfig{'helpsettings'}};
15750: }
1.285 raeburn 15751: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 15752: foreach my $item (@toggles) {
15753: if ($defaultchecked{$item} eq 'on') {
15754: if ($current{$item} eq '') {
15755: if ($env{'form.'.$item} eq '0') {
15756: $changes{$item} = 1;
15757: }
15758: } elsif ($current{$item} ne $env{'form.'.$item}) {
15759: $changes{$item} = 1;
15760: }
15761: } elsif ($defaultchecked{$item} eq 'off') {
15762: if ($current{$item} eq '') {
15763: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 15764: $changes{$item} = 1;
15765: }
1.282 raeburn 15766: } elsif ($current{$item} ne $env{'form.'.$item}) {
15767: $changes{$item} = 1;
15768: }
15769: }
15770: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
15771: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
15772: }
15773: }
1.285 raeburn 15774: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 15775: my $confname = $dom.'-domainconfig';
15776: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 15777: my (@allpos,%newsettings,%changedprivs,$newrole);
15778: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 15779: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 15780: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 15781: my %lt = &Apache::lonlocal::texthash(
15782: s => 'system',
15783: d => 'domain',
15784: order => 'Display order',
15785: access => 'Role usage',
1.291 raeburn 15786: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 15787: dh => 'All with domain helpdesk role',
15788: da => 'All with domain helpdesk assistant role',
1.285 raeburn 15789: none => 'None',
15790: status => 'Determined based on institutional status',
15791: inc => 'Include all, but exclude specific personnel',
15792: exc => 'Exclude all, but include specific personnel',
15793: );
15794: for (my $num=0; $num<=$maxnum; $num++) {
15795: my ($prefix,$identifier,$rolename,%curr);
15796: if ($num == $maxnum) {
15797: next unless ($env{'form.newcusthelp'} == $maxnum);
15798: $identifier = 'custhelp'.$num;
15799: $prefix = 'helproles_'.$num;
15800: $rolename = $env{'form.custhelpname'.$num};
15801: $rolename=~s/[^A-Za-z0-9]//gs;
15802: next if ($rolename eq '');
15803: next if (exists($existing{'rolesdef_'.$rolename}));
15804: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15805: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15806: $newprivs{'c'},$confname,$dom);
15807: if ($result ne 'ok') {
15808: $errors .= '<li><span class="LC_error">'.
15809: &mt('An error occurred storing the new custom role: [_1]',
15810: $result).'</span></li>';
15811: next;
15812: } else {
15813: $changedprivs{$rolename} = \%newprivs;
15814: $newrole = $rolename;
15815: }
15816: } else {
15817: $prefix = 'helproles_'.$num;
15818: $rolename = $env{'form.'.$prefix};
15819: next if ($rolename eq '');
15820: next unless (exists($existing{'rolesdef_'.$rolename}));
15821: $identifier = 'custhelp'.$num;
15822: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15823: my %currprivs;
1.289 raeburn 15824: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 15825: split(/\_/,$existing{'rolesdef_'.$rolename});
15826: foreach my $level ('c','d','s') {
15827: if ($newprivs{$level} ne $currprivs{$level}) {
15828: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15829: $newprivs{'c'},$confname,$dom);
15830: if ($result ne 'ok') {
15831: $errors .= '<li><span class="LC_error">'.
15832: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15833: $rolename,$result).'</span></li>';
15834: } else {
15835: $changedprivs{$rolename} = \%newprivs;
15836: }
15837: last;
15838: }
15839: }
15840: if (ref($current{'adhoc'}) eq 'HASH') {
15841: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15842: %curr = %{$current{'adhoc'}{$rolename}};
15843: }
15844: }
15845: }
15846: my $newpos = $env{'form.'.$prefix.'_pos'};
15847: $newpos =~ s/\D+//g;
15848: $allpos[$newpos] = $rolename;
15849: my $newdesc = $env{'form.'.$prefix.'_desc'};
15850: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15851: if ($curr{'desc'}) {
15852: if ($curr{'desc'} ne $newdesc) {
15853: $changes{'customrole'}{$rolename}{'desc'} = 1;
15854: $newsettings{$rolename}{'desc'} = $newdesc;
15855: }
15856: } elsif ($newdesc ne '') {
15857: $changes{'customrole'}{$rolename}{'desc'} = 1;
15858: $newsettings{$rolename}{'desc'} = $newdesc;
15859: }
15860: my $access = $env{'form.'.$prefix.'_access'};
15861: if (grep(/^\Q$access\E$/,@accesstypes)) {
15862: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15863: if ($access eq 'status') {
15864: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15865: if (scalar(@statuses) == 0) {
1.289 raeburn 15866: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 15867: } else {
15868: my (@shownstatus,$numtypes);
15869: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15870: if (ref($types) eq 'ARRAY') {
15871: $numtypes = scalar(@{$types});
15872: foreach my $type (sort(@statuses)) {
15873: if ($type eq 'default') {
15874: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15875: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15876: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15877: push(@shownstatus,$usertypes->{$type});
15878: }
15879: }
15880: }
15881: if (grep(/^default$/,@statuses)) {
15882: push(@shownstatus,$othertitle);
15883: }
15884: if (scalar(@shownstatus) == 1+$numtypes) {
15885: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15886: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15887: } else {
15888: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15889: if (ref($curr{'status'}) eq 'ARRAY') {
15890: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15891: if (@diffs) {
15892: $changes{'customrole'}{$rolename}{$access} = 1;
15893: }
15894: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15895: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 15896: }
1.166 raeburn 15897: }
15898: }
1.285 raeburn 15899: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15900: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15901: my @newspecstaff;
15902: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15903: foreach my $person (sort(@personnel)) {
15904: if ($domhelpdesk{$person}) {
15905: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15906: }
15907: }
15908: if (ref($curr{$access}) eq 'ARRAY') {
15909: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15910: if (@diffs) {
15911: $changes{'customrole'}{$rolename}{$access} = 1;
15912: }
15913: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15914: $changes{'customrole'}{$rolename}{$access} = 1;
15915: }
15916: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15917: my ($uname,$udom) = split(/:/,$person);
15918: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15919: }
15920: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 15921: }
1.285 raeburn 15922: } else {
15923: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15924: }
15925: unless ($curr{'access'} eq $access) {
15926: $changes{'customrole'}{$rolename}{'access'} = 1;
15927: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 15928: }
15929: }
1.285 raeburn 15930: if (@allpos > 0) {
15931: my $idx = 0;
15932: foreach my $rolename (@allpos) {
15933: if ($rolename ne '') {
15934: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15935: if (ref($current{'adhoc'}) eq 'HASH') {
15936: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15937: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15938: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 15939: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 15940: }
15941: }
1.282 raeburn 15942: }
1.285 raeburn 15943: $idx ++;
1.166 raeburn 15944: }
15945: }
1.118 jms 15946: }
1.123 jms 15947: my $putresult;
15948: if (keys(%changes) > 0) {
1.166 raeburn 15949: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 15950: if ($putresult eq 'ok') {
1.285 raeburn 15951: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15952: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15953: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15954: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15955: }
15956: }
15957: my $cachetime = 24*60*60;
15958: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15959: if (ref($lastactref) eq 'HASH') {
15960: $lastactref->{'domdefaults'} = 1;
15961: }
15962: } else {
15963: $errors .= '<li><span class="LC_error">'.
15964: &mt('An error occurred storing the settings: [_1]',
15965: $putresult).'</span></li>';
15966: }
15967: }
15968: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15969: $resulttext = &mt('Changes made:').'<ul>';
15970: my (%shownprivs,@levelorder);
15971: @levelorder = ('c','d','s');
15972: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 15973: foreach my $item (sort(keys(%changes))) {
15974: if ($item eq 'submitbugs') {
15975: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15976: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15977: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 15978: } elsif ($item eq 'customrole') {
15979: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 15980: my @keyorder = ('order','desc','access','status','exc','inc');
15981: my %keytext = &Apache::lonlocal::texthash(
15982: order => 'Order',
15983: desc => 'Role description',
15984: access => 'Role usage',
1.300 droeschl 15985: status => 'Allowed institutional types',
1.285 raeburn 15986: exc => 'Allowed personnel',
15987: inc => 'Disallowed personnel',
15988: );
1.282 raeburn 15989: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 15990: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15991: if ($role eq $newrole) {
15992: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15993: $role).'<ul>';
15994: } else {
15995: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15996: $role).'<ul>';
15997: }
15998: foreach my $key (@keyorder) {
15999: if ($changes{'customrole'}{$role}{$key}) {
16000: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
16001: $keytext{$key},$newsettings{$role}{$key}).
16002: '</li>';
16003: }
16004: }
16005: if (ref($changedprivs{$role}) eq 'HASH') {
16006: $shownprivs{$role} = 1;
16007: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
16008: foreach my $level (@levelorder) {
16009: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
16010: next if ($item eq '');
16011: my ($priv) = split(/\&/,$item,2);
16012: if (&Apache::lonnet::plaintext($priv)) {
16013: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
16014: unless ($level eq 'c') {
16015: $resulttext .= ' ('.$lt{$level}.')';
16016: }
16017: $resulttext .= '</li>';
16018: }
16019: }
16020: }
16021: $resulttext .= '</ul>';
16022: }
16023: $resulttext .= '</ul></li>';
16024: }
16025: }
16026: }
16027: }
16028: }
16029: }
16030: if (keys(%changedprivs)) {
16031: foreach my $role (sort(keys(%changedprivs))) {
16032: unless ($shownprivs{$role}) {
16033: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
16034: $role).'<ul>'.
16035: '<li>'.&mt('Privileges set to :').'<ul>';
16036: foreach my $level (@levelorder) {
16037: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
16038: next if ($item eq '');
16039: my ($priv) = split(/\&/,$item,2);
16040: if (&Apache::lonnet::plaintext($priv)) {
16041: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
16042: unless ($level eq 'c') {
16043: $resulttext .= ' ('.$lt{$level}.')';
16044: }
16045: $resulttext .= '</li>';
16046: }
1.282 raeburn 16047: }
16048: }
1.285 raeburn 16049: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 16050: }
16051: }
16052: }
1.285 raeburn 16053: $resulttext .= '</ul>';
16054: } else {
16055: $resulttext = &mt('No changes made to help settings');
1.118 jms 16056: }
16057: if ($errors) {
1.168 raeburn 16058: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 16059: $errors.'</ul>';
1.118 jms 16060: }
16061: return $resulttext;
16062: }
16063:
1.121 raeburn 16064: sub modify_coursedefaults {
1.212 raeburn 16065: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 16066: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 16067: my %defaultchecked = (
16068: 'canuse_pdfforms' => 'off',
16069: 'uselcmath' => 'on',
16070: 'usejsme' => 'on'
16071: );
16072: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 16073: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 16074: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
16075: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
16076: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 16077: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 16078: my %staticdefaults = (
16079: anonsurvey_threshold => 10,
16080: uploadquota => 500,
1.257 raeburn 16081: postsubmit => 60,
1.276 raeburn 16082: mysqltables => 172800,
1.198 raeburn 16083: );
1.314 raeburn 16084: my %texoptions = (
16085: MathJax => 'MathJax',
16086: mimetex => &mt('Convert to Images'),
16087: tth => &mt('TeX to HTML'),
16088: );
1.121 raeburn 16089: $defaultshash{'coursedefaults'} = {};
16090:
16091: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
16092: if ($domconfig{'coursedefaults'} eq '') {
16093: $domconfig{'coursedefaults'} = {};
16094: }
16095: }
16096:
16097: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
16098: foreach my $item (@toggles) {
16099: if ($defaultchecked{$item} eq 'on') {
16100: if (($domconfig{'coursedefaults'}{$item} eq '') &&
16101: ($env{'form.'.$item} eq '0')) {
16102: $changes{$item} = 1;
1.192 raeburn 16103: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 16104: $changes{$item} = 1;
16105: }
16106: } elsif ($defaultchecked{$item} eq 'off') {
16107: if (($domconfig{'coursedefaults'}{$item} eq '') &&
16108: ($env{'form.'.$item} eq '1')) {
16109: $changes{$item} = 1;
16110: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
16111: $changes{$item} = 1;
16112: }
16113: }
16114: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
16115: }
1.198 raeburn 16116: foreach my $item (@numbers) {
16117: my ($currdef,$newdef);
1.208 raeburn 16118: $newdef = $env{'form.'.$item};
1.198 raeburn 16119: if ($item eq 'anonsurvey_threshold') {
16120: $currdef = $domconfig{'coursedefaults'}{$item};
16121: $newdef =~ s/\D//g;
16122: if ($newdef eq '' || $newdef < 1) {
16123: $newdef = 1;
16124: }
16125: $defaultshash{'coursedefaults'}{$item} = $newdef;
16126: } else {
1.276 raeburn 16127: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
16128: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
16129: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 16130: }
16131: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 16132: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 16133: }
16134: if ($currdef ne $newdef) {
16135: if ($item eq 'anonsurvey_threshold') {
16136: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
16137: $changes{$item} = 1;
16138: }
1.276 raeburn 16139: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 16140: my $setting = $1;
1.276 raeburn 16141: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
16142: $changes{$setting} = 1;
1.198 raeburn 16143: }
16144: }
1.139 raeburn 16145: }
16146: }
1.314 raeburn 16147: my $texengine;
16148: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
16149: $texengine = $env{'form.texengine'};
1.349 ! raeburn 16150: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
! 16151: if ($currdef eq '') {
! 16152: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 16153: $changes{'texengine'} = 1;
16154: }
1.349 ! raeburn 16155: } elsif ($currdef ne $texengine) {
1.314 raeburn 16156: $changes{'texengine'} = 1;
16157: }
16158: }
16159: if ($texengine ne '') {
16160: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
16161: }
1.264 raeburn 16162: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
16163: my @currclonecode;
16164: if (ref($currclone) eq 'HASH') {
16165: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
16166: @currclonecode = @{$currclone->{'instcode'}};
16167: }
16168: }
16169: my $newclone;
1.289 raeburn 16170: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 16171: $newclone = $env{'form.canclone'};
16172: }
16173: if ($newclone eq 'instcode') {
16174: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
16175: my (%codedefaults,@code_order,@clonecode);
16176: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
16177: \@code_order);
16178: foreach my $item (@code_order) {
16179: if (grep(/^\Q$item\E$/,@newcodes)) {
16180: push(@clonecode,$item);
16181: }
16182: }
16183: if (@clonecode) {
16184: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
16185: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
16186: if (@diffs) {
16187: $changes{'canclone'} = 1;
16188: }
16189: } else {
16190: $newclone eq '';
16191: }
16192: } elsif ($newclone ne '') {
1.289 raeburn 16193: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
16194: }
1.264 raeburn 16195: if ($newclone ne $currclone) {
16196: $changes{'canclone'} = 1;
16197: }
1.257 raeburn 16198: my %credits;
16199: foreach my $type (@types) {
16200: unless ($type eq 'community') {
16201: $credits{$type} = $env{'form.'.$type.'_credits'};
16202: $credits{$type} =~ s/[^\d.]+//g;
16203: }
16204: }
16205: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
16206: ($env{'form.coursecredits'} eq '1')) {
16207: $changes{'coursecredits'} = 1;
16208: foreach my $type (keys(%credits)) {
16209: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
16210: }
16211: } else {
1.289 raeburn 16212: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 16213: foreach my $type (@types) {
16214: unless ($type eq 'community') {
1.289 raeburn 16215: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 16216: $changes{'coursecredits'} = 1;
16217: }
16218: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
16219: }
16220: }
16221: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
16222: foreach my $type (@types) {
16223: unless ($type eq 'community') {
16224: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
16225: $changes{'coursecredits'} = 1;
16226: last;
16227: }
16228: }
16229: }
16230: }
16231: }
16232: if ($env{'form.postsubmit'} eq '1') {
16233: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
16234: my %currtimeout;
16235: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
16236: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
16237: $changes{'postsubmit'} = 1;
16238: }
16239: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
16240: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
16241: }
16242: } else {
16243: $changes{'postsubmit'} = 1;
16244: }
16245: foreach my $type (@types) {
16246: my $timeout = $env{'form.'.$type.'_timeout'};
16247: $timeout =~ s/\D//g;
16248: if ($timeout == $staticdefaults{'postsubmit'}) {
16249: $timeout = '';
16250: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
16251: $timeout = '0';
16252: }
16253: unless ($timeout eq '') {
16254: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
16255: }
16256: if (exists($currtimeout{$type})) {
16257: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 16258: $changes{'postsubmit'} = 1;
1.257 raeburn 16259: }
16260: } elsif ($timeout ne '') {
16261: $changes{'postsubmit'} = 1;
16262: }
16263: }
16264: } else {
16265: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
16266: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
16267: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
16268: $changes{'postsubmit'} = 1;
16269: }
16270: } else {
16271: $changes{'postsubmit'} = 1;
16272: }
1.192 raeburn 16273: }
1.121 raeburn 16274: }
16275: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16276: $dom);
16277: if ($putresult eq 'ok') {
16278: if (keys(%changes) > 0) {
1.213 raeburn 16279: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 16280: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 16281: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 16282: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
16283: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 16284: if ($changes{$item}) {
16285: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
16286: }
1.289 raeburn 16287: }
1.192 raeburn 16288: if ($changes{'coursecredits'}) {
16289: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 16290: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
16291: $domdefaults{$type.'credits'} =
16292: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
16293: }
16294: }
16295: }
16296: if ($changes{'postsubmit'}) {
16297: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
16298: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
16299: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
16300: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
16301: $domdefaults{$type.'postsubtimeout'} =
16302: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
16303: }
16304: }
1.192 raeburn 16305: }
16306: }
1.198 raeburn 16307: if ($changes{'uploadquota'}) {
16308: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
16309: foreach my $type (@types) {
16310: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
16311: }
16312: }
16313: }
1.264 raeburn 16314: if ($changes{'canclone'}) {
16315: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
16316: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
16317: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
16318: if (@clonecodes) {
16319: $domdefaults{'canclone'} = join('+',@clonecodes);
16320: }
16321: }
16322: } else {
16323: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
16324: }
16325: }
1.121 raeburn 16326: my $cachetime = 24*60*60;
16327: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 16328: if (ref($lastactref) eq 'HASH') {
16329: $lastactref->{'domdefaults'} = 1;
16330: }
1.121 raeburn 16331: }
16332: $resulttext = &mt('Changes made:').'<ul>';
16333: foreach my $item (sort(keys(%changes))) {
16334: if ($item eq 'canuse_pdfforms') {
16335: if ($env{'form.'.$item} eq '1') {
16336: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
16337: } else {
16338: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
16339: }
1.257 raeburn 16340: } elsif ($item eq 'uselcmath') {
16341: if ($env{'form.'.$item} eq '1') {
16342: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
16343: } else {
16344: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
16345: }
16346: } elsif ($item eq 'usejsme') {
16347: if ($env{'form.'.$item} eq '1') {
16348: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
16349: } else {
1.289 raeburn 16350: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 16351: }
1.314 raeburn 16352: } elsif ($item eq 'texengine') {
16353: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
16354: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
16355: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
16356: }
1.139 raeburn 16357: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 16358: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 16359: } elsif ($item eq 'uploadquota') {
16360: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
16361: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
16362: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
16363: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 16364: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 16365: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 16366: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
16367: '</ul>'.
16368: '</li>';
16369: } else {
16370: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
16371: }
1.276 raeburn 16372: } elsif ($item eq 'mysqltables') {
16373: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
16374: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
16375: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
16376: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
16377: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
16378: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
16379: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
16380: '</ul>'.
16381: '</li>';
16382: } else {
16383: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
16384: }
1.257 raeburn 16385: } elsif ($item eq 'postsubmit') {
16386: if ($domdefaults{'postsubmit'} eq 'off') {
16387: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
16388: } else {
16389: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 16390: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 16391: $resulttext .= &mt('durations:').'<ul>';
16392: foreach my $type (@types) {
16393: $resulttext .= '<li>';
16394: my $timeout;
16395: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
16396: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
16397: }
16398: my $display;
16399: if ($timeout eq '0') {
16400: $display = &mt('unlimited');
16401: } elsif ($timeout eq '') {
16402: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
16403: } else {
16404: $display = &mt('[quant,_1,second]',$timeout);
16405: }
16406: if ($type eq 'community') {
16407: $resulttext .= &mt('Communities');
16408: } elsif ($type eq 'official') {
16409: $resulttext .= &mt('Official courses');
16410: } elsif ($type eq 'unofficial') {
16411: $resulttext .= &mt('Unofficial courses');
16412: } elsif ($type eq 'textbook') {
16413: $resulttext .= &mt('Textbook courses');
1.271 raeburn 16414: } elsif ($type eq 'placement') {
16415: $resulttext .= &mt('Placement tests');
1.257 raeburn 16416: }
16417: $resulttext .= ' -- '.$display.'</li>';
16418: }
16419: $resulttext .= '</ul>';
16420: }
1.289 raeburn 16421: $resulttext .= '</li>';
1.257 raeburn 16422: }
1.192 raeburn 16423: } elsif ($item eq 'coursecredits') {
16424: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
16425: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 16426: ($domdefaults{'unofficialcredits'} eq '') &&
16427: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 16428: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
16429: } else {
16430: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
16431: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
16432: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 16433: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 16434: '</ul>'.
16435: '</li>';
16436: }
16437: } else {
16438: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
16439: }
1.264 raeburn 16440: } elsif ($item eq 'canclone') {
16441: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
16442: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
16443: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
16444: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
16445: }
16446: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
16447: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
16448: } else {
1.289 raeburn 16449: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 16450: }
1.140 raeburn 16451: }
1.121 raeburn 16452: }
16453: $resulttext .= '</ul>';
16454: } else {
16455: $resulttext = &mt('No changes made to course defaults');
16456: }
16457: } else {
16458: $resulttext = '<span class="LC_error">'.
16459: &mt('An error occurred: [_1]',$putresult).'</span>';
16460: }
16461: return $resulttext;
16462: }
16463:
1.231 raeburn 16464: sub modify_selfenrollment {
16465: my ($dom,$lastactref,%domconfig) = @_;
16466: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 16467: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 16468: my %titles = &tool_titles();
1.232 raeburn 16469: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
16470: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 16471: $ordered{'default'} = ['types','registered','approval','limit'];
16472:
16473: my (%roles,%shown,%toplevel);
16474: $roles{'0'} = &Apache::lonnet::plaintext('dc');
16475:
16476: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
16477: if ($domconfig{'selfenrollment'} eq '') {
16478: $domconfig{'selfenrollment'} = {};
16479: }
16480: }
16481: %toplevel = (
16482: admin => 'Configuration Rights',
16483: default => 'Default settings',
16484: validation => 'Validation of self-enrollment requests',
16485: );
1.233 raeburn 16486: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 16487:
16488: if (ref($ordered{'admin'}) eq 'ARRAY') {
16489: foreach my $item (@{$ordered{'admin'}}) {
16490: foreach my $type (@types) {
16491: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
16492: $selfenrollhash{'admin'}{$type}{$item} = 1;
16493: } else {
16494: $selfenrollhash{'admin'}{$type}{$item} = 0;
16495: }
16496: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
16497: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
16498: if ($selfenrollhash{'admin'}{$type}{$item} ne
16499: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
16500: push(@{$changes{'admin'}{$type}},$item);
16501: }
16502: } else {
16503: if (!$selfenrollhash{'admin'}{$type}{$item}) {
16504: push(@{$changes{'admin'}{$type}},$item);
16505: }
16506: }
16507: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
16508: push(@{$changes{'admin'}{$type}},$item);
16509: }
16510: }
16511: }
16512: }
16513:
16514: foreach my $item (@{$ordered{'default'}}) {
16515: foreach my $type (@types) {
16516: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
16517: if ($item eq 'types') {
16518: unless (($value eq 'all') || ($value eq 'dom')) {
16519: $value = '';
16520: }
16521: } elsif ($item eq 'registered') {
16522: unless ($value eq '1') {
16523: $value = 0;
16524: }
16525: } elsif ($item eq 'approval') {
16526: unless ($value =~ /^[012]$/) {
16527: $value = 0;
16528: }
16529: } else {
16530: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
16531: $value = 'none';
16532: }
16533: }
16534: $selfenrollhash{'default'}{$type}{$item} = $value;
16535: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
16536: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
16537: if ($selfenrollhash{'default'}{$type}{$item} ne
16538: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
16539: push(@{$changes{'default'}{$type}},$item);
16540: }
16541: } else {
16542: push(@{$changes{'default'}{$type}},$item);
16543: }
16544: } else {
16545: push(@{$changes{'default'}{$type}},$item);
16546: }
16547: if ($item eq 'limit') {
16548: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
16549: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
16550: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
16551: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
16552: }
16553: } else {
16554: $selfenrollhash{'default'}{$type}{'cap'} = '';
16555: }
16556: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
16557: if ($selfenrollhash{'default'}{$type}{'cap'} ne
16558: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
16559: push(@{$changes{'default'}{$type}},'cap');
16560: }
16561: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
16562: push(@{$changes{'default'}{$type}},'cap');
16563: }
16564: }
16565: }
16566: }
16567:
16568: foreach my $item (@{$itemsref}) {
16569: if ($item eq 'fields') {
16570: my @changed;
16571: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
16572: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
16573: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
16574: }
16575: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16576: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
16577: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
16578: $domconfig{'selfenrollment'}{'validation'}{$item});
16579: } else {
16580: @changed = @{$selfenrollhash{'validation'}{$item}};
16581: }
16582: } else {
16583: @changed = @{$selfenrollhash{'validation'}{$item}};
16584: }
16585: if (@changed) {
16586: if ($selfenrollhash{'validation'}{$item}) {
16587: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
16588: } else {
16589: $changes{'validation'}{$item} = &mt('None');
16590: }
16591: }
16592: } else {
16593: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
16594: if ($item eq 'markup') {
16595: if ($env{'form.selfenroll_validation_'.$item}) {
16596: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
16597: }
16598: }
16599: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16600: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
16601: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
16602: }
16603: }
16604: }
16605: }
16606:
16607: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
16608: $dom);
16609: if ($putresult eq 'ok') {
16610: if (keys(%changes) > 0) {
16611: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16612: $resulttext = &mt('Changes made:').'<ul>';
16613: foreach my $key ('admin','default','validation') {
16614: if (ref($changes{$key}) eq 'HASH') {
16615: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
16616: if ($key eq 'validation') {
16617: foreach my $item (@{$itemsref}) {
16618: if (exists($changes{$key}{$item})) {
16619: if ($item eq 'markup') {
16620: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16621: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
16622: } else {
16623: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16624: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
16625: }
16626: }
16627: }
16628: } else {
16629: foreach my $type (@types) {
16630: if ($type eq 'community') {
16631: $roles{'1'} = &mt('Community personnel');
16632: } else {
16633: $roles{'1'} = &mt('Course personnel');
16634: }
16635: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 16636: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16637: if ($key eq 'admin') {
16638: my @mgrdc = ();
16639: if (ref($ordered{$key}) eq 'ARRAY') {
16640: foreach my $item (@{$ordered{'admin'}}) {
16641: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16642: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
16643: push(@mgrdc,$item);
16644: }
16645: }
16646: }
16647: if (@mgrdc) {
16648: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
16649: } else {
16650: delete($domdefaults{$type.'selfenrolladmdc'});
16651: }
16652: }
16653: } else {
16654: if (ref($ordered{$key}) eq 'ARRAY') {
16655: foreach my $item (@{$ordered{$key}}) {
16656: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16657: $domdefaults{$type.'selfenroll'.$item} =
16658: $selfenrollhash{$key}{$type}{$item};
16659: }
16660: }
16661: }
16662: }
16663: }
1.231 raeburn 16664: $resulttext .= '<li>'.$titles{$type}.'<ul>';
16665: foreach my $item (@{$ordered{$key}}) {
16666: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16667: $resulttext .= '<li>';
16668: if ($key eq 'admin') {
16669: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
16670: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
16671: } else {
16672: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
16673: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
16674: }
16675: $resulttext .= '</li>';
16676: }
16677: }
16678: $resulttext .= '</ul></li>';
16679: }
16680: }
16681: $resulttext .= '</ul></li>';
16682: }
16683: }
1.305 raeburn 16684: }
16685: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
16686: my $cachetime = 24*60*60;
16687: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16688: if (ref($lastactref) eq 'HASH') {
16689: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 16690: }
1.231 raeburn 16691: }
16692: $resulttext .= '</ul>';
16693: } else {
16694: $resulttext = &mt('No changes made to self-enrollment settings');
16695: }
16696: } else {
16697: $resulttext = '<span class="LC_error">'.
16698: &mt('An error occurred: [_1]',$putresult).'</span>';
16699: }
16700: return $resulttext;
16701: }
16702:
1.137 raeburn 16703: sub modify_usersessions {
1.212 raeburn 16704: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 16705: my @hostingtypes = ('version','excludedomain','includedomain');
16706: my @offloadtypes = ('primary','default');
16707: my %types = (
16708: remote => \@hostingtypes,
16709: hosted => \@hostingtypes,
16710: spares => \@offloadtypes,
16711: );
16712: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 16713: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 16714: my (%by_ip,%by_location,@intdoms,@instdoms);
16715: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 16716: my @locations = sort(keys(%by_location));
1.137 raeburn 16717: my (%defaultshash,%changes);
16718: foreach my $prefix (@prefixes) {
16719: $defaultshash{'usersessions'}{$prefix} = {};
16720: }
1.212 raeburn 16721: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 16722: my $resulttext;
1.138 raeburn 16723: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 16724: foreach my $prefix (@prefixes) {
1.145 raeburn 16725: next if ($prefix eq 'spares');
16726: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 16727: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16728: if ($type eq 'version') {
16729: my $value = $env{'form.'.$prefix.'_'.$type};
16730: my $okvalue;
16731: if ($value ne '') {
16732: if (grep(/^\Q$value\E$/,@lcversions)) {
16733: $okvalue = $value;
16734: }
16735: }
16736: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16737: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16738: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
16739: if ($inuse == 0) {
16740: $changes{$prefix}{$type} = 1;
16741: } else {
16742: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
16743: $changes{$prefix}{$type} = 1;
16744: }
16745: if ($okvalue ne '') {
16746: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16747: }
16748: }
16749: } else {
16750: if (($inuse == 1) && ($okvalue ne '')) {
16751: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16752: $changes{$prefix}{$type} = 1;
16753: }
16754: }
16755: } else {
16756: if (($inuse == 1) && ($okvalue ne '')) {
16757: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16758: $changes{$prefix}{$type} = 1;
16759: }
16760: }
16761: } else {
16762: if (($inuse == 1) && ($okvalue ne '')) {
16763: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16764: $changes{$prefix}{$type} = 1;
16765: }
16766: }
16767: } else {
16768: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16769: my @okvals;
16770: foreach my $val (@vals) {
1.138 raeburn 16771: if ($val =~ /:/) {
16772: my @items = split(/:/,$val);
16773: foreach my $item (@items) {
16774: if (ref($by_location{$item}) eq 'ARRAY') {
16775: push(@okvals,$item);
16776: }
16777: }
16778: } else {
16779: if (ref($by_location{$val}) eq 'ARRAY') {
16780: push(@okvals,$val);
16781: }
1.137 raeburn 16782: }
16783: }
16784: @okvals = sort(@okvals);
16785: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16786: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16787: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16788: if ($inuse == 0) {
16789: $changes{$prefix}{$type} = 1;
16790: } else {
16791: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16792: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
16793: if (@changed > 0) {
16794: $changes{$prefix}{$type} = 1;
16795: }
16796: }
16797: } else {
16798: if ($inuse == 1) {
16799: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16800: $changes{$prefix}{$type} = 1;
16801: }
16802: }
16803: } else {
16804: if ($inuse == 1) {
16805: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16806: $changes{$prefix}{$type} = 1;
16807: }
16808: }
16809: } else {
16810: if ($inuse == 1) {
16811: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16812: $changes{$prefix}{$type} = 1;
16813: }
16814: }
16815: }
16816: }
16817: }
1.145 raeburn 16818:
16819: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16820: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16821: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16822: my $savespares;
16823:
16824: foreach my $lonhost (sort(keys(%servers))) {
16825: my $serverhomeID =
16826: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16827: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16828: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16829: my %spareschg;
16830: foreach my $type (@{$types{'spares'}}) {
16831: my @okspares;
16832: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16833: foreach my $server (@checked) {
1.152 raeburn 16834: if (&Apache::lonnet::hostname($server) ne '') {
16835: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16836: unless (grep(/^\Q$server\E$/,@okspares)) {
16837: push(@okspares,$server);
16838: }
1.145 raeburn 16839: }
16840: }
16841: }
16842: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16843: my $newspare;
1.152 raeburn 16844: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16845: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16846: $newspare = $new;
16847: }
16848: }
1.152 raeburn 16849: my @spares;
16850: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16851: @spares = sort(@okspares,$newspare);
16852: } else {
16853: @spares = sort(@okspares);
16854: }
16855: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16856: if (ref($spareid{$lonhost}) eq 'HASH') {
16857: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16858: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16859: if (@diffs > 0) {
16860: $spareschg{$type} = 1;
16861: }
16862: }
16863: }
16864: }
16865: if (keys(%spareschg) > 0) {
16866: $changes{'spares'}{$lonhost} = \%spareschg;
16867: }
16868: }
1.261 raeburn 16869: $defaultshash{'usersessions'}{'offloadnow'} = {};
16870: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16871: my @okoffload;
16872: if (@offloadnow) {
16873: foreach my $server (@offloadnow) {
16874: if (&Apache::lonnet::hostname($server) ne '') {
16875: unless (grep(/^\Q$server\E$/,@okoffload)) {
16876: push(@okoffload,$server);
16877: }
16878: }
16879: }
16880: if (@okoffload) {
16881: foreach my $lonhost (@okoffload) {
16882: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16883: }
16884: }
16885: }
1.145 raeburn 16886: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16887: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16888: if (ref($changes{'spares'}) eq 'HASH') {
16889: if (keys(%{$changes{'spares'}}) > 0) {
16890: $savespares = 1;
16891: }
16892: }
16893: } else {
16894: $savespares = 1;
16895: }
1.261 raeburn 16896: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
16897: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
16898: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
16899: $changes{'offloadnow'} = 1;
16900: last;
16901: }
16902: }
16903: unless ($changes{'offloadnow'}) {
1.289 raeburn 16904: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 16905: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
16906: $changes{'offloadnow'} = 1;
16907: last;
16908: }
16909: }
16910: }
16911: } elsif (@okoffload) {
16912: $changes{'offloadnow'} = 1;
16913: }
16914: } elsif (@okoffload) {
16915: $changes{'offloadnow'} = 1;
1.145 raeburn 16916: }
1.147 raeburn 16917: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16918: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16919: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16920: $dom);
16921: if ($putresult eq 'ok') {
16922: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16923: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16924: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16925: }
16926: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16927: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16928: }
1.261 raeburn 16929: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16930: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16931: }
1.137 raeburn 16932: }
16933: my $cachetime = 24*60*60;
16934: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 16935: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 16936: if (ref($lastactref) eq 'HASH') {
16937: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 16938: $lastactref->{'usersessions'} = 1;
1.212 raeburn 16939: }
1.147 raeburn 16940: if (keys(%changes) > 0) {
16941: my %lt = &usersession_titles();
16942: $resulttext = &mt('Changes made:').'<ul>';
16943: foreach my $prefix (@prefixes) {
16944: if (ref($changes{$prefix}) eq 'HASH') {
16945: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16946: if ($prefix eq 'spares') {
16947: if (ref($changes{$prefix}) eq 'HASH') {
16948: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16949: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16950: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 16951: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16952: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16953: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16954: foreach my $type (@{$types{$prefix}}) {
16955: if ($changes{$prefix}{$lonhost}{$type}) {
16956: my $offloadto = &mt('None');
16957: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16958: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16959: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16960: }
1.145 raeburn 16961: }
1.147 raeburn 16962: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16963: }
1.137 raeburn 16964: }
16965: }
1.147 raeburn 16966: $resulttext .= '</li>';
1.137 raeburn 16967: }
16968: }
1.147 raeburn 16969: } else {
16970: foreach my $type (@{$types{$prefix}}) {
16971: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 16972: my ($newvalue,$notinuse);
1.147 raeburn 16973: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16974: if (ref($defaultshash{'usersessions'}{$prefix})) {
16975: if ($type eq 'version') {
16976: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 16977: } else {
16978: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16979: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16980: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16981: }
16982: } else {
16983: $notinuse = 1;
1.147 raeburn 16984: }
1.145 raeburn 16985: }
16986: }
16987: }
1.147 raeburn 16988: if ($newvalue eq '') {
16989: if ($type eq 'version') {
16990: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 16991: } elsif ($notinuse) {
16992: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 16993: } else {
16994: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16995: }
1.145 raeburn 16996: } else {
1.147 raeburn 16997: if ($type eq 'version') {
1.344 raeburn 16998: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 16999: }
17000: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 17001: }
1.137 raeburn 17002: }
17003: }
17004: }
1.147 raeburn 17005: $resulttext .= '</ul>';
1.137 raeburn 17006: }
17007: }
1.261 raeburn 17008: if ($changes{'offloadnow'}) {
17009: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
17010: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
17011: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
17012: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
17013: $resulttext .= '<li>'.$lonhost.'</li>';
17014: }
17015: $resulttext .= '</ul>';
17016: } else {
17017: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
17018: }
17019: } else {
17020: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
17021: }
17022: }
1.147 raeburn 17023: $resulttext .= '</ul>';
17024: } else {
17025: $resulttext = $nochgmsg;
1.137 raeburn 17026: }
17027: } else {
17028: $resulttext = '<span class="LC_error">'.
17029: &mt('An error occurred: [_1]',$putresult).'</span>';
17030: }
17031: } else {
1.147 raeburn 17032: $resulttext = $nochgmsg;
1.137 raeburn 17033: }
17034: return $resulttext;
17035: }
17036:
1.275 raeburn 17037: sub modify_ssl {
17038: my ($dom,$lastactref,%domconfig) = @_;
17039: my (%by_ip,%by_location,@intdoms,@instdoms);
17040: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17041: my @locations = sort(keys(%by_location));
17042: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17043: my (%defaultshash,%changes);
17044: my $action = 'ssl';
1.293 raeburn 17045: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 17046: foreach my $prefix (@prefixes) {
17047: $defaultshash{$action}{$prefix} = {};
17048: }
17049: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17050: my $resulttext;
17051: my %iphost = &Apache::lonnet::get_iphost();
17052: my @reptypes = ('certreq','nocertreq');
17053: my @connecttypes = ('dom','intdom','other');
17054: my %types = (
1.293 raeburn 17055: connto => \@connecttypes,
17056: connfrom => \@connecttypes,
17057: replication => \@reptypes,
1.275 raeburn 17058: );
17059: foreach my $prefix (sort(keys(%types))) {
17060: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 17061: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 17062: my $value = 'yes';
17063: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
17064: $value = $env{'form.'.$prefix.'_'.$type};
17065: }
1.335 raeburn 17066: if (ref($domconfig{$action}) eq 'HASH') {
17067: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
17068: if ($domconfig{$action}{$prefix}{$type} ne '') {
17069: if ($value ne $domconfig{$action}{$prefix}{$type}) {
17070: $changes{$prefix}{$type} = 1;
17071: }
17072: $defaultshash{$action}{$prefix}{$type} = $value;
17073: } else {
17074: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 17075: $changes{$prefix}{$type} = 1;
17076: }
17077: } else {
17078: $defaultshash{$action}{$prefix}{$type} = $value;
17079: $changes{$prefix}{$type} = 1;
17080: }
17081: } else {
17082: $defaultshash{$action}{$prefix}{$type} = $value;
17083: $changes{$prefix}{$type} = 1;
17084: }
17085: if (($type eq 'dom') && (keys(%servers) == 1)) {
17086: delete($changes{$prefix}{$type});
17087: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
17088: delete($changes{$prefix}{$type});
17089: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
17090: delete($changes{$prefix}{$type});
17091: }
17092: } elsif ($prefix eq 'replication') {
17093: if (@locations > 0) {
17094: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
17095: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
17096: my @okvals;
17097: foreach my $val (@vals) {
17098: if ($val =~ /:/) {
17099: my @items = split(/:/,$val);
17100: foreach my $item (@items) {
17101: if (ref($by_location{$item}) eq 'ARRAY') {
17102: push(@okvals,$item);
17103: }
17104: }
17105: } else {
17106: if (ref($by_location{$val}) eq 'ARRAY') {
17107: push(@okvals,$val);
17108: }
17109: }
17110: }
17111: @okvals = sort(@okvals);
17112: if (ref($domconfig{$action}) eq 'HASH') {
17113: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
17114: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
17115: if ($inuse == 0) {
17116: $changes{$prefix}{$type} = 1;
17117: } else {
17118: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17119: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
17120: if (@changed > 0) {
17121: $changes{$prefix}{$type} = 1;
17122: }
17123: }
17124: } else {
17125: if ($inuse == 1) {
17126: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17127: $changes{$prefix}{$type} = 1;
17128: }
17129: }
17130: } else {
17131: if ($inuse == 1) {
17132: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17133: $changes{$prefix}{$type} = 1;
17134: }
17135: }
17136: } else {
17137: if ($inuse == 1) {
17138: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17139: $changes{$prefix}{$type} = 1;
17140: }
17141: }
17142: }
17143: }
17144: }
17145: }
1.336 raeburn 17146: if (keys(%changes)) {
17147: foreach my $prefix (keys(%changes)) {
17148: if (ref($changes{$prefix}) eq 'HASH') {
17149: if (scalar(keys(%{$changes{$prefix}})) == 0) {
17150: delete($changes{$prefix});
17151: }
17152: } else {
17153: delete($changes{$prefix});
17154: }
17155: }
17156: }
1.275 raeburn 17157: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
17158: if (keys(%changes) > 0) {
17159: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17160: $dom);
17161: if ($putresult eq 'ok') {
17162: if (ref($defaultshash{$action}) eq 'HASH') {
17163: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
17164: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
17165: }
1.293 raeburn 17166: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 17167: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 17168: }
17169: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 17170: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 17171: }
17172: }
17173: my $cachetime = 24*60*60;
17174: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17175: if (ref($lastactref) eq 'HASH') {
17176: $lastactref->{'domdefaults'} = 1;
17177: }
17178: if (keys(%changes) > 0) {
17179: my %titles = &ssl_titles();
17180: $resulttext = &mt('Changes made:').'<ul>';
17181: foreach my $prefix (@prefixes) {
17182: if (ref($changes{$prefix}) eq 'HASH') {
17183: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
17184: foreach my $type (@{$types{$prefix}}) {
17185: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 17186: my ($newvalue,$notinuse);
1.275 raeburn 17187: if (ref($defaultshash{$action}) eq 'HASH') {
17188: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 17189: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 17190: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 17191: } else {
17192: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
17193: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
17194: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
17195: }
17196: } else {
17197: $notinuse = 1;
1.275 raeburn 17198: }
17199: }
17200: }
1.344 raeburn 17201: if ($notinuse) {
17202: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
17203: } elsif ($newvalue eq '') {
1.275 raeburn 17204: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
17205: } else {
17206: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
17207: }
17208: }
17209: }
17210: }
17211: $resulttext .= '</ul>';
17212: }
17213: }
17214: } else {
17215: $resulttext = $nochgmsg;
17216: }
17217: } else {
17218: $resulttext = '<span class="LC_error">'.
17219: &mt('An error occurred: [_1]',$putresult).'</span>';
17220: }
17221: } else {
17222: $resulttext = $nochgmsg;
17223: }
17224: return $resulttext;
17225: }
17226:
1.279 raeburn 17227: sub modify_trust {
17228: my ($dom,$lastactref,%domconfig) = @_;
17229: my (%by_ip,%by_location,@intdoms,@instdoms);
17230: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17231: my @locations = sort(keys(%by_location));
17232: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
17233: my @types = ('exc','inc');
17234: my (%defaultshash,%changes);
17235: foreach my $prefix (@prefixes) {
17236: $defaultshash{'trust'}{$prefix} = {};
17237: }
17238: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17239: my $resulttext;
17240: foreach my $prefix (@prefixes) {
17241: foreach my $type (@types) {
17242: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
17243: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
17244: my @okvals;
17245: foreach my $val (@vals) {
17246: if ($val =~ /:/) {
17247: my @items = split(/:/,$val);
17248: foreach my $item (@items) {
17249: if (ref($by_location{$item}) eq 'ARRAY') {
17250: push(@okvals,$item);
17251: }
17252: }
17253: } else {
17254: if (ref($by_location{$val}) eq 'ARRAY') {
17255: push(@okvals,$val);
17256: }
17257: }
17258: }
17259: @okvals = sort(@okvals);
17260: if (ref($domconfig{'trust'}) eq 'HASH') {
17261: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
17262: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
17263: if ($inuse == 0) {
17264: $changes{$prefix}{$type} = 1;
17265: } else {
17266: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
17267: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
17268: if (@changed > 0) {
17269: $changes{$prefix}{$type} = 1;
17270: }
17271: }
17272: } else {
17273: if ($inuse == 1) {
17274: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
17275: $changes{$prefix}{$type} = 1;
17276: }
17277: }
17278: } else {
17279: if ($inuse == 1) {
17280: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
17281: $changes{$prefix}{$type} = 1;
17282: }
17283: }
17284: } else {
17285: if ($inuse == 1) {
17286: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
17287: $changes{$prefix}{$type} = 1;
17288: }
17289: }
17290: }
17291: }
17292: my $nochgmsg = &mt('No changes made to trust settings.');
17293: if (keys(%changes) > 0) {
17294: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17295: $dom);
17296: if ($putresult eq 'ok') {
17297: if (ref($defaultshash{'trust'}) eq 'HASH') {
17298: foreach my $prefix (@prefixes) {
17299: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
17300: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
17301: }
17302: }
17303: }
17304: my $cachetime = 24*60*60;
17305: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17306: if (ref($lastactref) eq 'HASH') {
17307: $lastactref->{'domdefaults'} = 1;
17308: }
17309: if (keys(%changes) > 0) {
17310: my %lt = &trust_titles();
17311: $resulttext = &mt('Changes made:').'<ul>';
17312: foreach my $prefix (@prefixes) {
17313: if (ref($changes{$prefix}) eq 'HASH') {
17314: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
17315: foreach my $type (@types) {
17316: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 17317: my ($newvalue,$notinuse);
1.279 raeburn 17318: if (ref($defaultshash{'trust'}) eq 'HASH') {
17319: if (ref($defaultshash{'trust'}{$prefix})) {
17320: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
17321: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
17322: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
17323: }
1.344 raeburn 17324: } else {
17325: $notinuse = 1;
1.279 raeburn 17326: }
17327: }
17328: }
1.344 raeburn 17329: if ($notinuse) {
17330: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
17331: } elsif ($newvalue eq '') {
1.279 raeburn 17332: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
17333: } else {
17334: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
17335: }
17336: }
17337: }
17338: $resulttext .= '</ul>';
17339: }
17340: }
17341: $resulttext .= '</ul>';
17342: } else {
17343: $resulttext = $nochgmsg;
17344: }
17345: } else {
17346: $resulttext = '<span class="LC_error">'.
17347: &mt('An error occurred: [_1]',$putresult).'</span>';
17348: }
17349: } else {
17350: $resulttext = $nochgmsg;
17351: }
17352: return $resulttext;
17353: }
17354:
1.150 raeburn 17355: sub modify_loadbalancing {
17356: my ($dom,%domconfig) = @_;
17357: my $primary_id = &Apache::lonnet::domain($dom,'primary');
17358: my $intdom = &Apache::lonnet::internet_dom($primary_id);
17359: my ($othertitle,$usertypes,$types) =
17360: &Apache::loncommon::sorted_inst_types($dom);
17361: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 17362: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 17363: my @sparestypes = ('primary','default');
17364: my %typetitles = &sparestype_titles();
17365: my $resulttext;
1.342 raeburn 17366: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 17367: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
17368: %existing = %{$domconfig{'loadbalancing'}};
17369: }
17370: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 17371: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 17372: my ($saveloadbalancing,%defaultshash,%changes);
17373: my ($alltypes,$othertypes,$titles) =
17374: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
17375: my %ruletitles = &offloadtype_text();
17376: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
17377: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
17378: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
17379: if ($balancer eq '') {
17380: next;
17381: }
1.210 raeburn 17382: if (!exists($servers{$balancer})) {
1.171 raeburn 17383: if (exists($currbalancer{$balancer})) {
17384: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 17385: }
1.171 raeburn 17386: next;
17387: }
17388: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
17389: push(@{$changes{'delete'}},$balancer);
17390: next;
17391: }
17392: if (!exists($currbalancer{$balancer})) {
17393: push(@{$changes{'add'}},$balancer);
17394: }
17395: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
17396: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
17397: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
17398: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
17399: $saveloadbalancing = 1;
17400: }
17401: foreach my $sparetype (@sparestypes) {
17402: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
17403: my @offloadto;
17404: foreach my $target (@targets) {
17405: if (($servers{$target}) && ($target ne $balancer)) {
17406: if ($sparetype eq 'default') {
17407: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
17408: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 17409: }
17410: }
1.171 raeburn 17411: unless(grep(/^\Q$target\E$/,@offloadto)) {
17412: push(@offloadto,$target);
17413: }
1.150 raeburn 17414: }
17415: }
1.284 raeburn 17416: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
17417: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
17418: push(@offloadto,$balancer);
17419: }
17420: }
17421: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 17422: }
1.342 raeburn 17423: if ($env{'form.loadbalancing_cookie_'.$i}) {
17424: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
17425: if (exists($currbalancer{$balancer})) {
17426: unless ($currcookies{$balancer}) {
17427: $changes{'curr'}{$balancer}{'cookie'} = 1;
17428: }
17429: }
17430: } elsif (exists($currbalancer{$balancer})) {
17431: if ($currcookies{$balancer}) {
17432: $changes{'curr'}{$balancer}{'cookie'} = 1;
17433: }
17434: }
1.171 raeburn 17435: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 17436: foreach my $sparetype (@sparestypes) {
1.171 raeburn 17437: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
17438: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 17439: if (@targetdiffs > 0) {
1.171 raeburn 17440: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 17441: }
1.171 raeburn 17442: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17443: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17444: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 17445: }
17446: }
17447: }
17448: } else {
1.171 raeburn 17449: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 17450: foreach my $sparetype (@sparestypes) {
1.171 raeburn 17451: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17452: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17453: $changes{'curr'}{$balancer}{'targets'} = 1;
17454: }
1.150 raeburn 17455: }
17456: }
1.210 raeburn 17457: }
1.150 raeburn 17458: }
17459: my $ishomedom;
1.171 raeburn 17460: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
17461: $ishomedom = 1;
1.150 raeburn 17462: }
17463: if (ref($alltypes) eq 'ARRAY') {
17464: foreach my $type (@{$alltypes}) {
17465: my $rule;
1.210 raeburn 17466: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 17467: (!$ishomedom)) {
1.171 raeburn 17468: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
17469: }
17470: if ($rule eq 'specific') {
1.255 raeburn 17471: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 17472: if (exists($servers{$specifiedhost})) {
1.255 raeburn 17473: $rule = $specifiedhost;
17474: }
1.150 raeburn 17475: }
1.171 raeburn 17476: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
17477: if (ref($currrules{$balancer}) eq 'HASH') {
17478: if ($rule ne $currrules{$balancer}{$type}) {
17479: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 17480: }
17481: } elsif ($rule ne '') {
1.171 raeburn 17482: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 17483: }
17484: }
17485: }
1.171 raeburn 17486: }
17487: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
17488: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
17489: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
17490: $defaultshash{'loadbalancing'} = {};
17491: }
17492: my $putresult = &Apache::lonnet::put_dom('configuration',
17493: \%defaultshash,$dom);
17494: if ($putresult eq 'ok') {
17495: if (keys(%changes) > 0) {
1.252 raeburn 17496: my %toupdate;
1.171 raeburn 17497: if (ref($changes{'delete'}) eq 'ARRAY') {
17498: foreach my $balancer (sort(@{$changes{'delete'}})) {
17499: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 17500: $toupdate{$balancer} = 1;
1.150 raeburn 17501: }
1.171 raeburn 17502: }
17503: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 17504: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 17505: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 17506: $toupdate{$balancer} = 1;
1.171 raeburn 17507: }
17508: }
17509: if (ref($changes{'curr'}) eq 'HASH') {
17510: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 17511: $toupdate{$balancer} = 1;
1.171 raeburn 17512: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
17513: if ($changes{'curr'}{$balancer}{'targets'}) {
17514: my %offloadstr;
17515: foreach my $sparetype (@sparestypes) {
17516: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17517: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17518: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17519: }
17520: }
1.150 raeburn 17521: }
1.171 raeburn 17522: if (keys(%offloadstr) == 0) {
17523: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 17524: } else {
1.171 raeburn 17525: my $showoffload;
17526: foreach my $sparetype (@sparestypes) {
17527: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
17528: if (defined($offloadstr{$sparetype})) {
17529: $showoffload .= $offloadstr{$sparetype};
17530: } else {
17531: $showoffload .= &mt('None');
17532: }
17533: $showoffload .= (' 'x3);
17534: }
17535: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 17536: }
17537: }
17538: }
1.171 raeburn 17539: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
17540: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
17541: foreach my $type (@{$alltypes}) {
17542: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
17543: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17544: my $balancetext;
17545: if ($rule eq '') {
17546: $balancetext = $ruletitles{'default'};
1.209 raeburn 17547: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 17548: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 17549: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 17550: foreach my $sparetype (@sparestypes) {
17551: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17552: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17553: }
17554: }
1.253 raeburn 17555: foreach my $item (@{$alltypes}) {
17556: next if ($item =~ /^_LC_ipchange/);
17557: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
17558: if ($hasrule eq 'homeserver') {
17559: map { $toupdate{$_} = 1; } (keys(%libraryservers));
17560: } else {
17561: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
17562: if ($servers{$hasrule}) {
17563: $toupdate{$hasrule} = 1;
17564: }
17565: }
17566: }
17567: }
1.254 raeburn 17568: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
17569: $balancetext = $ruletitles{$rule};
17570: } else {
17571: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17572: $balancetext = $ruletitles{'particular'}.' '.$receiver;
17573: if ($receiver) {
17574: $toupdate{$receiver};
17575: }
17576: }
17577: } else {
17578: $balancetext = $ruletitles{$rule};
1.252 raeburn 17579: }
1.171 raeburn 17580: } else {
17581: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
17582: }
1.210 raeburn 17583: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 17584: }
17585: }
17586: }
17587: }
1.342 raeburn 17588: if ($changes{'curr'}{$balancer}{'cookie'}) {
17589: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
17590: $balancer).'</li>';
17591: }
1.252 raeburn 17592: if (keys(%toupdate)) {
17593: my %thismachine;
17594: my $updatedhere;
17595: my $cachetime = 60*60*24;
17596: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
17597: foreach my $lonhost (keys(%toupdate)) {
17598: if ($thismachine{$lonhost}) {
17599: unless ($updatedhere) {
17600: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
17601: $defaultshash{'loadbalancing'},
17602: $cachetime);
17603: $updatedhere = 1;
17604: }
17605: } else {
17606: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
17607: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
17608: }
17609: }
17610: }
1.150 raeburn 17611: }
1.171 raeburn 17612: }
17613: if ($resulttext ne '') {
17614: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 17615: } else {
17616: $resulttext = $nochgmsg;
17617: }
17618: } else {
1.171 raeburn 17619: $resulttext = $nochgmsg;
1.150 raeburn 17620: }
17621: } else {
1.171 raeburn 17622: $resulttext = '<span class="LC_error">'.
17623: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 17624: }
17625: } else {
1.171 raeburn 17626: $resulttext = $nochgmsg;
1.150 raeburn 17627: }
17628: return $resulttext;
17629: }
17630:
1.48 raeburn 17631: sub recurse_check {
17632: my ($chkcats,$categories,$depth,$name) = @_;
17633: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
17634: my $chg = 0;
17635: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
17636: my $category = $chkcats->[$depth]{$name}[$j];
17637: my $item;
17638: if ($category eq '') {
17639: $chg ++;
17640: } else {
17641: my $deeper = $depth + 1;
17642: $item = &escape($category).':'.&escape($name).':'.$depth;
17643: if ($chg) {
17644: $categories->{$item} -= $chg;
17645: }
17646: &recurse_check($chkcats,$categories,$deeper,$category);
17647: $deeper --;
17648: }
17649: }
17650: }
17651: return;
17652: }
17653:
17654: sub recurse_cat_deletes {
17655: my ($item,$coursecategories,$deletions) = @_;
17656: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
17657: my $subdepth = $depth + 1;
17658: if (ref($coursecategories) eq 'HASH') {
17659: foreach my $subitem (keys(%{$coursecategories})) {
17660: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
17661: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
17662: delete($coursecategories->{$subitem});
17663: $deletions->{$subitem} = 1;
17664: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 17665: }
1.48 raeburn 17666: }
17667: }
17668: return;
17669: }
17670:
1.125 raeburn 17671: sub active_dc_picker {
1.191 raeburn 17672: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 17673: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 17674: my @domcoord = keys(%domcoords);
17675: if (keys(%currhash)) {
17676: foreach my $dc (keys(%currhash)) {
17677: unless (exists($domcoords{$dc})) {
17678: push(@domcoord,$dc);
17679: }
17680: }
17681: }
17682: @domcoord = sort(@domcoord);
1.210 raeburn 17683: my $numdcs = scalar(@domcoord);
1.191 raeburn 17684: my $rows = 0;
17685: my $table;
1.125 raeburn 17686: if ($numdcs > 1) {
1.191 raeburn 17687: $table = '<table>';
17688: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 17689: my $rem = $i%($numinrow);
17690: if ($rem == 0) {
17691: if ($i > 0) {
1.191 raeburn 17692: $table .= '</tr>';
1.125 raeburn 17693: }
1.191 raeburn 17694: $table .= '<tr>';
17695: $rows ++;
1.125 raeburn 17696: }
1.191 raeburn 17697: my $check = '';
17698: if ($inputtype eq 'radio') {
17699: if (keys(%currhash) == 0) {
17700: if (!$i) {
17701: $check = ' checked="checked"';
17702: }
17703: } elsif (exists($currhash{$domcoord[$i]})) {
17704: $check = ' checked="checked"';
17705: }
17706: } else {
17707: if (exists($currhash{$domcoord[$i]})) {
17708: $check = ' checked="checked"';
1.125 raeburn 17709: }
17710: }
1.191 raeburn 17711: if ($i == @domcoord - 1) {
1.125 raeburn 17712: my $colsleft = $numinrow - $rem;
17713: if ($colsleft > 1) {
1.191 raeburn 17714: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 17715: } else {
1.191 raeburn 17716: $table .= '<td class="LC_left_item">';
1.125 raeburn 17717: }
17718: } else {
1.191 raeburn 17719: $table .= '<td class="LC_left_item">';
17720: }
17721: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
17722: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
17723: $table .= '<span class="LC_nobreak"><label>'.
17724: '<input type="'.$inputtype.'" name="'.$name.'"'.
17725: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
17726: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 17727: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 17728: }
1.219 raeburn 17729: $table .= '</label></span></td>';
1.191 raeburn 17730: }
17731: $table .= '</tr></table>';
17732: } elsif ($numdcs == 1) {
1.219 raeburn 17733: my ($dcname,$dcdom) = split(':',$domcoord[0]);
17734: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 17735: if ($inputtype eq 'radio') {
1.247 raeburn 17736: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 17737: if ($user ne $dcname.':'.$dcdom) {
17738: $table .= ' ('.$dcname.':'.$dcdom.')';
17739: }
1.191 raeburn 17740: } else {
17741: my $check;
17742: if (exists($currhash{$domcoord[0]})) {
17743: $check = ' checked="checked"';
1.125 raeburn 17744: }
1.247 raeburn 17745: $table = '<span class="LC_nobreak"><label>'.
17746: '<input type="checkbox" name="'.$name.'" '.
17747: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 17748: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 17749: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 17750: }
1.220 raeburn 17751: $table .= '</label></span>';
1.191 raeburn 17752: $rows ++;
1.125 raeburn 17753: }
17754: }
1.191 raeburn 17755: return ($numdcs,$table,$rows);
1.125 raeburn 17756: }
17757:
1.137 raeburn 17758: sub usersession_titles {
17759: return &Apache::lonlocal::texthash(
17760: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
17761: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 17762: spares => 'Servers offloaded to, when busy',
1.137 raeburn 17763: version => 'LON-CAPA version requirement',
1.138 raeburn 17764: excludedomain => 'Allow all, but exclude specific domains',
17765: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 17766: primary => 'Primary (checked first)',
1.154 raeburn 17767: default => 'Default',
1.137 raeburn 17768: );
17769: }
17770:
1.152 raeburn 17771: sub id_for_thisdom {
17772: my (%servers) = @_;
17773: my %altids;
17774: foreach my $server (keys(%servers)) {
17775: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17776: if ($serverhome ne $server) {
17777: $altids{$serverhome} = $server;
17778: }
17779: }
17780: return %altids;
17781: }
17782:
1.150 raeburn 17783: sub count_servers {
17784: my ($currbalancer,%servers) = @_;
17785: my (@spares,$numspares);
17786: foreach my $lonhost (sort(keys(%servers))) {
17787: next if ($currbalancer eq $lonhost);
17788: push(@spares,$lonhost);
17789: }
17790: if ($currbalancer) {
17791: $numspares = scalar(@spares);
17792: } else {
17793: $numspares = scalar(@spares) - 1;
17794: }
17795: return ($numspares,@spares);
17796: }
17797:
17798: sub lonbalance_targets_js {
1.171 raeburn 17799: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 17800: my $select = &mt('Select');
17801: my ($alltargets,$allishome,$allinsttypes,@alltypes);
17802: if (ref($servers) eq 'HASH') {
17803: $alltargets = join("','",sort(keys(%{$servers})));
17804: my @homedoms;
17805: foreach my $server (sort(keys(%{$servers}))) {
17806: if (&Apache::lonnet::host_domain($server) eq $dom) {
17807: push(@homedoms,'1');
17808: } else {
17809: push(@homedoms,'0');
17810: }
17811: }
17812: $allishome = join("','",@homedoms);
17813: }
17814: if (ref($types) eq 'ARRAY') {
17815: if (@{$types} > 0) {
17816: @alltypes = @{$types};
17817: }
17818: }
17819: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
17820: $allinsttypes = join("','",@alltypes);
1.342 raeburn 17821: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 17822: if (ref($settings) eq 'HASH') {
17823: %existing = %{$settings};
17824: }
17825: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 17826: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 17827: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 17828: return <<"END";
17829:
17830: <script type="text/javascript">
17831: // <![CDATA[
17832:
1.171 raeburn 17833: currBalancers = new Array('$balancers');
17834:
17835: function toggleTargets(balnum) {
17836: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17837: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
17838: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
17839: var prevbalancer = prevhostitem.value;
17840: var baltotal = document.getElementById('loadbalancing_total').value;
17841: prevhostitem.value = balancer;
17842: if (prevbalancer != '') {
17843: var prevIdx = currBalancers.indexOf(prevbalancer);
17844: if (prevIdx != -1) {
17845: currBalancers.splice(prevIdx,1);
17846: }
17847: }
1.150 raeburn 17848: if (balancer == '') {
1.171 raeburn 17849: hideSpares(balnum);
1.150 raeburn 17850: } else {
1.171 raeburn 17851: var currIdx = currBalancers.indexOf(balancer);
17852: if (currIdx == -1) {
17853: currBalancers.push(balancer);
17854: }
1.150 raeburn 17855: var homedoms = new Array('$allishome');
1.171 raeburn 17856: var ishomedom = homedoms[lonhostitem.selectedIndex];
17857: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 17858: }
1.171 raeburn 17859: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 17860: return;
17861: }
17862:
1.171 raeburn 17863: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 17864: var alltargets = new Array('$alltargets');
17865: var insttypes = new Array('$allinsttypes');
1.151 raeburn 17866: var offloadtypes = new Array('primary','default');
17867:
1.171 raeburn 17868: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17869: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 17870:
1.151 raeburn 17871: for (var i=0; i<offloadtypes.length; i++) {
17872: var count = 0;
17873: for (var j=0; j<alltargets.length; j++) {
17874: if (alltargets[j] != balancer) {
1.171 raeburn 17875: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17876: item.value = alltargets[j];
17877: item.style.textAlign='left';
17878: item.style.textFace='normal';
17879: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17880: if (currBalancers.indexOf(alltargets[j]) == -1) {
17881: item.disabled = '';
17882: } else {
17883: item.disabled = 'disabled';
17884: item.checked = false;
17885: }
1.151 raeburn 17886: count ++;
17887: }
1.150 raeburn 17888: }
17889: }
1.151 raeburn 17890: for (var k=0; k<insttypes.length; k++) {
17891: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 17892: if (ishomedom == 1) {
1.171 raeburn 17893: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17894: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17895: } else {
1.171 raeburn 17896: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17897: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 17898: }
17899: } else {
1.171 raeburn 17900: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17901: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17902: }
1.151 raeburn 17903: if ((insttypes[k] != '_LC_external') &&
17904: ((insttypes[k] != '_LC_internetdom') ||
17905: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 17906: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17907: item.options.length = 0;
17908: item.options[0] = new Option("","",true,true);
1.210 raeburn 17909: var idx = 0;
1.151 raeburn 17910: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 17911: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17912: idx ++;
17913: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 17914: }
17915: }
17916: }
17917: }
17918: return;
17919: }
17920:
1.171 raeburn 17921: function hideSpares(balnum) {
1.150 raeburn 17922: var alltargets = new Array('$alltargets');
17923: var insttypes = new Array('$allinsttypes');
17924: var offloadtypes = new Array('primary','default');
17925:
1.171 raeburn 17926: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17927: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 17928:
17929: var total = alltargets.length - 1;
17930: for (var i=0; i<offloadtypes; i++) {
17931: for (var j=0; j<total; j++) {
1.171 raeburn 17932: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17933: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17934: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 17935: }
1.150 raeburn 17936: }
17937: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 17938: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17939: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 17940: if (insttypes[k] != '_LC_external') {
1.171 raeburn 17941: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17942: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 17943: }
17944: }
17945: return;
17946: }
17947:
1.171 raeburn 17948: function checkOffloads(item,balnum,type) {
1.150 raeburn 17949: var alltargets = new Array('$alltargets');
17950: var offloadtypes = new Array('primary','default');
17951: if (item.checked) {
17952: var total = alltargets.length - 1;
17953: var other;
17954: if (type == offloadtypes[0]) {
1.151 raeburn 17955: other = offloadtypes[1];
1.150 raeburn 17956: } else {
1.151 raeburn 17957: other = offloadtypes[0];
1.150 raeburn 17958: }
17959: for (var i=0; i<total; i++) {
1.171 raeburn 17960: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 17961: if (server == item.value) {
1.171 raeburn 17962: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17963: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 17964: }
17965: }
17966: }
17967: }
17968: return;
17969: }
17970:
1.171 raeburn 17971: function singleServerToggle(balnum,type) {
17972: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 17973: if (offloadtoSelIdx == 0) {
1.171 raeburn 17974: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17975: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17976:
17977: } else {
1.171 raeburn 17978: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17979: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 17980: }
17981: return;
17982: }
17983:
1.171 raeburn 17984: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 17985: if (type == '_LC_external') {
1.171 raeburn 17986: return;
1.150 raeburn 17987: }
1.171 raeburn 17988: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 17989: for (var i=0; i<typesRules.length; i++) {
17990: if (formname.elements[typesRules[i]].checked) {
17991: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 17992: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17993: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17994: } else {
1.171 raeburn 17995: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17996: }
17997: }
17998: }
17999: return;
18000: }
18001:
18002: function balancerDeleteChange(balnum) {
18003: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
18004: var baltotal = document.getElementById('loadbalancing_total').value;
18005: var addtarget;
18006: var removetarget;
18007: var action = 'delete';
18008: if (document.getElementById('loadbalancing_delete_'+balnum)) {
18009: var lonhost = hostitem.value;
18010: var currIdx = currBalancers.indexOf(lonhost);
18011: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
18012: if (currIdx != -1) {
18013: currBalancers.splice(currIdx,1);
18014: }
18015: addtarget = lonhost;
18016: } else {
18017: if (currIdx == -1) {
18018: currBalancers.push(lonhost);
18019: }
18020: removetarget = lonhost;
18021: action = 'undelete';
18022: }
18023: balancerChange(balnum,baltotal,action,addtarget,removetarget);
18024: }
18025: return;
18026: }
18027:
18028: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
18029: if (baltotal > 1) {
18030: var offloadtypes = new Array('primary','default');
18031: var alltargets = new Array('$alltargets');
18032: var insttypes = new Array('$allinsttypes');
18033: for (var i=0; i<baltotal; i++) {
18034: if (i != balnum) {
18035: for (var j=0; j<offloadtypes.length; j++) {
18036: var total = alltargets.length - 1;
18037: for (var k=0; k<total; k++) {
18038: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
18039: var server = serveritem.value;
18040: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
18041: if (server == addtarget) {
18042: serveritem.disabled = '';
18043: }
18044: }
18045: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
18046: if (server == removetarget) {
18047: serveritem.disabled = 'disabled';
18048: serveritem.checked = false;
18049: }
18050: }
18051: }
18052: }
18053: for (var j=0; j<insttypes.length; j++) {
18054: if (insttypes[j] != '_LC_external') {
18055: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
18056: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
18057: var currSel = singleserver.selectedIndex;
18058: var currVal = singleserver.options[currSel].value;
18059: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
18060: var numoptions = singleserver.options.length;
18061: var needsnew = 1;
18062: for (var k=0; k<numoptions; k++) {
18063: if (singleserver.options[k] == addtarget) {
18064: needsnew = 0;
18065: break;
18066: }
18067: }
18068: if (needsnew == 1) {
18069: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
18070: }
18071: }
18072: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
18073: singleserver.options.length = 0;
18074: if ((currVal) && (currVal != removetarget)) {
18075: singleserver.options[0] = new Option("","",false,false);
18076: } else {
18077: singleserver.options[0] = new Option("","",true,true);
18078: }
18079: var idx = 0;
18080: for (var m=0; m<alltargets.length; m++) {
18081: if (currBalancers.indexOf(alltargets[m]) == -1) {
18082: idx ++;
18083: if (currVal == alltargets[m]) {
18084: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
18085: } else {
18086: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
18087: }
18088: }
18089: }
18090: }
18091: }
18092: }
18093: }
1.150 raeburn 18094: }
18095: }
18096: }
18097: return;
18098: }
18099:
1.152 raeburn 18100: // ]]>
18101: </script>
18102:
18103: END
18104: }
18105:
18106: sub new_spares_js {
18107: my @sparestypes = ('primary','default');
18108: my $types = join("','",@sparestypes);
18109: my $select = &mt('Select');
18110: return <<"END";
18111:
18112: <script type="text/javascript">
18113: // <![CDATA[
18114:
18115: function updateNewSpares(formname,lonhost) {
18116: var types = new Array('$types');
18117: var include = new Array();
18118: var exclude = new Array();
18119: for (var i=0; i<types.length; i++) {
18120: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
18121: for (var j=0; j<spareboxes.length; j++) {
18122: if (formname.elements[spareboxes[j]].checked) {
18123: exclude.push(formname.elements[spareboxes[j]].value);
18124: } else {
18125: include.push(formname.elements[spareboxes[j]].value);
18126: }
18127: }
18128: }
18129: for (var i=0; i<types.length; i++) {
18130: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
18131: var selIdx = newSpare.selectedIndex;
18132: var currnew = newSpare.options[selIdx].value;
18133: var okSpares = new Array();
18134: for (var j=0; j<newSpare.options.length; j++) {
18135: var possible = newSpare.options[j].value;
18136: if (possible != '') {
18137: if (exclude.indexOf(possible) == -1) {
18138: okSpares.push(possible);
18139: } else {
18140: if (currnew == possible) {
18141: selIdx = 0;
18142: }
18143: }
18144: }
18145: }
18146: for (var k=0; k<include.length; k++) {
18147: if (okSpares.indexOf(include[k]) == -1) {
18148: okSpares.push(include[k]);
18149: }
18150: }
18151: okSpares.sort();
18152: newSpare.options.length = 0;
18153: if (selIdx == 0) {
18154: newSpare.options[0] = new Option("$select","",true,true);
18155: } else {
18156: newSpare.options[0] = new Option("$select","",false,false);
18157: }
18158: for (var m=0; m<okSpares.length; m++) {
18159: var idx = m+1;
18160: var selThis = 0;
18161: if (selIdx != 0) {
18162: if (okSpares[m] == currnew) {
18163: selThis = 1;
18164: }
18165: }
18166: if (selThis == 1) {
18167: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
18168: } else {
18169: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
18170: }
18171: }
18172: }
18173: return;
18174: }
18175:
18176: function checkNewSpares(lonhost,type) {
18177: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
18178: var chosen = newSpare.options[newSpare.selectedIndex].value;
18179: if (chosen != '') {
18180: var othertype;
18181: var othernewSpare;
18182: if (type == 'primary') {
18183: othernewSpare = document.getElementById('newspare_default_'+lonhost);
18184: }
18185: if (type == 'default') {
18186: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
18187: }
18188: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
18189: othernewSpare.selectedIndex = 0;
18190: }
18191: }
18192: return;
18193: }
18194:
18195: // ]]>
18196: </script>
18197:
18198: END
18199:
18200: }
18201:
18202: sub common_domprefs_js {
18203: return <<"END";
18204:
18205: <script type="text/javascript">
18206: // <![CDATA[
18207:
1.150 raeburn 18208: function getIndicesByName(formname,item) {
1.152 raeburn 18209: var group = new Array();
1.150 raeburn 18210: for (var i=0;i<formname.elements.length;i++) {
18211: if (formname.elements[i].name == item) {
1.152 raeburn 18212: group.push(formname.elements[i].id);
1.150 raeburn 18213: }
18214: }
1.152 raeburn 18215: return group;
1.150 raeburn 18216: }
18217:
18218: // ]]>
18219: </script>
18220:
18221: END
1.152 raeburn 18222:
1.150 raeburn 18223: }
18224:
1.165 raeburn 18225: sub recaptcha_js {
18226: my %lt = &captcha_phrases();
18227: return <<"END";
18228:
18229: <script type="text/javascript">
18230: // <![CDATA[
18231:
18232: function updateCaptcha(caller,context) {
18233: var privitem;
18234: var pubitem;
18235: var privtext;
18236: var pubtext;
1.269 raeburn 18237: var versionitem;
18238: var versiontext;
1.165 raeburn 18239: if (document.getElementById(context+'_recaptchapub')) {
18240: pubitem = document.getElementById(context+'_recaptchapub');
18241: } else {
18242: return;
18243: }
18244: if (document.getElementById(context+'_recaptchapriv')) {
18245: privitem = document.getElementById(context+'_recaptchapriv');
18246: } else {
18247: return;
18248: }
18249: if (document.getElementById(context+'_recaptchapubtxt')) {
18250: pubtext = document.getElementById(context+'_recaptchapubtxt');
18251: } else {
18252: return;
18253: }
18254: if (document.getElementById(context+'_recaptchaprivtxt')) {
18255: privtext = document.getElementById(context+'_recaptchaprivtxt');
18256: } else {
18257: return;
18258: }
1.269 raeburn 18259: if (document.getElementById(context+'_recaptchaversion')) {
18260: versionitem = document.getElementById(context+'_recaptchaversion');
18261: } else {
18262: return;
18263: }
18264: if (document.getElementById(context+'_recaptchavertxt')) {
18265: versiontext = document.getElementById(context+'_recaptchavertxt');
18266: } else {
18267: return;
18268: }
1.165 raeburn 18269: if (caller.checked) {
18270: if (caller.value == 'recaptcha') {
18271: pubitem.type = 'text';
18272: privitem.type = 'text';
18273: pubitem.size = '40';
18274: privitem.size = '40';
18275: pubtext.innerHTML = "$lt{'pub'}";
18276: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 18277: versionitem.type = 'text';
18278: versionitem.size = '3';
1.289 raeburn 18279: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 18280: } else {
18281: pubitem.type = 'hidden';
18282: privitem.type = 'hidden';
1.269 raeburn 18283: versionitem.type = 'hidden';
1.165 raeburn 18284: pubtext.innerHTML = '';
18285: privtext.innerHTML = '';
1.269 raeburn 18286: versiontext.innerHTML = '';
1.165 raeburn 18287: }
18288: }
18289: return;
18290: }
18291:
18292: // ]]>
18293: </script>
18294:
18295: END
18296:
18297: }
18298:
1.236 raeburn 18299: sub toggle_display_js {
1.192 raeburn 18300: return <<"END";
18301:
18302: <script type="text/javascript">
18303: // <![CDATA[
18304:
1.236 raeburn 18305: function toggleDisplay(domForm,caller) {
18306: if (document.getElementById(caller)) {
18307: var divitem = document.getElementById(caller);
18308: var optionsElement = domForm.coursecredits;
1.264 raeburn 18309: var checkval = 1;
18310: var dispval = 'block';
1.303 raeburn 18311: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 18312: if (caller == 'emailoptions') {
18313: optionsElement = domForm.cancreate_email;
18314: }
1.257 raeburn 18315: if (caller == 'studentsubmission') {
18316: optionsElement = domForm.postsubmit;
18317: }
1.264 raeburn 18318: if (caller == 'cloneinstcode') {
18319: optionsElement = domForm.canclone;
18320: checkval = 'instcode';
18321: }
1.303 raeburn 18322: if (selfcreateRegExp.test(caller)) {
18323: optionsElement = domForm.elements[caller];
18324: checkval = 'other';
18325: dispval = 'inline'
18326: }
1.236 raeburn 18327: if (optionsElement.length) {
1.192 raeburn 18328: var currval;
1.236 raeburn 18329: for (var i=0; i<optionsElement.length; i++) {
18330: if (optionsElement[i].checked) {
18331: currval = optionsElement[i].value;
1.192 raeburn 18332: }
18333: }
1.264 raeburn 18334: if (currval == checkval) {
18335: divitem.style.display = dispval;
1.192 raeburn 18336: } else {
1.236 raeburn 18337: divitem.style.display = 'none';
1.192 raeburn 18338: }
18339: }
18340: }
18341: return;
18342: }
18343:
18344: // ]]>
18345: </script>
18346:
18347: END
18348:
18349: }
18350:
1.165 raeburn 18351: sub captcha_phrases {
18352: return &Apache::lonlocal::texthash (
18353: priv => 'Private key',
18354: pub => 'Public key',
18355: original => 'original (CAPTCHA)',
18356: recaptcha => 'successor (ReCAPTCHA)',
18357: notused => 'unused',
1.289 raeburn 18358: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 18359: );
18360: }
18361:
1.205 raeburn 18362: sub devalidate_remote_domconfs {
1.212 raeburn 18363: my ($dom,$cachekeys) = @_;
18364: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 18365: my %servers = &Apache::lonnet::internet_dom_servers($dom);
18366: my %thismachine;
18367: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 18368: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 18369: if (keys(%servers)) {
1.205 raeburn 18370: foreach my $server (keys(%servers)) {
18371: next if ($thismachine{$server});
1.212 raeburn 18372: my @cached;
18373: foreach my $name (@posscached) {
18374: if ($cachekeys->{$name}) {
18375: push(@cached,&escape($name).':'.&escape($dom));
18376: }
18377: }
18378: if (@cached) {
18379: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
18380: }
1.205 raeburn 18381: }
18382: }
18383: return;
18384: }
18385:
1.3 raeburn 18386: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>