Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.102.2.1
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.102.2 1(raebur 4:0): # $Id: domainprefs.pm,v 1.160.6.102 2019/10/15 03:50:23 raeburn Exp $
1.160.6.40 raeburn 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.160.6.78 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: ###############################################################
30: ##############################################################
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.160.6.13 raeburn 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.160.6.27 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 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.160.6.20 raeburn 98: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 99: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 100:
1.101 raeburn 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.160.6.30 raeburn 107: (official, unofficial, community, and textbook). In each case the radio buttons
108: 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.160.6.37 raeburn 168: use Apache::lonuserutils();
1.160.6.39 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.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.1 raeburn 177:
1.155 raeburn 178: my $registered_cleanup;
179: my $modified_urls;
180:
1.1 raeburn 181: sub handler {
182: my $r=shift;
183: if ($r->header_only) {
184: &Apache::loncommon::content_type($r,'text/html');
185: $r->send_http_header;
186: return OK;
187: }
188:
1.91 raeburn 189: my $context = 'domain';
1.1 raeburn 190: my $dom = $env{'request.role.domain'};
1.5 albertel 191: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 192: if (&Apache::lonnet::allowed('mau',$dom)) {
193: &Apache::loncommon::content_type($r,'text/html');
194: $r->send_http_header;
195: } else {
196: $env{'user.error.msg'}=
197: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
198: return HTTP_NOT_ACCEPTABLE;
199: }
1.155 raeburn 200:
201: $registered_cleanup=0;
202: @{$modified_urls}=();
203:
1.1 raeburn 204: &Apache::lonhtmlcommon::clear_breadcrumbs();
205: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 206: ['phase','actions']);
1.30 raeburn 207: my $phase = 'pickactions';
1.3 raeburn 208: if ( exists($env{'form.phase'}) ) {
209: $phase = $env{'form.phase'};
210: }
1.150 raeburn 211: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 212: my %domconfig =
1.6 raeburn 213: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 214: 'quotas','autoenroll','autoupdate','autocreate',
215: 'directorysrch','usercreation','usermodification',
216: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 217: 'serverstatuses','requestcourses','helpsettings',
218: 'coursedefaults','usersessions','loadbalancing',
1.160.6.102.2 1(raebur 219:0): 'requestauthor','selfenrollment','inststatus',
220:0): 'passwords','ltitools'],$dom);
221:0): if (ref($domconfig{'ltitools'}) eq 'HASH') {
222:0): my %encconfig =
223:0): &Apache::lonnet::get_dom('encconfig',['ltitools'],$dom);
224:0): if (ref($encconfig{'ltitools'}) eq 'HASH') {
225:0): foreach my $id (keys(%{$domconfig{'ltitools'}})) {
226:0): if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
227:0): foreach my $item ('key','secret') {
228:0): $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
229:0): }
230:0): }
231:0): }
232:0): }
233:0): }
1.160.6.98 raeburn 234: my @prefs_order = ('rolecolors','login','defaults','passwords','quotas','autoenroll',
1.125 raeburn 235: 'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34 raeburn 236: 'usercreation','selfcreation','usermodification','scantron',
1.160.6.5 raeburn 237: 'requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 238: 'serverstatuses','helpsettings','coursedefaults',
1.160.6.102.2 1(raebur 239:0): 'ltitools','selfenrollment','usersessions');
1.160.6.7 raeburn 240: my %existing;
241: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
242: %existing = %{$domconfig{'loadbalancing'}};
243: }
244: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 245: push(@prefs_order,'loadbalancing');
246: }
1.30 raeburn 247: my %prefs = (
248: 'rolecolors' =>
249: { text => 'Default color schemes',
1.67 raeburn 250: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 251: header => [{col1 => 'Student Settings',
252: col2 => '',},
253: {col1 => 'Coordinator Settings',
254: col2 => '',},
255: {col1 => 'Author Settings',
256: col2 => '',},
257: {col1 => 'Administrator Settings',
258: col2 => '',}],
1.160.6.37 raeburn 259: print => \&print_rolecolors,
260: modify => \&modify_rolecolors,
1.30 raeburn 261: },
1.110 raeburn 262: 'login' =>
1.30 raeburn 263: { text => 'Log-in page options',
1.67 raeburn 264: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 265: header => [{col1 => 'Log-in Page Items',
266: col2 => '',},
267: {col1 => 'Log-in Help',
1.160.6.56 raeburn 268: col2 => 'Value'},
269: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 270: col2 => 'Value'}],
1.160.6.37 raeburn 271: print => \&print_login,
272: modify => \&modify_login,
1.30 raeburn 273: },
1.43 raeburn 274: 'defaults' =>
1.160.6.40 raeburn 275: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 276: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 277: header => [{col1 => 'Setting',
1.160.6.40 raeburn 278: col2 => 'Value'},
279: {col1 => 'Institutional user types',
1.160.6.93 raeburn 280: col2 => 'Name displayed'}],
1.160.6.37 raeburn 281: print => \&print_defaults,
282: modify => \&modify_defaults,
1.43 raeburn 283: },
1.160.6.98 raeburn 284: 'passwords' =>
285: { text => 'Passwords (Internal authentication)',
286: help => 'Domain_Configuration_Passwords',
287: header => [{col1 => 'Resetting Forgotten Password',
288: col2 => 'Settings'},
289: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
290: col2 => 'Settings'},
291: {col1 => 'Rules for LON-CAPA Passwords',
292: col2 => 'Settings'},
293: {col1 => 'Course Owner Changing Student Passwords',
294: col2 => 'Settings'}],
295: print => \&print_passwords,
296: modify => \&modify_passwords,
297: },
1.30 raeburn 298: 'quotas' =>
1.160.6.20 raeburn 299: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 300: help => 'Domain_Configuration_Quotas',
1.77 raeburn 301: header => [{col1 => 'User affiliation',
1.72 raeburn 302: col2 => 'Available tools',
1.160.6.28 raeburn 303: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 304: print => \&print_quotas,
305: modify => \&modify_quotas,
1.30 raeburn 306: },
307: 'autoenroll' =>
308: { text => 'Auto-enrollment settings',
1.67 raeburn 309: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 310: header => [{col1 => 'Configuration setting',
311: col2 => 'Value(s)'}],
1.160.6.37 raeburn 312: print => \&print_autoenroll,
313: modify => \&modify_autoenroll,
1.30 raeburn 314: },
315: 'autoupdate' =>
316: { text => 'Auto-update settings',
1.67 raeburn 317: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 318: header => [{col1 => 'Setting',
319: col2 => 'Value',},
1.131 raeburn 320: {col1 => 'Setting',
321: col2 => 'Affiliation'},
1.43 raeburn 322: {col1 => 'User population',
1.160.6.35 raeburn 323: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 324: print => \&print_autoupdate,
325: modify => \&modify_autoupdate,
1.30 raeburn 326: },
1.125 raeburn 327: 'autocreate' =>
328: { text => 'Auto-course creation settings',
329: help => 'Domain_Configuration_Auto_Creation',
330: header => [{col1 => 'Configuration Setting',
331: col2 => 'Value',}],
1.160.6.37 raeburn 332: print => \&print_autocreate,
333: modify => \&modify_autocreate,
1.125 raeburn 334: },
1.30 raeburn 335: 'directorysrch' =>
1.160.6.72 raeburn 336: { text => 'Directory searches',
1.67 raeburn 337: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 338: header => [{col1 => 'Institutional Directory Setting',
339: col2 => 'Value',},
340: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 341: col2 => 'Value',}],
1.160.6.37 raeburn 342: print => \&print_directorysrch,
343: modify => \&modify_directorysrch,
1.30 raeburn 344: },
345: 'contacts' =>
1.160.6.78 raeburn 346: { text => 'E-mail addresses and helpform',
1.67 raeburn 347: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 348: header => [{col1 => 'Default e-mail addresses',
349: col2 => 'Value',},
350: {col1 => 'Recipient(s) for notifications',
351: col2 => 'Value',},
352: {col1 => 'Ask helpdesk form settings',
353: col2 => 'Value',},],
1.160.6.37 raeburn 354: print => \&print_contacts,
355: modify => \&modify_contacts,
1.30 raeburn 356: },
357: 'usercreation' =>
358: { text => 'User creation',
1.67 raeburn 359: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 360: header => [{col1 => 'Format rule type',
361: col2 => 'Format rules in force'},
1.34 raeburn 362: {col1 => 'User account creation',
363: col2 => 'Usernames which may be created',},
1.30 raeburn 364: {col1 => 'Context',
1.43 raeburn 365: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 366: print => \&print_usercreation,
367: modify => \&modify_usercreation,
1.30 raeburn 368: },
1.160.6.34 raeburn 369: 'selfcreation' =>
370: { text => 'Users self-creating accounts',
371: help => 'Domain_Configuration_Self_Creation',
372: header => [{col1 => 'Self-creation with institutional username',
373: col2 => 'Enabled?'},
374: {col1 => 'Institutional user type (login/SSO self-creation)',
375: col2 => 'Information user can enter'},
1.160.6.93 raeburn 376: {col1 => 'Self-creation with e-mail verification',
1.160.6.34 raeburn 377: col2 => 'Settings'}],
1.160.6.37 raeburn 378: print => \&print_selfcreation,
379: modify => \&modify_selfcreation,
1.160.6.34 raeburn 380: },
1.69 raeburn 381: 'usermodification' =>
1.33 raeburn 382: { text => 'User modification',
1.67 raeburn 383: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 384: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 385: col2 => 'User information updatable in author context'},
1.33 raeburn 386: {col1 => 'Target user has role',
1.160.6.35 raeburn 387: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 388: print => \&print_usermodification,
389: modify => \&modify_usermodification,
1.33 raeburn 390: },
1.69 raeburn 391: 'scantron' =>
1.160.6.97 raeburn 392: { text => 'Bubblesheet format',
1.67 raeburn 393: help => 'Domain_Configuration_Scantron_Format',
1.160.6.97 raeburn 394: header => [ {col1 => 'Bubblesheet format file',
395: col2 => ''},
396: {col1 => 'Bubblesheet data upload formats',
397: col2 => 'Settings'}],
1.160.6.37 raeburn 398: print => \&print_scantron,
399: modify => \&modify_scantron,
1.46 raeburn 400: },
1.86 raeburn 401: 'requestcourses' =>
402: {text => 'Request creation of courses',
403: help => 'Domain_Configuration_Request_Courses',
404: header => [{col1 => 'User affiliation',
1.102 raeburn 405: col2 => 'Availability/Processing of requests',},
406: {col1 => 'Setting',
1.160.6.30 raeburn 407: col2 => 'Value'},
408: {col1 => 'Available textbooks',
1.160.6.39 raeburn 409: col2 => ''},
1.160.6.46 raeburn 410: {col1 => 'Available templates',
411: col2 => ''},
1.160.6.39 raeburn 412: {col1 => 'Validation (not official courses)',
413: col2 => 'Value'},],
1.160.6.37 raeburn 414: print => \&print_quotas,
415: modify => \&modify_quotas,
1.86 raeburn 416: },
1.160.6.5 raeburn 417: 'requestauthor' =>
1.160.6.34 raeburn 418: {text => 'Request Authoring Space',
1.160.6.5 raeburn 419: help => 'Domain_Configuration_Request_Author',
420: header => [{col1 => 'User affiliation',
421: col2 => 'Availability/Processing of requests',},
422: {col1 => 'Setting',
423: col2 => 'Value'}],
1.160.6.37 raeburn 424: print => \&print_quotas,
425: modify => \&modify_quotas,
1.160.6.5 raeburn 426: },
1.69 raeburn 427: 'coursecategories' =>
1.120 raeburn 428: { text => 'Cataloging of courses/communities',
1.67 raeburn 429: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 430: header => [{col1 => 'Catalog type/availability',
431: col2 => '',},
432: {col1 => 'Category settings for standard catalog',
1.57 raeburn 433: col2 => '',},
434: {col1 => 'Categories',
435: col2 => '',
436: }],
1.160.6.37 raeburn 437: print => \&print_coursecategories,
438: modify => \&modify_coursecategories,
1.69 raeburn 439: },
440: 'serverstatuses' =>
1.77 raeburn 441: {text => 'Access to server status pages',
1.69 raeburn 442: help => 'Domain_Configuration_Server_Status',
443: header => [{col1 => 'Status Page',
444: col2 => 'Other named users',
445: col3 => 'Specific IPs',
446: }],
1.160.6.37 raeburn 447: print => \&print_serverstatuses,
448: modify => \&modify_serverstatuses,
1.69 raeburn 449: },
1.160.6.73 raeburn 450: 'helpsettings' =>
451: {text => 'Support settings',
452: help => 'Domain_Configuration_Help_Settings',
453: header => [{col1 => 'Help Page Settings (logged-in users)',
454: col2 => 'Value'},
455: {col1 => 'Helpdesk Roles',
456: col2 => 'Settings'},],
457: print => \&print_helpsettings,
458: modify => \&modify_helpsettings,
459: },
1.160.6.39 raeburn 460: 'coursedefaults' =>
1.160.6.16 raeburn 461: {text => 'Course/Community defaults',
462: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 463: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
464: col2 => 'Value',},
465: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 466: col2 => 'Value',},],
1.160.6.37 raeburn 467: print => \&print_coursedefaults,
468: modify => \&modify_coursedefaults,
469: },
1.160.6.39 raeburn 470: 'selfenrollment' =>
1.160.6.37 raeburn 471: {text => 'Self-enrollment in Course/Community',
472: help => 'Domain_Configuration_Selfenrollment',
473: header => [{col1 => 'Configuration Rights',
474: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
475: {col1 => 'Defaults',
476: col2 => 'Value'},
477: {col1 => 'Self-enrollment validation (optional)',
478: col2 => 'Value'},],
479: print => \&print_selfenrollment,
480: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 481: },
1.141 raeburn 482: 'usersessions' =>
1.145 raeburn 483: {text => 'User session hosting/offloading',
1.137 raeburn 484: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 485: header => [{col1 => 'Domain server',
486: col2 => 'Servers to offload sessions to when busy'},
487: {col1 => 'Hosting of users from other domains',
1.137 raeburn 488: col2 => 'Rules'},
489: {col1 => "Hosting domain's own users elsewhere",
490: col2 => 'Rules'}],
1.160.6.37 raeburn 491: print => \&print_usersessions,
492: modify => \&modify_usersessions,
1.137 raeburn 493: },
1.160.6.78 raeburn 494: 'loadbalancing' =>
1.160.6.7 raeburn 495: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 496: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 497: header => [{col1 => 'Balancers',
1.150 raeburn 498: col2 => 'Default destinations',
1.160.6.13 raeburn 499: col3 => 'User affiliation',
1.150 raeburn 500: col4 => 'Overrides'},
501: ],
1.160.6.37 raeburn 502: print => \&print_loadbalancing,
503: modify => \&modify_loadbalancing,
1.150 raeburn 504: },
1.160.6.102.2 1(raebur 505:0): 'ltitools' =>
506:0): {text => 'External Tools (LTI)',
507:0): help => 'Domain_Configuration_LTI_Tools',
508:0): header => [{col1 => 'Setting',
509:0): col2 => 'Value',}],
510:0): print => \&print_ltitools,
511:0): modify => \&modify_ltitools,
512:0): },
1.3 raeburn 513: );
1.110 raeburn 514: if (keys(%servers) > 1) {
515: $prefs{'login'} = { text => 'Log-in page options',
516: help => 'Domain_Configuration_Login_Page',
517: header => [{col1 => 'Log-in Service',
518: col2 => 'Server Setting',},
519: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 520: col2 => ''},
521: {col1 => 'Log-in Help',
1.160.6.56 raeburn 522: col2 => 'Value'},
523: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 524: col2 => 'Value'}],
1.160.6.37 raeburn 525: print => \&print_login,
526: modify => \&modify_login,
1.110 raeburn 527: };
528: }
1.160.6.13 raeburn 529:
1.6 raeburn 530: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 531: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 532: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 533: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 534: text=>"Settings to display/modify"});
1.9 raeburn 535: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 536:
1.3 raeburn 537: if ($phase eq 'process') {
1.160.6.27 raeburn 538: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
539: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 540: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 541: $r->rflush();
1.160.6.27 raeburn 542: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 543: }
1.30 raeburn 544: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 545: my $js = &recaptcha_js().
1.160.6.40 raeburn 546: &toggle_display_js();
1.160.6.7 raeburn 547: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 548: my ($othertitle,$usertypes,$types) =
549: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 550: $js .= &lonbalance_targets_js($dom,$types,\%servers,
551: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 552: &new_spares_js().
553: &common_domprefs_js().
554: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 555: }
1.160.6.30 raeburn 556: if (grep(/^requestcourses$/,@actions)) {
557: my $javascript_validations;
558: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
559: $js .= <<END;
560: <script type="text/javascript">
561: $javascript_validations
562: </script>
563: $coursebrowserjs
564: END
565: }
1.160.6.93 raeburn 566: if (grep(/^selfcreation$/,@actions)) {
567: $js .= &selfcreate_javascript();
568: }
1.160.6.78 raeburn 569: if (grep(/^contacts$/,@actions)) {
570: $js .= &contacts_javascript();
571: }
1.160.6.97 raeburn 572: if (grep(/^scantron$/,@actions)) {
573: $js .= &scantron_javascript();
574: }
1.150 raeburn 575: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 576: } else {
1.160.6.11 raeburn 577: # check if domconfig user exists for the domain.
578: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 579: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 580: &config_check($dom,$confname,$servadm);
581: unless ($configuserok eq 'ok') {
582: &Apache::lonconfigsettings::print_header($r,$phase,$context);
583: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
584: $confname).
585: '<br />'
586: );
587: if ($switchserver) {
588: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
589: '<br />'.
590: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
591: '<br />'.
592: &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).
593: '<br />'.
594: &mt('To do that now, use the following link: [_1]',$switchserver)
595: );
596: } else {
597: $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.').
598: '<br />'.
599: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
600: );
601: }
602: $r->print(&Apache::loncommon::end_page());
603: return OK;
604: }
1.21 raeburn 605: if (keys(%domconfig) == 0) {
606: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 607: my @ids=&Apache::lonnet::current_machine_ids();
608: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 609: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 610: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 611: my $custom_img_count = 0;
612: foreach my $img (@loginimages) {
613: if ($designhash{$dom.'.login.'.$img} ne '') {
614: $custom_img_count ++;
615: }
616: }
617: foreach my $role (@roles) {
618: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
619: $custom_img_count ++;
620: }
621: }
622: if ($custom_img_count > 0) {
1.94 raeburn 623: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 624: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 625: $r->print(
626: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
627: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
628: &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 />'.
629: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
630: if ($switch_server) {
1.30 raeburn 631: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 632: }
1.91 raeburn 633: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 634: return OK;
635: }
636: }
637: }
1.91 raeburn 638: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 639: }
640: return OK;
641: }
642:
643: sub process_changes {
1.160.6.24 raeburn 644: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 645: my %domconfig;
646: if (ref($values) eq 'HASH') {
647: %domconfig = %{$values};
648: }
1.3 raeburn 649: my $output;
650: if ($action eq 'login') {
1.160.6.24 raeburn 651: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 652: } elsif ($action eq 'rolecolors') {
1.9 raeburn 653: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 654: $lastactref,%domconfig);
1.3 raeburn 655: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 656: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 657: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 658: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 659: } elsif ($action eq 'autoupdate') {
660: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 661: } elsif ($action eq 'autocreate') {
662: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 663: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 664: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 665: } elsif ($action eq 'usercreation') {
1.28 raeburn 666: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 667: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 668: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 669: } elsif ($action eq 'usermodification') {
670: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 671: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 672: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 673: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 674: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 675: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 676: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 677: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 678: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 679: } elsif ($action eq 'serverstatuses') {
680: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 681: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 682: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 683: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 684: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 685: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 686: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 687: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 688: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 689: } elsif ($action eq 'selfenrollment') {
690: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 691: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 692: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 693: } elsif ($action eq 'loadbalancing') {
694: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.98 raeburn 695: } elsif ($action eq 'passwords') {
696: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.102.2 1(raebur 697:0): } elsif ($action eq 'ltitools') {
698:0): $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 699: }
700: return $output;
701: }
702:
703: sub print_config_box {
1.9 raeburn 704: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 705: my $rowtotal = 0;
1.49 raeburn 706: my $output;
707: if ($action eq 'coursecategories') {
708: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 709: } elsif ($action eq 'defaults') {
710: $output = &defaults_javascript($settings);
1.160.6.98 raeburn 711: } elsif ($action eq 'passwords') {
712: $output = &passwords_javascript();
1.160.6.73 raeburn 713: } elsif ($action eq 'helpsettings') {
714: my (%privs,%levelscurrent);
715: my %full=();
716: my %levels=(
717: course => {},
718: domain => {},
719: system => {},
720: );
721: my $context = 'domain';
722: my $crstype = 'Course';
723: my $formname = 'display';
724: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
725: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
726: $output =
727: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
728: \@templateroles);
1.91 raeburn 729: }
1.160.6.40 raeburn 730: $output .=
1.30 raeburn 731: '<table class="LC_nested_outer">
1.3 raeburn 732: <tr>
1.66 raeburn 733: <th align="left" valign="middle"><span class="LC_nobreak">'.
734: &mt($item->{text}).' '.
735: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
736: '</tr>';
1.30 raeburn 737: $rowtotal ++;
1.110 raeburn 738: my $numheaders = 1;
739: if (ref($item->{'header'}) eq 'ARRAY') {
740: $numheaders = scalar(@{$item->{'header'}});
741: }
742: if ($numheaders > 1) {
1.64 raeburn 743: my $colspan = '';
1.145 raeburn 744: my $rightcolspan = '';
1.160.6.42 raeburn 745: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 746: ($action eq 'directorysrch') ||
1.160.6.56 raeburn 747: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 748: $colspan = ' colspan="2"';
749: }
1.145 raeburn 750: if ($action eq 'usersessions') {
751: $rightcolspan = ' colspan="3"';
752: }
1.30 raeburn 753: $output .= '
1.3 raeburn 754: <tr>
755: <td>
756: <table class="LC_nested">
757: <tr class="LC_info_row">
1.59 bisitz 758: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 759: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 760: </tr>';
1.69 raeburn 761: $rowtotal ++;
1.160.6.37 raeburn 762: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 763: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 764: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78 raeburn 765: ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37 raeburn 766: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98 raeburn 767: } elsif ($action eq 'passwords') {
768: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 769: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 770: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97 raeburn 771: } elsif ($action eq 'scantron') {
772: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 773: } elsif ($action eq 'login') {
1.160.6.56 raeburn 774: if ($numheaders == 4) {
1.160.6.5 raeburn 775: $colspan = ' colspan="2"';
776: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
777: } else {
778: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
779: }
1.160.6.37 raeburn 780: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 781: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 782: } elsif ($action eq 'rolecolors') {
1.30 raeburn 783: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 784: }
1.30 raeburn 785: $output .= '
1.6 raeburn 786: </table>
787: </td>
788: </tr>
789: <tr>
790: <td>
791: <table class="LC_nested">
792: <tr class="LC_info_row">
1.160.6.37 raeburn 793: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 794: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 795: </tr>';
796: $rowtotal ++;
1.160.6.37 raeburn 797: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
798: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 799: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.98 raeburn 800: ($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.42 raeburn 801: if ($action eq 'coursecategories') {
802: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
803: $colspan = ' colspan="2"';
1.160.6.98 raeburn 804: } elsif ($action eq 'passwords') {
805: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.42 raeburn 806: } else {
807: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
808: }
809: $output .= '
1.63 raeburn 810: </table>
811: </td>
812: </tr>
813: <tr>
814: <td>
815: <table class="LC_nested">
816: <tr class="LC_info_row">
817: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 818: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 819: </tr>'."\n";
820: if ($action eq 'coursecategories') {
821: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.98 raeburn 822: } elsif ($action eq 'passwords') {
823: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal).'
824: </tr>
825: </table>
826: </td>
827: </tr>
828: <tr>
829: <td>
830: <table class="LC_nested">
831: <tr class="LC_info_row">
832: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
833: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n".
834: $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal).'
835: </table>
836: </td>
837: </tr>
838: <tr>';
1.160.6.42 raeburn 839: } else {
840: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
841: }
1.63 raeburn 842: $rowtotal ++;
1.160.6.57 raeburn 843: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 844: ($action eq 'defaults') || ($action eq 'directorysrch') ||
845: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 846: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97 raeburn 847: } elsif ($action eq 'scantron') {
848: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 849: } elsif ($action eq 'login') {
1.160.6.56 raeburn 850: if ($numheaders == 4) {
1.160.6.5 raeburn 851: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
852: </table>
853: </td>
854: </tr>
855: <tr>
856: <td>
857: <table class="LC_nested">
858: <tr class="LC_info_row">
859: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 860: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 861: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
862: $rowtotal ++;
863: } else {
864: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
865: }
1.160.6.56 raeburn 866: $output .= '
867: </table>
868: </td>
869: </tr>
870: <tr>
871: <td>
872: <table class="LC_nested">
873: <tr class="LC_info_row">';
874: if ($numheaders == 4) {
875: $output .= '
876: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
877: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
878: </tr>';
879: } else {
880: $output .= '
881: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
882: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
883: </tr>';
884: }
885: $rowtotal ++;
886: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 887: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 888: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
889: $rowtotal ++;
890: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 891: </table>
892: </td>
893: </tr>
894: <tr>
895: <td>
896: <table class="LC_nested">
897: <tr class="LC_info_row">
898: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
899: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 900: &textbookcourses_javascript($settings).
901: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
902: </table>
903: </td>
904: </tr>
905: <tr>
906: <td>
907: <table class="LC_nested">
908: <tr class="LC_info_row">
909: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
910: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
911: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 912: </table>
913: </td>
914: </tr>
915: <tr>
916: <td>
917: <table class="LC_nested">
918: <tr class="LC_info_row">
1.160.6.46 raeburn 919: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
920: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 921: </tr>'.
922: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 923: } elsif ($action eq 'requestauthor') {
924: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 925: $rowtotal ++;
1.122 jms 926: } elsif ($action eq 'rolecolors') {
1.30 raeburn 927: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 928: </table>
929: </td>
930: </tr>
931: <tr>
932: <td>
933: <table class="LC_nested">
934: <tr class="LC_info_row">
1.69 raeburn 935: <td class="LC_left_item"'.$colspan.' valign="top">'.
936: &mt($item->{'header'}->[2]->{'col1'}).'</td>
937: <td class="LC_right_item" valign="top">'.
938: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 939: </tr>'.
1.30 raeburn 940: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 941: </table>
942: </td>
943: </tr>
944: <tr>
945: <td>
946: <table class="LC_nested">
947: <tr class="LC_info_row">
1.59 bisitz 948: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
949: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 950: </tr>'.
1.30 raeburn 951: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
952: $rowtotal += 2;
1.6 raeburn 953: }
1.3 raeburn 954: } else {
1.30 raeburn 955: $output .= '
1.3 raeburn 956: <tr>
957: <td>
958: <table class="LC_nested">
1.30 raeburn 959: <tr class="LC_info_row">';
1.160.6.72 raeburn 960: if ($action eq 'login') {
1.30 raeburn 961: $output .= '
1.59 bisitz 962: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 963: } elsif ($action eq 'serverstatuses') {
964: $output .= '
965: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
966: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
967:
1.6 raeburn 968: } else {
1.30 raeburn 969: $output .= '
1.69 raeburn 970: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
971: }
1.72 raeburn 972: if (defined($item->{'header'}->[0]->{'col3'})) {
973: $output .= '<td class="LC_left_item" valign="top">'.
974: &mt($item->{'header'}->[0]->{'col2'});
975: if ($action eq 'serverstatuses') {
976: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
977: }
1.69 raeburn 978: } else {
979: $output .= '<td class="LC_right_item" valign="top">'.
980: &mt($item->{'header'}->[0]->{'col2'});
981: }
982: $output .= '</td>';
983: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 984: if (defined($item->{'header'}->[0]->{'col4'})) {
985: $output .= '<td class="LC_left_item" valign="top">'.
986: &mt($item->{'header'}->[0]->{'col3'});
987: } else {
988: $output .= '<td class="LC_right_item" valign="top">'.
989: &mt($item->{'header'}->[0]->{'col3'});
990: }
1.69 raeburn 991: if ($action eq 'serverstatuses') {
992: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
993: }
994: $output .= '</td>';
1.6 raeburn 995: }
1.150 raeburn 996: if ($item->{'header'}->[0]->{'col4'}) {
997: $output .= '<td class="LC_right_item" valign="top">'.
998: &mt($item->{'header'}->[0]->{'col4'});
999: }
1.69 raeburn 1000: $output .= '</tr>';
1.48 raeburn 1001: $rowtotal ++;
1.160.6.5 raeburn 1002: if ($action eq 'quotas') {
1.86 raeburn 1003: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 1004: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.102.2 1(raebur 1005:0): ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1006:0): ($action eq 'ltitools')) {
1.160.6.37 raeburn 1007: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1008: }
1.3 raeburn 1009: }
1.30 raeburn 1010: $output .= '
1.3 raeburn 1011: </table>
1012: </td>
1013: </tr>
1.30 raeburn 1014: </table><br />';
1015: return ($output,$rowtotal);
1.1 raeburn 1016: }
1017:
1.3 raeburn 1018: sub print_login {
1.160.6.5 raeburn 1019: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1020: my ($css_class,$datatable);
1.6 raeburn 1021: my %choices = &login_choices();
1.110 raeburn 1022:
1.160.6.5 raeburn 1023: if ($caller eq 'service') {
1.149 raeburn 1024: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1025: my $choice = $choices{'disallowlogin'};
1026: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1027: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1028: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1029: '<th>'.$choices{'server'}.'</th>'.
1030: '<th>'.$choices{'serverpath'}.'</th>'.
1031: '<th>'.$choices{'custompath'}.'</th>'.
1032: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1033: my %disallowed;
1034: if (ref($settings) eq 'HASH') {
1035: if (ref($settings->{'loginvia'}) eq 'HASH') {
1036: %disallowed = %{$settings->{'loginvia'}};
1037: }
1038: }
1039: foreach my $lonhost (sort(keys(%servers))) {
1040: my $direct = 'selected="selected"';
1.128 raeburn 1041: if (ref($disallowed{$lonhost}) eq 'HASH') {
1042: if ($disallowed{$lonhost}{'server'} ne '') {
1043: $direct = '';
1044: }
1.110 raeburn 1045: }
1.115 raeburn 1046: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1047: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1048: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1049: '</option>';
1.160.6.13 raeburn 1050: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1051: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1052: my $selected = '';
1.128 raeburn 1053: if (ref($disallowed{$lonhost}) eq 'HASH') {
1054: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1055: $selected = 'selected="selected"';
1056: }
1.110 raeburn 1057: }
1058: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1059: $servers{$hostid}.'</option>';
1060: }
1.128 raeburn 1061: $datatable .= '</select></td>'.
1062: '<td><select name="'.$lonhost.'_serverpath">';
1063: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1064: my $pathname = $path;
1065: if ($path eq 'custom') {
1066: $pathname = &mt('Custom Path').' ->';
1067: }
1068: my $selected = '';
1069: if (ref($disallowed{$lonhost}) eq 'HASH') {
1070: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1071: $selected = 'selected="selected"';
1072: }
1073: } elsif ($path eq '') {
1074: $selected = 'selected="selected"';
1075: }
1076: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1077: }
1078: $datatable .= '</select></td>';
1079: my ($custom,$exempt);
1080: if (ref($disallowed{$lonhost}) eq 'HASH') {
1081: $custom = $disallowed{$lonhost}{'custompath'};
1082: $exempt = $disallowed{$lonhost}{'exempt'};
1083: }
1084: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1085: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1086: '</tr>';
1.110 raeburn 1087: }
1088: $datatable .= '</table></td></tr>';
1089: return $datatable;
1.160.6.5 raeburn 1090: } elsif ($caller eq 'page') {
1091: my %defaultchecked = (
1092: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1093: 'helpdesk' => 'on',
1.160.6.5 raeburn 1094: 'adminmail' => 'off',
1095: 'newuser' => 'off',
1096: );
1.160.6.14 raeburn 1097: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1098: my (%checkedon,%checkedoff);
1.42 raeburn 1099: foreach my $item (@toggles) {
1.160.6.5 raeburn 1100: if ($defaultchecked{$item} eq 'on') {
1101: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1102: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1103: } elsif ($defaultchecked{$item} eq 'off') {
1104: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1105: $checkedon{$item} = ' ';
1106: }
1.1 raeburn 1107: }
1.160.6.5 raeburn 1108: my @images = ('img','logo','domlogo','login');
1109: my @logintext = ('textcol','bgcol');
1110: my @bgs = ('pgbg','mainbg','sidebg');
1111: my @links = ('link','alink','vlink');
1112: my %designhash = &Apache::loncommon::get_domainconf($dom);
1113: my %defaultdesign = %Apache::loncommon::defaultdesign;
1114: my (%is_custom,%designs);
1115: my %defaults = (
1116: font => $defaultdesign{'login.font'},
1117: );
1.6 raeburn 1118: foreach my $item (@images) {
1.160.6.5 raeburn 1119: $defaults{$item} = $defaultdesign{'login.'.$item};
1120: $defaults{'showlogo'}{$item} = 1;
1121: }
1122: foreach my $item (@bgs) {
1123: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1124: }
1.41 raeburn 1125: foreach my $item (@logintext) {
1.160.6.5 raeburn 1126: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1127: }
1.160.6.5 raeburn 1128: foreach my $item (@links) {
1129: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1130: }
1.160.6.5 raeburn 1131: if (ref($settings) eq 'HASH') {
1132: foreach my $item (@toggles) {
1133: if ($settings->{$item} eq '1') {
1134: $checkedon{$item} = ' checked="checked" ';
1135: $checkedoff{$item} = ' ';
1136: } elsif ($settings->{$item} eq '0') {
1137: $checkedoff{$item} = ' checked="checked" ';
1138: $checkedon{$item} = ' ';
1139: }
1.6 raeburn 1140: }
1.160.6.5 raeburn 1141: foreach my $item (@images) {
1142: if (defined($settings->{$item})) {
1143: $designs{$item} = $settings->{$item};
1144: $is_custom{$item} = 1;
1145: }
1146: if (defined($settings->{'showlogo'}{$item})) {
1147: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1148: }
1149: }
1150: foreach my $item (@logintext) {
1151: if ($settings->{$item} ne '') {
1152: $designs{'logintext'}{$item} = $settings->{$item};
1153: $is_custom{$item} = 1;
1154: }
1155: }
1156: if ($settings->{'font'} ne '') {
1157: $designs{'font'} = $settings->{'font'};
1158: $is_custom{'font'} = 1;
1159: }
1160: foreach my $item (@bgs) {
1161: if ($settings->{$item} ne '') {
1162: $designs{'bgs'}{$item} = $settings->{$item};
1163: $is_custom{$item} = 1;
1164: }
1165: }
1166: foreach my $item (@links) {
1167: if ($settings->{$item} ne '') {
1168: $designs{'links'}{$item} = $settings->{$item};
1169: $is_custom{$item} = 1;
1170: }
1171: }
1172: } else {
1173: if ($designhash{$dom.'.login.font'} ne '') {
1174: $designs{'font'} = $designhash{$dom.'.login.font'};
1175: $is_custom{'font'} = 1;
1176: }
1177: foreach my $item (@images) {
1178: if ($designhash{$dom.'.login.'.$item} ne '') {
1179: $designs{$item} = $designhash{$dom.'.login.'.$item};
1180: $is_custom{$item} = 1;
1181: }
1182: }
1183: foreach my $item (@bgs) {
1184: if ($designhash{$dom.'.login.'.$item} ne '') {
1185: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1186: $is_custom{$item} = 1;
1187: }
1188: }
1189: foreach my $item (@links) {
1190: if ($designhash{$dom.'.login.'.$item} ne '') {
1191: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1192: $is_custom{$item} = 1;
1193: }
1.6 raeburn 1194: }
1195: }
1.160.6.5 raeburn 1196: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1197: logo => 'Institution Logo',
1198: domlogo => 'Domain Logo',
1199: login => 'Login box');
1200: my $itemcount = 1;
1201: foreach my $item (@toggles) {
1202: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1203: $datatable .=
1204: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1205: '</td><td>'.
1206: '<span class="LC_nobreak"><label><input type="radio" name="'.
1207: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1208: '</label> <label><input type="radio" name="'.$item.'"'.
1209: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1210: '</tr>';
1211: $itemcount ++;
1.6 raeburn 1212: }
1.160.6.5 raeburn 1213: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1214: $datatable .= '</tr></table></td></tr>';
1215: } elsif ($caller eq 'help') {
1216: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1217: my $switchserver = &check_switchserver($dom,$confname);
1218: my $itemcount = 1;
1219: $defaulturl = '/adm/loginproblems.html';
1220: $defaulttype = 'default';
1221: %lt = &Apache::lonlocal::texthash (
1222: del => 'Delete?',
1223: rep => 'Replace:',
1224: upl => 'Upload:',
1225: default => 'Default',
1226: custom => 'Custom',
1227: );
1228: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1229: my @currlangs;
1230: if (ref($settings) eq 'HASH') {
1231: if (ref($settings->{'helpurl'}) eq 'HASH') {
1232: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1233: next if ($settings->{'helpurl'}{$key} eq '');
1234: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1235: $type{$key} = 'custom';
1236: unless ($key eq 'nolang') {
1237: push(@currlangs,$key);
1238: }
1239: }
1240: } elsif ($settings->{'helpurl'} ne '') {
1241: $type{'nolang'} = 'custom';
1242: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1243: }
1244: }
1.160.6.5 raeburn 1245: foreach my $lang ('nolang',sort(@currlangs)) {
1246: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1247: $datatable .= '<tr'.$css_class.'>';
1248: if ($url{$lang} eq '') {
1249: $url{$lang} = $defaulturl;
1250: }
1251: if ($type{$lang} eq '') {
1252: $type{$lang} = $defaulttype;
1253: }
1254: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1255: if ($lang eq 'nolang') {
1256: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1257: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1258: } else {
1259: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1260: $langchoices{$lang},
1261: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1262: }
1263: $datatable .= '</span></td>'."\n".
1264: '<td class="LC_left_item">';
1265: if ($type{$lang} eq 'custom') {
1266: $datatable .= '<span class="LC_nobreak"><label>'.
1267: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1268: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1269: } else {
1270: $datatable .= $lt{'upl'};
1271: }
1272: $datatable .='<br />';
1273: if ($switchserver) {
1274: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1275: } else {
1276: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1277: }
1.160.6.5 raeburn 1278: $datatable .= '</td></tr>';
1279: $itemcount ++;
1.6 raeburn 1280: }
1.160.6.5 raeburn 1281: my @addlangs;
1282: foreach my $lang (sort(keys(%langchoices))) {
1283: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1284: push(@addlangs,$lang);
1285: }
1286: if (@addlangs > 0) {
1287: my %toadd;
1288: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1289: $toadd{''} = &mt('Select');
1290: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1291: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1292: &mt('Add log-in help page for a specific language:').' '.
1293: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1294: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1295: if ($switchserver) {
1296: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1297: } else {
1298: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1299: }
1.160.6.5 raeburn 1300: $datatable .= '</td></tr>';
1301: $itemcount ++;
1.6 raeburn 1302: }
1.160.6.5 raeburn 1303: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1304: } elsif ($caller eq 'headtag') {
1305: my %domservers = &Apache::lonnet::get_servers($dom);
1306: my $choice = $choices{'headtag'};
1307: $css_class = ' class="LC_odd_row"';
1308: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1309: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1310: '<th>'.$choices{'current'}.'</th>'.
1311: '<th>'.$choices{'action'}.'</th>'.
1312: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1313: my (%currurls,%currexempt);
1314: if (ref($settings) eq 'HASH') {
1315: if (ref($settings->{'headtag'}) eq 'HASH') {
1316: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1317: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1318: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1319: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1320: }
1321: }
1322: }
1323: }
1324: my %lt = &Apache::lonlocal::texthash(
1325: del => 'Delete?',
1326: rep => 'Replace:',
1327: upl => 'Upload:',
1328: curr => 'View contents',
1329: none => 'None',
1330: );
1331: my $switchserver = &check_switchserver($dom,$confname);
1332: foreach my $lonhost (sort(keys(%domservers))) {
1333: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1334: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1335: if ($currurls{$lonhost}) {
1336: $datatable .= '<td class="LC_right_item"><a href="'.
1337: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1338: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1339: '">'.$lt{'curr'}.'</a></td>'.
1340: '<td><span class="LC_nobreak"><label>'.
1341: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1342: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1343: } else {
1344: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1345: }
1346: $datatable .='<br />';
1347: if ($switchserver) {
1348: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1349: } else {
1350: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1351: }
1.160.6.87 raeburn 1352: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1353: }
1354: $datatable .= '</table></td></tr>';
1.1 raeburn 1355: }
1.6 raeburn 1356: return $datatable;
1357: }
1358:
1359: sub login_choices {
1360: my %choices =
1361: &Apache::lonlocal::texthash (
1.116 bisitz 1362: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1363: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1364: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1365: disallowlogin => "Login page requests redirected",
1366: hostid => "Server",
1.128 raeburn 1367: server => "Redirect to:",
1368: serverpath => "Path",
1369: custompath => "Custom",
1370: exempt => "Exempt IP(s)",
1.110 raeburn 1371: directlogin => "No redirect",
1372: newuser => "Link to create a user account",
1373: img => "Header",
1374: logo => "Main Logo",
1375: domlogo => "Domain Logo",
1376: login => "Log-in Header",
1377: textcol => "Text color",
1378: bgcol => "Box color",
1379: bgs => "Background colors",
1380: links => "Link colors",
1381: font => "Font color",
1382: pgbg => "Header",
1383: mainbg => "Page",
1384: sidebg => "Login box",
1385: link => "Link",
1386: alink => "Active link",
1387: vlink => "Visited link",
1.160.6.56 raeburn 1388: headtag => "Custom markup",
1389: action => "Action",
1390: current => "Current",
1.6 raeburn 1391: );
1392: return %choices;
1393: }
1394:
1395: sub print_rolecolors {
1.30 raeburn 1396: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1397: my %choices = &color_font_choices();
1398: my @bgs = ('pgbg','tabbg','sidebg');
1399: my @links = ('link','alink','vlink');
1400: my @images = ('img');
1401: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1402: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1403: my %defaultdesign = %Apache::loncommon::defaultdesign;
1404: my (%is_custom,%designs);
1.160.6.22 raeburn 1405: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1406: if (ref($settings) eq 'HASH') {
1407: if (ref($settings->{$role}) eq 'HASH') {
1408: if ($settings->{$role}->{'img'} ne '') {
1409: $designs{'img'} = $settings->{$role}->{'img'};
1410: $is_custom{'img'} = 1;
1411: }
1412: if ($settings->{$role}->{'font'} ne '') {
1413: $designs{'font'} = $settings->{$role}->{'font'};
1414: $is_custom{'font'} = 1;
1415: }
1.97 tempelho 1416: if ($settings->{$role}->{'fontmenu'} ne '') {
1417: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1418: $is_custom{'fontmenu'} = 1;
1419: }
1.6 raeburn 1420: foreach my $item (@bgs) {
1421: if ($settings->{$role}->{$item} ne '') {
1422: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1423: $is_custom{$item} = 1;
1424: }
1425: }
1426: foreach my $item (@links) {
1427: if ($settings->{$role}->{$item} ne '') {
1428: $designs{'links'}{$item} = $settings->{$role}->{$item};
1429: $is_custom{$item} = 1;
1430: }
1431: }
1432: }
1433: } else {
1434: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1435: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1436: $is_custom{'img'} = 1;
1437: }
1.97 tempelho 1438: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1439: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1440: $is_custom{'fontmenu'} = 1;
1441: }
1.6 raeburn 1442: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1443: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1444: $is_custom{'font'} = 1;
1445: }
1446: foreach my $item (@bgs) {
1447: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1448: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1449: $is_custom{$item} = 1;
1450:
1451: }
1452: }
1453: foreach my $item (@links) {
1454: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1455: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1456: $is_custom{$item} = 1;
1457: }
1458: }
1459: }
1460: my $itemcount = 1;
1.30 raeburn 1461: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1462: $datatable .= '</tr></table></td></tr>';
1463: return $datatable;
1464: }
1465:
1.160.6.22 raeburn 1466: sub role_defaults {
1467: my ($role,$bgs,$links,$images,$logintext) = @_;
1468: my %defaults;
1469: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1470: return %defaults;
1471: }
1472: my %defaultdesign = %Apache::loncommon::defaultdesign;
1473: if ($role eq 'login') {
1474: %defaults = (
1475: font => $defaultdesign{$role.'.font'},
1476: );
1477: if (ref($logintext) eq 'ARRAY') {
1478: foreach my $item (@{$logintext}) {
1479: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1480: }
1481: }
1482: foreach my $item (@{$images}) {
1483: $defaults{'showlogo'}{$item} = 1;
1484: }
1485: } else {
1486: %defaults = (
1487: img => $defaultdesign{$role.'.img'},
1488: font => $defaultdesign{$role.'.font'},
1489: fontmenu => $defaultdesign{$role.'.fontmenu'},
1490: );
1491: }
1492: foreach my $item (@{$bgs}) {
1493: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1494: }
1495: foreach my $item (@{$links}) {
1496: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1497: }
1498: foreach my $item (@{$images}) {
1499: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1500: }
1501: return %defaults;
1502: }
1503:
1.6 raeburn 1504: sub display_color_options {
1.9 raeburn 1505: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1506: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1507: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1508: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1509: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1510: '<td>'.$choices->{'font'}.'</td>';
1511: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1512: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1513: } else {
1514: $datatable .= '<td> </td>';
1515: }
1.160.6.9 raeburn 1516: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1517:
1.8 raeburn 1518: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1519: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1520: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1521: ' </span></td></tr>';
1.107 raeburn 1522: unless ($role eq 'login') {
1523: $datatable .= '<tr'.$css_class.'>'.
1524: '<td>'.$choices->{'fontmenu'}.'</td>';
1525: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1526: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1527: } else {
1528: $datatable .= '<td> </td>';
1529: }
1.160.6.22 raeburn 1530: $current_color = $designs->{'fontmenu'} ?
1531: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1532: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1533: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1534: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1535: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1536: ' </span></td></tr>';
1.97 tempelho 1537: }
1.9 raeburn 1538: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1539: foreach my $img (@{$images}) {
1.18 albertel 1540: $itemcount ++;
1.6 raeburn 1541: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1542: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1543: '<td>'.$choices->{$img};
1.41 raeburn 1544: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1545: if ($role eq 'login') {
1546: if ($img eq 'login') {
1547: $login_hdr_pick =
1.135 bisitz 1548: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1549: $logincolors =
1550: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1551: $designs,$defaults);
1.70 raeburn 1552: } elsif ($img ne 'domlogo') {
1553: $datatable.= &logo_display_options($img,$defaults,$designs);
1554: }
1555: }
1556: $datatable .= '</td>';
1.6 raeburn 1557: if ($designs->{$img} ne '') {
1558: $imgfile = $designs->{$img};
1.18 albertel 1559: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1560: } else {
1561: $imgfile = $defaults->{$img};
1562: }
1563: if ($imgfile) {
1.9 raeburn 1564: my ($showfile,$fullsize);
1565: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1566: my $urldir = $1;
1567: my $filename = $2;
1568: my @info = &Apache::lonnet::stat_file($designs->{$img});
1569: if (@info) {
1570: my $thumbfile = 'tn-'.$filename;
1571: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1572: if (@thumb) {
1573: $showfile = $urldir.'/'.$thumbfile;
1574: } else {
1575: $showfile = $imgfile;
1576: }
1577: } else {
1578: $showfile = '';
1579: }
1580: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1581: $showfile = $imgfile;
1.6 raeburn 1582: my $imgdir = $1;
1583: my $filename = $2;
1.159 raeburn 1584: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1585: $showfile = "/$imgdir/tn-".$filename;
1586: } else {
1.159 raeburn 1587: my $input = $londocroot.$imgfile;
1588: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1589: if (!-e $output) {
1.9 raeburn 1590: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1591: my ($fullwidth,$fullheight) = &check_dimensions($input);
1592: if ($fullwidth ne '' && $fullheight ne '') {
1593: if ($fullwidth > $width && $fullheight > $height) {
1594: my $size = $width.'x'.$height;
1.160.6.88 raeburn 1595: my @args = ('convert','-sample',$size,$input,$output);
1596: system({$args[0]} @args);
1.159 raeburn 1597: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1598: }
1599: }
1.6 raeburn 1600: }
1601: }
1.16 raeburn 1602: }
1.6 raeburn 1603: if ($showfile) {
1.40 raeburn 1604: if ($showfile =~ m{^/(adm|res)/}) {
1605: if ($showfile =~ m{^/res/}) {
1606: my $local_showfile =
1607: &Apache::lonnet::filelocation('',$showfile);
1608: &Apache::lonnet::repcopy($local_showfile);
1609: }
1610: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1611: }
1612: if ($imgfile) {
1613: if ($imgfile =~ m{^/(adm|res)/}) {
1614: if ($imgfile =~ m{^/res/}) {
1615: my $local_imgfile =
1616: &Apache::lonnet::filelocation('',$imgfile);
1617: &Apache::lonnet::repcopy($local_imgfile);
1618: }
1619: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1620: } else {
1621: $fullsize = $imgfile;
1622: }
1623: }
1.41 raeburn 1624: $datatable .= '<td>';
1625: if ($img eq 'login') {
1.135 bisitz 1626: $datatable .= $login_hdr_pick;
1627: }
1.41 raeburn 1628: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1629: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1630: } else {
1.160.6.22 raeburn 1631: $datatable .= '<td> </td><td class="LC_left_item">'.
1632: &mt('Upload:').'<br />';
1.6 raeburn 1633: }
1634: } else {
1.160.6.22 raeburn 1635: $datatable .= '<td> </td><td class="LC_left_item">'.
1636: &mt('Upload:').'<br />';
1.6 raeburn 1637: }
1.9 raeburn 1638: if ($switchserver) {
1639: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1640: } else {
1.135 bisitz 1641: if ($img ne 'login') { # suppress file selection for Log-in header
1642: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1643: }
1.9 raeburn 1644: }
1645: $datatable .= '</td></tr>';
1.6 raeburn 1646: }
1647: $itemcount ++;
1648: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1649: $datatable .= '<tr'.$css_class.'>'.
1650: '<td>'.$choices->{'bgs'}.'</td>';
1651: my $bgs_def;
1652: foreach my $item (@{$bgs}) {
1653: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1654: $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 1655: }
1656: }
1657: if ($bgs_def) {
1.8 raeburn 1658: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1659: } else {
1660: $datatable .= '<td> </td>';
1661: }
1662: $datatable .= '<td class="LC_right_item">'.
1663: '<table border="0"><tr>';
1.160.6.13 raeburn 1664:
1.6 raeburn 1665: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1666: $datatable .= '<td align="center">'.$choices->{$item};
1667: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1668: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1669: $datatable .= ' ';
1.6 raeburn 1670: }
1.160.6.9 raeburn 1671: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1672: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1673: }
1674: $datatable .= '</tr></table></td></tr>';
1675: $itemcount ++;
1676: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1677: $datatable .= '<tr'.$css_class.'>'.
1678: '<td>'.$choices->{'links'}.'</td>';
1679: my $links_def;
1680: foreach my $item (@{$links}) {
1681: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1682: $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 1683: }
1684: }
1685: if ($links_def) {
1.8 raeburn 1686: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1687: } else {
1688: $datatable .= '<td> </td>';
1689: }
1690: $datatable .= '<td class="LC_right_item">'.
1691: '<table border="0"><tr>';
1692: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1693: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1694: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1695: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1696: $datatable.=' ';
1.6 raeburn 1697: }
1.160.6.9 raeburn 1698: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1699: '" /></td>';
1700: }
1.30 raeburn 1701: $$rowtotal += $itemcount;
1.3 raeburn 1702: return $datatable;
1703: }
1704:
1.70 raeburn 1705: sub logo_display_options {
1706: my ($img,$defaults,$designs) = @_;
1707: my $checkedon;
1708: if (ref($defaults) eq 'HASH') {
1709: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1710: if ($defaults->{'showlogo'}{$img}) {
1711: $checkedon = 'checked="checked" ';
1712: }
1713: }
1714: }
1715: if (ref($designs) eq 'HASH') {
1716: if (ref($designs->{'showlogo'}) eq 'HASH') {
1717: if (defined($designs->{'showlogo'}{$img})) {
1718: if ($designs->{'showlogo'}{$img} == 0) {
1719: $checkedon = '';
1720: } elsif ($designs->{'showlogo'}{$img} == 1) {
1721: $checkedon = 'checked="checked" ';
1722: }
1723: }
1724: }
1725: }
1726: return '<br /><label> <input type="checkbox" name="'.
1727: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1728: &mt('show').'</label>'."\n";
1729: }
1730:
1.41 raeburn 1731: sub login_header_options {
1.135 bisitz 1732: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1733: my $output = '';
1.41 raeburn 1734: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1735: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1736: if (!$is_custom->{'textcol'}) {
1737: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1738: ' ';
1739: }
1740: if (!$is_custom->{'bgcol'}) {
1741: $output .= $choices->{'bgcol'}.': '.
1742: '<span id="css_'.$role.'_font" style="background-color: '.
1743: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1744: }
1745: $output .= '<br />';
1746: }
1747: $output .='<br />';
1748: return $output;
1749: }
1750:
1751: sub login_text_colors {
1.160.6.22 raeburn 1752: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1753: my $color_menu = '<table border="0"><tr>';
1754: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1755: $color_menu .= '<td align="center">'.$choices->{$item};
1756: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1757: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1758: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1759: }
1760: $color_menu .= '</tr></table><br />';
1761: return $color_menu;
1762: }
1763:
1764: sub image_changes {
1765: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1766: my $output;
1.135 bisitz 1767: if ($img eq 'login') {
1.160.6.87 raeburn 1768: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1769: } elsif (!$is_custom) {
1.70 raeburn 1770: if ($img ne 'domlogo') {
1.160.6.87 raeburn 1771: $output = &mt('Default image:').'<br />';
1.41 raeburn 1772: } else {
1.160.6.87 raeburn 1773: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1774: }
1775: }
1.160.6.87 raeburn 1776: if ($img ne 'login') {
1.135 bisitz 1777: if ($img_import) {
1778: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1779: }
1780: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1781: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1782: if ($is_custom) {
1783: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1784: '<input type="checkbox" name="'.
1785: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1786: '</label> '.&mt('Replace:').'</span><br />';
1787: } else {
1.160.6.22 raeburn 1788: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1789: }
1.41 raeburn 1790: }
1791: return $output;
1792: }
1793:
1.3 raeburn 1794: sub print_quotas {
1.86 raeburn 1795: my ($dom,$settings,$rowtotal,$action) = @_;
1796: my $context;
1797: if ($action eq 'quotas') {
1798: $context = 'tools';
1799: } else {
1800: $context = $action;
1801: }
1.160.6.20 raeburn 1802: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1803: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1804: my $typecount = 0;
1.101 raeburn 1805: my ($css_class,%titles);
1.86 raeburn 1806: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1807: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1808: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1809: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1810: %titles = &courserequest_titles();
1.160.6.5 raeburn 1811: } elsif ($context eq 'requestauthor') {
1812: @usertools = ('author');
1813: @options = ('norequest','approval','automatic');
1814: %titles = &authorrequest_titles();
1.86 raeburn 1815: } else {
1.160.6.4 raeburn 1816: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1817: %titles = &tool_titles();
1.86 raeburn 1818: }
1.26 raeburn 1819: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1820: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1821: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1822: unless (($context eq 'requestcourses') ||
1823: ($context eq 'requestauthor')) {
1.86 raeburn 1824: if (ref($settings) eq 'HASH') {
1825: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1826: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1827: } else {
1828: $currdefquota = $settings->{$type};
1829: }
1.160.6.20 raeburn 1830: if (ref($settings->{authorquota}) eq 'HASH') {
1831: $currauthorquota = $settings->{authorquota}->{$type};
1832: }
1.78 raeburn 1833: }
1.72 raeburn 1834: }
1.3 raeburn 1835: if (defined($usertypes->{$type})) {
1836: $typecount ++;
1837: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1838: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1839: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1840: '<td class="LC_left_item">';
1.101 raeburn 1841: if ($context eq 'requestcourses') {
1842: $datatable .= '<table><tr>';
1843: }
1844: my %cell;
1.72 raeburn 1845: foreach my $item (@usertools) {
1.101 raeburn 1846: if ($context eq 'requestcourses') {
1847: my ($curroption,$currlimit);
1848: if (ref($settings) eq 'HASH') {
1849: if (ref($settings->{$item}) eq 'HASH') {
1850: $curroption = $settings->{$item}->{$type};
1851: if ($curroption =~ /^autolimit=(\d*)$/) {
1852: $currlimit = $1;
1853: }
1854: }
1855: }
1856: if (!$curroption) {
1857: $curroption = 'norequest';
1858: }
1859: $datatable .= '<th>'.$titles{$item}.'</th>';
1860: foreach my $option (@options) {
1861: my $val = $option;
1862: if ($option eq 'norequest') {
1863: $val = 0;
1864: }
1865: if ($option eq 'validate') {
1866: my $canvalidate = 0;
1867: if (ref($validations{$item}) eq 'HASH') {
1868: if ($validations{$item}{$type}) {
1869: $canvalidate = 1;
1870: }
1871: }
1872: next if (!$canvalidate);
1873: }
1874: my $checked = '';
1875: if ($option eq $curroption) {
1876: $checked = ' checked="checked"';
1877: } elsif ($option eq 'autolimit') {
1878: if ($curroption =~ /^autolimit/) {
1879: $checked = ' checked="checked"';
1880: }
1881: }
1882: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1883: '<input type="radio" name="crsreq_'.$item.
1884: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1885: $titles{$option}.'</label>';
1.101 raeburn 1886: if ($option eq 'autolimit') {
1.127 raeburn 1887: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1888: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1889: 'value="'.$currlimit.'" />';
1.101 raeburn 1890: }
1.127 raeburn 1891: $cell{$item} .= '</span> ';
1.103 raeburn 1892: if ($option eq 'autolimit') {
1.127 raeburn 1893: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1894: }
1.101 raeburn 1895: }
1.160.6.5 raeburn 1896: } elsif ($context eq 'requestauthor') {
1897: my $curroption;
1898: if (ref($settings) eq 'HASH') {
1899: $curroption = $settings->{$type};
1900: }
1901: if (!$curroption) {
1902: $curroption = 'norequest';
1903: }
1904: foreach my $option (@options) {
1905: my $val = $option;
1906: if ($option eq 'norequest') {
1907: $val = 0;
1908: }
1909: my $checked = '';
1910: if ($option eq $curroption) {
1911: $checked = ' checked="checked"';
1912: }
1913: $datatable .= '<span class="LC_nobreak"><label>'.
1914: '<input type="radio" name="authorreq_'.$type.
1915: '" value="'.$val.'"'.$checked.' />'.
1916: $titles{$option}.'</label></span> ';
1917: }
1.101 raeburn 1918: } else {
1919: my $checked = 'checked="checked" ';
1920: if (ref($settings) eq 'HASH') {
1921: if (ref($settings->{$item}) eq 'HASH') {
1922: if ($settings->{$item}->{$type} == 0) {
1923: $checked = '';
1924: } elsif ($settings->{$item}->{$type} == 1) {
1925: $checked = 'checked="checked" ';
1926: }
1.78 raeburn 1927: }
1.72 raeburn 1928: }
1.101 raeburn 1929: $datatable .= '<span class="LC_nobreak"><label>'.
1930: '<input type="checkbox" name="'.$context.'_'.$item.
1931: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1932: '</label></span> ';
1.72 raeburn 1933: }
1.101 raeburn 1934: }
1935: if ($context eq 'requestcourses') {
1936: $datatable .= '</tr><tr>';
1937: foreach my $item (@usertools) {
1.106 raeburn 1938: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1939: }
1940: $datatable .= '</tr></table>';
1.72 raeburn 1941: }
1.86 raeburn 1942: $datatable .= '</td>';
1.160.6.5 raeburn 1943: unless (($context eq 'requestcourses') ||
1944: ($context eq 'requestauthor')) {
1.86 raeburn 1945: $datatable .=
1.160.6.20 raeburn 1946: '<td class="LC_right_item">'.
1947: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1948: '<input type="text" name="quota_'.$type.
1.72 raeburn 1949: '" value="'.$currdefquota.
1.160.6.20 raeburn 1950: '" size="5" /></span>'.(' ' x 2).
1951: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1952: '<input type="text" name="authorquota_'.$type.
1953: '" value="'.$currauthorquota.
1954: '" size="5" /></span></td>';
1.86 raeburn 1955: }
1956: $datatable .= '</tr>';
1.3 raeburn 1957: }
1958: }
1959: }
1.160.6.5 raeburn 1960: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1961: $defaultquota = '20';
1.160.6.20 raeburn 1962: $authorquota = '500';
1.86 raeburn 1963: if (ref($settings) eq 'HASH') {
1964: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1965: $defaultquota = $settings->{'defaultquota'}->{'default'};
1966: } elsif (defined($settings->{'default'})) {
1967: $defaultquota = $settings->{'default'};
1968: }
1.160.6.20 raeburn 1969: if (ref($settings->{'authorquota'}) eq 'HASH') {
1970: $authorquota = $settings->{'authorquota'}->{'default'};
1971: }
1.3 raeburn 1972: }
1973: }
1974: $typecount ++;
1975: $css_class = $typecount%2?' class="LC_odd_row"':'';
1976: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1977: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1978: '<td class="LC_left_item">';
1.101 raeburn 1979: if ($context eq 'requestcourses') {
1980: $datatable .= '<table><tr>';
1981: }
1982: my %defcell;
1.72 raeburn 1983: foreach my $item (@usertools) {
1.101 raeburn 1984: if ($context eq 'requestcourses') {
1985: my ($curroption,$currlimit);
1986: if (ref($settings) eq 'HASH') {
1987: if (ref($settings->{$item}) eq 'HASH') {
1988: $curroption = $settings->{$item}->{'default'};
1989: if ($curroption =~ /^autolimit=(\d*)$/) {
1990: $currlimit = $1;
1991: }
1992: }
1993: }
1994: if (!$curroption) {
1995: $curroption = 'norequest';
1996: }
1997: $datatable .= '<th>'.$titles{$item}.'</th>';
1998: foreach my $option (@options) {
1999: my $val = $option;
2000: if ($option eq 'norequest') {
2001: $val = 0;
2002: }
2003: if ($option eq 'validate') {
2004: my $canvalidate = 0;
2005: if (ref($validations{$item}) eq 'HASH') {
2006: if ($validations{$item}{'default'}) {
2007: $canvalidate = 1;
2008: }
2009: }
2010: next if (!$canvalidate);
2011: }
2012: my $checked = '';
2013: if ($option eq $curroption) {
2014: $checked = ' checked="checked"';
2015: } elsif ($option eq 'autolimit') {
2016: if ($curroption =~ /^autolimit/) {
2017: $checked = ' checked="checked"';
2018: }
2019: }
2020: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2021: '<input type="radio" name="crsreq_'.$item.
2022: '_default" value="'.$val.'"'.$checked.' />'.
2023: $titles{$option}.'</label>';
2024: if ($option eq 'autolimit') {
1.127 raeburn 2025: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2026: $item.'_limit_default" size="1" '.
2027: 'value="'.$currlimit.'" />';
2028: }
1.127 raeburn 2029: $defcell{$item} .= '</span> ';
1.104 raeburn 2030: if ($option eq 'autolimit') {
1.127 raeburn 2031: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2032: }
1.101 raeburn 2033: }
1.160.6.5 raeburn 2034: } elsif ($context eq 'requestauthor') {
2035: my $curroption;
2036: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2037: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2038: }
2039: if (!$curroption) {
2040: $curroption = 'norequest';
2041: }
2042: foreach my $option (@options) {
2043: my $val = $option;
2044: if ($option eq 'norequest') {
2045: $val = 0;
2046: }
2047: my $checked = '';
2048: if ($option eq $curroption) {
2049: $checked = ' checked="checked"';
2050: }
2051: $datatable .= '<span class="LC_nobreak"><label>'.
2052: '<input type="radio" name="authorreq_default"'.
2053: ' value="'.$val.'"'.$checked.' />'.
2054: $titles{$option}.'</label></span> ';
2055: }
1.101 raeburn 2056: } else {
2057: my $checked = 'checked="checked" ';
2058: if (ref($settings) eq 'HASH') {
2059: if (ref($settings->{$item}) eq 'HASH') {
2060: if ($settings->{$item}->{'default'} == 0) {
2061: $checked = '';
2062: } elsif ($settings->{$item}->{'default'} == 1) {
2063: $checked = 'checked="checked" ';
2064: }
1.78 raeburn 2065: }
1.72 raeburn 2066: }
1.101 raeburn 2067: $datatable .= '<span class="LC_nobreak"><label>'.
2068: '<input type="checkbox" name="'.$context.'_'.$item.
2069: '" value="default" '.$checked.'/>'.$titles{$item}.
2070: '</label></span> ';
2071: }
2072: }
2073: if ($context eq 'requestcourses') {
2074: $datatable .= '</tr><tr>';
2075: foreach my $item (@usertools) {
1.106 raeburn 2076: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2077: }
1.101 raeburn 2078: $datatable .= '</tr></table>';
1.72 raeburn 2079: }
1.86 raeburn 2080: $datatable .= '</td>';
1.160.6.5 raeburn 2081: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2082: $datatable .= '<td class="LC_right_item">'.
2083: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2084: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2085: $defaultquota.'" size="5" /></span>'.(' ' x2).
2086: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2087: '<input type="text" name="authorquota" value="'.
2088: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2089: }
2090: $datatable .= '</tr>';
1.72 raeburn 2091: $typecount ++;
2092: $css_class = $typecount%2?' class="LC_odd_row"':'';
2093: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2094: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2095: if ($context eq 'requestcourses') {
1.109 raeburn 2096: $datatable .= &mt('(overrides affiliation, if set)').
2097: '</td>'.
2098: '<td class="LC_left_item">'.
2099: '<table><tr>';
1.101 raeburn 2100: } else {
1.109 raeburn 2101: $datatable .= &mt('(overrides affiliation, if checked)').
2102: '</td>'.
2103: '<td class="LC_left_item" colspan="2">'.
2104: '<br />';
1.101 raeburn 2105: }
2106: my %advcell;
1.72 raeburn 2107: foreach my $item (@usertools) {
1.101 raeburn 2108: if ($context eq 'requestcourses') {
2109: my ($curroption,$currlimit);
2110: if (ref($settings) eq 'HASH') {
2111: if (ref($settings->{$item}) eq 'HASH') {
2112: $curroption = $settings->{$item}->{'_LC_adv'};
2113: if ($curroption =~ /^autolimit=(\d*)$/) {
2114: $currlimit = $1;
2115: }
2116: }
2117: }
2118: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2119: my $checked = '';
2120: if ($curroption eq '') {
2121: $checked = ' checked="checked"';
2122: }
2123: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2124: '<input type="radio" name="crsreq_'.$item.
2125: '__LC_adv" value=""'.$checked.' />'.
2126: &mt('No override set').'</label></span> ';
1.101 raeburn 2127: foreach my $option (@options) {
2128: my $val = $option;
2129: if ($option eq 'norequest') {
2130: $val = 0;
2131: }
2132: if ($option eq 'validate') {
2133: my $canvalidate = 0;
2134: if (ref($validations{$item}) eq 'HASH') {
2135: if ($validations{$item}{'_LC_adv'}) {
2136: $canvalidate = 1;
2137: }
2138: }
2139: next if (!$canvalidate);
2140: }
2141: my $checked = '';
1.104 raeburn 2142: if ($val eq $curroption) {
1.101 raeburn 2143: $checked = ' checked="checked"';
2144: } elsif ($option eq 'autolimit') {
2145: if ($curroption =~ /^autolimit/) {
2146: $checked = ' checked="checked"';
2147: }
2148: }
2149: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2150: '<input type="radio" name="crsreq_'.$item.
2151: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2152: $titles{$option}.'</label>';
2153: if ($option eq 'autolimit') {
1.127 raeburn 2154: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2155: $item.'_limit__LC_adv" size="1" '.
2156: 'value="'.$currlimit.'" />';
2157: }
1.127 raeburn 2158: $advcell{$item} .= '</span> ';
1.104 raeburn 2159: if ($option eq 'autolimit') {
1.127 raeburn 2160: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2161: }
1.101 raeburn 2162: }
1.160.6.5 raeburn 2163: } elsif ($context eq 'requestauthor') {
2164: my $curroption;
2165: if (ref($settings) eq 'HASH') {
2166: $curroption = $settings->{'_LC_adv'};
2167: }
2168: my $checked = '';
2169: if ($curroption eq '') {
2170: $checked = ' checked="checked"';
2171: }
2172: $datatable .= '<span class="LC_nobreak"><label>'.
2173: '<input type="radio" name="authorreq__LC_adv"'.
2174: ' value=""'.$checked.' />'.
2175: &mt('No override set').'</label></span> ';
2176: foreach my $option (@options) {
2177: my $val = $option;
2178: if ($option eq 'norequest') {
2179: $val = 0;
2180: }
2181: my $checked = '';
2182: if ($val eq $curroption) {
2183: $checked = ' checked="checked"';
2184: }
2185: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2186: '<input type="radio" name="authorreq__LC_adv"'.
2187: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2188: $titles{$option}.'</label></span> ';
2189: }
1.101 raeburn 2190: } else {
2191: my $checked = 'checked="checked" ';
2192: if (ref($settings) eq 'HASH') {
2193: if (ref($settings->{$item}) eq 'HASH') {
2194: if ($settings->{$item}->{'_LC_adv'} == 0) {
2195: $checked = '';
2196: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2197: $checked = 'checked="checked" ';
2198: }
1.79 raeburn 2199: }
1.72 raeburn 2200: }
1.101 raeburn 2201: $datatable .= '<span class="LC_nobreak"><label>'.
2202: '<input type="checkbox" name="'.$context.'_'.$item.
2203: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2204: '</label></span> ';
2205: }
2206: }
2207: if ($context eq 'requestcourses') {
2208: $datatable .= '</tr><tr>';
2209: foreach my $item (@usertools) {
1.106 raeburn 2210: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2211: }
1.101 raeburn 2212: $datatable .= '</tr></table>';
1.72 raeburn 2213: }
1.98 raeburn 2214: $datatable .= '</td></tr>';
1.30 raeburn 2215: $$rowtotal += $typecount;
1.3 raeburn 2216: return $datatable;
2217: }
2218:
1.160.6.5 raeburn 2219: sub print_requestmail {
1.160.6.93 raeburn 2220: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2221: my ($now,$datatable,%currapp);
1.102 raeburn 2222: $now = time;
2223: if (ref($settings) eq 'HASH') {
2224: if (ref($settings->{'notify'}) eq 'HASH') {
2225: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2226: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2227: }
2228: }
2229: }
1.160.6.16 raeburn 2230: my $numinrow = 2;
1.160.6.34 raeburn 2231: my $css_class;
1.160.6.93 raeburn 2232: if ($$rowtotal%2) {
2233: $css_class = 'LC_odd_row';
2234: }
2235: if ($customcss) {
2236: $css_class .= " $customcss";
2237: }
2238: $css_class =~ s/^\s+//;
2239: if ($css_class) {
2240: $css_class = ' class="'.$css_class.'"';
2241: }
2242: if ($rowstyle) {
2243: $css_class .= ' style="'.$rowstyle.'"';
2244: }
1.160.6.5 raeburn 2245: my $text;
2246: if ($action eq 'requestcourses') {
2247: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2248: } elsif ($action eq 'requestauthor') {
2249: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2250: } else {
1.160.6.34 raeburn 2251: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2252: }
1.160.6.34 raeburn 2253: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2254: ' <td>'.$text.'</td>'.
1.102 raeburn 2255: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2256: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2257: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2258: if ($numdc > 0) {
2259: $datatable .= $table;
1.102 raeburn 2260: } else {
2261: $datatable .= &mt('There are no active Domain Coordinators');
2262: }
2263: $datatable .='</td></tr>';
2264: return $datatable;
2265: }
2266:
1.160.6.30 raeburn 2267: sub print_studentcode {
2268: my ($settings,$rowtotal) = @_;
2269: my $rownum = 0;
2270: my ($output,%current);
2271: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2272: if (ref($settings) eq 'HASH') {
2273: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2274: foreach my $type (@crstypes) {
2275: $current{$type} = $settings->{'uniquecode'}{$type};
2276: }
1.160.6.30 raeburn 2277: }
2278: }
2279: $output .= '<tr>'.
2280: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2281: '<td class="LC_left_item">';
2282: foreach my $type (@crstypes) {
2283: my $check = ' ';
2284: if ($current{$type}) {
2285: $check = ' checked="checked" ';
2286: }
2287: $output .= '<span class="LC_nobreak"><label>'.
2288: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2289: &mt($type).'</label></span>'.(' 'x2).' ';
2290: }
2291: $output .= '</td></tr>';
2292: $$rowtotal ++;
2293: return $output;
2294: }
2295:
2296: sub print_textbookcourses {
1.160.6.46 raeburn 2297: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2298: my $rownum = 0;
2299: my $css_class;
2300: my $itemcount = 1;
2301: my $maxnum = 0;
2302: my $bookshash;
2303: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2304: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2305: }
2306: my %ordered;
2307: if (ref($bookshash) eq 'HASH') {
2308: foreach my $item (keys(%{$bookshash})) {
2309: if (ref($bookshash->{$item}) eq 'HASH') {
2310: my $num = $bookshash->{$item}{'order'};
2311: $ordered{$num} = $item;
2312: }
2313: }
2314: }
2315: my $confname = $dom.'-domainconfig';
2316: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2317: my $maxnum = scalar(keys(%ordered));
2318: my $datatable;
1.160.6.30 raeburn 2319: if (keys(%ordered)) {
2320: my @items = sort { $a <=> $b } keys(%ordered);
2321: for (my $i=0; $i<@items; $i++) {
2322: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2323: my $key = $ordered{$items[$i]};
2324: my %coursehash=&Apache::lonnet::coursedescription($key);
2325: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2326: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2327: if (ref($bookshash->{$key}) eq 'HASH') {
2328: $subject = $bookshash->{$key}->{'subject'};
2329: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2330: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2331: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2332: $author = $bookshash->{$key}->{'author'};
2333: $image = $bookshash->{$key}->{'image'};
2334: if ($image ne '') {
2335: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2336: my $imagethumb = "$path/tn-".$imagefile;
2337: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2338: }
1.160.6.30 raeburn 2339: }
2340: }
1.160.6.46 raeburn 2341: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2342: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2343: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2344: for (my $k=0; $k<=$maxnum; $k++) {
2345: my $vpos = $k+1;
2346: my $selstr;
2347: if ($k == $i) {
2348: $selstr = ' selected="selected" ';
2349: }
2350: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2351: }
2352: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2353: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2354: &mt('Delete?').'</label></span></td>'.
2355: '<td colspan="2">'.
1.160.6.46 raeburn 2356: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2357: (' 'x2).
1.160.6.46 raeburn 2358: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2359: if ($type eq 'textbooks') {
2360: $datatable .= (' 'x2).
1.160.6.47 raeburn 2361: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2362: (' 'x2).
1.160.6.46 raeburn 2363: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2364: (' 'x2).
2365: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2366: if ($image) {
2367: $datatable .= '<span class="LC_nobreak">'.
2368: $imgsrc.
2369: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2370: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2371: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2372: }
2373: if ($switchserver) {
2374: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2375: } else {
2376: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2377: }
1.160.6.30 raeburn 2378: }
1.160.6.46 raeburn 2379: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2380: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2381: $coursetitle.'</span></td></tr>'."\n";
2382: $itemcount ++;
2383: }
2384: }
2385: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2386: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2387: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2388: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2389: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2390: for (my $k=0; $k<$maxnum+1; $k++) {
2391: my $vpos = $k+1;
2392: my $selstr;
2393: if ($k == $maxnum) {
2394: $selstr = ' selected="selected" ';
2395: }
2396: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2397: }
2398: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2399: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2400: '<td colspan="2">'.
1.160.6.46 raeburn 2401: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2402: (' 'x2).
1.160.6.46 raeburn 2403: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2404: (' 'x2);
2405: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2406: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2407: (' 'x2).
2408: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2409: (' 'x2).
2410: '<span class="LC_nobreak">'.&mt('Image:').' ';
2411: if ($switchserver) {
2412: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2413: } else {
2414: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2415: }
1.160.6.87 raeburn 2416: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2417: }
1.160.6.87 raeburn 2418: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2419: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2420: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2421: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2422: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2423: '</span></td>'."\n".
2424: '</tr>'."\n";
2425: $itemcount ++;
2426: return $datatable;
2427: }
2428:
2429: sub textbookcourses_javascript {
1.160.6.46 raeburn 2430: my ($settings) = @_;
2431: return unless(ref($settings) eq 'HASH');
2432: my (%ordered,%total,%jstext);
2433: foreach my $type ('textbooks','templates') {
2434: $total{$type} = 0;
2435: if (ref($settings->{$type}) eq 'HASH') {
2436: foreach my $item (keys(%{$settings->{$type}})) {
2437: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2438: my $num = $settings->{$type}->{$item}{'order'};
2439: $ordered{$type}{$num} = $item;
2440: }
2441: }
2442: $total{$type} = scalar(keys(%{$settings->{$type}}));
2443: }
2444: my @jsarray = ();
2445: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2446: push(@jsarray,$ordered{$type}{$item});
2447: }
2448: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2449: }
2450: return <<"ENDSCRIPT";
2451: <script type="text/javascript">
2452: // <![CDATA[
1.160.6.46 raeburn 2453: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2454: var changedVal;
1.160.6.46 raeburn 2455: $jstext{'textbooks'};
2456: $jstext{'templates'};
2457: var newpos;
2458: var maxh;
2459: if (caller == 'textbooks') {
2460: newpos = 'textbooks_addbook_pos';
2461: maxh = 1 + $total{'textbooks'};
2462: } else {
2463: newpos = 'templates_addbook_pos';
2464: maxh = 1 + $total{'templates'};
2465: }
1.160.6.30 raeburn 2466: var current = new Array;
2467: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2468: if (item == newpos) {
2469: changedVal = newitemVal;
2470: } else {
2471: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2472: current[newitemVal] = newpos;
2473: }
1.160.6.46 raeburn 2474: if (caller == 'textbooks') {
2475: for (var i=0; i<textbooks.length; i++) {
2476: var elementName = 'textbooks_'+textbooks[i];
2477: if (elementName != item) {
2478: if (form.elements[elementName]) {
2479: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2480: current[currVal] = elementName;
2481: }
2482: }
2483: }
2484: }
2485: if (caller == 'templates') {
2486: for (var i=0; i<templates.length; i++) {
2487: var elementName = 'templates_'+templates[i];
2488: if (elementName != item) {
2489: if (form.elements[elementName]) {
2490: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2491: current[currVal] = elementName;
2492: }
1.160.6.30 raeburn 2493: }
2494: }
2495: }
2496: var oldVal;
2497: for (var j=0; j<maxh; j++) {
2498: if (current[j] == undefined) {
2499: oldVal = j;
2500: }
2501: }
2502: if (oldVal < changedVal) {
2503: for (var k=oldVal+1; k<=changedVal ; k++) {
2504: var elementName = current[k];
2505: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2506: }
2507: } else {
2508: for (var k=changedVal; k<oldVal; k++) {
2509: var elementName = current[k];
2510: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2511: }
2512: }
2513: return;
2514: }
2515:
2516: // ]]>
2517: </script>
2518:
2519: ENDSCRIPT
2520: }
2521:
1.160.6.102.2 1(raebur 2522:0): sub ltitools_javascript {
2523:0): my ($settings) = @_;
2524:0): return unless(ref($settings) eq 'HASH');
2525:0): my (%ordered,$total,%jstext);
2526:0): $total = 0;
2527:0): foreach my $item (keys(%{$settings})) {
2528:0): if (ref($settings->{$item}) eq 'HASH') {
2529:0): my $num = $settings->{$item}{'order'};
2530:0): $ordered{$num} = $item;
2531:0): }
2532:0): }
2533:0): $total = scalar(keys(%{$settings}));
2534:0): my @jsarray = ();
2535:0): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2536:0): push(@jsarray,$ordered{$item});
2537:0): }
2538:0): my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2539:0): return <<"ENDSCRIPT";
2540:0): <script type="text/javascript">
2541:0): // <![CDATA[
2542:0): function reorderLTI(form,item) {
2543:0): var changedVal;
2544:0): $jstext
2545:0): var newpos = 'ltitools_add_pos';
2546:0): var maxh = 1 + $total;
2547:0): var current = new Array;
2548:0): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2549:0): if (item == newpos) {
2550:0): changedVal = newitemVal;
2551:0): } else {
2552:0): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2553:0): current[newitemVal] = newpos;
2554:0): }
2555:0): for (var i=0; i<ltitools.length; i++) {
2556:0): var elementName = 'ltitools_'+ltitools[i];
2557:0): if (elementName != item) {
2558:0): if (form.elements[elementName]) {
2559:0): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2560:0): current[currVal] = elementName;
2561:0): }
2562:0): }
2563:0): }
2564:0): var oldVal;
2565:0): for (var j=0; j<maxh; j++) {
2566:0): if (current[j] == undefined) {
2567:0): oldVal = j;
2568:0): }
2569:0): }
2570:0): if (oldVal < changedVal) {
2571:0): for (var k=oldVal+1; k<=changedVal ; k++) {
2572:0): var elementName = current[k];
2573:0): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2574:0): }
2575:0): } else {
2576:0): for (var k=changedVal; k<oldVal; k++) {
2577:0): var elementName = current[k];
2578:0): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2579:0): }
2580:0): }
2581:0): return;
2582:0): }
2583:0):
2584:0): // ]]>
2585:0): </script>
2586:0):
2587:0): ENDSCRIPT
2588:0): }
2589:0):
1.3 raeburn 2590: sub print_autoenroll {
1.30 raeburn 2591: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2592: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2593: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2594: if (ref($settings) eq 'HASH') {
2595: if (exists($settings->{'run'})) {
2596: if ($settings->{'run'} eq '0') {
2597: $runoff = ' checked="checked" ';
2598: $runon = ' ';
2599: } else {
2600: $runon = ' checked="checked" ';
2601: $runoff = ' ';
2602: }
2603: } else {
2604: if ($autorun) {
2605: $runon = ' checked="checked" ';
2606: $runoff = ' ';
2607: } else {
2608: $runoff = ' checked="checked" ';
2609: $runon = ' ';
2610: }
2611: }
1.129 raeburn 2612: if (exists($settings->{'co-owners'})) {
2613: if ($settings->{'co-owners'} eq '0') {
2614: $coownersoff = ' checked="checked" ';
2615: $coownerson = ' ';
2616: } else {
2617: $coownerson = ' checked="checked" ';
2618: $coownersoff = ' ';
2619: }
2620: } else {
2621: $coownersoff = ' checked="checked" ';
2622: $coownerson = ' ';
2623: }
1.3 raeburn 2624: if (exists($settings->{'sender_domain'})) {
2625: $defdom = $settings->{'sender_domain'};
2626: }
1.160.6.68 raeburn 2627: if (exists($settings->{'autofailsafe'})) {
2628: $failsafe = $settings->{'autofailsafe'};
2629: }
1.14 raeburn 2630: } else {
2631: if ($autorun) {
2632: $runon = ' checked="checked" ';
2633: $runoff = ' ';
2634: } else {
2635: $runoff = ' checked="checked" ';
2636: $runon = ' ';
2637: }
1.3 raeburn 2638: }
2639: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2640: my $notif_sender;
2641: if (ref($settings) eq 'HASH') {
2642: $notif_sender = $settings->{'sender_uname'};
2643: }
1.3 raeburn 2644: my $datatable='<tr class="LC_odd_row">'.
2645: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2646: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2647: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2648: $runon.' value="1" />'.&mt('Yes').'</label> '.
2649: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2650: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2651: '</tr><tr>'.
2652: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2653: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2654: &mt('username').': '.
2655: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2656: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2657: ': '.$domform.'</span></td></tr>'.
2658: '<tr class="LC_odd_row">'.
2659: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2660: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2661: '<input type="radio" name="autoassign_coowners"'.
2662: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2663: '<label><input type="radio" name="autoassign_coowners"'.
2664: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2665: '</tr><tr>'.
2666: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2667: '<td class="LC_right_item"><span class="LC_nobreak">'.
2668: '<input type="text" name="autoenroll_failsafe"'.
1.160.6.87 raeburn 2669: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.160.6.68 raeburn 2670: $$rowtotal += 4;
1.3 raeburn 2671: return $datatable;
2672: }
2673:
2674: sub print_autoupdate {
1.30 raeburn 2675: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2676: my $datatable;
2677: if ($position eq 'top') {
2678: my $updateon = ' ';
2679: my $updateoff = ' checked="checked" ';
2680: my $classlistson = ' ';
2681: my $classlistsoff = ' checked="checked" ';
2682: if (ref($settings) eq 'HASH') {
2683: if ($settings->{'run'} eq '1') {
2684: $updateon = $updateoff;
2685: $updateoff = ' ';
2686: }
2687: if ($settings->{'classlists'} eq '1') {
2688: $classlistson = $classlistsoff;
2689: $classlistsoff = ' ';
2690: }
2691: }
2692: my %title = (
2693: run => 'Auto-update active?',
2694: classlists => 'Update information in classlists?',
2695: );
2696: $datatable = '<tr class="LC_odd_row">'.
2697: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2698: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2699: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2700: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2701: '<label><input type="radio" name="autoupdate_run"'.
2702: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2703: '</tr><tr>'.
2704: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2705: '<td class="LC_right_item"><span class="LC_nobreak">'.
2706: '<label><input type="radio" name="classlists"'.
2707: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2708: '<label><input type="radio" name="classlists"'.
2709: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2710: '</tr>';
1.30 raeburn 2711: $$rowtotal += 2;
1.131 raeburn 2712: } elsif ($position eq 'middle') {
2713: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2714: my $numinrow = 3;
2715: my $locknamesettings;
2716: $datatable .= &insttypes_row($settings,$types,$usertypes,
2717: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 2718: 'lockablenames',$rowtotal);
1.131 raeburn 2719: $$rowtotal ++;
1.3 raeburn 2720: } else {
1.44 raeburn 2721: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2722: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2723: 'permanentemail','id');
1.33 raeburn 2724: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2725: my $numrows = 0;
1.26 raeburn 2726: if (ref($types) eq 'ARRAY') {
2727: if (@{$types} > 0) {
2728: $datatable =
2729: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2730: \@fields,$types,\$numrows);
1.30 raeburn 2731: $$rowtotal += @{$types};
1.26 raeburn 2732: }
1.3 raeburn 2733: }
2734: $datatable .=
2735: &usertype_update_row($settings,{'default' => $othertitle},
2736: \%fieldtitles,\@fields,['default'],
2737: \$numrows);
1.30 raeburn 2738: $$rowtotal ++;
1.3 raeburn 2739: }
2740: return $datatable;
2741: }
2742:
1.125 raeburn 2743: sub print_autocreate {
2744: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2745: my (%createon,%createoff,%currhash);
1.125 raeburn 2746: my @types = ('xml','req');
2747: if (ref($settings) eq 'HASH') {
2748: foreach my $item (@types) {
2749: $createoff{$item} = ' checked="checked" ';
2750: $createon{$item} = ' ';
2751: if (exists($settings->{$item})) {
2752: if ($settings->{$item}) {
2753: $createon{$item} = ' checked="checked" ';
2754: $createoff{$item} = ' ';
2755: }
2756: }
2757: }
1.160.6.16 raeburn 2758: if ($settings->{'xmldc'} ne '') {
2759: $currhash{$settings->{'xmldc'}} = 1;
2760: }
1.125 raeburn 2761: } else {
2762: foreach my $item (@types) {
2763: $createoff{$item} = ' checked="checked" ';
2764: $createon{$item} = ' ';
2765: }
2766: }
2767: $$rowtotal += 2;
1.160.6.16 raeburn 2768: my $numinrow = 2;
1.125 raeburn 2769: my $datatable='<tr class="LC_odd_row">'.
2770: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2771: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2772: '<input type="radio" name="autocreate_xml"'.
2773: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2774: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2775: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2776: '</td></tr><tr>'.
2777: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2778: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2779: '<input type="radio" name="autocreate_req"'.
2780: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2781: '<label><input type="radio" name="autocreate_req"'.
2782: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2783: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2784: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2785: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2786: if ($numdc > 1) {
1.160.6.50 raeburn 2787: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2788: '</td><td class="LC_left_item">';
1.125 raeburn 2789: } else {
1.160.6.50 raeburn 2790: $datatable .= &mt('Course creation processed as:').
2791: '</td><td class="LC_right_item">';
1.125 raeburn 2792: }
1.160.6.50 raeburn 2793: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2794: $$rowtotal += $rows;
1.125 raeburn 2795: return $datatable;
2796: }
2797:
1.23 raeburn 2798: sub print_directorysrch {
1.160.6.72 raeburn 2799: my ($position,$dom,$settings,$rowtotal) = @_;
2800: my $datatable;
2801: if ($position eq 'top') {
2802: my $instsrchon = ' ';
2803: my $instsrchoff = ' checked="checked" ';
2804: my ($exacton,$containson,$beginson);
2805: my $instlocalon = ' ';
2806: my $instlocaloff = ' checked="checked" ';
2807: if (ref($settings) eq 'HASH') {
2808: if ($settings->{'available'} eq '1') {
2809: $instsrchon = $instsrchoff;
2810: $instsrchoff = ' ';
2811: }
2812: if ($settings->{'localonly'} eq '1') {
2813: $instlocalon = $instlocaloff;
2814: $instlocaloff = ' ';
2815: }
2816: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2817: foreach my $type (@{$settings->{'searchtypes'}}) {
2818: if ($type eq 'exact') {
2819: $exacton = ' checked="checked" ';
2820: } elsif ($type eq 'contains') {
2821: $containson = ' checked="checked" ';
2822: } elsif ($type eq 'begins') {
2823: $beginson = ' checked="checked" ';
2824: }
2825: }
2826: } else {
2827: if ($settings->{'searchtypes'} eq 'exact') {
2828: $exacton = ' checked="checked" ';
2829: } elsif ($settings->{'searchtypes'} eq 'contains') {
2830: $containson = ' checked="checked" ';
2831: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2832: $exacton = ' checked="checked" ';
2833: $containson = ' checked="checked" ';
2834: }
2835: }
1.23 raeburn 2836: }
1.160.6.72 raeburn 2837: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2838: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2839:
1.160.6.72 raeburn 2840: my $numinrow = 4;
2841: my $cansrchrow = 0;
2842: $datatable='<tr class="LC_odd_row">'.
2843: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2844: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2845: '<input type="radio" name="dirsrch_available"'.
2846: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2847: '<label><input type="radio" name="dirsrch_available"'.
2848: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2849: '</tr><tr>'.
2850: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2851: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2852: '<input type="radio" name="dirsrch_instlocalonly"'.
2853: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2854: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2855: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2856: '</tr>';
2857: $$rowtotal += 2;
2858: if (ref($usertypes) eq 'HASH') {
2859: if (keys(%{$usertypes}) > 0) {
2860: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 2861: $numinrow,$othertitle,'cansearch',
2862: $rowtotal);
1.160.6.72 raeburn 2863: $cansrchrow = 1;
2864: }
1.26 raeburn 2865: }
1.160.6.72 raeburn 2866: if ($cansrchrow) {
2867: $$rowtotal ++;
2868: $datatable .= '<tr>';
2869: } else {
2870: $datatable .= '<tr class="LC_odd_row">';
2871: }
2872: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2873: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2874: foreach my $title (@{$titleorder}) {
2875: if (defined($searchtitles->{$title})) {
2876: my $check = ' ';
2877: if (ref($settings) eq 'HASH') {
2878: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2879: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2880: $check = ' checked="checked" ';
2881: }
1.39 raeburn 2882: }
1.25 raeburn 2883: }
1.160.6.72 raeburn 2884: $datatable .= '<td class="LC_left_item">'.
2885: '<span class="LC_nobreak"><label>'.
2886: '<input type="checkbox" name="searchby" '.
2887: 'value="'.$title.'"'.$check.'/>'.
2888: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2889: }
2890: }
1.160.6.72 raeburn 2891: $datatable .= '</tr></table></td></tr>';
2892: $$rowtotal ++;
2893: if ($cansrchrow) {
2894: $datatable .= '<tr class="LC_odd_row">';
2895: } else {
2896: $datatable .= '<tr>';
2897: }
2898: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2899: '<td class="LC_left_item" colspan="2">'.
2900: '<span class="LC_nobreak"><label>'.
2901: '<input type="checkbox" name="searchtypes" '.
2902: $exacton.' value="exact" />'.&mt('Exact match').
2903: '</label> '.
2904: '<label><input type="checkbox" name="searchtypes" '.
2905: $beginson.' value="begins" />'.&mt('Begins with').
2906: '</label> '.
2907: '<label><input type="checkbox" name="searchtypes" '.
2908: $containson.' value="contains" />'.&mt('Contains').
2909: '</label></span></td></tr>';
2910: $$rowtotal ++;
1.26 raeburn 2911: } else {
1.160.6.72 raeburn 2912: my $domsrchon = ' checked="checked" ';
2913: my $domsrchoff = ' ';
2914: my $domlocalon = ' ';
2915: my $domlocaloff = ' checked="checked" ';
2916: if (ref($settings) eq 'HASH') {
2917: if ($settings->{'lclocalonly'} eq '1') {
2918: $domlocalon = $domlocaloff;
2919: $domlocaloff = ' ';
2920: }
2921: if ($settings->{'lcavailable'} eq '0') {
2922: $domsrchoff = $domsrchon;
2923: $domsrchon = ' ';
2924: }
2925: }
2926: $datatable='<tr class="LC_odd_row">'.
2927: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2928: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2929: '<input type="radio" name="dirsrch_domavailable"'.
2930: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2931: '<label><input type="radio" name="dirsrch_domavailable"'.
2932: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2933: '</tr><tr>'.
2934: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2935: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2936: '<input type="radio" name="dirsrch_domlocalonly"'.
2937: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2938: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2939: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2940: '</tr>';
2941: $$rowtotal += 2;
1.26 raeburn 2942: }
1.25 raeburn 2943: return $datatable;
2944: }
2945:
1.28 raeburn 2946: sub print_contacts {
1.160.6.78 raeburn 2947: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2948: my $datatable;
2949: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 2950: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2951: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
2952: if ($position eq 'top') {
2953: if (ref($settings) eq 'HASH') {
2954: foreach my $item (@contacts) {
2955: if (exists($settings->{$item})) {
2956: $to{$item} = $settings->{$item};
2957: }
1.28 raeburn 2958: }
2959: }
1.160.6.78 raeburn 2960: } elsif ($position eq 'middle') {
2961: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 2962: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 2963: foreach my $type (@mailings) {
1.160.6.78 raeburn 2964: $otheremails{$type} = '';
2965: }
2966: } else {
2967: @mailings = ('helpdeskmail','otherdomsmail');
2968: foreach my $type (@mailings) {
2969: $otheremails{$type} = '';
2970: }
2971: $bccemails{'helpdeskmail'} = '';
2972: $bccemails{'otherdomsmail'} = '';
2973: $includestr{'helpdeskmail'} = '';
2974: $includestr{'otherdomsmail'} = '';
2975: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
2976: }
2977: if (ref($settings) eq 'HASH') {
2978: unless ($position eq 'top') {
2979: foreach my $type (@mailings) {
2980: if (exists($settings->{$type})) {
2981: if (ref($settings->{$type}) eq 'HASH') {
2982: foreach my $item (@contacts) {
2983: if ($settings->{$type}{$item}) {
2984: $checked{$type}{$item} = ' checked="checked" ';
2985: }
1.28 raeburn 2986: }
1.160.6.78 raeburn 2987: $otheremails{$type} = $settings->{$type}{'others'};
2988: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2989: $bccemails{$type} = $settings->{$type}{'bcc'};
2990: if ($settings->{$type}{'include'} ne '') {
2991: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2992: $includestr{$type} = &unescape($includestr{$type});
2993: }
2994: }
2995: }
2996: } elsif ($type eq 'lonstatusmail') {
2997: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2998: }
2999: }
3000: }
3001: if ($position eq 'bottom') {
3002: foreach my $type (@mailings) {
3003: $bccemails{$type} = $settings->{$type}{'bcc'};
3004: if ($settings->{$type}{'include'} ne '') {
3005: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3006: $includestr{$type} = &unescape($includestr{$type});
3007: }
3008: }
3009: if (ref($settings->{'helpform'}) eq 'HASH') {
3010: if (ref($fields) eq 'ARRAY') {
3011: foreach my $field (@{$fields}) {
3012: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3013: }
1.160.6.78 raeburn 3014: }
3015: if (exists($settings->{'helpform'}{'maxsize'})) {
3016: $maxsize = $settings->{'helpform'}{'maxsize'};
3017: } else {
3018: $maxsize = '1.0';
3019: }
3020: } else {
3021: if (ref($fields) eq 'ARRAY') {
3022: foreach my $field (@{$fields}) {
3023: $currfield{$field} = 'yes';
1.134 raeburn 3024: }
1.28 raeburn 3025: }
1.160.6.78 raeburn 3026: $maxsize = '1.0';
1.28 raeburn 3027: }
3028: }
3029: } else {
1.160.6.78 raeburn 3030: if ($position eq 'top') {
3031: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3032: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3033: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3034: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3035: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3036: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3037: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3038: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 3039: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 3040: } elsif ($position eq 'bottom') {
3041: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3042: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3043: if (ref($fields) eq 'ARRAY') {
3044: foreach my $field (@{$fields}) {
3045: $currfield{$field} = 'yes';
3046: }
3047: }
3048: $maxsize = '1.0';
3049: }
1.28 raeburn 3050: }
3051: my ($titles,$short_titles) = &contact_titles();
3052: my $rownum = 0;
3053: my $css_class;
1.160.6.78 raeburn 3054: if ($position eq 'top') {
3055: foreach my $item (@contacts) {
3056: $css_class = $rownum%2?' class="LC_odd_row"':'';
3057: $datatable .= '<tr'.$css_class.'>'.
3058: '<td><span class="LC_nobreak">'.$titles->{$item}.
3059: '</span></td><td class="LC_right_item">'.
3060: '<input type="text" name="'.$item.'" value="'.
3061: $to{$item}.'" /></td></tr>';
3062: $rownum ++;
3063: }
1.160.6.101 raeburn 3064: } elsif ($position eq 'bottom') {
3065: $css_class = $rownum%2?' class="LC_odd_row"':'';
3066: $datatable .= '<tr'.$css_class.'>'.
3067: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3068: &mt('(e-mail, subject, and description always shown)').
3069: '</td><td class="LC_left_item">';
3070: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3071: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3072: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3073: foreach my $field (@{$fields}) {
3074: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3075: if (($field eq 'screenshot') || ($field eq 'cc')) {
3076: $datatable .= ' '.&mt('(logged-in users)');
3077: }
3078: $datatable .='</td><td>';
3079: my $clickaction;
3080: if ($field eq 'screenshot') {
3081: $clickaction = ' onclick="screenshotSize(this);"';
3082: }
3083: if (ref($possoptions->{$field}) eq 'ARRAY') {
3084: foreach my $option (@{$possoptions->{$field}}) {
3085: my $checked;
3086: if ($currfield{$field} eq $option) {
3087: $checked = ' checked="checked"';
3088: }
3089: $datatable .= '<span class="LC_nobreak"><label>'.
3090: '<input type="radio" name="helpform_'.$field.'" '.
3091: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3092: '</label></span>'.(' 'x2);
3093: }
3094: }
3095: if ($field eq 'screenshot') {
3096: my $display;
3097: if ($currfield{$field} eq 'no') {
3098: $display = ' style="display:none"';
3099: }
3100: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
3101: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3102: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3103: }
3104: $datatable .= '</td></tr>';
3105: }
3106: $datatable .= '</table>';
3107: }
3108: $datatable .= '</td></tr>'."\n";
3109: $rownum ++;
3110: }
3111: unless ($position eq 'top') {
1.160.6.78 raeburn 3112: foreach my $type (@mailings) {
3113: $css_class = $rownum%2?' class="LC_odd_row"':'';
3114: $datatable .= '<tr'.$css_class.'>'.
3115: '<td><span class="LC_nobreak">'.
3116: $titles->{$type}.': </span></td>'.
3117: '<td class="LC_left_item">';
3118: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3119: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3120: }
3121: $datatable .= '<span class="LC_nobreak">';
3122: foreach my $item (@contacts) {
3123: $datatable .= '<label>'.
3124: '<input type="checkbox" name="'.$type.'"'.
3125: $checked{$type}{$item}.
3126: ' value="'.$item.'" />'.$short_titles->{$item}.
3127: '</label> ';
3128: }
3129: $datatable .= '</span><br />'.&mt('Others').': '.
3130: '<input type="text" name="'.$type.'_others" '.
3131: 'value="'.$otheremails{$type}.'" />';
3132: my %locchecked;
3133: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3134: foreach my $loc ('s','b') {
3135: if ($includeloc{$type} eq $loc) {
3136: $locchecked{$loc} = ' checked="checked"';
3137: last;
3138: }
3139: }
3140: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3141: '<input type="text" name="'.$type.'_bcc" '.
3142: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3143: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3144: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 3145: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 3146: '<span class="LC_nobreak">'.&mt('Location:').' '.
3147: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3148: (' 'x2).
3149: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3150: '</span></fieldset>';
3151: }
3152: $datatable .= '</td></tr>'."\n";
3153: $rownum ++;
3154: }
1.28 raeburn 3155: }
1.160.6.78 raeburn 3156: if ($position eq 'middle') {
3157: my %choices;
3158: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
3159: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3160: &mt('LON-CAPA core group - MSU'),600,500));
3161: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3162: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3163: &mt('LON-CAPA core group - MSU'),600,500));
3164: my @toggles = ('reporterrors','reportupdates');
3165: my %defaultchecked = ('reporterrors' => 'on',
3166: 'reportupdates' => 'on');
3167: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3168: \%choices,$rownum);
3169: $datatable .= $reports;
3170: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 3171: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3172: my (@posstypes,%usertypeshash);
3173: if (ref($types) eq 'ARRAY') {
3174: @posstypes = @{$types};
3175: }
3176: if (@posstypes) {
3177: if (ref($usertypes) eq 'HASH') {
3178: %usertypeshash = %{$usertypes};
3179: }
3180: my @overridden;
3181: my $numinrow = 4;
3182: if (ref($settings) eq 'HASH') {
3183: if (ref($settings->{'overrides'}) eq 'HASH') {
3184: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3185: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3186: push(@overridden,$key);
3187: foreach my $item (@contacts) {
3188: if ($settings->{'overrides'}{$key}{$item}) {
3189: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3190: }
3191: }
3192: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3193: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3194: $includeloc{'override_'.$key} = '';
3195: $includestr{'override_'.$key} = '';
3196: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3197: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3198: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3199: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3200: }
1.160.6.78 raeburn 3201: }
3202: }
3203: }
1.160.6.101 raeburn 3204: }
3205: my $customclass = 'LC_helpdesk_override';
3206: my $optionsprefix = 'LC_options_helpdesk_';
3207:
3208: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3209:
3210: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3211: $numinrow,$othertitle,'overrides',
3212: \$rownum,$onclicktypes,$customclass);
3213: $rownum ++;
3214: $usertypeshash{'default'} = $othertitle;
3215: foreach my $status (@posstypes) {
3216: my $css_class;
3217: if ($rownum%2) {
3218: $css_class = 'LC_odd_row ';
3219: }
3220: $css_class .= $customclass;
3221: my $rowid = $optionsprefix.$status;
3222: my $hidden = 1;
3223: my $currstyle = 'display:none';
3224: if (grep(/^\Q$status\E$/,@overridden)) {
3225: $currstyle = 'display:table-row';
3226: $hidden = 0;
3227: }
3228: my $key = 'override_'.$status;
3229: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3230: $includeloc{$key},$includestr{$key},$status,$rowid,
3231: $usertypeshash{$status},$css_class,$currstyle,
3232: \@contacts,$short_titles);
3233: unless ($hidden) {
3234: $rownum ++;
1.160.6.78 raeburn 3235: }
3236: }
1.134 raeburn 3237: }
1.28 raeburn 3238: }
1.30 raeburn 3239: $$rowtotal += $rownum;
1.28 raeburn 3240: return $datatable;
3241: }
3242:
1.160.6.101 raeburn 3243: sub overridden_helpdesk {
3244: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3245: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3246: my $class = 'LC_left_item';
3247: if ($css_class) {
3248: $css_class = ' class="'.$css_class.'"';
3249: }
3250: if ($rowid) {
3251: $rowid = ' id="'.$rowid.'"';
3252: }
3253: if ($rowstyle) {
3254: $rowstyle = ' style="'.$rowstyle.'"';
3255: }
3256: my ($output,$description);
3257: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3258: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3259: "<td>$description</td>\n".
3260: '<td class="'.$class.'" colspan="2">'.
3261: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3262: '<span class="LC_nobreak">';
3263: if (ref($contacts) eq 'ARRAY') {
3264: foreach my $item (@{$contacts}) {
3265: my $check;
3266: if (ref($checked) eq 'HASH') {
3267: $check = $checked->{$item};
3268: }
3269: my $title;
3270: if (ref($short_titles) eq 'HASH') {
3271: $title = $short_titles->{$item};
3272: }
3273: $output .= '<label>'.
3274: '<input type="checkbox" name="override_'.$type.'"'.$check.
3275: ' value="'.$item.'" />'.$title.'</label> ';
3276: }
3277: }
3278: $output .= '</span><br />'.&mt('Others').': '.
3279: '<input type="text" name="override_'.$type.'_others" '.
3280: 'value="'.$otheremails.'" />';
3281: my %locchecked;
3282: foreach my $loc ('s','b') {
3283: if ($includeloc eq $loc) {
3284: $locchecked{$loc} = ' checked="checked"';
3285: last;
3286: }
3287: }
3288: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3289: '<input type="text" name="override_'.$type.'_bcc" '.
3290: 'value="'.$bccemails.'" /></fieldset>'.
3291: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3292: &mt('Text automatically added to e-mail:').' '.
3293: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
3294: '<span class="LC_nobreak">'.&mt('Location:').' '.
3295: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3296: (' 'x2).
3297: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3298: '</span></fieldset>'.
3299: '</td></tr>'."\n";
3300: return $output;
3301: }
3302:
1.160.6.78 raeburn 3303: sub contacts_javascript {
3304: return <<"ENDSCRIPT";
3305:
3306: <script type="text/javascript">
3307: // <![CDATA[
3308:
3309: function screenshotSize(field) {
3310: if (document.getElementById('help_screenshotsize')) {
3311: if (field.value == 'no') {
3312: document.getElementById('help_screenshotsize').style.display="none";
3313: } else {
3314: document.getElementById('help_screenshotsize').style.display="";
3315: }
3316: }
3317: return;
3318: }
3319:
1.160.6.101 raeburn 3320: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3321: if (form.elements[checkbox].length != undefined) {
3322: var count = 0;
3323: if (docount) {
3324: for (var i=0; i<form.elements[checkbox].length; i++) {
3325: if (form.elements[checkbox][i].checked) {
3326: count ++;
3327: }
3328: }
3329: }
3330: for (var i=0; i<form.elements[checkbox].length; i++) {
3331: var type = form.elements[checkbox][i].value;
3332: if (document.getElementById(prefix+type)) {
3333: if (form.elements[checkbox][i].checked) {
3334: document.getElementById(prefix+type).style.display = 'table-row';
3335: if (count % 2 == 1) {
3336: document.getElementById(prefix+type).className = target+' LC_odd_row';
3337: } else {
3338: document.getElementById(prefix+type).className = target;
3339: }
3340: count ++;
3341: } else {
3342: document.getElementById(prefix+type).style.display = 'none';
3343: }
3344: }
3345: }
3346: }
3347: return;
3348: }
3349:
1.160.6.78 raeburn 3350: // ]]>
3351: </script>
3352:
3353: ENDSCRIPT
3354: }
3355:
1.118 jms 3356: sub print_helpsettings {
1.160.6.73 raeburn 3357: my ($position,$dom,$settings,$rowtotal) = @_;
3358: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3359: my $formname = 'display';
1.160.6.5 raeburn 3360: my ($datatable,$itemcount);
1.160.6.73 raeburn 3361: if ($position eq 'top') {
3362: $itemcount = 1;
3363: my (%choices,%defaultchecked,@toggles);
3364: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3365: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3366: &mt('LON-CAPA bug tracker'),600,500));
3367: %defaultchecked = ('submitbugs' => 'on');
3368: @toggles = ('submitbugs');
3369: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3370: \%choices,$itemcount);
3371: $$rowtotal ++;
3372: } else {
3373: my $css_class;
3374: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3375: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 3376: if (ref($settings) eq 'HASH') {
3377: if (ref($settings->{'adhoc'}) eq 'HASH') {
3378: %current = %{$settings->{'adhoc'}};
3379: }
1.160.6.77 raeburn 3380: }
3381: my $count = 0;
3382: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3383: if ($key=~/^rolesdef\_(\w+)$/) {
3384: my $rolename = $1;
1.160.6.77 raeburn 3385: my (%privs,$order);
1.160.6.73 raeburn 3386: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3387: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3388: if (ref($current{$rolename}) eq 'HASH') {
3389: $order = $current{$rolename}{'order'};
3390: }
3391: if ($order eq '') {
3392: $order = $count;
3393: }
3394: $ordered{$order} = $rolename;
3395: $count++;
1.160.6.73 raeburn 3396: }
3397: }
1.160.6.77 raeburn 3398: my $maxnum = scalar(keys(%ordered));
3399: my @roles_by_num = ();
3400: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3401: push(@roles_by_num,$item);
3402: }
3403: my $context = 'domprefs';
3404: my $crstype = 'Course';
3405: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3406: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3407: my ($numstatustypes,@jsarray);
3408: if (ref($types) eq 'ARRAY') {
3409: if (@{$types} > 0) {
3410: $numstatustypes = scalar(@{$types});
3411: push(@accesstypes,'status');
3412: @jsarray = ('bystatus');
3413: }
3414: }
1.160.6.86 raeburn 3415: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3416: if (keys(%domhelpdesk)) {
3417: push(@accesstypes,('inc','exc'));
3418: push(@jsarray,('notinc','notexc'));
3419: }
3420: my $hiddenstr = join("','",@jsarray);
3421: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3422: my $context = 'domprefs';
3423: my $crstype = 'Course';
1.160.6.77 raeburn 3424: my $prefix = 'helproles_';
3425: my $add_class = 'LC_hidden';
3426: foreach my $num (@roles_by_num) {
3427: my $role = $ordered{$num};
3428: my ($desc,$access,@statuses);
3429: if (ref($current{$role}) eq 'HASH') {
3430: $desc = $current{$role}{'desc'};
3431: $access = $current{$role}{'access'};
3432: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3433: @statuses = @{$current{$role}{'insttypes'}};
3434: }
3435: }
3436: if ($desc eq '') {
3437: $desc = $role;
3438: }
3439: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3440: my %full=();
3441: my %levels= (
3442: course => {},
3443: domain => {},
3444: system => {},
3445: );
3446: my %levelscurrent=(
3447: course => {},
3448: domain => {},
3449: system => {},
3450: );
3451: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3452: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3453: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3454: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3455: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3456: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3457: for (my $k=0; $k<=$maxnum; $k++) {
3458: my $vpos = $k+1;
3459: my $selstr;
3460: if ($k == $num) {
3461: $selstr = ' selected="selected" ';
3462: }
3463: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3464: }
3465: $datatable .= '</select>'.(' 'x2).
3466: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3467: '</td>'.
3468: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3469: &mt('Name shown to users:').
3470: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3471: '</fieldset>'.
3472: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3473: $othertitle,$usertypes,$types,\%domhelpdesk).
3474: '<fieldset>'.
3475: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3476: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3477: \%levelscurrent,$identifier,
3478: 'LC_hidden',$prefix.$num.'_privs').
3479: '</fieldset></td>';
1.160.6.73 raeburn 3480: $itemcount ++;
3481: }
3482: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3483: my $newcust = 'custhelp'.$count;
3484: my (%privs,%levelscurrent);
3485: my %full=();
3486: my %levels= (
3487: course => {},
3488: domain => {},
3489: system => {},
3490: );
3491: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3492: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3493: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3494: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3495: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3496: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3497: for (my $k=0; $k<$maxnum+1; $k++) {
3498: my $vpos = $k+1;
3499: my $selstr;
3500: if ($k == $maxnum) {
3501: $selstr = ' selected="selected" ';
3502: }
3503: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3504: }
3505: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3506: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3507: '</label></span></td>'.
1.160.6.77 raeburn 3508: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3509: '<span class="LC_nobreak">'.
3510: &mt('Internal name:').
3511: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3512: '</span>'.(' 'x4).
3513: '<span class="LC_nobreak">'.
3514: &mt('Name shown to users:').
3515: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3516: '</span></fieldset>'.
3517: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3518: $usertypes,$types,\%domhelpdesk).
3519: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3520: &Apache::lonuserutils::custom_role_header($context,$crstype,
3521: \@templateroles,$newcust).
3522: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3523: \%levelscurrent,$newcust).
1.160.6.87 raeburn 3524: '</fieldset>'.
3525: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
3526: '</td></tr>';
1.160.6.73 raeburn 3527: $count ++;
3528: $$rowtotal += $count;
3529: }
1.160.6.5 raeburn 3530: return $datatable;
1.121 raeburn 3531: }
3532:
1.160.6.77 raeburn 3533: sub adhocbutton {
3534: my ($prefix,$num,$field,$visibility) = @_;
3535: my %lt = &Apache::lonlocal::texthash(
3536: show => 'Show details',
3537: hide => 'Hide details',
3538: );
3539: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3540: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3541: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3542: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3543: }
3544:
3545: sub helpsettings_javascript {
3546: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3547: return unless(ref($roles_by_num) eq 'ARRAY');
3548: my %html_js_lt = &Apache::lonlocal::texthash(
3549: show => 'Show details',
3550: hide => 'Hide details',
3551: );
3552: &html_escape(\%html_js_lt);
3553: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3554: return <<"ENDSCRIPT";
3555: <script type="text/javascript">
3556: // <![CDATA[
3557:
3558: function reorderHelpRoles(form,item) {
3559: var changedVal;
3560: $jstext
3561: var newpos = 'helproles_${total}_pos';
3562: var maxh = 1 + $total;
3563: var current = new Array();
3564: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3565: if (item == newpos) {
3566: changedVal = newitemVal;
3567: } else {
3568: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3569: current[newitemVal] = newpos;
3570: }
3571: for (var i=0; i<helproles.length; i++) {
3572: var elementName = 'helproles_'+helproles[i]+'_pos';
3573: if (elementName != item) {
3574: if (form.elements[elementName]) {
3575: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3576: current[currVal] = elementName;
3577: }
3578: }
3579: }
3580: var oldVal;
3581: for (var j=0; j<maxh; j++) {
3582: if (current[j] == undefined) {
3583: oldVal = j;
3584: }
3585: }
3586: if (oldVal < changedVal) {
3587: for (var k=oldVal+1; k<=changedVal ; k++) {
3588: var elementName = current[k];
3589: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3590: }
3591: } else {
3592: for (var k=changedVal; k<oldVal; k++) {
3593: var elementName = current[k];
3594: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3595: }
3596: }
3597: return;
3598: }
3599:
3600: function helpdeskAccess(num) {
3601: var curraccess = null;
3602: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3603: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3604: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3605: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3606: }
3607: }
3608: }
3609: var shown = Array();
3610: var hidden = Array();
3611: if (curraccess == 'none') {
3612: hidden = Array('$hiddenstr');
3613: } else {
3614: if (curraccess == 'status') {
3615: shown = Array('bystatus');
3616: hidden = Array('notinc','notexc');
3617: } else {
3618: if (curraccess == 'exc') {
3619: shown = Array('notexc');
3620: hidden = Array('notinc','bystatus');
3621: }
3622: if (curraccess == 'inc') {
3623: shown = Array('notinc');
3624: hidden = Array('notexc','bystatus');
3625: }
1.160.6.79 raeburn 3626: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3627: hidden = Array('notinc','notexc','bystatus');
3628: }
3629: }
3630: }
3631: if (hidden.length > 0) {
3632: for (var i=0; i<hidden.length; i++) {
3633: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3634: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3635: }
3636: }
3637: }
3638: if (shown.length > 0) {
3639: for (var i=0; i<shown.length; i++) {
3640: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3641: if (shown[i] == 'privs') {
3642: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3643: } else {
3644: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3645: }
3646: }
3647: }
3648: }
3649: return;
3650: }
3651:
3652: function toggleHelpdeskItem(num,field) {
3653: if (document.getElementById('helproles_'+num+'_'+field)) {
3654: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3655: document.getElementById('helproles_'+num+'_'+field).className =
3656: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3657: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3658: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3659: }
3660: } else {
3661: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3662: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3663: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3664: }
3665: }
3666: }
3667: return;
3668: }
3669:
3670: // ]]>
3671: </script>
3672:
3673: ENDSCRIPT
3674: }
3675:
3676: sub helpdeskroles_access {
3677: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3678: $usertypes,$types,$domhelpdesk) = @_;
3679: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3680: my %lt = &Apache::lonlocal::texthash(
3681: 'rou' => 'Role usage',
3682: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3683: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3684: 'dh' => 'All with domain helpdesk role',
3685: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3686: 'none' => 'None',
3687: 'status' => 'Determined based on institutional status',
3688: 'inc' => 'Include all, but exclude specific personnel',
3689: 'exc' => 'Exclude all, but include specific personnel',
3690: );
3691: my %usecheck = (
3692: all => ' checked="checked"',
3693: );
3694: my %displaydiv = (
3695: status => 'none',
3696: inc => 'none',
3697: exc => 'none',
3698: priv => 'block',
3699: );
3700: my $output;
3701: if (ref($current) eq 'HASH') {
3702: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3703: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3704: $usecheck{$current->{access}} = $usecheck{'all'};
3705: delete($usecheck{'all'});
3706: if ($current->{access} =~ /^(status|inc|exc)$/) {
3707: my $access = $1;
3708: $displaydiv{$access} = 'inline';
3709: } elsif ($current->{access} eq 'none') {
3710: $displaydiv{'priv'} = 'none';
3711: }
3712: }
3713: }
3714: }
3715: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3716: '<p>'.$lt{'whi'}.'</p>';
3717: foreach my $access (@{$accesstypes}) {
3718: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3719: ' onclick="helpdeskAccess('."'$num'".');" />'.
3720: $lt{$access}.'</label>';
3721: if ($access eq 'status') {
3722: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3723: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3724: $othertitle,$usertypes,$types).
3725: '</div>';
3726: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3727: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3728: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3729: '</div>';
3730: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3731: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3732: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3733: '</div>';
3734: }
3735: $output .= '</p>';
3736: }
3737: $output .= '</fieldset>';
3738: return $output;
3739: }
3740:
1.121 raeburn 3741: sub radiobutton_prefs {
1.160.6.16 raeburn 3742: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3743: $additional,$align) = @_;
1.121 raeburn 3744: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3745: (ref($choices) eq 'HASH'));
3746:
3747: my (%checkedon,%checkedoff,$datatable,$css_class);
3748:
3749: foreach my $item (@{$toggles}) {
3750: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3751: $checkedon{$item} = ' checked="checked" ';
3752: $checkedoff{$item} = ' ';
1.121 raeburn 3753: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3754: $checkedoff{$item} = ' checked="checked" ';
3755: $checkedon{$item} = ' ';
3756: }
3757: }
3758: if (ref($settings) eq 'HASH') {
1.121 raeburn 3759: foreach my $item (@{$toggles}) {
1.118 jms 3760: if ($settings->{$item} eq '1') {
3761: $checkedon{$item} = ' checked="checked" ';
3762: $checkedoff{$item} = ' ';
3763: } elsif ($settings->{$item} eq '0') {
3764: $checkedoff{$item} = ' checked="checked" ';
3765: $checkedon{$item} = ' ';
3766: }
3767: }
1.121 raeburn 3768: }
1.160.6.16 raeburn 3769: if ($onclick) {
3770: $onclick = ' onclick="'.$onclick.'"';
3771: }
1.121 raeburn 3772: foreach my $item (@{$toggles}) {
1.118 jms 3773: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3774: $datatable .=
1.160.6.16 raeburn 3775: '<tr'.$css_class.'><td valign="top">'.
3776: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3777: '</span></td>';
3778: if ($align eq 'left') {
3779: $datatable .= '<td class="LC_left_item">';
3780: } else {
3781: $datatable .= '<td class="LC_right_item">';
3782: }
3783: $datatable .=
3784: '<span class="LC_nobreak">'.
1.118 jms 3785: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3786: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3787: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3788: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3789: '</span>'.$additional.
3790: '</td>'.
1.118 jms 3791: '</tr>';
3792: $itemcount ++;
1.121 raeburn 3793: }
3794: return ($datatable,$itemcount);
3795: }
3796:
1.160.6.102.2 1(raebur 3797:0): sub print_ltitools {
3798:0): my ($dom,$settings,$rowtotal) = @_;
3799:0): my $rownum = 0;
3800:0): my $css_class;
3801:0): my $itemcount = 1;
3802:0): my $maxnum = 0;
3803:0): my %ordered;
3804:0): if (ref($settings) eq 'HASH') {
3805:0): foreach my $item (keys(%{$settings})) {
3806:0): if (ref($settings->{$item}) eq 'HASH') {
3807:0): my $num = $settings->{$item}{'order'};
3808:0): $ordered{$num} = $item;
3809:0): }
3810:0): }
3811:0): }
3812:0): my $confname = $dom.'-domainconfig';
3813:0): my $switchserver = &check_switchserver($dom,$confname);
3814:0): my $maxnum = scalar(keys(%ordered));
3815:0): my $datatable = <itools_javascript($settings);
3816:0): my %lt = <itools_names();
3817:0): my @courseroles = ('cc','in','ta','ep','st');
3818:0): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3819:0): my @fields = ('fullname','firstname','lastname','email','user','roles');
3820:0): if (keys(%ordered)) {
3821:0): my @items = sort { $a <=> $b } keys(%ordered);
3822:0): for (my $i=0; $i<@items; $i++) {
3823:0): $css_class = $itemcount%2?' class="LC_odd_row"':'';
3824:0): my $item = $ordered{$items[$i]};
3825:0): my ($title,$key,$secret,$url,$imgsrc,$version);
3826:0): if (ref($settings->{$item}) eq 'HASH') {
3827:0): $title = $settings->{$item}->{'title'};
3828:0): $url = $settings->{$item}->{'url'};
3829:0): $key = $settings->{$item}->{'key'};
3830:0): $secret = $settings->{$item}->{'secret'};
3831:0): my $image = $settings->{$item}->{'image'};
3832:0): if ($image ne '') {
3833:0): $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3834:0): }
3835:0): }
3836:0): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3837:0): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3838:0): .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3839:0): for (my $k=0; $k<=$maxnum; $k++) {
3840:0): my $vpos = $k+1;
3841:0): my $selstr;
3842:0): if ($k == $i) {
3843:0): $selstr = ' selected="selected" ';
3844:0): }
3845:0): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3846:0): }
3847:0): $datatable .= '</select>'.(' 'x2).
3848:0): '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3849:0): &mt('Delete?').'</label></span></td>'.
3850:0): '<td colspan="2">'.
3851:0): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3852:0): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3853:0): (' 'x2).
3854:0): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3855:0): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3856:0): (' 'x2).
3857:0): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3858:0): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3859:0): '<br /><br />'.
3860:0): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3861:0): ' value="'.$url.'" /></span>'.
3862:0): (' 'x2).
3863:0): '<span class="LC_nobreak">'.$lt{'key'}.
3864:0): '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3865:0): (' 'x2).
3866:0): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3867:0): '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3868:0): '<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>'.
3869:0): '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3870:0): '</fieldset>'.
3871:0): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3872:0): '<span class="LC_nobreak">'.&mt('Display target:');
3873:0): my %currdisp;
3874:0): if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3875:0): if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3876:0): $currdisp{'window'} = ' checked="checked"';
3877:0): } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
3878:0): $currdisp{'tab'} = ' checked="checked"';
3879:0): } else {
3880:0): $currdisp{'iframe'} = ' checked="checked"';
3881:0): }
3882:0): if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3883:0): $currdisp{'width'} = $1;
3884:0): }
3885:0): if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3886:0): $currdisp{'height'} = $1;
3887:0): }
3888:0): $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
3889:0): $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
3890:0): } else {
3891:0): $currdisp{'iframe'} = ' checked="checked"';
3892:0): }
3893:0): foreach my $disp ('iframe','tab','window') {
3894:0): $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3895:0): $lt{$disp}.'</label>'.(' 'x2);
3896:0): }
3897:0): $datatable .= (' 'x4);
3898:0): foreach my $dimen ('width','height') {
3899:0): $datatable .= '<label>'.$lt{$dimen}.' '.
3900:0): '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3901:0): (' 'x2);
3902:0): }
3903:0): $datatable .= '<br />'.
3904:0): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3905:0): '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
3906:0): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3907:0): '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
3908:0): '</textarea></div><div style=""></div><br />';
3909:0): $datatable .= '<br />';
3910:0): foreach my $extra ('passback','roster') {
3911:0): my $checkedon = '';
3912:0): my $checkedoff = ' checked="checked"';
3913:0): if ($settings->{$item}->{$extra}) {
3914:0): $checkedon = $checkedoff;
3915:0): $checkedoff = '';
3916:0): }
3917:0): $datatable .= $lt{$extra}.' '.
3918:0): '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3919:0): &mt('Yes').'</label>'.(' 'x2).
3920:0): '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3921:0): &mt('No').'</label>'.(' 'x4);
3922:0): }
3923:0): $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3924:0): if ($imgsrc) {
3925:0): $datatable .= $imgsrc.
3926:0): '<label><input type="checkbox" name="ltitools_image_del"'.
3927:0): ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3928:0): '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3929:0): } else {
3930:0): $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3931:0): }
3932:0): if ($switchserver) {
3933:0): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3934:0): } else {
3935:0): $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3936:0): }
3937:0): $datatable .= '</span></fieldset>';
3938:0): my (%checkedfields,%rolemaps);
3939:0): if (ref($settings->{$item}) eq 'HASH') {
3940:0): if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3941:0): %checkedfields = %{$settings->{$item}->{'fields'}};
3942:0): }
3943:0): if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3944:0): %rolemaps = %{$settings->{$item}->{'roles'}};
3945:0): $checkedfields{'roles'} = 1;
3946:0): }
3947:0): }
3948:0): $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3949:0): '<span class="LC_nobreak">';
3950:0): foreach my $field (@fields) {
3951:0): my $checked;
3952:0): if ($checkedfields{$field}) {
3953:0): $checked = ' checked="checked"';
3954:0): }
3955:0): $datatable .= '<label>'.
3956:0): '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3957:0): $lt{$field}.'</label>'.(' ' x2);
3958:0): }
3959:0): $datatable .= '</span></fieldset>'.
3960:0): '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3961:0): foreach my $role (@courseroles) {
3962:0): my ($selected,$selectnone);
3963:0): if (!$rolemaps{$role}) {
3964:0): $selectnone = ' selected="selected"';
3965:0): }
3966:0): $datatable .= '<td align="center">'.
3967:0): &Apache::lonnet::plaintext($role,'Course').'<br />'.
3968:0): '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3969:0): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3970:0): foreach my $ltirole (@ltiroles) {
3971:0): unless ($selectnone) {
3972:0): if ($rolemaps{$role} eq $ltirole) {
3973:0): $selected = ' selected="selected"';
3974:0): } else {
3975:0): $selected = '';
3976:0): }
3977:0): }
3978:0): $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3979:0): }
3980:0): $datatable .= '</select></td>';
3981:0): }
3982:0): $datatable .= '</tr></table></fieldset>';
3983:0): my %courseconfig;
3984:0): if (ref($settings->{$item}) eq 'HASH') {
3985:0): if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3986:0): %courseconfig = %{$settings->{$item}->{'crsconf'}};
3987:0): }
3988:0): }
3989:0): $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3990:0): foreach my $item ('label','title','target','linktext','explanation') {
3991:0): my $checked;
3992:0): if ($courseconfig{$item}) {
3993:0): $checked = ' checked="checked"';
3994:0): }
3995:0): $datatable .= '<label>'.
3996:0): '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3997:0): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3998:0): }
3999:0): $datatable .= '</span></fieldset>'.
4000:0): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4001:0): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4002:0): if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4003:0): my %custom = %{$settings->{$item}->{'custom'}};
4004:0): if (keys(%custom) > 0) {
4005:0): foreach my $key (sort(keys(%custom))) {
4006:0): $datatable .= '<tr><td><span class="LC_nobreak">'.
4007:0): '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4008:0): $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4009:0): '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4010:0): ' value="'.$custom{$key}.'" /></td></tr>';
4011:0): }
4012:0): }
4013:0): }
4014:0): $datatable .= '<tr><td><span class="LC_nobreak">'.
4015:0): '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4016:0): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4017:0): '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4018:0): $datatable .= '</table></fieldset></td></tr>'."\n";
4019:0): $itemcount ++;
4020:0): }
4021:0): }
4022:0): $css_class = $itemcount%2?' class="LC_odd_row"':'';
4023:0): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
4024:0): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4025:0): '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4026:0): '<select name="ltitools_add_pos"'.$chgstr.'>';
4027:0): for (my $k=0; $k<$maxnum+1; $k++) {
4028:0): my $vpos = $k+1;
4029:0): my $selstr;
4030:0): if ($k == $maxnum) {
4031:0): $selstr = ' selected="selected" ';
4032:0): }
4033:0): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4034:0): }
4035:0): $datatable .= '</select> '."\n".
4036:0): '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
4037:0): '<td colspan="2">'.
4038:0): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4039:0): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
4040:0): (' 'x2).
4041:0): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4042:0): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4043:0): (' 'x2).
4044:0): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4045:0): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
4046:0): '<br />'.
4047:0): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
4048:0): (' 'x2).
4049:0): '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4050:0): (' 'x2).
4051:0): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4052:0): '<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".
4053:0): '</fieldset>'.
4054:0): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4055:0): '<span class="LC_nobreak">'.&mt('Display target:');
4056:0): my %defaultdisp;
4057:0): $defaultdisp{'iframe'} = ' checked="checked"';
4058:0): foreach my $disp ('iframe','tab','window') {
4059:0): $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4060:0): $lt{$disp}.'</label>'.(' 'x2);
4061:0): }
4062:0): $datatable .= (' 'x4);
4063:0): foreach my $dimen ('width','height') {
4064:0): $datatable .= '<label>'.$lt{$dimen}.' '.
4065:0): '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4066:0): (' 'x2);
4067:0): }
4068:0): $datatable .= '<br />'.
4069:0): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4070:0): '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
4071:0): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4072:0): '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4073:0): '</div><div style=""></div><br />';
4074:0): foreach my $extra ('passback','roster') {
4075:0): $datatable .= $lt{$extra}.' '.
4076:0): '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
4077:0): &mt('Yes').'</label>'.(' 'x2).
4078:0): '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
4079:0): &mt('No').'</label>'.(' 'x4);
4080:0): }
4081:0): $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
4082:0): '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4083:0): if ($switchserver) {
4084:0): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4085:0): } else {
4086:0): $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4087:0): }
4088:0): $datatable .= '</span></fieldset>'.
4089:0): '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4090:0): '<span class="LC_nobreak">';
4091:0): foreach my $field (@fields) {
4092:0): $datatable .= '<label>'.
4093:0): '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
4094:0): $lt{$field}.'</label>'.(' ' x2);
4095:0): }
4096:0): $datatable .= '</span></fieldset>'.
4097:0): '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4098:0): foreach my $role (@courseroles) {
4099:0): my ($checked,$checkednone);
4100:0): $datatable .= '<td align="center">'.
4101:0): &Apache::lonnet::plaintext($role,'Course').'<br />'.
4102:0): '<select name="ltitools_add_roles_'.$role.'">'.
4103:0): '<option value="" selected="selected">'.&mt('Select').'</option>';
4104:0): foreach my $ltirole (@ltiroles) {
4105:0): $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4106:0): }
4107:0): $datatable .= '</select></td>';
4108:0): }
4109:0): $datatable .= '</tr></table></fieldset>'.
4110:0): '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
4111:0): foreach my $item ('label','title','target','linktext','explanation') {
4112:0): $datatable .= '<label>'.
4113:0): '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4114:0): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4115:0): }
4116:0): $datatable .= '</span></fieldset>'.
4117:0): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4118:0): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4119:0): '<tr><td><span class="LC_nobreak">'.
4120:0): '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4121:0): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4122:0): '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4123:0): '</table></fieldset></td></tr>'."\n".
4124:0): '</td>'."\n".
4125:0): '</tr>'."\n";
4126:0): $itemcount ++;
4127:0): return $datatable;
4128:0): }
4129:0):
4130:0): sub ltitools_names {
4131:0): my %lt = &Apache::lonlocal::texthash(
4132:0): 'title' => 'Title',
4133:0): 'version' => 'Version',
4134:0): 'msgtype' => 'Message Type',
4135:0): 'url' => 'URL',
4136:0): 'key' => 'Key',
4137:0): 'secret' => 'Secret',
4138:0): 'icon' => 'Icon',
4139:0): 'user' => 'Username:domain',
4140:0): 'fullname' => 'Full Name',
4141:0): 'firstname' => 'First Name',
4142:0): 'lastname' => 'Last Name',
4143:0): 'email' => 'E-mail',
4144:0): 'roles' => 'Role',
4145:0): 'window' => 'Window',
4146:0): 'tab' => 'Tab',
4147:0): 'iframe' => 'iFrame',
4148:0): 'height' => 'Height',
4149:0): 'width' => 'Width',
4150:0): 'linktext' => 'Default Link Text',
4151:0): 'explanation' => 'Default Explanation',
4152:0): 'passback' => 'Tool can return grades:',
4153:0): 'roster' => 'Tool can retrieve roster:',
4154:0): 'crstarget' => 'Display target',
4155:0): 'crslabel' => 'Course label',
4156:0): 'crstitle' => 'Course title',
4157:0): 'crslinktext' => 'Link Text',
4158:0): 'crsexplanation' => 'Explanation',
4159:0): );
4160:0):
4161:0): return %lt;
4162:0): }
4163:0):
1.121 raeburn 4164: sub print_coursedefaults {
1.139 raeburn 4165: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 4166: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4167: my $itemcount = 1;
1.160.6.16 raeburn 4168: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 4169: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 4170: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4171: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 4172: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4173: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.90 raeburn 4174: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 4175: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 4176: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 4177: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 4178: );
1.160.6.21 raeburn 4179: my %staticdefaults = (
4180: anonsurvey_threshold => 10,
4181: uploadquota => 500,
1.160.6.57 raeburn 4182: postsubmit => 60,
1.160.6.70 raeburn 4183: mysqltables => 172800,
1.160.6.21 raeburn 4184: );
1.139 raeburn 4185: if ($position eq 'top') {
1.160.6.57 raeburn 4186: %defaultchecked = (
4187: 'uselcmath' => 'on',
4188: 'usejsme' => 'on',
1.160.6.64 raeburn 4189: 'canclone' => 'none',
1.160.6.57 raeburn 4190: );
4191: @toggles = ('uselcmath','usejsme');
1.160.6.90 raeburn 4192: my $deftex = $Apache::lonnet::deftex;
4193: if (ref($settings) eq 'HASH') {
4194: if ($settings->{'texengine'}) {
4195: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4196: $deftex = $settings->{'texengine'};
4197: }
4198: }
4199: }
4200: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4201: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4202: '<span class="LC_nobreak">'.$choices{'texengine'}.
4203: '</span></td><td class="LC_right_item">'.
4204: '<select name="texengine">'."\n";
4205: my %texoptions = (
4206: MathJax => 'MathJax',
4207: mimetex => &mt('Convert to Images'),
4208: tth => &mt('TeX to HTML'),
4209: );
4210: foreach my $renderer ('MathJax','mimetex','tth') {
4211: my $selected = '';
4212: if ($renderer eq $deftex) {
4213: $selected = ' selected="selected"';
4214: }
4215: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
4216: }
4217: $mathdisp .= '</select></td></tr>'."\n";
4218: $itemcount ++;
1.139 raeburn 4219: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4220: \%choices,$itemcount);
1.160.6.90 raeburn 4221: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 4222: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4223: $datatable .=
4224: '<tr'.$css_class.'><td valign="top">'.
4225: '<span class="LC_nobreak">'.$choices{'canclone'}.
4226: '</span></td><td class="LC_left_item">';
4227: my $currcanclone = 'none';
4228: my $onclick;
4229: my @cloneoptions = ('none','domain');
4230: my %clonetitles = (
4231: none => 'No additional course requesters',
4232: domain => "Any course requester in course's domain",
4233: instcode => 'Course requests for official courses ...',
4234: );
4235: my (%codedefaults,@code_order,@posscodes);
4236: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4237: \@code_order) eq 'ok') {
4238: if (@code_order > 0) {
4239: push(@cloneoptions,'instcode');
4240: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4241: }
4242: }
4243: if (ref($settings) eq 'HASH') {
4244: if ($settings->{'canclone'}) {
4245: if (ref($settings->{'canclone'}) eq 'HASH') {
4246: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4247: if (@code_order > 0) {
4248: $currcanclone = 'instcode';
4249: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4250: }
4251: }
4252: } elsif ($settings->{'canclone'} eq 'domain') {
4253: $currcanclone = $settings->{'canclone'};
4254: }
4255: }
4256: }
4257: foreach my $option (@cloneoptions) {
4258: my ($checked,$additional);
4259: if ($currcanclone eq $option) {
4260: $checked = ' checked="checked"';
4261: }
4262: if ($option eq 'instcode') {
4263: if (@code_order) {
4264: my $show = 'none';
4265: if ($checked) {
4266: $show = 'block';
4267: }
4268: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4269: &mt('Institutional codes for new and cloned course have identical:').
4270: '<br />';
4271: foreach my $item (@code_order) {
4272: my $codechk;
4273: if ($checked) {
4274: if (grep(/^\Q$item\E$/,@posscodes)) {
4275: $codechk = ' checked="checked"';
4276: }
4277: }
4278: $additional .= '<label>'.
4279: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4280: $item.'</label>';
4281: }
4282: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4283: }
4284: }
4285: $datatable .=
4286: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4287: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4288: '</label> '.$additional.'</span><br />';
4289: }
4290: $datatable .= '</td>'.
4291: '</tr>';
4292: $itemcount ++;
1.139 raeburn 4293: } else {
4294: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 4295: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 4296: my $currusecredits = 0;
1.160.6.57 raeburn 4297: my $postsubmitclient = 1;
1.160.6.30 raeburn 4298: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 4299: if (ref($settings) eq 'HASH') {
4300: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 4301: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4302: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4303: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4304: }
4305: }
1.160.6.16 raeburn 4306: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 4307: foreach my $type (@types) {
4308: next if ($type eq 'community');
4309: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4310: if ($defcredits{$type} ne '') {
4311: $currusecredits = 1;
4312: }
4313: }
4314: }
4315: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4316: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4317: $postsubmitclient = 0;
4318: foreach my $type (@types) {
4319: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4320: }
4321: } else {
4322: foreach my $type (@types) {
4323: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4324: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4325: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4326: } else {
4327: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4328: }
4329: } else {
4330: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4331: }
4332: }
4333: }
4334: } else {
4335: foreach my $type (@types) {
4336: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 4337: }
4338: }
1.160.6.70 raeburn 4339: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4340: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4341: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4342: }
4343: } else {
4344: foreach my $type (@types) {
4345: $currmysql{$type} = $staticdefaults{'mysqltables'};
4346: }
4347: }
1.160.6.58 raeburn 4348: } else {
4349: foreach my $type (@types) {
4350: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4351: }
1.139 raeburn 4352: }
4353: if (!$currdefresponder) {
1.160.6.21 raeburn 4354: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4355: } elsif ($currdefresponder < 1) {
4356: $currdefresponder = 1;
4357: }
1.160.6.21 raeburn 4358: foreach my $type (@types) {
4359: if ($curruploadquota{$type} eq '') {
4360: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4361: }
4362: }
1.139 raeburn 4363: $datatable .=
1.160.6.16 raeburn 4364: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4365: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4366: '</span></td>'.
4367: '<td class="LC_right_item"><span class="LC_nobreak">'.
4368: '<input type="text" name="anonsurvey_threshold"'.
4369: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 4370: '</td></tr>'."\n";
4371: $itemcount ++;
4372: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4373: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4374: $choices{'uploadquota'}.
4375: '</span></td>'.
4376: '<td align="right" class="LC_right_item">'.
4377: '<table><tr>';
1.160.6.21 raeburn 4378: foreach my $type (@types) {
4379: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4380: '<input type="text" name="uploadquota_'.$type.'"'.
4381: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4382: }
4383: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 4384: $itemcount ++;
1.160.6.40 raeburn 4385: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 4386: my $display = 'none';
4387: if ($currusecredits) {
4388: $display = 'block';
4389: }
4390: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 4391: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4392: foreach my $type (@types) {
4393: next if ($type eq 'community');
4394: $additional .= '<td align="center">'.&mt($type).'<br />'.
4395: '<input type="text" name="'.$type.'_credits"'.
4396: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4397: }
4398: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 4399: %defaultchecked = ('coursecredits' => 'off');
4400: @toggles = ('coursecredits');
4401: my $current = {
4402: 'coursecredits' => $currusecredits,
4403: };
4404: (my $table,$itemcount) =
4405: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4406: \%choices,$itemcount,$onclick,$additional,'left');
4407: $datatable .= $table;
4408: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4409: my $display = 'none';
4410: if ($postsubmitclient) {
4411: $display = 'block';
4412: }
4413: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 4414: &mt('Number of seconds submit is disabled').'<br />'.
4415: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4416: '<table><tr>';
1.160.6.57 raeburn 4417: foreach my $type (@types) {
4418: $additional .= '<td align="center">'.&mt($type).'<br />'.
4419: '<input type="text" name="'.$type.'_timeout" value="'.
4420: $deftimeout{$type}.'" size="5" /></td>';
4421: }
4422: $additional .= '</tr></table></div>'."\n";
4423: %defaultchecked = ('postsubmit' => 'on');
4424: @toggles = ('postsubmit');
1.160.6.70 raeburn 4425: $current = {
4426: 'postsubmit' => $postsubmitclient,
4427: };
1.160.6.57 raeburn 4428: ($table,$itemcount) =
4429: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4430: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 4431: $datatable .= $table;
1.160.6.70 raeburn 4432: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4433: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4434: $choices{'mysqltables'}.
4435: '</span></td>'.
4436: '<td align="right" class="LC_right_item">'.
4437: '<table><tr>';
4438: foreach my $type (@types) {
4439: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4440: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 4441: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 4442: }
4443: $datatable .= '</tr></table></td></tr>'."\n";
4444: $itemcount ++;
4445:
1.160.6.37 raeburn 4446: }
4447: $$rowtotal += $itemcount;
4448: return $datatable;
4449: }
4450:
4451: sub print_selfenrollment {
4452: my ($position,$dom,$settings,$rowtotal) = @_;
4453: my ($css_class,$datatable);
4454: my $itemcount = 1;
4455: my @types = ('official','unofficial','community','textbook');
4456: if (($position eq 'top') || ($position eq 'middle')) {
4457: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4458: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4459: my @rows;
4460: my $key;
4461: if ($position eq 'top') {
4462: $key = 'admin';
4463: if (ref($rowsref) eq 'ARRAY') {
4464: @rows = @{$rowsref};
4465: }
4466: } elsif ($position eq 'middle') {
4467: $key = 'default';
4468: @rows = ('types','registered','approval','limit');
4469: }
4470: foreach my $row (@rows) {
4471: if (defined($titlesref->{$row})) {
4472: $itemcount ++;
4473: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4474: $datatable .= '<tr'.$css_class.'>'.
4475: '<td>'.$titlesref->{$row}.'</td>'.
4476: '<td class="LC_left_item">'.
4477: '<table><tr>';
4478: my (%current,%currentcap);
4479: if (ref($settings) eq 'HASH') {
4480: if (ref($settings->{$key}) eq 'HASH') {
4481: foreach my $type (@types) {
4482: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4483: $current{$type} = $settings->{$key}->{$type}->{$row};
4484: }
4485: if (($row eq 'limit') && ($key eq 'default')) {
4486: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4487: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4488: }
4489: }
4490: }
4491: }
4492: }
4493: my %roles = (
4494: '0' => &Apache::lonnet::plaintext('dc'),
4495: );
4496:
4497: foreach my $type (@types) {
4498: unless (($row eq 'registered') && ($key eq 'default')) {
4499: $datatable .= '<th>'.&mt($type).'</th>';
4500: }
4501: }
4502: unless (($row eq 'registered') && ($key eq 'default')) {
4503: $datatable .= '</tr><tr>';
4504: }
4505: foreach my $type (@types) {
4506: if ($type eq 'community') {
4507: $roles{'1'} = &mt('Community personnel');
4508: } else {
4509: $roles{'1'} = &mt('Course personnel');
4510: }
4511: $datatable .= '<td style="vertical-align: top">';
4512: if ($position eq 'top') {
4513: my %checked;
4514: if ($current{$type} eq '0') {
4515: $checked{'0'} = ' checked="checked"';
4516: } else {
4517: $checked{'1'} = ' checked="checked"';
4518: }
4519: foreach my $role ('1','0') {
4520: $datatable .= '<span class="LC_nobreak"><label>'.
4521: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4522: 'value="'.$role.'"'.$checked{$role}.' />'.
4523: $roles{$role}.'</label></span> ';
4524: }
4525: } else {
4526: if ($row eq 'types') {
4527: my %checked;
4528: if ($current{$type} =~ /^(all|dom)$/) {
4529: $checked{$1} = ' checked="checked"';
4530: } else {
4531: $checked{''} = ' checked="checked"';
4532: }
4533: foreach my $val ('','dom','all') {
4534: $datatable .= '<span class="LC_nobreak"><label>'.
4535: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4536: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4537: }
4538: } elsif ($row eq 'registered') {
4539: my %checked;
4540: if ($current{$type} eq '1') {
4541: $checked{'1'} = ' checked="checked"';
4542: } else {
4543: $checked{'0'} = ' checked="checked"';
4544: }
4545: foreach my $val ('0','1') {
4546: $datatable .= '<span class="LC_nobreak"><label>'.
4547: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4548: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4549: }
4550: } elsif ($row eq 'approval') {
4551: my %checked;
4552: if ($current{$type} =~ /^([12])$/) {
4553: $checked{$1} = ' checked="checked"';
4554: } else {
4555: $checked{'0'} = ' checked="checked"';
4556: }
4557: for my $val (0..2) {
4558: $datatable .= '<span class="LC_nobreak"><label>'.
4559: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4560: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4561: }
4562: } elsif ($row eq 'limit') {
4563: my %checked;
4564: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4565: $checked{$1} = ' checked="checked"';
4566: } else {
4567: $checked{'none'} = ' checked="checked"';
4568: }
4569: my $cap;
4570: if ($currentcap{$type} =~ /^\d+$/) {
4571: $cap = $currentcap{$type};
4572: }
4573: foreach my $val ('none','allstudents','selfenrolled') {
4574: $datatable .= '<span class="LC_nobreak"><label>'.
4575: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4576: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4577: }
4578: $datatable .= '<br />'.
4579: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4580: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4581: '</span>';
4582: }
4583: }
4584: $datatable .= '</td>';
4585: }
4586: $datatable .= '</tr>';
4587: }
4588: $datatable .= '</table></td></tr>';
4589: }
4590: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 4591: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4592: }
4593: $$rowtotal += $itemcount;
4594: return $datatable;
4595: }
4596:
4597: sub print_validation_rows {
4598: my ($caller,$dom,$settings,$rowtotal) = @_;
4599: my ($itemsref,$namesref,$fieldsref);
4600: if ($caller eq 'selfenroll') {
4601: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4602: } elsif ($caller eq 'requestcourses') {
4603: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4604: }
4605: my %currvalidation;
4606: if (ref($settings) eq 'HASH') {
4607: if (ref($settings->{'validation'}) eq 'HASH') {
4608: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 4609: }
1.160.6.39 raeburn 4610: }
4611: my $datatable;
4612: my $itemcount = 0;
4613: foreach my $item (@{$itemsref}) {
4614: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4615: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4616: $namesref->{$item}.
4617: '</span></td>'.
4618: '<td class="LC_left_item">';
4619: if (($item eq 'url') || ($item eq 'button')) {
4620: $datatable .= '<span class="LC_nobreak">'.
4621: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4622: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4623: } elsif ($item eq 'fields') {
4624: my @currfields;
4625: if (ref($currvalidation{$item}) eq 'ARRAY') {
4626: @currfields = @{$currvalidation{$item}};
4627: }
4628: foreach my $field (@{$fieldsref}) {
4629: my $check = '';
4630: if (grep(/^\Q$field\E$/,@currfields)) {
4631: $check = ' checked="checked"';
4632: }
4633: $datatable .= '<span class="LC_nobreak"><label>'.
4634: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4635: ' value="'.$field.'"'.$check.' />'.$field.
4636: '</label></span> ';
4637: }
4638: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 4639: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 4640: $currvalidation{$item}.
1.160.6.37 raeburn 4641: '</textarea>';
1.160.6.39 raeburn 4642: }
4643: $datatable .= '</td></tr>'."\n";
4644: if (ref($rowtotal)) {
1.160.6.37 raeburn 4645: $itemcount ++;
4646: }
1.139 raeburn 4647: }
1.160.6.39 raeburn 4648: if ($caller eq 'requestcourses') {
4649: my %currhash;
1.160.6.51 raeburn 4650: if (ref($settings) eq 'HASH') {
4651: if (ref($settings->{'validation'}) eq 'HASH') {
4652: if ($settings->{'validation'}{'dc'} ne '') {
4653: $currhash{$settings->{'validation'}{'dc'}} = 1;
4654: }
1.160.6.39 raeburn 4655: }
4656: }
4657: my $numinrow = 2;
4658: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4659: 'validationdc',%currhash);
1.160.6.50 raeburn 4660: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 4661: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 4662: if ($numdc > 1) {
1.160.6.50 raeburn 4663: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 4664: } else {
1.160.6.50 raeburn 4665: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 4666: }
1.160.6.50 raeburn 4667: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 4668: $itemcount ++;
4669: }
4670: if (ref($rowtotal)) {
4671: $$rowtotal += $itemcount;
4672: }
1.121 raeburn 4673: return $datatable;
1.118 jms 4674: }
4675:
1.160.6.98 raeburn 4676: sub print_passwords {
4677: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
4678: my ($datatable,$css_class);
4679: my $itemcount = 0;
4680: my %titles = &Apache::lonlocal::texthash (
4681: captcha => '"Forgot Password" CAPTCHA validation',
4682: link => 'Reset link expiration (hours)',
4683: case => 'Case-sensitive usernames/e-mail',
4684: prelink => 'Information required (form 1)',
4685: postlink => 'Information required (form 2)',
4686: emailsrc => 'LON-CAPA e-mail address type(s)',
4687: customtext => 'Domain specific text (HTML)',
4688: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
4689: intauth_check => 'Check bcrypt cost if authenticated',
4690: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
4691: permanent => 'Permanent e-mail address',
4692: critical => 'Critical notification address',
4693: notify => 'Notification address',
4694: min => 'Minimum password length',
4695: max => 'Maximum password length',
4696: chars => 'Required characters',
4697: numsaved => 'Number of previous passwords to save and disallow reuse',
4698: );
4699: if ($position eq 'top') {
4700: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4701: my $shownlinklife = 2;
4702: my $prelink = 'both';
4703: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
4704: if (ref($settings) eq 'HASH') {
4705: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
4706: $shownlinklife = $settings->{resetlink};
4707: }
4708: if (ref($settings->{resetcase}) eq 'ARRAY') {
4709: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
4710: }
4711: if ($settings->{resetprelink} =~ /^(both|either)$/) {
4712: $prelink = $settings->{resetprelink};
4713: }
4714: if (ref($settings->{resetpostlink}) eq 'HASH') {
4715: %postlink = %{$settings->{resetpostlink}};
4716: }
4717: if (ref($settings->{resetemail}) eq 'ARRAY') {
4718: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
4719: }
4720: if ($settings->{resetremove}) {
4721: $nostdtext = 1;
4722: }
4723: if ($settings->{resetcustom}) {
4724: $customurl = $settings->{resetcustom};
4725: }
4726: } else {
4727: if (ref($types) eq 'ARRAY') {
4728: foreach my $item (@{$types}) {
4729: $casesens{$item} = 1;
4730: $postlink{$item} = ['username','email'];
4731: }
4732: }
4733: $casesens{'default'} = 1;
4734: $postlink{'default'} = ['username','email'];
4735: $prelink = 'both';
4736: %emailsrc = (
4737: permanent => 1,
4738: critical => 1,
4739: notify => 1,
4740: );
4741: }
4742: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
4743: $itemcount ++;
4744: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4745: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
4746: '<td class="LC_left_item">'.
4747: '<input type="textbox" value="'.$shownlinklife.'" '.
4748: 'name="passwords_link" size="3" /></td></tr>';
4749: $itemcount ++;
4750: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4751: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
4752: '<td class="LC_left_item">';
4753: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4754: foreach my $item (@{$types}) {
4755: my $checkedcase;
4756: if ($casesens{$item}) {
4757: $checkedcase = ' checked="checked"';
4758: }
4759: $datatable .= '<span class="LC_nobreak"><label>'.
4760: '<input type="checkbox" name="passwords_case_sensitive" value="'.
4761: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
4762: '<span> ';
4763: }
4764: }
4765: my $checkedcase;
4766: if ($casesens{'default'}) {
4767: $checkedcase = ' checked="checked"';
4768: }
4769: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
4770: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
4771: $othertitle.'</label></span></td>';
4772: $itemcount ++;
4773: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4774: my %checkedpre = (
4775: both => ' checked="checked"',
4776: either => '',
4777: );
4778: if ($prelink eq 'either') {
4779: $checkedpre{either} = ' checked="checked"';
4780: $checkedpre{both} = '';
4781: }
4782: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
4783: '<td class="LC_left_item"><span class="LC_nobreak">'.
4784: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
4785: &mt('Both username and e-mail address').'</label></span> '.
4786: '<span class="LC_nobreak"><label>'.
4787: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
4788: &mt('Either username or e-mail address').'</label></span></td></tr>';
4789: $itemcount ++;
4790: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4791: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
4792: '<td class="LC_left_item">';
4793: my %postlinked;
4794: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4795: foreach my $item (@{$types}) {
4796: undef(%postlinked);
4797: $datatable .= '<fieldset style="display: inline-block;">'.
4798: '<legend>'.$usertypes->{$item}.'</legend>';
4799: if (ref($postlink{$item}) eq 'ARRAY') {
4800: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
4801: }
4802: foreach my $field ('email','username') {
4803: my $checked;
4804: if ($postlinked{$field}) {
4805: $checked = ' checked="checked"';
4806: }
4807: $datatable .= '<span class="LC_nobreak"><label>'.
4808: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
4809: $field.'"'.$checked.' />'.$field.'</label>'.
4810: '<span> ';
4811: }
4812: $datatable .= '</fieldset>';
4813: }
4814: }
4815: if (ref($postlink{'default'}) eq 'ARRAY') {
4816: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
4817: }
4818: $datatable .= '<fieldset style="display: inline-block;">'.
4819: '<legend>'.$othertitle.'</legend>';
4820: foreach my $field ('email','username') {
4821: my $checked;
4822: if ($postlinked{$field}) {
4823: $checked = ' checked="checked"';
4824: }
4825: $datatable .= '<span class="LC_nobreak"><label>'.
4826: '<input type="checkbox" name="passwords_postlink_default" value="'.
4827: $field.'"'.$checked.' />'.$field.'</label>'.
4828: '<span> ';
4829: }
4830: $datatable .= '</fieldset></td></tr>';
4831: $itemcount ++;
4832: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4833: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
4834: '<td class="LC_left_item">';
4835: foreach my $type ('permanent','critical','notify') {
4836: my $checkedemail;
4837: if ($emailsrc{$type}) {
4838: $checkedemail = ' checked="checked"';
4839: }
4840: $datatable .= '<span class="LC_nobreak"><label>'.
4841: '<input type="checkbox" name="passwords_emailsrc" value="'.
4842: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
4843: '<span> ';
4844: }
4845: $datatable .= '</td></tr>';
4846: $itemcount ++;
4847: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4848: my $switchserver = &check_switchserver($dom,$confname);
4849: my ($showstd,$noshowstd);
4850: if ($nostdtext) {
4851: $noshowstd = ' checked="checked"';
4852: } else {
4853: $showstd = ' checked="checked"';
4854: }
4855: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
4856: '<td class="LC_left_item"><span class="LC_nobreak">'.
4857: &mt('Retain standard text:').
4858: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
4859: &mt('Yes').'</label>'.' '.
4860: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
4861: &mt('No').'</label></span><br />'.
4862: '<span class="LC_fontsize_small">'.
4863: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
4864: &mt('Include custom text:');
4865: if ($customurl) {
4866: my $link = &Apache::loncommon::modal_link($customurl,&mt('Custom text file'),600,500,
4867: undef,undef,undef,undef,'background-color:#ffffff');
4868: $datatable .= '<span class="LC_nobreak"> '.$link.
4869: '<label><input type="checkbox" name="passwords_custom_del"'.
4870: ' value="1" />'.&mt('Delete?').'</label></span>'.
4871: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
4872: }
4873: if ($switchserver) {
4874: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
4875: } else {
4876: $datatable .='<span class="LC_nobreak"> '.
4877: '<input type="file" name="passwords_customfile" /></span>';
4878: }
4879: $datatable .= '</td></tr>';
4880: } elsif ($position eq 'middle') {
4881: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
4882: my @items = ('intauth_cost','intauth_check','intauth_switch');
4883: my %defaults;
4884: if (ref($domconf{'defaults'}) eq 'HASH') {
4885: %defaults = %{$domconf{'defaults'}};
4886: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
4887: $defaults{'intauth_cost'} = 10;
4888: }
4889: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
4890: $defaults{'intauth_check'} = 0;
4891: }
4892: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
4893: $defaults{'intauth_switch'} = 0;
4894: }
4895: } else {
4896: %defaults = (
4897: 'intauth_cost' => 10,
4898: 'intauth_check' => 0,
4899: 'intauth_switch' => 0,
4900: );
4901: }
4902: foreach my $item (@items) {
4903: if ($itemcount%2) {
4904: $css_class = '';
4905: } else {
4906: $css_class = ' class="LC_odd_row" ';
4907: }
4908: $datatable .= '<tr'.$css_class.'>'.
4909: '<td><span class="LC_nobreak">'.$titles{$item}.
4910: '</span></td><td class="LC_left_item" colspan="3">';
4911: if ($item eq 'intauth_switch') {
4912: my @options = (0,1,2);
4913: my %optiondesc = &Apache::lonlocal::texthash (
4914: 0 => 'No',
4915: 1 => 'Yes',
4916: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
4917: );
4918: $datatable .= '<table width="100%">';
4919: foreach my $option (@options) {
4920: my $checked = ' ';
4921: if ($defaults{$item} eq $option) {
4922: $checked = ' checked="checked"';
4923: }
4924: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
4925: '<label><input type="radio" name="'.$item.
4926: '" value="'.$option.'"'.$checked.' />'.
4927: $optiondesc{$option}.'</label></span></td></tr>';
4928: }
4929: $datatable .= '</table>';
4930: } elsif ($item eq 'intauth_check') {
4931: my @options = (0,1,2);
4932: my %optiondesc = &Apache::lonlocal::texthash (
4933: 0 => 'No',
4934: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
4935: 2 => 'Yes, disallow login if stored cost is less than domain default',
4936: );
4937: $datatable .= '<table width="100%">';
4938: foreach my $option (@options) {
4939: my $checked = ' ';
4940: my $onclick;
4941: if ($defaults{$item} eq $option) {
4942: $checked = ' checked="checked"';
4943: }
4944: if ($option == 2) {
4945: $onclick = ' onclick="javascript:warnIntAuth(this);"';
4946: }
4947: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
4948: '<label><input type="radio" name="'.$item.
4949: '" value="'.$option.'"'.$checked.$onclick.' />'.
4950: $optiondesc{$option}.'</label></span></td></tr>';
4951: }
4952: $datatable .= '</table>';
4953: } else {
4954: $datatable .= '<input type="text" name="'.$item.'" value="'.
4955: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
4956: }
4957: $datatable .= '</td></tr>';
4958: $itemcount ++;
4959: }
4960: } elsif ($position eq 'lower') {
4961: my ($min,$max,%chars,$numsaved);
1.160.6.99 raeburn 4962: $min = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 4963: if (ref($settings) eq 'HASH') {
4964: if ($settings->{min}) {
4965: $min = $settings->{min};
4966: }
4967: if ($settings->{max}) {
4968: $max = $settings->{max};
4969: }
4970: if (ref($settings->{chars}) eq 'ARRAY') {
4971: map { $chars{$_} = 1; } (@{$settings->{chars}});
4972: }
4973: if ($settings->{numsaved}) {
4974: $numsaved = $settings->{numsaved};
4975: }
4976: }
4977: my %rulenames = &Apache::lonlocal::texthash(
4978: uc => 'At least one upper case letter',
4979: lc => 'At least one lower case letter',
4980: num => 'At least one number',
4981: spec => 'At least one non-alphanumeric',
4982: );
4983: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4984: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
4985: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 4986: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
4987: 'onblur="javascript:warnIntPass(this);" />'.
4988: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.160.6.98 raeburn 4989: '</span></td></tr>';
4990: $itemcount ++;
4991: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4992: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
4993: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 4994: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
4995: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 4996: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
4997: '</span></td></tr>';
4998: $itemcount ++;
4999: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5000: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
5001: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
5002: '</span></td>';
5003: my $numinrow = 2;
5004: my @possrules = ('uc','lc','num','spec');
5005: $datatable .= '<td class="LC_left_item"><table>';
5006: for (my $i=0; $i<@possrules; $i++) {
5007: my ($rem,$checked);
5008: if ($chars{$possrules[$i]}) {
5009: $checked = ' checked="checked"';
5010: }
5011: $rem = $i%($numinrow);
5012: if ($rem == 0) {
5013: if ($i > 0) {
5014: $datatable .= '</tr>';
5015: }
5016: $datatable .= '<tr>';
5017: }
5018: $datatable .= '<td><span class="LC_nobreak"><label>'.
5019: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
5020: $rulenames{$possrules[$i]}.'</label></span></td>';
5021: }
5022: my $rem = @possrules%($numinrow);
5023: my $colsleft = $numinrow - $rem;
5024: if ($colsleft > 1 ) {
5025: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5026: ' </td>';
5027: } elsif ($colsleft == 1) {
5028: $datatable .= '<td class="LC_left_item"> </td>';
5029: }
5030: $datatable .='</table></td></tr>';
5031: $itemcount ++;
5032: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5033: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
5034: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.100 raeburn 5035: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
1.160.6.99 raeburn 5036: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5037: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
5038: '</span></td></tr>';
5039: } else {
5040: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5041: my %ownerchg = (
5042: by => {},
5043: for => {},
5044: );
5045: my %ownertitles = &Apache::lonlocal::texthash (
5046: by => 'Course owner status(es) allowed',
5047: for => 'Student status(es) allowed',
5048: );
5049: if (ref($settings) eq 'HASH') {
5050: if (ref($settings->{crsownerchg}) eq 'HASH') {
5051: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
5052: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
5053: }
5054: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
5055: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
5056: }
5057: }
5058: }
5059: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5060: $datatable .= '<tr '.$css_class.'>'.
5061: '<td>'.
5062: &mt('Requirements').'<ul>'.
5063: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
5064: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
5065: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
5066: '<li>'.&mt('User, course, and student share same domain').'</li>'.
5067: '</ul>'.
5068: '</td>'.
5069: '<td class="LC_left_item">';
5070: foreach my $item ('by','for') {
5071: $datatable .= '<fieldset style="display: inline-block;">'.
5072: '<legend>'.$ownertitles{$item}.'</legend>';
5073: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5074: foreach my $type (@{$types}) {
5075: my $checked;
5076: if ($ownerchg{$item}{$type}) {
5077: $checked = ' checked="checked"';
5078: }
5079: $datatable .= '<span class="LC_nobreak"><label>'.
5080: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
5081: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
5082: '<span> ';
5083: }
5084: }
5085: my $checked;
5086: if ($ownerchg{$item}{'default'}) {
5087: $checked = ' checked="checked"';
5088: }
5089: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5090: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
5091: $othertitle.'</label></span></fieldset>';
5092: }
5093: $datatable .= '</td></tr>';
5094: }
5095: return $datatable;
5096: }
5097:
1.137 raeburn 5098: sub print_usersessions {
5099: my ($position,$dom,$settings,$rowtotal) = @_;
5100: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 5101: my (%by_ip,%by_location,@intdoms);
5102: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 5103:
5104: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5105: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5106: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5107: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5108: my $itemcount = 1;
5109: if ($position eq 'top') {
1.152 raeburn 5110: if (keys(%serverhomes) > 1) {
1.145 raeburn 5111: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 5112: my $curroffloadnow;
5113: if (ref($settings) eq 'HASH') {
5114: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5115: $curroffloadnow = $settings->{'offloadnow'};
5116: }
5117: }
5118: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 5119: } else {
1.140 raeburn 5120: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 5121: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 5122: }
1.137 raeburn 5123: } else {
1.145 raeburn 5124: if (keys(%by_location) == 0) {
5125: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 5126: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 5127: } else {
5128: my %lt = &usersession_titles();
5129: my $numinrow = 5;
5130: my $prefix;
5131: my @types;
5132: if ($position eq 'bottom') {
5133: $prefix = 'remote';
5134: @types = ('version','excludedomain','includedomain');
5135: } else {
5136: $prefix = 'hosted';
5137: @types = ('excludedomain','includedomain');
5138: }
5139: my (%current,%checkedon,%checkedoff);
5140: my @lcversions = &Apache::lonnet::all_loncaparevs();
5141: my @locations = sort(keys(%by_location));
5142: foreach my $type (@types) {
5143: $checkedon{$type} = '';
5144: $checkedoff{$type} = ' checked="checked"';
5145: }
5146: if (ref($settings) eq 'HASH') {
5147: if (ref($settings->{$prefix}) eq 'HASH') {
5148: foreach my $key (keys(%{$settings->{$prefix}})) {
5149: $current{$key} = $settings->{$prefix}{$key};
5150: if ($key eq 'version') {
5151: if ($current{$key} ne '') {
5152: $checkedon{$key} = ' checked="checked"';
5153: $checkedoff{$key} = '';
5154: }
5155: } elsif (ref($current{$key}) eq 'ARRAY') {
5156: $checkedon{$key} = ' checked="checked"';
5157: $checkedoff{$key} = '';
5158: }
1.137 raeburn 5159: }
5160: }
5161: }
1.145 raeburn 5162: foreach my $type (@types) {
5163: next if ($type ne 'version' && !@locations);
5164: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5165: $datatable .= '<tr'.$css_class.'>
5166: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
5167: <span class="LC_nobreak">
5168: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5169: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5170: if ($type eq 'version') {
5171: my $selector = '<select name="'.$prefix.'_version">';
5172: foreach my $version (@lcversions) {
5173: my $selected = '';
5174: if ($current{'version'} eq $version) {
5175: $selected = ' selected="selected"';
5176: }
5177: $selector .= ' <option value="'.$version.'"'.
5178: $selected.'>'.$version.'</option>';
5179: }
5180: $selector .= '</select> ';
5181: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5182: } else {
5183: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5184: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5185: ' />'.(' 'x2).
5186: '<input type="button" value="'.&mt('uncheck all').'" '.
5187: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5188: "\n".
5189: '</div><div><table>';
5190: my $rem;
5191: for (my $i=0; $i<@locations; $i++) {
5192: my ($showloc,$value,$checkedtype);
5193: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
5194: my $ip = $by_location{$locations[$i]}->[0];
5195: if (ref($by_ip{$ip}) eq 'ARRAY') {
5196: $value = join(':',@{$by_ip{$ip}});
5197: $showloc = join(', ',@{$by_ip{$ip}});
5198: if (ref($current{$type}) eq 'ARRAY') {
5199: foreach my $loc (@{$by_ip{$ip}}) {
5200: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5201: $checkedtype = ' checked="checked"';
5202: last;
5203: }
5204: }
1.138 raeburn 5205: }
5206: }
5207: }
1.145 raeburn 5208: $rem = $i%($numinrow);
5209: if ($rem == 0) {
5210: if ($i > 0) {
5211: $datatable .= '</tr>';
5212: }
5213: $datatable .= '<tr>';
5214: }
5215: $datatable .= '<td class="LC_left_item">'.
5216: '<span class="LC_nobreak"><label>'.
5217: '<input type="checkbox" name="'.$prefix.'_'.$type.
5218: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5219: '</label></span></td>';
1.137 raeburn 5220: }
1.145 raeburn 5221: $rem = @locations%($numinrow);
5222: my $colsleft = $numinrow - $rem;
5223: if ($colsleft > 1 ) {
5224: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5225: ' </td>';
5226: } elsif ($colsleft == 1) {
5227: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5228: }
1.145 raeburn 5229: $datatable .= '</tr></table>';
1.137 raeburn 5230: }
1.145 raeburn 5231: $datatable .= '</td></tr>';
5232: $itemcount ++;
1.137 raeburn 5233: }
5234: }
5235: }
5236: $$rowtotal += $itemcount;
5237: return $datatable;
5238: }
5239:
1.138 raeburn 5240: sub build_location_hashes {
5241: my ($intdoms,$by_ip,$by_location) = @_;
5242: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
5243: (ref($by_location) eq 'HASH'));
5244: my %iphost = &Apache::lonnet::get_iphost();
5245: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5246: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5247: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5248: foreach my $id (@{$iphost{$primary_ip}}) {
5249: my $intdom = &Apache::lonnet::internet_dom($id);
5250: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5251: push(@{$intdoms},$intdom);
5252: }
5253: }
5254: }
5255: foreach my $ip (keys(%iphost)) {
5256: if (ref($iphost{$ip}) eq 'ARRAY') {
5257: foreach my $id (@{$iphost{$ip}}) {
5258: my $location = &Apache::lonnet::internet_dom($id);
5259: if ($location) {
5260: next if (grep(/^\Q$location\E$/,@{$intdoms}));
5261: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5262: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5263: push(@{$by_ip->{$ip}},$location);
5264: }
5265: } else {
5266: $by_ip->{$ip} = [$location];
5267: }
5268: }
5269: }
5270: }
5271: }
5272: foreach my $ip (sort(keys(%{$by_ip}))) {
5273: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5274: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5275: my $first = $by_ip->{$ip}->[0];
5276: if (ref($by_location->{$first}) eq 'ARRAY') {
5277: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5278: push(@{$by_location->{$first}},$ip);
5279: }
5280: } else {
5281: $by_location->{$first} = [$ip];
5282: }
5283: }
5284: }
5285: return;
5286: }
5287:
1.145 raeburn 5288: sub current_offloads_to {
5289: my ($dom,$settings,$servers) = @_;
5290: my (%spareid,%otherdomconfigs);
1.152 raeburn 5291: if (ref($servers) eq 'HASH') {
1.145 raeburn 5292: foreach my $lonhost (sort(keys(%{$servers}))) {
5293: my $gotspares;
1.152 raeburn 5294: if (ref($settings) eq 'HASH') {
5295: if (ref($settings->{'spares'}) eq 'HASH') {
5296: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5297: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5298: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5299: $gotspares = 1;
5300: }
1.145 raeburn 5301: }
5302: }
5303: unless ($gotspares) {
5304: my $gotspares;
5305: my $serverhomeID =
5306: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5307: my $serverhomedom =
5308: &Apache::lonnet::host_domain($serverhomeID);
5309: if ($serverhomedom ne $dom) {
5310: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5311: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5312: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5313: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5314: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5315: $gotspares = 1;
5316: }
5317: }
5318: } else {
5319: $otherdomconfigs{$serverhomedom} =
5320: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5321: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5322: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5323: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5324: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5325: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5326: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5327: $gotspares = 1;
5328: }
5329: }
5330: }
5331: }
5332: }
5333: }
5334: }
5335: unless ($gotspares) {
5336: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5337: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5338: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5339: } else {
5340: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5341: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5342: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5343: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5344: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5345: } else {
1.150 raeburn 5346: my %what = (
5347: spareid => 1,
5348: );
5349: my ($result,$returnhash) =
5350: &Apache::lonnet::get_remote_globals($lonhost,\%what);
5351: if ($result eq 'ok') {
5352: if (ref($returnhash) eq 'HASH') {
5353: if (ref($returnhash->{'spareid'}) eq 'HASH') {
5354: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5355: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5356: }
5357: }
1.145 raeburn 5358: }
5359: }
5360: }
5361: }
5362: }
5363: }
5364: return %spareid;
5365: }
5366:
5367: sub spares_row {
1.160.6.61 raeburn 5368: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 5369: my $css_class;
5370: my $numinrow = 4;
5371: my $itemcount = 1;
5372: my $datatable;
1.152 raeburn 5373: my %typetitles = &sparestype_titles();
5374: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5375: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5376: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5377: my ($othercontrol,$serverdom);
5378: if ($serverhome ne $server) {
5379: $serverdom = &Apache::lonnet::host_domain($serverhome);
5380: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5381: } else {
5382: $serverdom = &Apache::lonnet::host_domain($server);
5383: if ($serverdom ne $dom) {
5384: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5385: }
5386: }
5387: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 5388: my $checkednow;
5389: if (ref($curroffloadnow) eq 'HASH') {
5390: if ($curroffloadnow->{$server}) {
5391: $checkednow = ' checked="checked"';
5392: }
5393: }
1.145 raeburn 5394: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5395: $datatable .= '<tr'.$css_class.'>
5396: <td rowspan="2">
1.160.6.13 raeburn 5397: <span class="LC_nobreak">'.
5398: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 5399: ,'<b>'.$server.'</b>').'</span><br />'.
5400: '<span class="LC_nobreak">'."\n".
5401: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
5402: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 5403: "\n";
1.145 raeburn 5404: my (%current,%canselect);
1.152 raeburn 5405: my @choices =
5406: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5407: foreach my $type ('primary','default') {
5408: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5409: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5410: my @spares = @{$spareid->{$server}{$type}};
5411: if (@spares > 0) {
1.152 raeburn 5412: if ($othercontrol) {
5413: $current{$type} = join(', ',@spares);
5414: } else {
5415: $current{$type} .= '<table>';
5416: my $numspares = scalar(@spares);
5417: for (my $i=0; $i<@spares; $i++) {
5418: my $rem = $i%($numinrow);
5419: if ($rem == 0) {
5420: if ($i > 0) {
5421: $current{$type} .= '</tr>';
5422: }
5423: $current{$type} .= '<tr>';
1.145 raeburn 5424: }
1.152 raeburn 5425: $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'".');" /> '.
5426: $spareid->{$server}{$type}[$i].
5427: '</label></td>'."\n";
5428: }
5429: my $rem = @spares%($numinrow);
5430: my $colsleft = $numinrow - $rem;
5431: if ($colsleft > 1 ) {
5432: $current{$type} .= '<td colspan="'.$colsleft.
5433: '" class="LC_left_item">'.
5434: ' </td>';
5435: } elsif ($colsleft == 1) {
5436: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5437: }
1.152 raeburn 5438: $current{$type} .= '</tr></table>';
1.150 raeburn 5439: }
1.145 raeburn 5440: }
5441: }
5442: if ($current{$type} eq '') {
5443: $current{$type} = &mt('None specified');
5444: }
1.152 raeburn 5445: if ($othercontrol) {
5446: if ($type eq 'primary') {
5447: $canselect{$type} = $othercontrol;
5448: }
5449: } else {
5450: $canselect{$type} =
5451: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5452: '<select name="newspare_'.$type.'_'.$server.'" '.
5453: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5454: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5455: if (@choices > 0) {
5456: foreach my $lonhost (@choices) {
5457: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5458: }
5459: }
5460: $canselect{$type} .= '</select>'."\n";
5461: }
5462: } else {
5463: $current{$type} = &mt('Could not be determined');
5464: if ($type eq 'primary') {
5465: $canselect{$type} = $othercontrol;
5466: }
1.145 raeburn 5467: }
1.152 raeburn 5468: if ($type eq 'default') {
5469: $datatable .= '<tr'.$css_class.'>';
5470: }
5471: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5472: '<td>'.$current{$type}.'</td>'."\n".
5473: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5474: }
5475: $itemcount ++;
5476: }
5477: }
5478: $$rowtotal += $itemcount;
5479: return $datatable;
5480: }
5481:
1.152 raeburn 5482: sub possible_newspares {
5483: my ($server,$currspares,$serverhomes,$altids) = @_;
5484: my $serverhostname = &Apache::lonnet::hostname($server);
5485: my %excluded;
5486: if ($serverhostname ne '') {
5487: %excluded = (
5488: $serverhostname => 1,
5489: );
5490: }
5491: if (ref($currspares) eq 'HASH') {
5492: foreach my $type (keys(%{$currspares})) {
5493: if (ref($currspares->{$type}) eq 'ARRAY') {
5494: if (@{$currspares->{$type}} > 0) {
5495: foreach my $curr (@{$currspares->{$type}}) {
5496: my $hostname = &Apache::lonnet::hostname($curr);
5497: $excluded{$hostname} = 1;
5498: }
5499: }
5500: }
5501: }
5502: }
5503: my @choices;
5504: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5505: if (keys(%{$serverhomes}) > 1) {
5506: foreach my $name (sort(keys(%{$serverhomes}))) {
5507: unless ($excluded{$name}) {
5508: if (exists($altids->{$serverhomes->{$name}})) {
5509: push(@choices,$altids->{$serverhomes->{$name}});
5510: } else {
5511: push(@choices,$serverhomes->{$name});
1.145 raeburn 5512: }
5513: }
5514: }
5515: }
5516: }
1.152 raeburn 5517: return sort(@choices);
1.145 raeburn 5518: }
5519:
1.150 raeburn 5520: sub print_loadbalancing {
5521: my ($dom,$settings,$rowtotal) = @_;
5522: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5523: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5524: my $numinrow = 1;
5525: my $datatable;
5526: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 5527: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 5528: if (ref($settings) eq 'HASH') {
5529: %existing = %{$settings};
5530: }
5531: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5532: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 5533: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 5534: } else {
5535: return;
5536: }
5537: my ($othertitle,$usertypes,$types) =
5538: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 5539: my $rownum = 8;
1.150 raeburn 5540: if (ref($types) eq 'ARRAY') {
5541: $rownum += scalar(@{$types});
5542: }
1.160.6.7 raeburn 5543: my @css_class = ('LC_odd_row','LC_even_row');
5544: my $balnum = 0;
5545: my $islast;
5546: my (@toshow,$disabledtext);
5547: if (keys(%currbalancer) > 0) {
5548: @toshow = sort(keys(%currbalancer));
5549: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5550: push(@toshow,'');
5551: }
5552: } else {
5553: @toshow = ('');
5554: $disabledtext = &mt('No existing load balancer');
5555: }
5556: foreach my $lonhost (@toshow) {
5557: if ($balnum == scalar(@toshow)-1) {
5558: $islast = 1;
5559: } else {
5560: $islast = 0;
5561: }
5562: my $cssidx = $balnum%2;
5563: my $targets_div_style = 'display: none';
5564: my $disabled_div_style = 'display: block';
5565: my $homedom_div_style = 'display: none';
5566: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5567: '<td rowspan="'.$rownum.'" valign="top">'.
5568: '<p>';
5569: if ($lonhost eq '') {
5570: $datatable .= '<span class="LC_nobreak">';
5571: if (keys(%currbalancer) > 0) {
5572: $datatable .= &mt('Add balancer:');
5573: } else {
5574: $datatable .= &mt('Enable balancer:');
5575: }
5576: $datatable .= ' '.
5577: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5578: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5579: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5580: '<option value="" selected="selected">'.&mt('None').
5581: '</option>'."\n";
5582: foreach my $server (sort(keys(%servers))) {
5583: next if ($currbalancer{$server});
5584: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5585: }
5586: $datatable .=
5587: '</select>'."\n".
5588: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5589: } else {
5590: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5591: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5592: &mt('Stop balancing').'</label>'.
5593: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5594: $targets_div_style = 'display: block';
5595: $disabled_div_style = 'display: none';
5596: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5597: $homedom_div_style = 'display: block';
5598: }
5599: }
5600: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5601: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5602: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5603: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5604: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5605: my @sparestypes = ('primary','default');
5606: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 5607: my %hostherechecked = (
5608: no => ' checked="checked"',
5609: );
1.160.6.94 raeburn 5610: my %balcookiechecked = (
5611: no => ' checked="checked"',
5612: );
1.160.6.7 raeburn 5613: foreach my $sparetype (@sparestypes) {
5614: my $targettable;
5615: for (my $i=0; $i<$numspares; $i++) {
5616: my $checked;
5617: if (ref($currtargets{$lonhost}) eq 'HASH') {
5618: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5619: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5620: $checked = ' checked="checked"';
5621: }
5622: }
5623: }
5624: my ($chkboxval,$disabled);
5625: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5626: $chkboxval = $spares[$i];
5627: }
5628: if (exists($currbalancer{$spares[$i]})) {
5629: $disabled = ' disabled="disabled"';
5630: }
5631: $targettable .=
1.160.6.55 raeburn 5632: '<td><span class="LC_nobreak"><label>'.
5633: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 5634: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.160.6.55 raeburn 5635: '</span></label></span></td>';
1.160.6.7 raeburn 5636: my $rem = $i%($numinrow);
5637: if ($rem == 0) {
5638: if (($i > 0) && ($i < $numspares-1)) {
5639: $targettable .= '</tr>';
5640: }
5641: if ($i < $numspares-1) {
5642: $targettable .= '<tr>';
1.150 raeburn 5643: }
5644: }
5645: }
1.160.6.7 raeburn 5646: if ($targettable ne '') {
5647: my $rem = $numspares%($numinrow);
5648: my $colsleft = $numinrow - $rem;
5649: if ($colsleft > 1 ) {
5650: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5651: ' </td>';
5652: } elsif ($colsleft == 1) {
5653: $targettable .= '<td class="LC_left_item"> </td>';
5654: }
5655: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5656: '<table><tr>'.$targettable.'</tr></table><br />';
5657: }
1.160.6.76 raeburn 5658: $hostherechecked{$sparetype} = '';
5659: if (ref($currtargets{$lonhost}) eq 'HASH') {
5660: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5661: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5662: $hostherechecked{$sparetype} = ' checked="checked"';
5663: $hostherechecked{'no'} = '';
5664: }
5665: }
5666: }
5667: }
1.160.6.94 raeburn 5668: if ($currcookies{$lonhost}) {
5669: %balcookiechecked = (
5670: yes => ' checked="checked"',
5671: );
5672: }
1.160.6.76 raeburn 5673: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5674: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5675: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5676: foreach my $sparetype (@sparestypes) {
5677: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5678: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5679: '</i></label><br />';
1.160.6.7 raeburn 5680: }
1.160.6.94 raeburn 5681: $datatable .= &mt('Use balancer cookie').'<br />'.
5682: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
5683: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
5684: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
5685: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
5686: '</div></td></tr>'.
1.160.6.7 raeburn 5687: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5688: $othertitle,$usertypes,$types,\%servers,
5689: \%currbalancer,$lonhost,
5690: $targets_div_style,$homedom_div_style,
5691: $css_class[$cssidx],$balnum,$islast);
5692: $$rowtotal += $rownum;
5693: $balnum ++;
5694: }
5695: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5696: return $datatable;
5697: }
5698:
5699: sub get_loadbalancers_config {
1.160.6.94 raeburn 5700: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 5701: return unless ((ref($servers) eq 'HASH') &&
5702: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 5703: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
5704: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 5705: if (keys(%{$existing}) > 0) {
5706: my $oldlonhost;
5707: foreach my $key (sort(keys(%{$existing}))) {
5708: if ($key eq 'lonhost') {
5709: $oldlonhost = $existing->{'lonhost'};
5710: $currbalancer->{$oldlonhost} = 1;
5711: } elsif ($key eq 'targets') {
5712: if ($oldlonhost) {
5713: $currtargets->{$oldlonhost} = $existing->{'targets'};
5714: }
5715: } elsif ($key eq 'rules') {
5716: if ($oldlonhost) {
5717: $currrules->{$oldlonhost} = $existing->{'rules'};
5718: }
5719: } elsif (ref($existing->{$key}) eq 'HASH') {
5720: $currbalancer->{$key} = 1;
5721: $currtargets->{$key} = $existing->{$key}{'targets'};
5722: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 5723: if ($existing->{$key}{'cookie'}) {
5724: $currcookies->{$key} = 1;
5725: }
1.150 raeburn 5726: }
5727: }
1.160.6.7 raeburn 5728: } else {
5729: my ($balancerref,$targetsref) =
5730: &Apache::lonnet::get_lonbalancer_config($servers);
5731: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5732: foreach my $server (sort(keys(%{$balancerref}))) {
5733: $currbalancer->{$server} = 1;
5734: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5735: }
5736: }
5737: }
1.160.6.7 raeburn 5738: return;
1.150 raeburn 5739: }
5740:
5741: sub loadbalancing_rules {
5742: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 5743: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5744: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5745: my $output;
1.160.6.7 raeburn 5746: my $num = 0;
5747: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5748: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5749: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5750: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 5751: $num ++;
1.150 raeburn 5752: my $current;
5753: if (ref($currrules) eq 'HASH') {
5754: $current = $currrules->{$type};
5755: }
1.160.6.55 raeburn 5756: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 5757: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5758: $current = '';
5759: }
5760: }
5761: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 5762: $servers,$currbalancer,$lonhost,$dom,
5763: $targets_div_style,$homedom_div_style,
5764: $css_class,$balnum,$num,$islast);
1.150 raeburn 5765: }
5766: }
5767: return $output;
5768: }
5769:
5770: sub loadbalancing_titles {
5771: my ($dom,$intdom,$usertypes,$types) = @_;
5772: my %othertypes = (
5773: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5774: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5775: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5776: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 5777: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5778: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5779: );
1.160.6.26 raeburn 5780: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 5781: my @available;
1.150 raeburn 5782: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 5783: @available = @{$types};
1.150 raeburn 5784: }
1.160.6.89 raeburn 5785: unless (grep(/^default$/,@available)) {
5786: push(@available,'default');
5787: }
5788: unshift(@alltypes,@available);
1.150 raeburn 5789: my %titles;
5790: foreach my $type (@alltypes) {
5791: if ($type =~ /^_LC_/) {
5792: $titles{$type} = $othertypes{$type};
5793: } elsif ($type eq 'default') {
5794: $titles{$type} = &mt('All users from [_1]',$dom);
5795: if (ref($types) eq 'ARRAY') {
5796: if (@{$types} > 0) {
5797: $titles{$type} = &mt('Other users from [_1]',$dom);
5798: }
5799: }
5800: } elsif (ref($usertypes) eq 'HASH') {
5801: $titles{$type} = $usertypes->{$type};
5802: }
5803: }
5804: return (\@alltypes,\%othertypes,\%titles);
5805: }
5806:
5807: sub loadbalance_rule_row {
1.160.6.7 raeburn 5808: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5809: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 5810: my @rulenames;
1.150 raeburn 5811: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 5812: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 5813: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5814: } else {
1.160.6.26 raeburn 5815: @rulenames = ('default','homeserver');
5816: if ($type eq '_LC_external') {
5817: push(@rulenames,'externalbalancer');
5818: } else {
5819: push(@rulenames,'specific');
5820: }
5821: push(@rulenames,'none');
1.150 raeburn 5822: }
5823: my $style = $targets_div_style;
1.160.6.55 raeburn 5824: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5825: $style = $homedom_div_style;
5826: }
1.160.6.7 raeburn 5827: my $space;
5828: if ($islast && $num == 1) {
5829: $space = '<div display="inline-block"> </div>';
5830: }
5831: my $output =
5832: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5833: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5834: '<td valaign="top">'.$space.
5835: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5836: for (my $i=0; $i<@rulenames; $i++) {
5837: my $rule = $rulenames[$i];
5838: my ($checked,$extra);
5839: if ($rulenames[$i] eq 'default') {
5840: $rule = '';
5841: }
5842: if ($rulenames[$i] eq 'specific') {
5843: if (ref($servers) eq 'HASH') {
5844: my $default;
5845: if (($current ne '') && (exists($servers->{$current}))) {
5846: $checked = ' checked="checked"';
5847: }
5848: unless ($checked) {
5849: $default = ' selected="selected"';
5850: }
1.160.6.7 raeburn 5851: $extra =
5852: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5853: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5854: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5855: '<option value=""'.$default.'></option>'."\n";
5856: foreach my $server (sort(keys(%{$servers}))) {
5857: if (ref($currbalancer) eq 'HASH') {
5858: next if (exists($currbalancer->{$server}));
5859: }
1.150 raeburn 5860: my $selected;
1.160.6.7 raeburn 5861: if ($server eq $current) {
1.150 raeburn 5862: $selected = ' selected="selected"';
5863: }
1.160.6.7 raeburn 5864: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5865: }
5866: $extra .= '</select>';
5867: }
5868: } elsif ($rule eq $current) {
5869: $checked = ' checked="checked"';
5870: }
5871: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 5872: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5873: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5874: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 5875: ')"'.$checked.' /> ';
1.160.6.56 raeburn 5876: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 5877: $output .= $ruletitles{'particular'};
5878: } else {
5879: $output .= $ruletitles{$rulenames[$i]};
5880: }
5881: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5882: }
5883: $output .= '</div></td></tr>'."\n";
5884: return $output;
5885: }
5886:
5887: sub offloadtype_text {
5888: my %ruletitles = &Apache::lonlocal::texthash (
5889: 'default' => 'Offloads to default destinations',
5890: 'homeserver' => "Offloads to user's home server",
5891: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5892: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 5893: 'none' => 'No offload',
1.160.6.26 raeburn 5894: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5895: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 5896: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5897: );
5898: return %ruletitles;
5899: }
5900:
5901: sub sparestype_titles {
5902: my %typestitles = &Apache::lonlocal::texthash (
5903: 'primary' => 'primary',
5904: 'default' => 'default',
5905: );
5906: return %typestitles;
5907: }
5908:
1.28 raeburn 5909: sub contact_titles {
5910: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 5911: 'supportemail' => 'Support E-mail address',
5912: 'adminemail' => 'Default Server Admin E-mail address',
5913: 'errormail' => 'Error reports to be e-mailed to',
5914: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 5915: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
5916: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 5917: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5918: 'requestsmail' => 'E-mail from course requests requiring approval',
5919: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 5920: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 5921: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.28 raeburn 5922: );
5923: my %short_titles = &Apache::lonlocal::texthash (
5924: adminemail => 'Admin E-mail address',
5925: supportemail => 'Support E-mail',
5926: );
5927: return (\%titles,\%short_titles);
5928: }
5929:
1.160.6.78 raeburn 5930: sub helpform_fields {
5931: my %titles = &Apache::lonlocal::texthash (
5932: 'username' => 'Name',
5933: 'user' => 'Username/domain',
5934: 'phone' => 'Phone',
5935: 'cc' => 'Cc e-mail',
5936: 'course' => 'Course Details',
5937: 'section' => 'Sections',
5938: 'screenshot' => 'File upload',
5939: );
5940: my @fields = ('username','phone','user','course','section','cc','screenshot');
5941: my %possoptions = (
5942: username => ['yes','no','req'],
5943: phone => ['yes','no','req'],
5944: user => ['yes','no'],
5945: cc => ['yes','no'],
5946: course => ['yes','no'],
5947: section => ['yes','no'],
5948: screenshot => ['yes','no'],
5949: );
5950: my %fieldoptions = &Apache::lonlocal::texthash (
5951: 'yes' => 'Optional',
5952: 'req' => 'Required',
5953: 'no' => "Not shown",
5954: );
5955: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5956: }
5957:
1.72 raeburn 5958: sub tool_titles {
5959: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 5960: aboutme => 'Personal web page',
1.86 raeburn 5961: blog => 'Blog',
1.160.6.4 raeburn 5962: webdav => 'WebDAV',
1.86 raeburn 5963: portfolio => 'Portfolio',
1.88 bisitz 5964: official => 'Official courses (with institutional codes)',
5965: unofficial => 'Unofficial courses',
1.98 raeburn 5966: community => 'Communities',
1.160.6.30 raeburn 5967: textbook => 'Textbook courses',
1.86 raeburn 5968: );
1.72 raeburn 5969: return %titles;
5970: }
5971:
1.101 raeburn 5972: sub courserequest_titles {
5973: my %titles = &Apache::lonlocal::texthash (
5974: official => 'Official',
5975: unofficial => 'Unofficial',
5976: community => 'Communities',
1.160.6.30 raeburn 5977: textbook => 'Textbook',
1.101 raeburn 5978: norequest => 'Not allowed',
1.104 raeburn 5979: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5980: validate => 'With validation',
5981: autolimit => 'Numerical limit',
1.103 raeburn 5982: unlimited => '(blank for unlimited)',
1.101 raeburn 5983: );
5984: return %titles;
5985: }
5986:
1.160.6.5 raeburn 5987: sub authorrequest_titles {
5988: my %titles = &Apache::lonlocal::texthash (
5989: norequest => 'Not allowed',
5990: approval => 'Approval by Dom. Coord.',
5991: automatic => 'Automatic approval',
5992: );
5993: return %titles;
5994: }
5995:
1.101 raeburn 5996: sub courserequest_conditions {
5997: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5998: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 5999: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6000: );
6001: return %conditions;
6002: }
6003:
6004:
1.27 raeburn 6005: sub print_usercreation {
1.30 raeburn 6006: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6007: my $numinrow = 4;
1.28 raeburn 6008: my $datatable;
6009: if ($position eq 'top') {
1.30 raeburn 6010: $$rowtotal ++;
1.34 raeburn 6011: my $rowcount = 0;
1.32 raeburn 6012: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6013: if (ref($rules) eq 'HASH') {
6014: if (keys(%{$rules}) > 0) {
1.32 raeburn 6015: $datatable .= &user_formats_row('username',$settings,$rules,
6016: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6017: $$rowtotal ++;
1.32 raeburn 6018: $rowcount ++;
6019: }
6020: }
6021: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6022: if (ref($idrules) eq 'HASH') {
6023: if (keys(%{$idrules}) > 0) {
6024: $datatable .= &user_formats_row('id',$settings,$idrules,
6025: $idruleorder,$numinrow,$rowcount);
6026: $$rowtotal ++;
6027: $rowcount ++;
1.28 raeburn 6028: }
6029: }
1.39 raeburn 6030: if ($rowcount == 0) {
6031: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6032: $$rowtotal ++;
6033: $rowcount ++;
6034: }
1.34 raeburn 6035: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 6036: my @creators = ('author','course','requestcrs');
1.37 raeburn 6037: my ($rules,$ruleorder) =
6038: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6039: my %lt = &usercreation_types();
6040: my %checked;
6041: if (ref($settings) eq 'HASH') {
6042: if (ref($settings->{'cancreate'}) eq 'HASH') {
6043: foreach my $item (@creators) {
6044: $checked{$item} = $settings->{'cancreate'}{$item};
6045: }
6046: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6047: foreach my $item (@creators) {
6048: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6049: $checked{$item} = 'none';
6050: }
6051: }
6052: }
6053: }
6054: my $rownum = 0;
6055: foreach my $item (@creators) {
6056: $rownum ++;
1.160.6.34 raeburn 6057: if ($checked{$item} eq '') {
6058: $checked{$item} = 'any';
1.34 raeburn 6059: }
6060: my $css_class;
6061: if ($rownum%2) {
6062: $css_class = '';
6063: } else {
6064: $css_class = ' class="LC_odd_row" ';
6065: }
6066: $datatable .= '<tr'.$css_class.'>'.
6067: '<td><span class="LC_nobreak">'.$lt{$item}.
6068: '</span></td><td align="right">';
1.160.6.34 raeburn 6069: my @options = ('any');
6070: if (ref($rules) eq 'HASH') {
6071: if (keys(%{$rules}) > 0) {
6072: push(@options,('official','unofficial'));
1.37 raeburn 6073: }
6074: }
1.160.6.34 raeburn 6075: push(@options,'none');
1.37 raeburn 6076: foreach my $option (@options) {
1.50 raeburn 6077: my $type = 'radio';
1.34 raeburn 6078: my $check = ' ';
1.160.6.34 raeburn 6079: if ($checked{$item} eq $option) {
6080: $check = ' checked="checked" ';
1.34 raeburn 6081: }
6082: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6083: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6084: $item.'" value="'.$option.'"'.$check.'/> '.
6085: $lt{$option}.'</label> </span>';
6086: }
6087: $datatable .= '</td></tr>';
6088: }
1.28 raeburn 6089: } else {
6090: my @contexts = ('author','course','domain');
6091: my @authtypes = ('int','krb4','krb5','loc');
6092: my %checked;
6093: if (ref($settings) eq 'HASH') {
6094: if (ref($settings->{'authtypes'}) eq 'HASH') {
6095: foreach my $item (@contexts) {
6096: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6097: foreach my $auth (@authtypes) {
6098: if ($settings->{'authtypes'}{$item}{$auth}) {
6099: $checked{$item}{$auth} = ' checked="checked" ';
6100: }
6101: }
6102: }
6103: }
1.27 raeburn 6104: }
1.35 raeburn 6105: } else {
6106: foreach my $item (@contexts) {
1.36 raeburn 6107: foreach my $auth (@authtypes) {
1.35 raeburn 6108: $checked{$item}{$auth} = ' checked="checked" ';
6109: }
6110: }
1.27 raeburn 6111: }
1.28 raeburn 6112: my %title = &context_names();
6113: my %authname = &authtype_names();
6114: my $rownum = 0;
6115: my $css_class;
6116: foreach my $item (@contexts) {
6117: if ($rownum%2) {
6118: $css_class = '';
6119: } else {
6120: $css_class = ' class="LC_odd_row" ';
6121: }
1.30 raeburn 6122: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6123: '<td>'.$title{$item}.
6124: '</td><td class="LC_left_item">'.
6125: '<span class="LC_nobreak">';
6126: foreach my $auth (@authtypes) {
6127: $datatable .= '<label>'.
6128: '<input type="checkbox" name="'.$item.'_auth" '.
6129: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6130: $authname{$auth}.'</label> ';
6131: }
6132: $datatable .= '</span></td></tr>';
6133: $rownum ++;
1.27 raeburn 6134: }
1.30 raeburn 6135: $$rowtotal += $rownum;
1.27 raeburn 6136: }
6137: return $datatable;
6138: }
6139:
1.160.6.34 raeburn 6140: sub print_selfcreation {
6141: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 6142: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6143: $emaildomain,$datatable);
1.160.6.34 raeburn 6144: if (ref($settings) eq 'HASH') {
6145: if (ref($settings->{'cancreate'}) eq 'HASH') {
6146: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 6147: if (ref($createsettings) eq 'HASH') {
6148: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6149: @selfcreate = @{$createsettings->{'selfcreate'}};
6150: } elsif ($createsettings->{'selfcreate'} ne '') {
6151: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6152: @selfcreate = ('email','login','sso');
6153: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6154: @selfcreate = ($createsettings->{'selfcreate'});
6155: }
6156: }
6157: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6158: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 6159: }
1.160.6.93 raeburn 6160: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6161: $emailoptions = $createsettings->{'emailoptions'};
6162: }
6163: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6164: $emailverified = $createsettings->{'emailverified'};
6165: }
6166: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6167: $emaildomain = $createsettings->{'emaildomain'};
6168: }
1.160.6.34 raeburn 6169: }
6170: }
6171: }
6172: my %radiohash;
6173: my $numinrow = 4;
6174: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 6175: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 6176: if ($position eq 'top') {
6177: my %choices = &Apache::lonlocal::texthash (
6178: cancreate_login => 'Institutional Login',
6179: cancreate_sso => 'Institutional Single Sign On',
6180: );
6181: my @toggles = sort(keys(%choices));
6182: my %defaultchecked = (
6183: 'cancreate_login' => 'off',
6184: 'cancreate_sso' => 'off',
6185: );
1.160.6.35 raeburn 6186: my ($onclick,$itemcount);
1.160.6.34 raeburn 6187: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6188: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 6189: $$rowtotal += $itemcount;
1.160.6.34 raeburn 6190:
6191: if (ref($usertypes) eq 'HASH') {
6192: if (keys(%{$usertypes}) > 0) {
6193: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6194: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 6195: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 6196: $$rowtotal ++;
6197: }
6198: }
1.160.6.44 raeburn 6199: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6200: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6201: $fieldtitles{'inststatus'} = &mt('Institutional status');
6202: my $rem;
6203: my $numperrow = 2;
6204: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6205: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 6206: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 6207: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 6208: '<table>'."\n";
1.160.6.44 raeburn 6209: for (my $i=0; $i<@fields; $i++) {
6210: $rem = $i%($numperrow);
6211: if ($rem == 0) {
6212: if ($i > 0) {
6213: $datatable .= '</tr>';
6214: }
6215: $datatable .= '<tr>';
6216: }
6217: my $currval;
1.160.6.51 raeburn 6218: if (ref($createsettings) eq 'HASH') {
6219: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6220: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6221: }
1.160.6.44 raeburn 6222: }
6223: $datatable .= '<td class="LC_left_item">'.
6224: '<span class="LC_nobreak">'.
6225: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6226: 'value="'.$currval.'" size="10" /> '.
6227: $fieldtitles{$fields[$i]}.'</span></td>';
6228: }
6229: my $colsleft = $numperrow - $rem;
6230: if ($colsleft > 1 ) {
6231: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6232: ' </td>';
6233: } elsif ($colsleft == 1) {
6234: $datatable .= '<td class="LC_left_item"> </td>';
6235: }
6236: $datatable .= '</tr></table></td></tr>';
6237: $$rowtotal ++;
1.160.6.34 raeburn 6238: } elsif ($position eq 'middle') {
6239: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 6240: my @posstypes;
1.160.6.34 raeburn 6241: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 6242: @posstypes = @{$types};
6243: }
6244: unless (grep(/^default$/,@posstypes)) {
6245: push(@posstypes,'default');
6246: }
6247: my %usertypeshash;
6248: if (ref($usertypes) eq 'HASH') {
6249: %usertypeshash = %{$usertypes};
6250: }
6251: $usertypeshash{'default'} = $othertitle;
6252: foreach my $status (@posstypes) {
6253: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6254: $numinrow,$$rowtotal,\%usertypeshash);
6255: $$rowtotal ++;
1.160.6.34 raeburn 6256: }
6257: } else {
1.160.6.40 raeburn 6258: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 6259: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 6260: );
6261: my @toggles = sort(keys(%choices));
6262: my %defaultchecked = (
6263: 'cancreate_email' => 'off',
6264: );
1.160.6.93 raeburn 6265: my $customclass = 'LC_selfcreate_email';
6266: my $classprefix = 'LC_canmodify_emailusername_';
6267: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 6268: my $display = 'none';
1.160.6.93 raeburn 6269: my $rowstyle = 'display:none';
1.160.6.40 raeburn 6270: if (grep(/^\Qemail\E$/,@selfcreate)) {
6271: $display = 'block';
1.160.6.93 raeburn 6272: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 6273: }
1.160.6.93 raeburn 6274: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6275: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6276: \%choices,$$rowtotal,$onclick);
6277: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6278: $rowstyle);
6279: $$rowtotal ++;
6280: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6281: $rowstyle);
6282: $$rowtotal ++;
6283: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 6284: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 6285: my ($emailrules,$emailruleorder) =
6286: &Apache::lonnet::inst_userrules($dom,'email');
6287: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6288: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6289: if (ref($types) eq 'ARRAY') {
6290: @posstypes = @{$types};
6291: }
6292: if (@posstypes) {
6293: unless (grep(/^default$/,@posstypes)) {
6294: push(@posstypes,'default');
1.160.6.89 raeburn 6295: }
6296: if (ref($usertypes) eq 'HASH') {
6297: %usertypeshash = %{$usertypes};
6298: }
1.160.6.93 raeburn 6299: my $currassign;
6300: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6301: $currassign = {
6302: selfassign => $domdefaults{'inststatusguest'},
6303: };
6304: @ordered = @{$domdefaults{'inststatusguest'}};
6305: } else {
6306: $currassign = { selfassign => [] };
6307: }
6308: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6309: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6310: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6311: $numinrow,$othertitle,'selfassign',
6312: $rowtotal,$onclicktypes,$customclass,
6313: $rowstyle);
6314: $$rowtotal ++;
1.160.6.89 raeburn 6315: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 6316: foreach my $status (@posstypes) {
6317: my $css_class;
6318: if ($$rowtotal%2) {
6319: $css_class = 'LC_odd_row ';
6320: }
6321: $css_class .= $customclass;
6322: my $rowid = $optionsprefix.$status;
6323: my $hidden = 1;
6324: my $currstyle = 'display:none';
6325: if (grep(/^\Q$status\E$/,@ordered)) {
6326: $currstyle = $rowstyle;
6327: $hidden = 0;
6328: }
6329: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6330: $emailrules,$emailruleorder,$settings,$status,$rowid,
6331: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6332: unless ($hidden) {
6333: $$rowtotal ++;
6334: }
1.160.6.89 raeburn 6335: }
6336: } else {
1.160.6.93 raeburn 6337: my $css_class;
6338: if ($$rowtotal%2) {
6339: $css_class = 'LC_odd_row ';
6340: }
6341: $css_class .= $customclass;
1.160.6.89 raeburn 6342: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 6343: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6344: $emailrules,$emailruleorder,$settings,'default','',
6345: $othertitle,$css_class,$rowstyle,$intdom);
6346: $$rowtotal ++;
1.160.6.34 raeburn 6347: }
1.160.6.35 raeburn 6348: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
6349: $numinrow = 1;
1.160.6.93 raeburn 6350: if (@posstypes) {
6351: foreach my $status (@posstypes) {
6352: my $rowid = $classprefix.$status;
6353: my $datarowstyle = 'display:none';
6354: if (grep(/^\Q$status\E$/,@ordered)) {
6355: $datarowstyle = $rowstyle;
6356: }
6357: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6358: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6359: $infotitles,$rowid,$customclass,$datarowstyle);
6360: unless ($datarowstyle eq 'display:none') {
6361: $$rowtotal ++;
6362: }
1.160.6.34 raeburn 6363: }
1.160.6.93 raeburn 6364: } else {
6365: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
6366: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6367: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 6368: }
6369: }
6370: return $datatable;
6371: }
6372:
1.160.6.93 raeburn 6373: sub selfcreate_javascript {
6374: return <<"ENDSCRIPT";
6375:
6376: <script type="text/javascript">
6377: // <![CDATA[
6378:
6379: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6380: var x = document.getElementsByClassName(target);
6381: var insttypes = 0;
6382: var insttypeRegExp = new RegExp(prefix);
6383: if ((x.length != undefined) && (x.length > 0)) {
6384: if (form.elements[radio].length != undefined) {
6385: for (var i=0; i<form.elements[radio].length; i++) {
6386: if (form.elements[radio][i].checked) {
6387: if (form.elements[radio][i].value == 1) {
6388: for (var j=0; j<x.length; j++) {
6389: if (x[j].id == 'undefined') {
6390: x[j].style.display = 'table-row';
6391: } else if (insttypeRegExp.test(x[j].id)) {
6392: insttypes ++;
6393: } else {
6394: x[j].style.display = 'table-row';
6395: }
6396: }
6397: } else {
6398: for (var j=0; j<x.length; j++) {
6399: x[j].style.display = 'none';
6400: }
1.160.6.40 raeburn 6401: }
1.160.6.93 raeburn 6402: break;
6403: }
6404: }
6405: if (insttypes > 0) {
6406: toggleDataRow(form,checkbox,target,altprefix);
6407: toggleDataRow(form,checkbox,target,prefix,1);
6408: }
6409: }
6410: }
6411: return;
6412: }
6413:
6414: function toggleDataRow(form,checkbox,target,prefix,docount) {
6415: if (form.elements[checkbox].length != undefined) {
6416: var count = 0;
6417: if (docount) {
6418: for (var i=0; i<form.elements[checkbox].length; i++) {
6419: if (form.elements[checkbox][i].checked) {
6420: count ++;
6421: }
6422: }
6423: }
6424: for (var i=0; i<form.elements[checkbox].length; i++) {
6425: var type = form.elements[checkbox][i].value;
6426: if (document.getElementById(prefix+type)) {
6427: if (form.elements[checkbox][i].checked) {
6428: document.getElementById(prefix+type).style.display = 'table-row';
6429: if (count % 2 == 1) {
6430: document.getElementById(prefix+type).className = target+' LC_odd_row';
6431: } else {
6432: document.getElementById(prefix+type).className = target;
6433: }
6434: count ++;
1.160.6.40 raeburn 6435: } else {
1.160.6.93 raeburn 6436: document.getElementById(prefix+type).style.display = 'none';
6437: }
6438: }
6439: }
6440: }
6441: return;
6442: }
6443:
6444: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
6445: var caller = radio+'_'+status;
6446: if (form.elements[caller].length != undefined) {
6447: for (var i=0; i<form.elements[caller].length; i++) {
6448: if (form.elements[caller][i].checked) {
6449: if (document.getElementById(altprefix+'_inst_'+status)) {
6450: var curr = form.elements[caller][i].value;
6451: if (prefix) {
6452: document.getElementById(prefix+'_'+status).style.display = 'none';
6453: }
6454: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
6455: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
6456: if (curr == 'custom') {
6457: if (prefix) {
6458: document.getElementById(prefix+'_'+status).style.display = 'inline';
6459: }
6460: } else if (curr == 'inst') {
6461: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
6462: } else if (curr == 'noninst') {
6463: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 6464: }
1.160.6.93 raeburn 6465: break;
1.160.6.40 raeburn 6466: }
1.160.6.93 raeburn 6467: }
6468: }
6469: }
6470: }
6471:
6472: // ]]>
6473: </script>
6474:
6475: ENDSCRIPT
6476: }
6477:
6478: sub noninst_users {
6479: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
6480: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
6481: my $class = 'LC_left_item';
6482: if ($css_class) {
6483: $css_class = ' class="'.$css_class.'"';
6484: }
6485: if ($rowid) {
6486: $rowid = ' id="'.$rowid.'"';
6487: }
6488: if ($rowstyle) {
6489: $rowstyle = ' style="'.$rowstyle.'"';
6490: }
6491: my ($output,$description);
6492: if ($type eq 'default') {
6493: $description = &mt('Requests for: [_1]',$typetitle);
6494: } else {
6495: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
6496: }
6497: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
6498: "<td>$description</td>\n".
6499: '<td class="'.$class.'" colspan="2">'.
6500: '<table><tr>';
6501: my %headers = &Apache::lonlocal::texthash(
6502: approve => 'Processing',
6503: email => 'E-mail',
6504: username => 'Username',
6505: );
6506: foreach my $item ('approve','email','username') {
6507: $output .= '<th>'.$headers{$item}.'</th>';
6508: }
6509: $output .= '</tr><tr>';
6510: foreach my $item ('approve','email','username') {
6511: $output .= '<td valign="top">';
6512: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
6513: if ($item eq 'approve') {
6514: %choices = &Apache::lonlocal::texthash (
6515: automatic => 'Automatically approved',
6516: approval => 'Queued for approval',
6517: );
6518: @options = ('automatic','approval');
6519: $hashref = $processing;
6520: $defoption = 'automatic';
6521: $name = 'cancreate_emailprocess_'.$type;
6522: } elsif ($item eq 'email') {
6523: %choices = &Apache::lonlocal::texthash (
6524: any => 'Any e-mail',
6525: inst => 'Institutional only',
6526: noninst => 'Non-institutional only',
6527: custom => 'Custom restrictions',
6528: );
6529: @options = ('any','inst','noninst');
6530: my $showcustom;
6531: if (ref($emailrules) eq 'HASH') {
6532: if (keys(%{$emailrules}) > 0) {
6533: push(@options,'custom');
6534: $showcustom = 'cancreate_emailrule';
6535: if (ref($settings) eq 'HASH') {
6536: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
6537: foreach my $rule (@{$settings->{'email_rule'}}) {
6538: if (exists($emailrules->{$rule})) {
6539: $hascustom ++;
6540: }
6541: }
6542: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
6543: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
6544: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
6545: if (exists($emailrules->{$rule})) {
6546: $hascustom ++;
6547: }
6548: }
6549: }
6550: }
6551: }
6552: }
6553: }
6554: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
6555: "'cancreate_emaildomain','$type'".');"';
6556: $hashref = $emailoptions;
6557: $defoption = 'any';
6558: $name = 'cancreate_emailoptions_'.$type;
6559: } elsif ($item eq 'username') {
6560: %choices = &Apache::lonlocal::texthash (
6561: all => 'Same as e-mail',
6562: first => 'Omit @domain',
6563: free => 'Free to choose',
6564: );
6565: @options = ('all','first','free');
6566: $hashref = $emailverified;
6567: $defoption = 'all';
6568: $name = 'cancreate_usernameoptions_'.$type;
6569: }
6570: foreach my $option (@options) {
6571: my $checked;
6572: if (ref($hashref) eq 'HASH') {
6573: if ($type eq '') {
6574: if (!exists($hashref->{'default'})) {
6575: if ($option eq $defoption) {
6576: $checked = ' checked="checked"';
6577: }
6578: } else {
6579: if ($hashref->{'default'} eq $option) {
6580: $checked = ' checked="checked"';
6581: }
1.160.6.40 raeburn 6582: }
6583: } else {
1.160.6.93 raeburn 6584: if (!exists($hashref->{$type})) {
6585: if ($option eq $defoption) {
6586: $checked = ' checked="checked"';
6587: }
6588: } else {
6589: if ($hashref->{$type} eq $option) {
6590: $checked = ' checked="checked"';
6591: }
1.160.6.40 raeburn 6592: }
6593: }
1.160.6.93 raeburn 6594: } elsif (($item eq 'email') && ($hascustom)) {
6595: if ($option eq 'custom') {
6596: $checked = ' checked="checked"';
6597: }
6598: } elsif ($option eq $defoption) {
6599: $checked = ' checked="checked"';
6600: }
6601: $output .= '<span class="LC_nobreak"><label>'.
6602: '<input type="radio" name="'.$name.'"'.
6603: $checked.' value="'.$option.'"'.$onclick.' />'.
6604: $choices{$option}.'</label></span><br />';
6605: if ($item eq 'email') {
6606: if ($option eq 'custom') {
6607: my $id = 'cancreate_emailrule_'.$type;
6608: my $display = 'none';
6609: if ($checked) {
6610: $display = 'inline';
6611: }
6612: my $numinrow = 2;
6613: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
6614: '<legend>'.&mt('Disallow').'</legend><table>'.
6615: &user_formats_row('email',$settings,$emailrules,
6616: $emailruleorder,$numinrow,'',$type);
6617: '</table></fieldset>';
6618: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
6619: my %text = &Apache::lonlocal::texthash (
6620: inst => 'must end:',
6621: noninst => 'cannot end:',
6622: );
6623: my $value;
6624: if (ref($emaildomain) eq 'HASH') {
6625: if (ref($emaildomain->{$type}) eq 'HASH') {
6626: $value = $emaildomain->{$type}->{$option};
6627: }
6628: }
6629: if ($value eq '') {
6630: $value = '@'.$intdom;
6631: }
6632: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
6633: my $display = 'none';
6634: if ($checked) {
6635: $display = 'inline';
6636: }
6637: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
6638: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
6639: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
6640: '</div>';
6641: }
1.160.6.40 raeburn 6642: }
6643: }
1.160.6.93 raeburn 6644: $output .= '</td>'."\n";
1.160.6.40 raeburn 6645: }
1.160.6.93 raeburn 6646: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 6647: return $output;
6648: }
6649:
1.160.6.5 raeburn 6650: sub captcha_choice {
1.160.6.93 raeburn 6651: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 6652: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
6653: $vertext,$currver);
1.160.6.5 raeburn 6654: my %lt = &captcha_phrases();
6655: $keyentry = 'hidden';
1.160.6.98 raeburn 6656: my $colspan=2;
1.160.6.5 raeburn 6657: if ($context eq 'cancreate') {
1.160.6.34 raeburn 6658: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 6659: } elsif ($context eq 'login') {
6660: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 6661: } elsif ($context eq 'passwords') {
6662: $rowname = &mt('"Forgot Password" CAPTCHA validation');
6663: $colspan=1;
1.160.6.5 raeburn 6664: }
6665: if (ref($settings) eq 'HASH') {
6666: if ($settings->{'captcha'}) {
6667: $checked{$settings->{'captcha'}} = ' checked="checked"';
6668: } else {
6669: $checked{'original'} = ' checked="checked"';
6670: }
6671: if ($settings->{'captcha'} eq 'recaptcha') {
6672: $pubtext = $lt{'pub'};
6673: $privtext = $lt{'priv'};
6674: $keyentry = 'text';
1.160.6.69 raeburn 6675: $vertext = $lt{'ver'};
6676: $currver = $settings->{'recaptchaversion'};
6677: if ($currver ne '2') {
6678: $currver = 1;
6679: }
1.160.6.5 raeburn 6680: }
6681: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
6682: $currpub = $settings->{'recaptchakeys'}{'public'};
6683: $currpriv = $settings->{'recaptchakeys'}{'private'};
6684: }
6685: } else {
6686: $checked{'original'} = ' checked="checked"';
6687: }
1.160.6.93 raeburn 6688: my $css_class;
6689: if ($itemcount%2) {
6690: $css_class = 'LC_odd_row';
6691: }
6692: if ($customcss) {
6693: $css_class .= " $customcss";
6694: }
6695: $css_class =~ s/^\s+//;
6696: if ($css_class) {
6697: $css_class = ' class="'.$css_class.'"';
6698: }
6699: if ($rowstyle) {
6700: $css_class .= ' style="'.$rowstyle.'"';
6701: }
1.160.6.5 raeburn 6702: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 6703: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 6704: '<table><tr><td>'."\n";
6705: foreach my $option ('original','recaptcha','notused') {
6706: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6707: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6708: $lt{$option}.'</label></span>';
6709: unless ($option eq 'notused') {
6710: $output .= (' 'x2)."\n";
6711: }
6712: }
6713: #
6714: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6715: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
6716: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
6717: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
6718: #
6719: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 6720: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 6721: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6722: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6723: $currpub.'" size="40" /></span><br />'."\n".
6724: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6725: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 6726: $currpriv.'" size="40" /></span><br />'.
6727: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6728: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6729: $currver.'" size="3" /></span><br />'.
6730: '</td></tr></table>'."\n".
1.160.6.5 raeburn 6731: '</td></tr>';
6732: return $output;
6733: }
6734:
1.32 raeburn 6735: sub user_formats_row {
1.160.6.93 raeburn 6736: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 6737: my $output;
6738: my %text = (
6739: 'username' => 'new usernames',
6740: 'id' => 'IDs',
6741: );
1.160.6.93 raeburn 6742: unless ($type eq 'email') {
6743: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6744: $output = '<tr '.$css_class.'>'.
6745: '<td><span class="LC_nobreak">'.
6746: &mt("Format rules to check for $text{$type}: ").
6747: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 6748: }
1.27 raeburn 6749: my $rem;
6750: if (ref($ruleorder) eq 'ARRAY') {
6751: for (my $i=0; $i<@{$ruleorder}; $i++) {
6752: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6753: my $rem = $i%($numinrow);
6754: if ($rem == 0) {
6755: if ($i > 0) {
6756: $output .= '</tr>';
6757: }
6758: $output .= '<tr>';
6759: }
6760: my $check = ' ';
1.39 raeburn 6761: if (ref($settings) eq 'HASH') {
6762: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6763: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6764: $check = ' checked="checked" ';
6765: }
1.160.6.93 raeburn 6766: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
6767: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
6768: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
6769: $check = ' checked="checked" ';
6770: }
6771: }
1.27 raeburn 6772: }
6773: }
1.160.6.93 raeburn 6774: my $name = $type.'_rule';
6775: if ($type eq 'email') {
6776: $name .= '_'.$status;
6777: }
1.27 raeburn 6778: $output .= '<td class="LC_left_item">'.
6779: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 6780: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 6781: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6782: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6783: }
6784: }
6785: $rem = @{$ruleorder}%($numinrow);
6786: }
1.160.6.93 raeburn 6787: my $colsleft;
6788: if ($rem) {
6789: $colsleft = $numinrow - $rem;
6790: }
1.27 raeburn 6791: if ($colsleft > 1 ) {
6792: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6793: ' </td>';
6794: } elsif ($colsleft == 1) {
6795: $output .= '<td class="LC_left_item"> </td>';
6796: }
1.160.6.93 raeburn 6797: $output .= '</tr></table>';
6798: unless ($type eq 'email') {
6799: $output .= '</td></tr>';
6800: }
1.27 raeburn 6801: return $output;
6802: }
6803:
1.34 raeburn 6804: sub usercreation_types {
6805: my %lt = &Apache::lonlocal::texthash (
6806: author => 'When adding a co-author',
6807: course => 'When adding a user to a course',
1.100 raeburn 6808: requestcrs => 'When requesting a course',
1.34 raeburn 6809: any => 'Any',
6810: official => 'Institutional only ',
6811: unofficial => 'Non-institutional only',
6812: none => 'None',
6813: );
6814: return %lt;
1.48 raeburn 6815: }
1.34 raeburn 6816:
1.160.6.34 raeburn 6817: sub selfcreation_types {
6818: my %lt = &Apache::lonlocal::texthash (
6819: selfcreate => 'User creates own account',
6820: any => 'Any',
6821: official => 'Institutional only ',
6822: unofficial => 'Non-institutional only',
6823: email => 'E-mail address',
6824: login => 'Institutional Login',
6825: sso => 'SSO',
6826: );
6827: }
6828:
1.28 raeburn 6829: sub authtype_names {
6830: my %lt = &Apache::lonlocal::texthash(
6831: int => 'Internal',
6832: krb4 => 'Kerberos 4',
6833: krb5 => 'Kerberos 5',
6834: loc => 'Local',
6835: );
6836: return %lt;
6837: }
6838:
6839: sub context_names {
6840: my %context_title = &Apache::lonlocal::texthash(
6841: author => 'Creating users when an Author',
6842: course => 'Creating users when in a course',
6843: domain => 'Creating users when a Domain Coordinator',
6844: );
6845: return %context_title;
6846: }
6847:
1.33 raeburn 6848: sub print_usermodification {
6849: my ($position,$dom,$settings,$rowtotal) = @_;
6850: my $numinrow = 4;
6851: my ($context,$datatable,$rowcount);
6852: if ($position eq 'top') {
6853: $rowcount = 0;
6854: $context = 'author';
6855: foreach my $role ('ca','aa') {
6856: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6857: $numinrow,$rowcount);
6858: $$rowtotal ++;
6859: $rowcount ++;
6860: }
1.160.6.37 raeburn 6861: } elsif ($position eq 'bottom') {
1.33 raeburn 6862: $context = 'course';
6863: $rowcount = 0;
6864: foreach my $role ('st','ep','ta','in','cr') {
6865: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6866: $numinrow,$rowcount);
6867: $$rowtotal ++;
6868: $rowcount ++;
6869: }
6870: }
6871: return $datatable;
6872: }
6873:
1.43 raeburn 6874: sub print_defaults {
1.160.6.40 raeburn 6875: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6876: my $rownum = 0;
1.160.6.80 raeburn 6877: my ($datatable,$css_class,$titles);
6878: unless ($position eq 'bottom') {
6879: $titles = &defaults_titles($dom);
6880: }
1.160.6.40 raeburn 6881: if ($position eq 'top') {
6882: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6883: 'datelocale_def','portal_def');
6884: my %defaults;
6885: if (ref($settings) eq 'HASH') {
6886: %defaults = %{$settings};
1.43 raeburn 6887: } else {
1.160.6.40 raeburn 6888: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6889: foreach my $item (@items) {
6890: $defaults{$item} = $domdefaults{$item};
6891: }
1.43 raeburn 6892: }
1.160.6.40 raeburn 6893: foreach my $item (@items) {
6894: if ($rownum%2) {
6895: $css_class = '';
6896: } else {
6897: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 6898: }
1.160.6.40 raeburn 6899: $datatable .= '<tr'.$css_class.'>'.
6900: '<td><span class="LC_nobreak">'.$titles->{$item}.
6901: '</span></td><td class="LC_right_item" colspan="3">';
6902: if ($item eq 'auth_def') {
6903: my @authtypes = ('internal','krb4','krb5','localauth');
6904: my %shortauth = (
6905: internal => 'int',
6906: krb4 => 'krb4',
6907: krb5 => 'krb5',
6908: localauth => 'loc'
6909: );
6910: my %authnames = &authtype_names();
6911: foreach my $auth (@authtypes) {
6912: my $checked = ' ';
6913: if ($defaults{$item} eq $auth) {
6914: $checked = ' checked="checked" ';
6915: }
6916: $datatable .= '<label><input type="radio" name="'.$item.
6917: '" value="'.$auth.'"'.$checked.'/>'.
6918: $authnames{$shortauth{$auth}}.'</label> ';
6919: }
6920: } elsif ($item eq 'timezone_def') {
6921: my $includeempty = 1;
6922: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6923: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 6924: my $includeempty = 1;
6925: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6926: } elsif ($item eq 'lang_def') {
6927: my $includeempty = 1;
6928: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 6929: } else {
1.160.6.98 raeburn 6930: my $size;
6931: if ($item eq 'portal_def') {
6932: $size = ' size="25"';
6933: }
1.160.6.80 raeburn 6934: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98 raeburn 6935: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 6936: }
6937: $datatable .= '</td></tr>';
6938: $rownum ++;
6939: }
1.160.6.40 raeburn 6940: } else {
1.160.6.80 raeburn 6941: my %defaults;
1.160.6.40 raeburn 6942: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 6943: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 6944: my $maxnum = @{$settings->{'inststatusorder'}};
6945: for (my $i=0; $i<$maxnum; $i++) {
6946: $css_class = $rownum%2?' class="LC_odd_row"':'';
6947: my $item = $settings->{'inststatusorder'}->[$i];
6948: my $title = $settings->{'inststatustypes'}->{$item};
6949: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6950: $datatable .= '<tr'.$css_class.'>'.
6951: '<td><span class="LC_nobreak">'.
6952: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6953: for (my $k=0; $k<=$maxnum; $k++) {
6954: my $vpos = $k+1;
6955: my $selstr;
6956: if ($k == $i) {
6957: $selstr = ' selected="selected" ';
6958: }
6959: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6960: }
6961: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6962: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6963: &mt('delete').'</span></td>'.
6964: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6965: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 6966: '</span></td></tr>';
1.160.6.40 raeburn 6967: }
6968: $css_class = $rownum%2?' class="LC_odd_row"':'';
6969: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6970: $datatable .= '<tr '.$css_class.'>'.
6971: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6972: for (my $k=0; $k<=$maxnum; $k++) {
6973: my $vpos = $k+1;
6974: my $selstr;
6975: if ($k == $maxnum) {
6976: $selstr = ' selected="selected" ';
6977: }
6978: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6979: }
6980: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 6981: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 6982: ' '.&mt('(new)').
6983: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6984: &mt('Name displayed:').
6985: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6986: '</tr>'."\n";
6987: $rownum ++;
1.141 raeburn 6988: }
1.43 raeburn 6989: }
6990: }
6991: $$rowtotal += $rownum;
6992: return $datatable;
6993: }
6994:
1.160.6.5 raeburn 6995: sub get_languages_hash {
6996: my %langchoices;
6997: foreach my $id (&Apache::loncommon::languageids()) {
6998: my $code = &Apache::loncommon::supportedlanguagecode($id);
6999: if ($code ne '') {
7000: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7001: }
7002: }
7003: return %langchoices;
7004: }
7005:
1.43 raeburn 7006: sub defaults_titles {
1.141 raeburn 7007: my ($dom) = @_;
1.43 raeburn 7008: my %titles = &Apache::lonlocal::texthash (
7009: 'auth_def' => 'Default authentication type',
7010: 'auth_arg_def' => 'Default authentication argument',
7011: 'lang_def' => 'Default language',
1.54 raeburn 7012: 'timezone_def' => 'Default timezone',
1.68 raeburn 7013: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7014: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 7015: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7016: 'intauth_check' => 'Check bcrypt cost if authenticated',
7017: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7018: );
1.141 raeburn 7019: if ($dom) {
7020: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7021: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7022: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7023: $protocol = 'http' if ($protocol ne 'https');
7024: if ($uint_dom) {
7025: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7026: $uint_dom);
7027: }
7028: }
1.43 raeburn 7029: return (\%titles);
7030: }
7031:
1.160.6.97 raeburn 7032: sub print_scantron {
7033: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
7034: if ($position eq 'top') {
7035: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
7036: } else {
7037: return &print_scantronconfig($dom,$settings,\$rowtotal);
7038: }
7039: }
7040:
7041: sub scantron_javascript {
7042: return <<"ENDSCRIPT";
7043:
7044: <script type="text/javascript">
7045: // <![CDATA[
7046:
7047: function toggleScantron(form) {
7048: var csvfieldset = new Array();
7049: if (document.getElementById('scantroncsv_cols')) {
7050: csvfieldset.push(document.getElementById('scantroncsv_cols'));
7051: }
7052: if (document.getElementById('scantroncsv_options')) {
7053: csvfieldset.push(document.getElementById('scantroncsv_options'));
7054: }
7055: if (csvfieldset.length) {
7056: if (document.getElementById('scantronconfcsv')) {
7057: var scantroncsv = document.getElementById('scantronconfcsv');
7058: if (scantroncsv.checked) {
7059: for (var i=0; i<csvfieldset.length; i++) {
7060: csvfieldset[i].style.display = 'block';
7061: }
7062: } else {
7063: for (var i=0; i<csvfieldset.length; i++) {
7064: csvfieldset[i].style.display = 'none';
7065: }
7066: var csvselects = document.getElementsByClassName('scantronconfig_csv');
7067: if (csvselects.length) {
7068: for (var j=0; j<csvselects.length; j++) {
7069: csvselects[j].selectedIndex = 0;
7070: }
7071: }
7072: }
7073: }
7074: }
7075: return;
7076: }
7077: // ]]>
7078: </script>
7079:
7080: ENDSCRIPT
7081:
7082: }
7083:
1.46 raeburn 7084: sub print_scantronformat {
7085: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7086: my $itemcount = 1;
1.60 raeburn 7087: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7088: %confhash);
1.46 raeburn 7089: my $switchserver = &check_switchserver($dom,$confname);
7090: my %lt = &Apache::lonlocal::texthash (
1.95 www 7091: default => 'Default bubblesheet format file error',
7092: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7093: );
7094: my %scantronfiles = (
7095: default => 'default.tab',
7096: custom => 'custom.tab',
7097: );
7098: foreach my $key (keys(%scantronfiles)) {
7099: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7100: .$scantronfiles{$key};
7101: }
7102: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7103: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7104: if (!$switchserver) {
7105: my $servadm = $r->dir_config('lonAdmEMail');
7106: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7107: if ($configuserok eq 'ok') {
7108: if ($author_ok eq 'ok') {
7109: my %legacyfile = (
1.160.6.97 raeburn 7110: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7111: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 7112: );
7113: my %md5chk;
7114: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7115: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7116: chomp($md5chk{$type});
1.46 raeburn 7117: }
7118: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7119: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 7120: ($scantronurls{$type},my $error) =
1.46 raeburn 7121: &legacy_scantronformat($r,$dom,$confname,
7122: $type,$legacyfile{$type},
7123: $scantronurls{$type},
7124: $scantronfiles{$type});
1.60 raeburn 7125: if ($error ne '') {
7126: $error{$type} = $error;
7127: }
7128: }
7129: if (keys(%error) == 0) {
7130: $is_custom = 1;
1.160.6.97 raeburn 7131: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 7132: $scantronurls{'custom'};
1.160.6.97 raeburn 7133: my $putresult =
1.60 raeburn 7134: &Apache::lonnet::put_dom('configuration',
7135: \%confhash,$dom);
7136: if ($putresult ne 'ok') {
1.160.6.97 raeburn 7137: $error{'custom'} =
1.60 raeburn 7138: '<span class="LC_error">'.
7139: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7140: }
1.46 raeburn 7141: }
7142: } else {
1.60 raeburn 7143: ($scantronurls{'default'},my $error) =
1.46 raeburn 7144: &legacy_scantronformat($r,$dom,$confname,
7145: 'default',$legacyfile{'default'},
7146: $scantronurls{'default'},
7147: $scantronfiles{'default'});
1.60 raeburn 7148: if ($error eq '') {
7149: $confhash{'scantron'}{'scantronformat'} = '';
7150: my $putresult =
7151: &Apache::lonnet::put_dom('configuration',
7152: \%confhash,$dom);
7153: if ($putresult ne 'ok') {
7154: $error{'default'} =
7155: '<span class="LC_error">'.
7156: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7157: }
7158: } else {
7159: $error{'default'} = $error;
7160: }
1.46 raeburn 7161: }
7162: }
7163: }
7164: } else {
1.95 www 7165: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7166: }
7167: }
7168: if (ref($settings) eq 'HASH') {
7169: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7170: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7171: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7172: $scantronurl = '';
7173: } else {
7174: $scantronurl = $settings->{'scantronformat'};
7175: }
7176: $is_custom = 1;
7177: } else {
7178: $scantronurl = $scantronurls{'default'};
7179: }
7180: } else {
1.60 raeburn 7181: if ($is_custom) {
7182: $scantronurl = $scantronurls{'custom'};
7183: } else {
7184: $scantronurl = $scantronurls{'default'};
7185: }
1.46 raeburn 7186: }
7187: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7188: $datatable .= '<tr'.$css_class.'>';
7189: if (!$is_custom) {
1.65 raeburn 7190: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7191: '<span class="LC_nobreak">';
1.46 raeburn 7192: if ($scantronurl) {
1.160.6.21 raeburn 7193: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7194: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7195: } else {
7196: $datatable = &mt('File unavailable for display');
7197: }
1.65 raeburn 7198: $datatable .= '</span></td>';
1.60 raeburn 7199: if (keys(%error) == 0) {
7200: $datatable .= '<td valign="bottom">';
7201: if (!$switchserver) {
7202: $datatable .= &mt('Upload:').'<br />';
7203: }
7204: } else {
7205: my $errorstr;
7206: foreach my $key (sort(keys(%error))) {
7207: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7208: }
7209: $datatable .= '<td>'.$errorstr;
7210: }
1.46 raeburn 7211: } else {
7212: if (keys(%error) > 0) {
7213: my $errorstr;
7214: foreach my $key (sort(keys(%error))) {
7215: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7216: }
1.60 raeburn 7217: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7218: } elsif ($scantronurl) {
1.160.6.26 raeburn 7219: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 7220: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7221: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 7222: $link.
7223: '<label><input type="checkbox" name="scantronformat_del"'.
7224: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7225: '<td><span class="LC_nobreak"> '.
7226: &mt('Replace:').'</span><br />';
1.46 raeburn 7227: }
7228: }
7229: if (keys(%error) == 0) {
7230: if ($switchserver) {
7231: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7232: } else {
1.65 raeburn 7233: $datatable .='<span class="LC_nobreak"> '.
7234: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7235: }
7236: }
7237: $datatable .= '</td></tr>';
7238: $$rowtotal ++;
7239: return $datatable;
7240: }
7241:
7242: sub legacy_scantronformat {
7243: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7244: my ($url,$error);
7245: my @statinfo = &Apache::lonnet::stat_file($newurl);
7246: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7247: (my $result,$url) =
7248: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7249: '','',$newfile);
7250: if ($result ne 'ok') {
1.130 raeburn 7251: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7252: }
7253: }
7254: return ($url,$error);
7255: }
1.43 raeburn 7256:
1.160.6.97 raeburn 7257: sub print_scantronconfig {
7258: my ($dom,$settings,$rowtotal) = @_;
7259: my $itemcount = 2;
7260: my $is_checked = ' checked="checked"';
7261: my %optionson = (
7262: hdr => ' checked="checked"',
7263: pad => ' checked="checked"',
7264: rem => ' checked="checked"',
7265: );
7266: my %optionsoff = (
7267: hdr => '',
7268: pad => '',
7269: rem => '',
7270: );
7271: my $currcsvsty = 'none';
7272: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
7273: my @fields = &scantroncsv_fields();
7274: my %titles = &scantronconfig_titles();
7275: if (ref($settings) eq 'HASH') {
7276: if (ref($settings->{config}) eq 'HASH') {
7277: if ($settings->{config}->{dat}) {
7278: $checked{'dat'} = $is_checked;
7279: }
7280: if (ref($settings->{config}->{csv}) eq 'HASH') {
7281: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
7282: %csvfields = %{$settings->{config}->{csv}->{fields}};
7283: if (keys(%csvfields) > 0) {
7284: $checked{'csv'} = $is_checked;
7285: $currcsvsty = 'block';
7286: }
7287: }
7288: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
7289: %csvoptions = %{$settings->{config}->{csv}->{options}};
7290: foreach my $option (keys(%optionson)) {
7291: unless ($csvoptions{$option}) {
7292: $optionsoff{$option} = $optionson{$option};
7293: $optionson{$option} = '';
7294: }
7295: }
7296: }
7297: }
7298: } else {
7299: $checked{'dat'} = $is_checked;
7300: }
7301: } else {
7302: $checked{'dat'} = $is_checked;
7303: }
7304: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
7305: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7306: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
7307: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
7308: foreach my $item ('dat','csv') {
7309: my $id;
7310: if ($item eq 'csv') {
7311: $id = 'id="scantronconfcsv" ';
7312: }
7313: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
7314: $titles{$item}.'</label>'.(' 'x3);
7315: if ($item eq 'csv') {
7316: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
7317: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
7318: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
7319: foreach my $col (@fields) {
7320: my $selnone;
7321: if ($csvfields{$col} eq '') {
7322: $selnone = ' selected="selected"';
7323: }
7324: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
7325: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
7326: '<option value=""'.$selnone.'></option>';
7327: for (my $i=0; $i<20; $i++) {
7328: my $shown = $i+1;
7329: my $sel;
7330: unless ($selnone) {
7331: if (exists($csvfields{$col})) {
7332: if ($csvfields{$col} == $i) {
7333: $sel = ' selected="selected"';
7334: }
7335: }
7336: }
7337: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
7338: }
7339: $datatable .= '</select></td></tr>';
7340: }
7341: $datatable .= '</table></fieldset>'.
7342: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
7343: '<legend>'.&mt('CSV Options').'</legend>';
7344: foreach my $option ('hdr','pad','rem') {
7345: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
7346: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
7347: &mt('Yes').'</label>'.(' 'x2)."\n".
7348: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
7349: }
7350: $datatable .= '</fieldset>';
7351: $itemcount ++;
7352: }
7353: }
7354: $datatable .= '</td></tr>';
7355: $$rowtotal ++;
7356: return $datatable;
7357: }
7358:
7359: sub scantronconfig_titles {
7360: return &Apache::lonlocal::texthash(
7361: dat => 'Standard format (.dat)',
7362: csv => 'Comma separated values (.csv)',
7363: hdr => 'Remove first line in file (contains column titles)',
7364: pad => 'Prepend 0s to PaperID',
7365: rem => 'Remove leading spaces (except Question Response columns)',
7366: CODE => 'CODE',
7367: ID => 'Student ID',
7368: PaperID => 'Paper ID',
7369: FirstName => 'First Name',
7370: LastName => 'Last Name',
7371: FirstQuestion => 'First Question Response',
7372: Section => 'Section',
7373: );
7374: }
7375:
7376: sub scantroncsv_fields {
7377: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
7378: }
7379:
1.49 raeburn 7380: sub print_coursecategories {
1.57 raeburn 7381: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7382: my $datatable;
7383: if ($position eq 'top') {
1.160.6.42 raeburn 7384: my (%checked);
7385: my @catitems = ('unauth','auth');
7386: my @cattypes = ('std','domonly','codesrch','none');
7387: $checked{'unauth'} = 'std';
7388: $checked{'auth'} = 'std';
7389: if (ref($settings) eq 'HASH') {
7390: foreach my $type (@cattypes) {
7391: if ($type eq $settings->{'unauth'}) {
7392: $checked{'unauth'} = $type;
7393: }
7394: if ($type eq $settings->{'auth'}) {
7395: $checked{'auth'} = $type;
7396: }
7397: }
7398: }
7399: my %lt = &Apache::lonlocal::texthash (
7400: unauth => 'Catalog type for unauthenticated users',
7401: auth => 'Catalog type for authenticated users',
7402: none => 'No catalog',
7403: std => 'Standard catalog',
7404: domonly => 'Domain-only catalog',
7405: codesrch => "Code search form",
7406: );
7407: my $itemcount = 0;
7408: foreach my $item (@catitems) {
7409: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7410: $datatable .= '<tr '.$css_class.'>'.
7411: '<td>'.$lt{$item}.'</td>'.
7412: '<td class="LC_right_item"><span class="LC_nobreak">';
7413: foreach my $type (@cattypes) {
7414: my $ischecked;
7415: if ($checked{$item} eq $type) {
7416: $ischecked=' checked="checked"';
7417: }
7418: $datatable .= '<label>'.
7419: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
7420: ' />'.$lt{$type}.'</label> ';
7421: }
1.160.6.87 raeburn 7422: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 7423: $itemcount ++;
7424: }
7425: $$rowtotal += $itemcount;
7426: } elsif ($position eq 'middle') {
1.57 raeburn 7427: my $toggle_cats_crs = ' ';
7428: my $toggle_cats_dom = ' checked="checked" ';
7429: my $can_cat_crs = ' ';
7430: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 7431: my $toggle_catscomm_comm = ' ';
7432: my $toggle_catscomm_dom = ' checked="checked" ';
7433: my $can_catcomm_comm = ' ';
7434: my $can_catcomm_dom = ' checked="checked" ';
7435:
1.57 raeburn 7436: if (ref($settings) eq 'HASH') {
7437: if ($settings->{'togglecats'} eq 'crs') {
7438: $toggle_cats_crs = $toggle_cats_dom;
7439: $toggle_cats_dom = ' ';
7440: }
7441: if ($settings->{'categorize'} eq 'crs') {
7442: $can_cat_crs = $can_cat_dom;
7443: $can_cat_dom = ' ';
7444: }
1.120 raeburn 7445: if ($settings->{'togglecatscomm'} eq 'comm') {
7446: $toggle_catscomm_comm = $toggle_catscomm_dom;
7447: $toggle_catscomm_dom = ' ';
7448: }
7449: if ($settings->{'categorizecomm'} eq 'comm') {
7450: $can_catcomm_comm = $can_catcomm_dom;
7451: $can_catcomm_dom = ' ';
7452: }
1.57 raeburn 7453: }
7454: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 7455: togglecats => 'Show/Hide a course in catalog',
7456: togglecatscomm => 'Show/Hide a community in catalog',
7457: categorize => 'Assign a category to a course',
7458: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7459: );
7460: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 7461: dom => 'Set in Domain',
7462: crs => 'Set in Course',
7463: comm => 'Set in Community',
1.57 raeburn 7464: );
7465: $datatable = '<tr class="LC_odd_row">'.
7466: '<td>'.$title{'togglecats'}.'</td>'.
7467: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7468: '<input type="radio" name="togglecats"'.
7469: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7470: '<label><input type="radio" name="togglecats"'.
7471: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
7472: '</tr><tr>'.
7473: '<td>'.$title{'categorize'}.'</td>'.
7474: '<td class="LC_right_item"><span class="LC_nobreak">'.
7475: '<label><input type="radio" name="categorize"'.
7476: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7477: '<label><input type="radio" name="categorize"'.
7478: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 7479: '</tr><tr class="LC_odd_row">'.
7480: '<td>'.$title{'togglecatscomm'}.'</td>'.
7481: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7482: '<input type="radio" name="togglecatscomm"'.
7483: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7484: '<label><input type="radio" name="togglecatscomm"'.
7485: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
7486: '</tr><tr>'.
7487: '<td>'.$title{'categorizecomm'}.'</td>'.
7488: '<td class="LC_right_item"><span class="LC_nobreak">'.
7489: '<label><input type="radio" name="categorizecomm"'.
7490: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7491: '<label><input type="radio" name="categorizecomm"'.
7492: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 7493: '</tr>';
1.120 raeburn 7494: $$rowtotal += 4;
1.57 raeburn 7495: } else {
7496: my $css_class;
7497: my $itemcount = 1;
7498: my $cathash;
7499: if (ref($settings) eq 'HASH') {
7500: $cathash = $settings->{'cats'};
7501: }
7502: if (ref($cathash) eq 'HASH') {
7503: my (@cats,@trails,%allitems,%idx,@jsarray);
7504: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
7505: \%allitems,\%idx,\@jsarray);
7506: my $maxdepth = scalar(@cats);
7507: my $colattrib = '';
7508: if ($maxdepth > 2) {
7509: $colattrib = ' colspan="2" ';
7510: }
7511: my @path;
7512: if (@cats > 0) {
7513: if (ref($cats[0]) eq 'ARRAY') {
7514: my $numtop = @{$cats[0]};
7515: my $maxnum = $numtop;
1.120 raeburn 7516: my %default_names = (
7517: instcode => &mt('Official courses'),
7518: communities => &mt('Communities'),
7519: );
7520:
7521: if ((!grep(/^instcode$/,@{$cats[0]})) ||
7522: ($cathash->{'instcode::0'} eq '') ||
7523: (!grep(/^communities$/,@{$cats[0]})) ||
7524: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 7525: $maxnum ++;
7526: }
7527: my $lastidx;
7528: for (my $i=0; $i<$numtop; $i++) {
7529: my $parent = $cats[0][$i];
7530: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7531: my $item = &escape($parent).'::0';
7532: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
7533: $lastidx = $idx{$item};
7534: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7535: .'<select name="'.$item.'"'.$chgstr.'>';
7536: for (my $k=0; $k<=$maxnum; $k++) {
7537: my $vpos = $k+1;
7538: my $selstr;
7539: if ($k == $i) {
7540: $selstr = ' selected="selected" ';
7541: }
7542: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7543: }
1.160.6.29 raeburn 7544: $datatable .= '</select></span></td><td>';
1.120 raeburn 7545: if ($parent eq 'instcode' || $parent eq 'communities') {
7546: $datatable .= '<span class="LC_nobreak">'
7547: .$default_names{$parent}.'</span>';
7548: if ($parent eq 'instcode') {
7549: $datatable .= '<br /><span class="LC_nobreak">('
7550: .&mt('with institutional codes')
7551: .')</span></td><td'.$colattrib.'>';
7552: } else {
7553: $datatable .= '<table><tr><td>';
7554: }
7555: $datatable .= '<span class="LC_nobreak">'
7556: .'<label><input type="radio" name="'
7557: .$parent.'" value="1" checked="checked" />'
7558: .&mt('Display').'</label>';
7559: if ($parent eq 'instcode') {
7560: $datatable .= ' ';
7561: } else {
7562: $datatable .= '</span></td></tr><tr><td>'
7563: .'<span class="LC_nobreak">';
7564: }
7565: $datatable .= '<label><input type="radio" name="'
7566: .$parent.'" value="0" />'
7567: .&mt('Do not display').'</label></span>';
7568: if ($parent eq 'communities') {
7569: $datatable .= '</td></tr></table>';
7570: }
7571: $datatable .= '</td>';
1.57 raeburn 7572: } else {
7573: $datatable .= $parent
1.160.6.29 raeburn 7574: .' <span class="LC_nobreak"><label>'
7575: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 7576: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
7577: }
7578: my $depth = 1;
7579: push(@path,$parent);
7580: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
7581: pop(@path);
7582: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
7583: $itemcount ++;
7584: }
1.48 raeburn 7585: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 7586: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
7587: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 7588: for (my $k=0; $k<=$maxnum; $k++) {
7589: my $vpos = $k+1;
7590: my $selstr;
1.57 raeburn 7591: if ($k == $numtop) {
1.48 raeburn 7592: $selstr = ' selected="selected" ';
7593: }
7594: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7595: }
1.59 bisitz 7596: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 7597: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
7598: .'</tr>'."\n";
1.48 raeburn 7599: $itemcount ++;
1.120 raeburn 7600: foreach my $default ('instcode','communities') {
7601: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
7602: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7603: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
7604: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
7605: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
7606: for (my $k=0; $k<=$maxnum; $k++) {
7607: my $vpos = $k+1;
7608: my $selstr;
7609: if ($k == $maxnum) {
7610: $selstr = ' selected="selected" ';
7611: }
7612: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 7613: }
1.120 raeburn 7614: $datatable .= '</select></span></td>'.
7615: '<td><span class="LC_nobreak">'.
7616: $default_names{$default}.'</span>';
7617: if ($default eq 'instcode') {
7618: $datatable .= '<br /><span class="LC_nobreak">('
7619: .&mt('with institutional codes').')</span>';
7620: }
7621: $datatable .= '</td>'
7622: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
7623: .&mt('Display').'</label> '
7624: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
7625: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 7626: }
7627: }
7628: }
1.57 raeburn 7629: } else {
7630: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 7631: }
7632: } else {
1.160.6.87 raeburn 7633: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 7634: .&initialize_categories($itemcount);
1.48 raeburn 7635: }
1.57 raeburn 7636: $$rowtotal += $itemcount;
1.48 raeburn 7637: }
7638: return $datatable;
7639: }
7640:
1.69 raeburn 7641: sub print_serverstatuses {
7642: my ($dom,$settings,$rowtotal) = @_;
7643: my $datatable;
7644: my @pages = &serverstatus_pages();
7645: my (%namedaccess,%machineaccess);
7646: foreach my $type (@pages) {
7647: $namedaccess{$type} = '';
7648: $machineaccess{$type}= '';
7649: }
7650: if (ref($settings) eq 'HASH') {
7651: foreach my $type (@pages) {
7652: if (exists($settings->{$type})) {
7653: if (ref($settings->{$type}) eq 'HASH') {
7654: foreach my $key (keys(%{$settings->{$type}})) {
7655: if ($key eq 'namedusers') {
7656: $namedaccess{$type} = $settings->{$type}->{$key};
7657: } elsif ($key eq 'machines') {
7658: $machineaccess{$type} = $settings->{$type}->{$key};
7659: }
7660: }
7661: }
7662: }
7663: }
7664: }
1.81 raeburn 7665: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7666: my $rownum = 0;
7667: my $css_class;
7668: foreach my $type (@pages) {
7669: $rownum ++;
7670: $css_class = $rownum%2?' class="LC_odd_row"':'';
7671: $datatable .= '<tr'.$css_class.'>'.
7672: '<td><span class="LC_nobreak">'.
7673: $titles->{$type}.'</span></td>'.
7674: '<td class="LC_left_item">'.
7675: '<input type="text" name="'.$type.'_namedusers" '.
7676: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
7677: '<td class="LC_right_item">'.
7678: '<span class="LC_nobreak">'.
7679: '<input type="text" name="'.$type.'_machines" '.
7680: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 7681: '</span></td></tr>'."\n";
1.69 raeburn 7682: }
7683: $$rowtotal += $rownum;
7684: return $datatable;
7685: }
7686:
7687: sub serverstatus_pages {
7688: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 7689: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 7690: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 7691: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 7692: }
7693:
1.160.6.40 raeburn 7694: sub defaults_javascript {
7695: my ($settings) = @_;
1.160.6.98 raeburn 7696: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 7697: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
7698: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
7699: if ($maxnum eq '') {
7700: $maxnum = 0;
7701: }
7702: $maxnum ++;
1.160.6.51 raeburn 7703: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 7704: return <<"ENDSCRIPT";
7705: <script type="text/javascript">
7706: // <![CDATA[
7707: function reorderTypes(form,caller) {
7708: var changedVal;
7709: $jstext
7710: var newpos = 'addinststatus_pos';
7711: var current = new Array;
7712: var maxh = $maxnum;
7713: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7714: var oldVal;
7715: if (caller == newpos) {
7716: changedVal = newitemVal;
7717: } else {
7718: var curritem = 'inststatus_pos_'+caller;
7719: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
7720: current[newitemVal] = newpos;
7721: }
7722: for (var i=0; i<inststatuses.length; i++) {
7723: if (inststatuses[i] != caller) {
7724: var elementName = 'inststatus_pos_'+inststatuses[i];
7725: if (form.elements[elementName]) {
7726: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7727: current[currVal] = elementName;
7728: }
7729: }
7730: }
7731: for (var j=0; j<maxh; j++) {
7732: if (current[j] == undefined) {
7733: oldVal = j;
7734: }
7735: }
7736: if (oldVal < changedVal) {
7737: for (var k=oldVal+1; k<=changedVal ; k++) {
7738: var elementName = current[k];
7739: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7740: }
7741: } else {
7742: for (var k=changedVal; k<oldVal; k++) {
7743: var elementName = current[k];
7744: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7745: }
7746: }
7747: return;
7748: }
7749:
7750: // ]]>
7751: </script>
7752:
7753: ENDSCRIPT
7754: }
7755: }
7756:
1.160.6.98 raeburn 7757: sub passwords_javascript {
1.160.6.99 raeburn 7758: my %intalert = &Apache::lonlocal::texthash (
7759: authcheck => '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.',
7760: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
7761: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
7762: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
7763: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
7764: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
7765: );
7766: &js_escape(\%intalert);
7767: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 7768: my $intauthjs = <<"ENDSCRIPT";
7769:
7770: function warnIntAuth(field) {
7771: if (field.name == 'intauth_check') {
7772: if (field.value == '2') {
1.160.6.99 raeburn 7773: alert('$intalert{authcheck}');
1.160.6.98 raeburn 7774: }
7775: }
7776: if (field.name == 'intauth_cost') {
7777: field.value.replace(/\s/g,'');
7778: if (field.value != '') {
7779: var regexdigit=/^\\d+\$/;
7780: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 7781: alert('$intalert{authcost}');
7782: }
7783: }
7784: }
7785: return;
7786: }
7787:
7788: function warnIntPass(field) {
7789: field.value.replace(/^\s+/,'');
7790: field.value.replace(/\s+\$/,'');
7791: var regexdigit=/^\\d+\$/;
7792: if (field.name == 'passwords_min') {
7793: if (field.value == '') {
7794: alert('$intalert{passmin}');
7795: field.value = '$defmin';
7796: } else {
7797: if (!regexdigit.test(field.value)) {
7798: alert('$intalert{passmin}');
7799: field.value = '$defmin';
7800: }
7801: var minval = parseInt(field.value,10);
7802: if (minval < $defmin) {
7803: alert('$intalert{passmin}');
7804: field.value = '$defmin';
7805: }
7806: }
7807: } else {
7808: if (field.value == '0') {
7809: field.value = '';
7810: }
7811: if (field.value != '') {
7812: if (field.name == 'passwords_expire') {
7813: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
7814: if (!regexpposnum.test(field.value)) {
7815: alert('$intalert{passexp}');
7816: field.value = '';
7817: } else {
7818: var expval = parseFloat(field.value);
7819: if (expval == 0) {
7820: alert('$intalert{passexp}');
7821: field.value = '';
7822: }
7823: }
7824: } else {
7825: if (!regexdigit.test(field.value)) {
7826: if (field.name == 'passwords_max') {
7827: alert('$intalert{passmax}');
7828: } else {
7829: if (field.name == 'passwords_numsaved') {
7830: alert('$intalert{passnum}');
7831: }
7832: }
7833: }
7834: field.value = '';
1.160.6.98 raeburn 7835: }
7836: }
7837: }
7838: return;
7839: }
7840:
7841: ENDSCRIPT
7842: return &Apache::lonhtmlcommon::scripttag($intauthjs);
7843: }
7844:
1.49 raeburn 7845: sub coursecategories_javascript {
7846: my ($settings) = @_;
1.57 raeburn 7847: my ($output,$jstext,$cathash);
1.49 raeburn 7848: if (ref($settings) eq 'HASH') {
1.57 raeburn 7849: $cathash = $settings->{'cats'};
7850: }
7851: if (ref($cathash) eq 'HASH') {
1.49 raeburn 7852: my (@cats,@jsarray,%idx);
1.57 raeburn 7853: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 7854: if (@jsarray > 0) {
7855: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7856: for (my $i=0; $i<@jsarray; $i++) {
7857: if (ref($jsarray[$i]) eq 'ARRAY') {
7858: my $catstr = join('","',@{$jsarray[$i]});
7859: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7860: }
7861: }
7862: }
7863: } else {
7864: $jstext = ' var categories = Array(1);'."\n".
7865: ' categories[0] = Array("instcode_pos");'."\n";
7866: }
1.160.6.42 raeburn 7867: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7868: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 7869: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7870: &js_escape(\$instcode_reserved);
7871: &js_escape(\$communities_reserved);
7872: &js_escape(\$choose_again);
1.49 raeburn 7873: $output = <<"ENDSCRIPT";
7874: <script type="text/javascript">
1.109 raeburn 7875: // <![CDATA[
1.49 raeburn 7876: function reorderCats(form,parent,item,idx) {
7877: var changedVal;
7878: $jstext
7879: var newpos = 'addcategory_pos';
7880: if (parent == '') {
7881: var has_instcode = 0;
7882: var maxtop = categories[idx].length;
7883: for (var j=0; j<maxtop; j++) {
7884: if (categories[idx][j] == 'instcode::0') {
7885: has_instcode == 1;
7886: }
7887: }
7888: if (has_instcode == 0) {
7889: categories[idx][maxtop] = 'instcode_pos';
7890: }
7891: } else {
7892: newpos += '_'+parent;
7893: }
7894: var maxh = 1 + categories[idx].length;
7895: var current = new Array;
7896: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7897: if (item == newpos) {
7898: changedVal = newitemVal;
7899: } else {
7900: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7901: current[newitemVal] = newpos;
7902: }
7903: for (var i=0; i<categories[idx].length; i++) {
7904: var elementName = categories[idx][i];
7905: if (elementName != item) {
7906: if (form.elements[elementName]) {
7907: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7908: current[currVal] = elementName;
7909: }
7910: }
7911: }
7912: var oldVal;
7913: for (var j=0; j<maxh; j++) {
7914: if (current[j] == undefined) {
7915: oldVal = j;
7916: }
7917: }
7918: if (oldVal < changedVal) {
7919: for (var k=oldVal+1; k<=changedVal ; k++) {
7920: var elementName = current[k];
7921: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7922: }
7923: } else {
7924: for (var k=changedVal; k<oldVal; k++) {
7925: var elementName = current[k];
7926: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7927: }
7928: }
7929: return;
7930: }
1.120 raeburn 7931:
7932: function categoryCheck(form) {
7933: if (form.elements['addcategory_name'].value == 'instcode') {
7934: alert('$instcode_reserved\\n$choose_again');
7935: return false;
7936: }
7937: if (form.elements['addcategory_name'].value == 'communities') {
7938: alert('$communities_reserved\\n$choose_again');
7939: return false;
7940: }
7941: return true;
7942: }
7943:
1.109 raeburn 7944: // ]]>
1.49 raeburn 7945: </script>
7946:
7947: ENDSCRIPT
7948: return $output;
7949: }
7950:
1.48 raeburn 7951: sub initialize_categories {
7952: my ($itemcount) = @_;
1.120 raeburn 7953: my ($datatable,$css_class,$chgstr);
7954: my %default_names = (
7955: instcode => 'Official courses (with institutional codes)',
7956: communities => 'Communities',
7957: );
7958: my $select0 = ' selected="selected"';
7959: my $select1 = '';
7960: foreach my $default ('instcode','communities') {
7961: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 7962: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 7963: if ($default eq 'communities') {
7964: $select1 = $select0;
7965: $select0 = '';
7966: }
7967: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7968: .'<select name="'.$default.'_pos">'
7969: .'<option value="0"'.$select0.'>1</option>'
7970: .'<option value="1"'.$select1.'>2</option>'
7971: .'<option value="2">3</option></select> '
7972: .$default_names{$default}
7973: .'</span></td><td><span class="LC_nobreak">'
7974: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7975: .&mt('Display').'</label> <label>'
7976: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7977: .'</label></span></td></tr>';
1.120 raeburn 7978: $itemcount ++;
7979: }
1.48 raeburn 7980: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7981: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7982: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7983: .'<select name="addcategory_pos"'.$chgstr.'>'
7984: .'<option value="0">1</option>'
7985: .'<option value="1">2</option>'
7986: .'<option value="2" selected="selected">3</option></select> '
1.160.6.87 raeburn 7987: .&mt('Add category').'</span></td><tda<span class="LC_nobreak">>'.&mt('Name:')
7988: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
7989: .'</td></tr>';
1.48 raeburn 7990: return $datatable;
7991: }
7992:
7993: sub build_category_rows {
1.49 raeburn 7994: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7995: my ($text,$name,$item,$chgstr);
1.48 raeburn 7996: if (ref($cats) eq 'ARRAY') {
7997: my $maxdepth = scalar(@{$cats});
7998: if (ref($cats->[$depth]) eq 'HASH') {
7999: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8000: my $numchildren = @{$cats->[$depth]{$parent}};
8001: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 8002: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8003: my ($idxnum,$parent_name,$parent_item);
8004: my $higher = $depth - 1;
8005: if ($higher == 0) {
8006: $parent_name = &escape($parent).'::'.$higher;
8007: } else {
8008: if (ref($path) eq 'ARRAY') {
8009: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8010: }
8011: }
8012: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8013: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8014: if ($j < $numchildren) {
1.48 raeburn 8015: $name = $cats->[$depth]{$parent}[$j];
8016: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8017: $idxnum = $idx->{$item};
8018: } else {
8019: $name = $parent_name;
8020: $item = $parent_item;
1.48 raeburn 8021: }
1.49 raeburn 8022: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8023: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8024: for (my $i=0; $i<=$numchildren; $i++) {
8025: my $vpos = $i+1;
8026: my $selstr;
8027: if ($j == $i) {
8028: $selstr = ' selected="selected" ';
8029: }
8030: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8031: }
8032: $text .= '</select> ';
8033: if ($j < $numchildren) {
8034: my $deeper = $depth+1;
8035: $text .= $name.' '
8036: .'<label><input type="checkbox" name="deletecategory" value="'
8037: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8038: if(ref($path) eq 'ARRAY') {
8039: push(@{$path},$name);
1.49 raeburn 8040: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8041: pop(@{$path});
8042: }
8043: } else {
1.160.6.87 raeburn 8044: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 8045: if ($j == $numchildren) {
8046: $text .= $name;
8047: } else {
8048: $text .= $item;
8049: }
8050: $text .= '" value="" />';
8051: }
8052: $text .= '</td></tr>';
8053: }
8054: $text .= '</table></td>';
8055: } else {
8056: my $higher = $depth-1;
8057: if ($higher == 0) {
8058: $name = &escape($parent).'::'.$higher;
8059: } else {
8060: if (ref($path) eq 'ARRAY') {
8061: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8062: }
8063: }
8064: my $colspan;
8065: if ($parent ne 'instcode') {
8066: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 8067: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 8068: }
8069: }
8070: }
8071: }
8072: return $text;
8073: }
8074:
1.33 raeburn 8075: sub modifiable_userdata_row {
1.160.6.93 raeburn 8076: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8077: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 8078: my ($role,$rolename,$statustype);
8079: $role = $item;
1.160.6.34 raeburn 8080: if ($context eq 'cancreate') {
1.160.6.93 raeburn 8081: if ($item =~ /^(emailusername)_(.+)$/) {
8082: $role = $1;
8083: $statustype = $2;
1.160.6.35 raeburn 8084: if (ref($usertypes) eq 'HASH') {
8085: if ($usertypes->{$statustype}) {
8086: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8087: } else {
8088: $rolename = &mt('Data provided by user');
8089: }
8090: }
1.160.6.34 raeburn 8091: }
8092: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8093: if (ref($usertypes) eq 'HASH') {
8094: $rolename = $usertypes->{$role};
8095: } else {
8096: $rolename = $role;
8097: }
1.33 raeburn 8098: } else {
1.63 raeburn 8099: if ($role eq 'cr') {
8100: $rolename = &mt('Custom role');
8101: } else {
8102: $rolename = &Apache::lonnet::plaintext($role);
8103: }
1.33 raeburn 8104: }
1.160.6.34 raeburn 8105: my (@fields,%fieldtitles);
8106: if (ref($fieldsref) eq 'ARRAY') {
8107: @fields = @{$fieldsref};
8108: } else {
8109: @fields = ('lastname','firstname','middlename','generation',
8110: 'permanentemail','id');
8111: }
8112: if ((ref($titlesref) eq 'HASH')) {
8113: %fieldtitles = %{$titlesref};
8114: } else {
8115: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8116: }
1.33 raeburn 8117: my $output;
1.160.6.93 raeburn 8118: my $css_class;
8119: if ($rowcount%2) {
8120: $css_class = 'LC_odd_row';
8121: }
8122: if ($customcss) {
8123: $css_class .= " $customcss";
8124: }
8125: $css_class =~ s/^\s+//;
8126: if ($css_class) {
8127: $css_class = ' class="'.$css_class.'"';
8128: }
8129: if ($rowstyle) {
8130: $css_class .= ' style="'.$rowstyle.'"';
8131: }
8132: if ($rowid) {
8133: $rowid = ' id="'.$rowid.'"';
8134: }
8135:
8136: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8137: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8138: '<td class="LC_left_item" colspan="2"><table>';
8139: my $rem;
8140: my %checks;
8141: if (ref($settings) eq 'HASH') {
8142: if (ref($settings->{$context}) eq 'HASH') {
8143: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 8144: my $hashref = $settings->{$context}->{$role};
8145: if ($role eq 'emailusername') {
8146: if ($statustype) {
8147: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8148: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 8149: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 8150: foreach my $field (@fields) {
8151: if ($hashref->{$field}) {
8152: $checks{$field} = $hashref->{$field};
8153: }
8154: }
8155: }
8156: }
8157: }
8158: } else {
8159: if (ref($hashref) eq 'HASH') {
8160: foreach my $field (@fields) {
8161: if ($hashref->{$field}) {
8162: $checks{$field} = ' checked="checked" ';
8163: }
8164: }
1.33 raeburn 8165: }
8166: }
8167: }
8168: }
8169: }
1.160.6.93 raeburn 8170:
8171: my $total = scalar(@fields);
8172: for (my $i=0; $i<$total; $i++) {
8173: $rem = $i%($numinrow);
1.33 raeburn 8174: if ($rem == 0) {
8175: if ($i > 0) {
8176: $output .= '</tr>';
8177: }
8178: $output .= '<tr>';
8179: }
8180: my $check = ' ';
1.160.6.35 raeburn 8181: unless ($role eq 'emailusername') {
8182: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 8183: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 8184: } else {
8185: if ($role eq 'st') {
8186: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 8187: $check = ' checked="checked" ';
1.160.6.35 raeburn 8188: }
1.33 raeburn 8189: }
8190: }
8191: }
8192: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 8193: '<span class="LC_nobreak">';
8194: if ($role eq 'emailusername') {
8195: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8196: $checks{$fields[$i]} = 'omit';
8197: }
8198: foreach my $option ('required','optional','omit') {
8199: my $checked='';
8200: if ($checks{$fields[$i]} eq $option) {
8201: $checked='checked="checked" ';
8202: }
8203: $output .= '<label>'.
8204: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
8205: &mt($option).'</label>'.(' ' x2);
8206: }
8207: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8208: } else {
8209: $output .= '<label>'.
8210: '<input type="checkbox" name="canmodify_'.$role.'" '.
8211: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8212: '</label>';
8213: }
8214: $output .= '</span></td>';
1.33 raeburn 8215: }
1.160.6.93 raeburn 8216: $rem = $total%$numinrow;
8217: my $colsleft;
8218: if ($rem) {
8219: $colsleft = $numinrow - $rem;
8220: }
8221: if ($colsleft > 1) {
1.33 raeburn 8222: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8223: ' </td>';
8224: } elsif ($colsleft == 1) {
8225: $output .= '<td class="LC_left_item"> </td>';
8226: }
8227: $output .= '</tr></table></td></tr>';
8228: return $output;
8229: }
1.28 raeburn 8230:
1.93 raeburn 8231: sub insttypes_row {
1.160.6.93 raeburn 8232: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8233: $customcss,$rowstyle) = @_;
1.93 raeburn 8234: my %lt = &Apache::lonlocal::texthash (
8235: cansearch => 'Users allowed to search',
8236: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8237: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 8238: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 8239: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8240: );
8241: my $showdom;
8242: if ($context eq 'cansearch') {
8243: $showdom = ' ('.$dom.')';
8244: }
1.160.6.5 raeburn 8245: my $class = 'LC_left_item';
8246: if ($context eq 'statustocreate') {
8247: $class = 'LC_right_item';
8248: }
1.160.6.93 raeburn 8249: my $css_class;
8250: if ($$rowtotal%2) {
8251: $css_class = 'LC_odd_row';
8252: }
8253: if ($customcss) {
8254: $css_class .= ' '.$customcss;
8255: }
8256: $css_class =~ s/^\s+//;
8257: if ($css_class) {
8258: $css_class = ' class="'.$css_class.'"';
8259: }
8260: if ($rowstyle) {
8261: $css_class .= ' style="'.$rowstyle.'"';
8262: }
8263: if ($onclick) {
8264: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 8265: }
8266: my $output = '<tr'.$css_class.'>'.
8267: '<td>'.$lt{$context}.$showdom.
8268: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8269: my $rem;
8270: if (ref($types) eq 'ARRAY') {
8271: for (my $i=0; $i<@{$types}; $i++) {
8272: if (defined($usertypes->{$types->[$i]})) {
8273: my $rem = $i%($numinrow);
8274: if ($rem == 0) {
8275: if ($i > 0) {
8276: $output .= '</tr>';
8277: }
8278: $output .= '<tr>';
1.23 raeburn 8279: }
1.26 raeburn 8280: my $check = ' ';
1.99 raeburn 8281: if (ref($settings) eq 'HASH') {
8282: if (ref($settings->{$context}) eq 'ARRAY') {
8283: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8284: $check = ' checked="checked" ';
8285: }
1.160.6.101 raeburn 8286: } elsif (ref($settings->{$context}) eq 'HASH') {
8287: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8288: $check = ' checked="checked" ';
8289: }
1.99 raeburn 8290: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8291: $check = ' checked="checked" ';
8292: }
1.23 raeburn 8293: }
1.26 raeburn 8294: $output .= '<td class="LC_left_item">'.
8295: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8296: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 8297: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 8298: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8299: }
8300: }
1.26 raeburn 8301: $rem = @{$types}%($numinrow);
1.23 raeburn 8302: }
8303: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 8304: if ($context eq 'overrides') {
8305: if ($colsleft > 1) {
8306: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8307: } else {
8308: $output .= '<td class="LC_left_item">';
8309: }
8310: $output .= ' ';
1.23 raeburn 8311: } else {
1.160.6.101 raeburn 8312: if ($rem == 0) {
8313: $output .= '<tr>';
8314: }
8315: if ($colsleft > 1) {
8316: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8317: } else {
8318: $output .= '<td class="LC_left_item">';
8319: }
8320: my $defcheck = ' ';
8321: if (ref($settings) eq 'HASH') {
8322: if (ref($settings->{$context}) eq 'ARRAY') {
8323: if (grep(/^default$/,@{$settings->{$context}})) {
8324: $defcheck = ' checked="checked" ';
8325: }
8326: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8327: $defcheck = ' checked="checked" ';
8328: }
1.26 raeburn 8329: }
1.160.6.101 raeburn 8330: $output .= '<span class="LC_nobreak"><label>'.
8331: '<input type="checkbox" name="'.$context.'" '.
8332: 'value="default"'.$defcheck.$onclick.' />'.
8333: $othertitle.'</label></span>';
1.23 raeburn 8334: }
1.160.6.101 raeburn 8335: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8336: return $output;
1.23 raeburn 8337: }
8338:
8339: sub sorted_searchtitles {
8340: my %searchtitles = &Apache::lonlocal::texthash(
8341: 'uname' => 'username',
8342: 'lastname' => 'last name',
8343: 'lastfirst' => 'last name, first name',
8344: );
8345: my @titleorder = ('uname','lastname','lastfirst');
8346: return (\%searchtitles,\@titleorder);
8347: }
8348:
1.25 raeburn 8349: sub sorted_searchtypes {
8350: my %srchtypes_desc = (
8351: exact => 'is exact match',
8352: contains => 'contains ..',
8353: begins => 'begins with ..',
8354: );
8355: my @srchtypeorder = ('exact','begins','contains');
8356: return (\%srchtypes_desc,\@srchtypeorder);
8357: }
8358:
1.3 raeburn 8359: sub usertype_update_row {
8360: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8361: my $datatable;
8362: my $numinrow = 4;
8363: foreach my $type (@{$types}) {
8364: if (defined($usertypes->{$type})) {
8365: $$rownums ++;
8366: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8367: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8368: '</td><td class="LC_left_item"><table>';
8369: for (my $i=0; $i<@{$fields}; $i++) {
8370: my $rem = $i%($numinrow);
8371: if ($rem == 0) {
8372: if ($i > 0) {
8373: $datatable .= '</tr>';
8374: }
8375: $datatable .= '<tr>';
8376: }
8377: my $check = ' ';
1.39 raeburn 8378: if (ref($settings) eq 'HASH') {
8379: if (ref($settings->{'fields'}) eq 'HASH') {
8380: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8381: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8382: $check = ' checked="checked" ';
8383: }
1.3 raeburn 8384: }
8385: }
8386: }
8387:
8388: if ($i == @{$fields}-1) {
8389: my $colsleft = $numinrow - $rem;
8390: if ($colsleft > 1) {
8391: $datatable .= '<td colspan="'.$colsleft.'">';
8392: } else {
8393: $datatable .= '<td>';
8394: }
8395: } else {
8396: $datatable .= '<td>';
8397: }
1.8 raeburn 8398: $datatable .= '<span class="LC_nobreak"><label>'.
8399: '<input type="checkbox" name="updateable_'.$type.
8400: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8401: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8402: }
8403: $datatable .= '</tr></table></td></tr>';
8404: }
8405: }
8406: return $datatable;
1.1 raeburn 8407: }
8408:
8409: sub modify_login {
1.160.6.24 raeburn 8410: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 8411: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8412: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8413: %title = ( coursecatalog => 'Display course catalog',
8414: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 8415: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 8416: newuser => 'Link for visitors to create a user account',
8417: loginheader => 'Log-in box header');
8418: @offon = ('off','on');
1.112 raeburn 8419: if (ref($domconfig{login}) eq 'HASH') {
8420: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8421: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8422: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8423: }
8424: }
8425: }
1.9 raeburn 8426: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8427: \%domconfig,\%loginhash);
1.160.6.14 raeburn 8428: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8429: foreach my $item (@toggles) {
8430: $loginhash{login}{$item} = $env{'form.'.$item};
8431: }
1.41 raeburn 8432: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 8433: if (ref($colchanges{'login'}) eq 'HASH') {
8434: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8435: \%loginhash);
8436: }
1.110 raeburn 8437:
1.149 raeburn 8438: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 8439: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 8440: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 8441: if (keys(%servers) > 1) {
8442: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 8443: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8444: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8445: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8446: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8447: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8448: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8449: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8450: $changes{'loginvia'}{$lonhost} = 1;
8451: } else {
8452: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8453: $changes{'loginvia'}{$lonhost} = 1;
8454: }
8455: } else {
8456: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8457: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8458: $changes{'loginvia'}{$lonhost} = 1;
8459: }
8460: }
8461: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8462: foreach my $item (@loginvia_attribs) {
8463: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
8464: }
8465: } else {
8466: foreach my $item (@loginvia_attribs) {
8467: my $new = $env{'form.'.$lonhost.'_'.$item};
8468: if (($item eq 'serverpath') && ($new eq 'custom')) {
8469: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
8470: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8471: $new = '/';
8472: }
8473: }
8474: if (($item eq 'custompath') &&
8475: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8476: $new = '';
8477: }
8478: if ($new ne $curr_loginvia{$lonhost}{$item}) {
8479: $changes{'loginvia'}{$lonhost} = 1;
8480: }
8481: if ($item eq 'exempt') {
1.160.6.56 raeburn 8482: $new = &check_exempt_addresses($new);
1.128 raeburn 8483: }
8484: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8485: }
8486: }
1.112 raeburn 8487: } else {
1.128 raeburn 8488: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8489: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 8490: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 8491: foreach my $item (@loginvia_attribs) {
8492: my $new = $env{'form.'.$lonhost.'_'.$item};
8493: if (($item eq 'serverpath') && ($new eq 'custom')) {
8494: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8495: $new = '/';
8496: }
8497: }
8498: if (($item eq 'custompath') &&
8499: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8500: $new = '';
8501: }
8502: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8503: }
1.110 raeburn 8504: }
8505: }
8506: }
8507: }
1.119 raeburn 8508:
1.160.6.5 raeburn 8509: my $servadm = $r->dir_config('lonAdmEMail');
8510: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
8511: if (ref($domconfig{'login'}) eq 'HASH') {
8512: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
8513: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
8514: if ($lang eq 'nolang') {
8515: push(@currlangs,$lang);
8516: } elsif (defined($langchoices{$lang})) {
8517: push(@currlangs,$lang);
8518: } else {
8519: next;
8520: }
8521: }
8522: }
8523: }
8524: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
8525: if (@currlangs > 0) {
8526: foreach my $lang (@currlangs) {
8527: if (grep(/^\Q$lang\E$/,@delurls)) {
8528: $changes{'helpurl'}{$lang} = 1;
8529: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
8530: $changes{'helpurl'}{$lang} = 1;
8531: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
8532: push(@newlangs,$lang);
8533: } else {
8534: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8535: }
8536: }
8537: }
8538: unless (grep(/^nolang$/,@currlangs)) {
8539: if ($env{'form.loginhelpurl_nolang.filename'}) {
8540: $changes{'helpurl'}{'nolang'} = 1;
8541: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
8542: push(@newlangs,'nolang');
8543: }
8544: }
8545: if ($env{'form.loginhelpurl_add_lang'}) {
8546: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
8547: ($env{'form.loginhelpurl_add_file.filename'})) {
8548: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
8549: $addedfile = $env{'form.loginhelpurl_add_lang'};
8550: }
8551: }
8552: if ((@newlangs > 0) || ($addedfile)) {
8553: my $error;
8554: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8555: if ($configuserok eq 'ok') {
8556: if ($switchserver) {
8557: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
8558: } elsif ($author_ok eq 'ok') {
8559: my @allnew = @newlangs;
8560: if ($addedfile ne '') {
8561: push(@allnew,$addedfile);
8562: }
8563: foreach my $lang (@allnew) {
8564: my $formelem = 'loginhelpurl_'.$lang;
8565: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
8566: $formelem = 'loginhelpurl_add_file';
8567: }
8568: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8569: "help/$lang",'','',$newfile{$lang});
8570: if ($result eq 'ok') {
8571: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
8572: $changes{'helpurl'}{$lang} = 1;
8573: } else {
8574: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
8575: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8576: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
8577: (!grep(/^\Q$lang\E$/,@delurls))) {
8578: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8579: }
8580: }
8581: }
8582: } else {
8583: $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);
8584: }
8585: } else {
8586: $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);
8587: }
8588: if ($error) {
8589: &Apache::lonnet::logthis($error);
8590: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8591: }
8592: }
1.160.6.56 raeburn 8593:
8594: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
8595: if (ref($domconfig{'login'}) eq 'HASH') {
8596: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
8597: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
8598: if ($domservers{$lonhost}) {
8599: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8600: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 8601: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 8602: }
8603: }
8604: }
8605: }
8606: }
8607: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
8608: foreach my $lonhost (sort(keys(%domservers))) {
8609: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8610: $changes{'headtag'}{$lonhost} = 1;
8611: } else {
8612: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
8613: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
8614: }
8615: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
8616: push(@newhosts,$lonhost);
8617: } elsif ($currheadtagurls{$lonhost}) {
8618: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
8619: if ($currexempt{$lonhost}) {
8620: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
8621: $changes{'headtag'}{$lonhost} = 1;
8622: }
8623: } elsif ($possexempt{$lonhost}) {
8624: $changes{'headtag'}{$lonhost} = 1;
8625: }
8626: if ($possexempt{$lonhost}) {
8627: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8628: }
8629: }
8630: }
8631: }
8632: if (@newhosts) {
8633: my $error;
8634: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8635: if ($configuserok eq 'ok') {
8636: if ($switchserver) {
8637: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
8638: } elsif ($author_ok eq 'ok') {
8639: foreach my $lonhost (@newhosts) {
8640: my $formelem = 'loginheadtag_'.$lonhost;
8641: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8642: "login/headtag/$lonhost",'','',
8643: $env{'form.loginheadtag_'.$lonhost.'.filename'});
8644: if ($result eq 'ok') {
8645: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
8646: $changes{'headtag'}{$lonhost} = 1;
8647: if ($possexempt{$lonhost}) {
8648: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8649: }
8650: } else {
8651: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
8652: $newheadtagurls{$lonhost},$result);
8653: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8654: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
8655: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
8656: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
8657: }
8658: }
8659: }
8660: } else {
8661: $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);
8662: }
8663: } else {
8664: $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);
8665: }
8666: if ($error) {
8667: &Apache::lonnet::logthis($error);
8668: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8669: }
8670: }
1.160.6.5 raeburn 8671: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
8672:
8673: my $defaulthelpfile = '/adm/loginproblems.html';
8674: my $defaulttext = &mt('Default in use');
8675:
1.1 raeburn 8676: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
8677: $dom);
8678: if ($putresult eq 'ok') {
1.160.6.14 raeburn 8679: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8680: my %defaultchecked = (
8681: 'coursecatalog' => 'on',
1.160.6.14 raeburn 8682: 'helpdesk' => 'on',
1.42 raeburn 8683: 'adminmail' => 'off',
1.43 raeburn 8684: 'newuser' => 'off',
1.42 raeburn 8685: );
1.55 raeburn 8686: if (ref($domconfig{'login'}) eq 'HASH') {
8687: foreach my $item (@toggles) {
8688: if ($defaultchecked{$item} eq 'on') {
8689: if (($domconfig{'login'}{$item} eq '0') &&
8690: ($env{'form.'.$item} eq '1')) {
8691: $changes{$item} = 1;
8692: } elsif (($domconfig{'login'}{$item} eq '' ||
8693: $domconfig{'login'}{$item} eq '1') &&
8694: ($env{'form.'.$item} eq '0')) {
8695: $changes{$item} = 1;
8696: }
8697: } elsif ($defaultchecked{$item} eq 'off') {
8698: if (($domconfig{'login'}{$item} eq '1') &&
8699: ($env{'form.'.$item} eq '0')) {
8700: $changes{$item} = 1;
8701: } elsif (($domconfig{'login'}{$item} eq '' ||
8702: $domconfig{'login'}{$item} eq '0') &&
8703: ($env{'form.'.$item} eq '1')) {
8704: $changes{$item} = 1;
8705: }
1.42 raeburn 8706: }
8707: }
1.41 raeburn 8708: }
1.6 raeburn 8709: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 8710: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8711: if (ref($lastactref) eq 'HASH') {
8712: $lastactref->{'domainconfig'} = 1;
8713: }
1.1 raeburn 8714: $resulttext = &mt('Changes made:').'<ul>';
8715: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 8716: if ($item eq 'loginvia') {
1.112 raeburn 8717: if (ref($changes{$item}) eq 'HASH') {
8718: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
8719: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 8720: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
8721: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
8722: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
8723: $protocol = 'http' if ($protocol ne 'https');
8724: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
8725:
8726: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
8727: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
8728: } else {
8729: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
8730: }
8731: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
8732: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
8733: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
8734: }
8735: $resulttext .= '</li>';
8736: } else {
8737: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
8738: }
1.112 raeburn 8739: } else {
1.128 raeburn 8740: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 8741: }
8742: }
1.128 raeburn 8743: $resulttext .= '</ul></li>';
1.112 raeburn 8744: }
1.160.6.5 raeburn 8745: } elsif ($item eq 'helpurl') {
8746: if (ref($changes{$item}) eq 'HASH') {
8747: foreach my $lang (sort(keys(%{$changes{$item}}))) {
8748: if (grep(/^\Q$lang\E$/,@delurls)) {
8749: my ($chg,$link);
8750: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
8751: if ($lang eq 'nolang') {
8752: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
8753: } else {
8754: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
8755: }
8756: $resulttext .= '<li>'.$chg.'</li>';
8757: } else {
8758: my $chg;
8759: if ($lang eq 'nolang') {
8760: $chg = &mt('custom log-in help file for no preferred language');
8761: } else {
8762: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
8763: }
8764: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
8765: $loginhash{'login'}{'helpurl'}{$lang}.
8766: '?inhibitmenu=yes',$chg,600,500).
8767: '</li>';
8768: }
8769: }
8770: }
1.160.6.56 raeburn 8771: } elsif ($item eq 'headtag') {
8772: if (ref($changes{$item}) eq 'HASH') {
8773: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8774: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8775: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
8776: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8777: $resulttext .= '<li><a href="'.
8778: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
8779: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
8780: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
8781: if ($possexempt{$lonhost}) {
8782: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
8783: } else {
8784: $resulttext .= &mt('included for any client IP');
8785: }
8786: $resulttext .= '</li>';
8787: }
8788: }
8789: }
1.160.6.5 raeburn 8790: } elsif ($item eq 'captcha') {
8791: if (ref($loginhash{'login'}) eq 'HASH') {
8792: my $chgtxt;
8793: if ($loginhash{'login'}{$item} eq 'notused') {
8794: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
8795: } else {
8796: my %captchas = &captcha_phrases();
8797: if ($captchas{$loginhash{'login'}{$item}}) {
8798: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
8799: } else {
8800: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
8801: }
8802: }
8803: $resulttext .= '<li>'.$chgtxt.'</li>';
8804: }
8805: } elsif ($item eq 'recaptchakeys') {
8806: if (ref($loginhash{'login'}) eq 'HASH') {
8807: my ($privkey,$pubkey);
8808: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
8809: $pubkey = $loginhash{'login'}{$item}{'public'};
8810: $privkey = $loginhash{'login'}{$item}{'private'};
8811: }
8812: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
8813: if (!$pubkey) {
8814: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
8815: } else {
8816: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8817: }
8818: if (!$privkey) {
8819: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
8820: } else {
1.160.6.53 raeburn 8821: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 8822: }
8823: $chgtxt .= '</ul>';
8824: $resulttext .= '<li>'.$chgtxt.'</li>';
8825: }
1.160.6.69 raeburn 8826: } elsif ($item eq 'recaptchaversion') {
8827: if (ref($loginhash{'login'}) eq 'HASH') {
8828: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
8829: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
8830: '</li>';
8831: }
8832: }
1.41 raeburn 8833: } else {
8834: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
8835: }
1.1 raeburn 8836: }
1.6 raeburn 8837: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 8838: } else {
8839: $resulttext = &mt('No changes made to log-in page settings');
8840: }
8841: } else {
1.11 albertel 8842: $resulttext = '<span class="LC_error">'.
8843: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8844: }
1.6 raeburn 8845: if ($errors) {
1.9 raeburn 8846: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 8847: $errors.'</ul>';
8848: }
8849: return $resulttext;
8850: }
8851:
1.160.6.56 raeburn 8852: sub check_exempt_addresses {
8853: my ($iplist) = @_;
8854: $iplist =~ s/^\s+//;
8855: $iplist =~ s/\s+$//;
8856: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
8857: my (@okips,$new);
8858: foreach my $ip (@poss_ips) {
8859: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
8860: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
8861: push(@okips,$ip);
8862: }
8863: }
8864: }
8865: if (@okips > 0) {
8866: $new = join(',',@okips);
8867: } else {
8868: $new = '';
8869: }
8870: return $new;
8871: }
8872:
1.6 raeburn 8873: sub color_font_choices {
8874: my %choices =
8875: &Apache::lonlocal::texthash (
8876: img => "Header",
8877: bgs => "Background colors",
8878: links => "Link colors",
1.55 raeburn 8879: images => "Images",
1.6 raeburn 8880: font => "Font color",
1.160.6.22 raeburn 8881: fontmenu => "Font menu",
1.76 raeburn 8882: pgbg => "Page",
1.6 raeburn 8883: tabbg => "Header",
8884: sidebg => "Border",
8885: link => "Link",
8886: alink => "Active link",
8887: vlink => "Visited link",
8888: );
8889: return %choices;
8890: }
8891:
8892: sub modify_rolecolors {
1.160.6.24 raeburn 8893: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8894: my ($resulttext,%rolehash);
8895: $rolehash{'rolecolors'} = {};
1.55 raeburn 8896: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8897: if ($domconfig{'rolecolors'} eq '') {
8898: $domconfig{'rolecolors'} = {};
8899: }
8900: }
1.9 raeburn 8901: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8902: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8903: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8904: $dom);
8905: if ($putresult eq 'ok') {
8906: if (keys(%changes) > 0) {
1.41 raeburn 8907: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8908: if (ref($lastactref) eq 'HASH') {
8909: $lastactref->{'domainconfig'} = 1;
8910: }
1.6 raeburn 8911: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8912: $rolehash{'rolecolors'});
8913: } else {
8914: $resulttext = &mt('No changes made to default color schemes');
8915: }
8916: } else {
1.11 albertel 8917: $resulttext = '<span class="LC_error">'.
8918: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8919: }
8920: if ($errors) {
8921: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8922: $errors.'</ul>';
8923: }
8924: return $resulttext;
8925: }
8926:
8927: sub modify_colors {
1.9 raeburn 8928: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8929: my (%changes,%choices);
1.51 raeburn 8930: my @bgs;
1.6 raeburn 8931: my @links = ('link','alink','vlink');
1.41 raeburn 8932: my @logintext;
1.6 raeburn 8933: my @images;
8934: my $servadm = $r->dir_config('lonAdmEMail');
8935: my $errors;
1.160.6.22 raeburn 8936: my %defaults;
1.6 raeburn 8937: foreach my $role (@{$roles}) {
8938: if ($role eq 'login') {
1.12 raeburn 8939: %choices = &login_choices();
1.41 raeburn 8940: @logintext = ('textcol','bgcol');
1.12 raeburn 8941: } else {
8942: %choices = &color_font_choices();
8943: }
8944: if ($role eq 'login') {
1.41 raeburn 8945: @images = ('img','logo','domlogo','login');
1.51 raeburn 8946: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8947: } else {
8948: @images = ('img');
1.160.6.22 raeburn 8949: @bgs = ('pgbg','tabbg','sidebg');
8950: }
8951: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8952: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8953: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8954: }
8955: if ($role eq 'login') {
8956: foreach my $item (@logintext) {
1.160.6.39 raeburn 8957: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8958: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8959: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8960: }
8961: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 8962: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8963: }
8964: }
8965: } else {
1.160.6.39 raeburn 8966: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8967: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8968: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8969: }
8970: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 8971: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8972: }
1.6 raeburn 8973: }
1.160.6.22 raeburn 8974: foreach my $item (@bgs) {
1.160.6.39 raeburn 8975: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8976: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8977: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8978: }
8979: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 8980: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8981: }
8982: }
8983: foreach my $item (@links) {
1.160.6.39 raeburn 8984: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8985: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8986: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8987: }
8988: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 8989: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8990: }
1.6 raeburn 8991: }
1.46 raeburn 8992: my ($configuserok,$author_ok,$switchserver) =
8993: &config_check($dom,$confname,$servadm);
1.9 raeburn 8994: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8995: if (ref($domconfig->{$role}) ne 'HASH') {
8996: $domconfig->{$role} = {};
8997: }
1.8 raeburn 8998: foreach my $img (@images) {
1.70 raeburn 8999: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9000: if (defined($env{'form.login_showlogo_'.$img})) {
9001: $confhash->{$role}{'showlogo'}{$img} = 1;
9002: } else {
9003: $confhash->{$role}{'showlogo'}{$img} = 0;
9004: }
9005: }
1.18 albertel 9006: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9007: && !defined($domconfig->{$role}{$img})
9008: && !$env{'form.'.$role.'_del_'.$img}
9009: && $env{'form.'.$role.'_import_'.$img}) {
9010: # import the old configured image from the .tab setting
9011: # if they haven't provided a new one
9012: $domconfig->{$role}{$img} =
9013: $env{'form.'.$role.'_import_'.$img};
9014: }
1.6 raeburn 9015: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9016: my $error;
1.6 raeburn 9017: if ($configuserok eq 'ok') {
1.9 raeburn 9018: if ($switchserver) {
1.12 raeburn 9019: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9020: } else {
9021: if ($author_ok eq 'ok') {
9022: my ($result,$logourl) =
9023: &publishlogo($r,'upload',$role.'_'.$img,
9024: $dom,$confname,$img,$width,$height);
9025: if ($result eq 'ok') {
9026: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9027: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9028: } else {
1.12 raeburn 9029: $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 9030: }
9031: } else {
1.46 raeburn 9032: $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 9033: }
9034: }
9035: } else {
1.46 raeburn 9036: $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 9037: }
9038: if ($error) {
1.8 raeburn 9039: &Apache::lonnet::logthis($error);
1.11 albertel 9040: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9041: }
9042: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9043: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9044: my $error;
9045: if ($configuserok eq 'ok') {
9046: # is confname an author?
9047: if ($switchserver eq '') {
9048: if ($author_ok eq 'ok') {
9049: my ($result,$logourl) =
9050: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9051: $dom,$confname,$img,$width,$height);
9052: if ($result eq 'ok') {
9053: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9054: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9055: }
9056: }
9057: }
9058: }
1.6 raeburn 9059: }
9060: }
9061: }
9062: if (ref($domconfig) eq 'HASH') {
9063: if (ref($domconfig->{$role}) eq 'HASH') {
9064: foreach my $img (@images) {
9065: if ($domconfig->{$role}{$img} ne '') {
9066: if ($env{'form.'.$role.'_del_'.$img}) {
9067: $confhash->{$role}{$img} = '';
1.12 raeburn 9068: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9069: } else {
1.9 raeburn 9070: if ($confhash->{$role}{$img} eq '') {
9071: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
9072: }
1.6 raeburn 9073: }
9074: } else {
9075: if ($env{'form.'.$role.'_del_'.$img}) {
9076: $confhash->{$role}{$img} = '';
1.12 raeburn 9077: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9078: }
9079: }
1.70 raeburn 9080: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
9081: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
9082: if ($confhash->{$role}{'showlogo'}{$img} ne
9083: $domconfig->{$role}{'showlogo'}{$img}) {
9084: $changes{$role}{'showlogo'}{$img} = 1;
9085: }
9086: } else {
9087: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9088: $changes{$role}{'showlogo'}{$img} = 1;
9089: }
9090: }
9091: }
9092: }
1.6 raeburn 9093: if ($domconfig->{$role}{'font'} ne '') {
9094: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
9095: $changes{$role}{'font'} = 1;
9096: }
9097: } else {
9098: if ($confhash->{$role}{'font'}) {
9099: $changes{$role}{'font'} = 1;
9100: }
9101: }
1.107 raeburn 9102: if ($role ne 'login') {
9103: if ($domconfig->{$role}{'fontmenu'} ne '') {
9104: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
9105: $changes{$role}{'fontmenu'} = 1;
9106: }
9107: } else {
9108: if ($confhash->{$role}{'fontmenu'}) {
9109: $changes{$role}{'fontmenu'} = 1;
9110: }
1.97 tempelho 9111: }
9112: }
1.6 raeburn 9113: foreach my $item (@bgs) {
9114: if ($domconfig->{$role}{$item} ne '') {
9115: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9116: $changes{$role}{'bgs'}{$item} = 1;
9117: }
9118: } else {
9119: if ($confhash->{$role}{$item}) {
9120: $changes{$role}{'bgs'}{$item} = 1;
9121: }
9122: }
9123: }
9124: foreach my $item (@links) {
9125: if ($domconfig->{$role}{$item} ne '') {
9126: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9127: $changes{$role}{'links'}{$item} = 1;
9128: }
9129: } else {
9130: if ($confhash->{$role}{$item}) {
9131: $changes{$role}{'links'}{$item} = 1;
9132: }
9133: }
9134: }
1.41 raeburn 9135: foreach my $item (@logintext) {
9136: if ($domconfig->{$role}{$item} ne '') {
9137: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9138: $changes{$role}{'logintext'}{$item} = 1;
9139: }
9140: } else {
9141: if ($confhash->{$role}{$item}) {
9142: $changes{$role}{'logintext'}{$item} = 1;
9143: }
9144: }
9145: }
1.6 raeburn 9146: } else {
9147: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9148: \@logintext,$confhash,\%changes);
1.6 raeburn 9149: }
9150: } else {
9151: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9152: \@logintext,$confhash,\%changes);
1.6 raeburn 9153: }
9154: }
9155: return ($errors,%changes);
9156: }
9157:
1.46 raeburn 9158: sub config_check {
9159: my ($dom,$confname,$servadm) = @_;
9160: my ($configuserok,$author_ok,$switchserver,%currroles);
9161: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
9162: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
9163: $confname,$servadm);
9164: if ($configuserok eq 'ok') {
9165: $switchserver = &check_switchserver($dom,$confname);
9166: if ($switchserver eq '') {
9167: $author_ok = &check_authorstatus($dom,$confname,%currroles);
9168: }
9169: }
9170: return ($configuserok,$author_ok,$switchserver);
9171: }
9172:
1.6 raeburn 9173: sub default_change_checker {
1.41 raeburn 9174: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 9175: foreach my $item (@{$links}) {
9176: if ($confhash->{$role}{$item}) {
9177: $changes->{$role}{'links'}{$item} = 1;
9178: }
9179: }
9180: foreach my $item (@{$bgs}) {
9181: if ($confhash->{$role}{$item}) {
9182: $changes->{$role}{'bgs'}{$item} = 1;
9183: }
9184: }
1.41 raeburn 9185: foreach my $item (@{$logintext}) {
9186: if ($confhash->{$role}{$item}) {
9187: $changes->{$role}{'logintext'}{$item} = 1;
9188: }
9189: }
1.6 raeburn 9190: foreach my $img (@{$images}) {
9191: if ($env{'form.'.$role.'_del_'.$img}) {
9192: $confhash->{$role}{$img} = '';
1.12 raeburn 9193: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 9194: }
1.70 raeburn 9195: if ($role eq 'login') {
9196: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9197: $changes->{$role}{'showlogo'}{$img} = 1;
9198: }
9199: }
1.6 raeburn 9200: }
9201: if ($confhash->{$role}{'font'}) {
9202: $changes->{$role}{'font'} = 1;
9203: }
1.48 raeburn 9204: }
1.6 raeburn 9205:
9206: sub display_colorchgs {
9207: my ($dom,$changes,$roles,$confhash) = @_;
9208: my (%choices,$resulttext);
9209: if (!grep(/^login$/,@{$roles})) {
9210: $resulttext = &mt('Changes made:').'<br />';
9211: }
9212: foreach my $role (@{$roles}) {
9213: if ($role eq 'login') {
9214: %choices = &login_choices();
9215: } else {
9216: %choices = &color_font_choices();
9217: }
9218: if (ref($changes->{$role}) eq 'HASH') {
9219: if ($role ne 'login') {
9220: $resulttext .= '<h4>'.&mt($role).'</h4>';
9221: }
9222: foreach my $key (sort(keys(%{$changes->{$role}}))) {
9223: if ($role ne 'login') {
9224: $resulttext .= '<ul>';
9225: }
9226: if (ref($changes->{$role}{$key}) eq 'HASH') {
9227: if ($role ne 'login') {
9228: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9229: }
9230: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 9231: if (($role eq 'login') && ($key eq 'showlogo')) {
9232: if ($confhash->{$role}{$key}{$item}) {
9233: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9234: } else {
9235: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9236: }
9237: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 9238: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9239: } else {
1.12 raeburn 9240: my $newitem = $confhash->{$role}{$item};
9241: if ($key eq 'images') {
9242: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
9243: }
9244: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 9245: }
9246: }
9247: if ($role ne 'login') {
9248: $resulttext .= '</ul></li>';
9249: }
9250: } else {
9251: if ($confhash->{$role}{$key} eq '') {
9252: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9253: } else {
9254: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9255: }
9256: }
9257: if ($role ne 'login') {
9258: $resulttext .= '</ul>';
9259: }
9260: }
9261: }
9262: }
1.3 raeburn 9263: return $resulttext;
1.1 raeburn 9264: }
9265:
1.9 raeburn 9266: sub thumb_dimensions {
9267: return ('200','50');
9268: }
9269:
1.16 raeburn 9270: sub check_dimensions {
9271: my ($inputfile) = @_;
9272: my ($fullwidth,$fullheight);
9273: if ($inputfile =~ m|^[/\w.\-]+$|) {
9274: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9275: my $imageinfo = <PIPE>;
9276: if (!close(PIPE)) {
9277: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9278: }
9279: chomp($imageinfo);
9280: my ($fullsize) =
1.21 raeburn 9281: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 9282: if ($fullsize) {
9283: ($fullwidth,$fullheight) = split(/x/,$fullsize);
9284: }
9285: }
9286: }
9287: return ($fullwidth,$fullheight);
9288: }
9289:
1.9 raeburn 9290: sub check_configuser {
9291: my ($uhome,$dom,$confname,$servadm) = @_;
9292: my ($configuserok,%currroles);
9293: if ($uhome eq 'no_host') {
9294: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 9295: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 9296: $configuserok =
9297: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
9298: $configpass,'','','','','',undef,$servadm);
9299: } else {
9300: $configuserok = 'ok';
9301: %currroles =
9302: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9303: }
9304: return ($configuserok,%currroles);
9305: }
9306:
9307: sub check_authorstatus {
9308: my ($dom,$confname,%currroles) = @_;
9309: my $author_ok;
1.40 raeburn 9310: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 9311: my $start = time;
9312: my $end = 0;
9313: $author_ok =
9314: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 9315: 'au',$end,$start,'','','domconfig');
1.9 raeburn 9316: } else {
9317: $author_ok = 'ok';
9318: }
9319: return $author_ok;
9320: }
9321:
9322: sub publishlogo {
1.46 raeburn 9323: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 9324: my ($output,$fname,$logourl);
9325: if ($action eq 'upload') {
9326: $fname=$env{'form.'.$formname.'.filename'};
9327: chop($env{'form.'.$formname});
9328: } else {
9329: ($fname) = ($formname =~ /([^\/]+)$/);
9330: }
1.46 raeburn 9331: if ($savefileas ne '') {
9332: $fname = $savefileas;
9333: }
1.9 raeburn 9334: $fname=&Apache::lonnet::clean_filename($fname);
9335: # See if there is anything left
9336: unless ($fname) { return ('error: no uploaded file'); }
9337: $fname="$subdir/$fname";
1.160.6.5 raeburn 9338: my $docroot=$r->dir_config('lonDocRoot');
9339: my $filepath="$docroot/priv";
9340: my $relpath = "$dom/$confname";
1.9 raeburn 9341: my ($fnamepath,$file,$fetchthumb);
9342: $file=$fname;
9343: if ($fname=~m|/|) {
9344: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9345: }
1.160.6.26 raeburn 9346: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9347: my $count;
1.160.6.5 raeburn 9348: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9349: $filepath.="/$parts[$count]";
9350: if ((-e $filepath)!=1) {
9351: mkdir($filepath,02770);
9352: }
9353: }
9354: # Check for bad extension and disallow upload
9355: if ($file=~/\.(\w+)$/ &&
9356: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9357: $output =
1.160.6.25 raeburn 9358: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9359: } elsif ($file=~/\.(\w+)$/ &&
9360: !defined(&Apache::loncommon::fileembstyle($1))) {
9361: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9362: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 9363: $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 9364: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 9365: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9366: } else {
9367: my $source = $filepath.'/'.$file;
9368: my $logfile;
1.160.6.88 raeburn 9369: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 9370: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9371: }
9372: print $logfile
9373: "\n================= Publish ".localtime()." ================\n".
9374: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9375: # Save the file
1.160.6.88 raeburn 9376: if (!open(FH,">",$source)) {
1.9 raeburn 9377: &Apache::lonnet::logthis('Failed to create '.$source);
9378: return (&mt('Failed to create file'));
9379: }
9380: if ($action eq 'upload') {
9381: if (!print FH ($env{'form.'.$formname})) {
9382: &Apache::lonnet::logthis('Failed to write to '.$source);
9383: return (&mt('Failed to write file'));
9384: }
9385: } else {
9386: my $original = &Apache::lonnet::filelocation('',$formname);
9387: if(!copy($original,$source)) {
9388: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9389: return (&mt('Failed to write file'));
9390: }
9391: }
9392: close(FH);
9393: chmod(0660, $source); # Permissions to rw-rw---.
9394:
9395: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9396: my $copyfile=$targetdir.'/'.$file;
9397:
9398: my @parts=split(/\//,$targetdir);
9399: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9400: for (my $count=5;$count<=$#parts;$count++) {
9401: $path.="/$parts[$count]";
9402: if (!-e $path) {
9403: print $logfile "\nCreating directory ".$path;
9404: mkdir($path,02770);
9405: }
9406: }
9407: my $versionresult;
9408: if (-e $copyfile) {
9409: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9410: } else {
9411: $versionresult = 'ok';
9412: }
9413: if ($versionresult eq 'ok') {
9414: if (copy($source,$copyfile)) {
9415: print $logfile "\nCopied original source to ".$copyfile."\n";
9416: $output = 'ok';
9417: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9418: push(@{$modified_urls},[$copyfile,$source]);
9419: my $metaoutput =
9420: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9421: unless ($registered_cleanup) {
9422: my $handlers = $r->get_handlers('PerlCleanupHandler');
9423: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9424: $registered_cleanup=1;
9425: }
1.9 raeburn 9426: } else {
9427: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9428: $output = &mt('Failed to copy file to RES space').", $!";
9429: }
9430: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9431: my $inputfile = $filepath.'/'.$file;
9432: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 9433: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9434: if ($fullwidth ne '' && $fullheight ne '') {
9435: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9436: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 9437: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
9438: system({$args[0]} @args);
1.16 raeburn 9439: chmod(0660, $filepath.'/tn-'.$file);
9440: if (-e $outfile) {
9441: my $copyfile=$targetdir.'/tn-'.$file;
9442: if (copy($outfile,$copyfile)) {
9443: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 9444: my $thumb_metaoutput =
9445: &write_metadata($dom,$confname,$formname,
9446: $targetdir,'tn-'.$file,$logfile);
9447: push(@{$modified_urls},[$copyfile,$outfile]);
9448: unless ($registered_cleanup) {
9449: my $handlers = $r->get_handlers('PerlCleanupHandler');
9450: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9451: $registered_cleanup=1;
9452: }
1.16 raeburn 9453: } else {
9454: print $logfile "\nUnable to write ".$copyfile.
9455: ':'.$!."\n";
9456: }
9457: }
1.9 raeburn 9458: }
9459: }
9460: }
9461: } else {
9462: $output = $versionresult;
9463: }
9464: }
9465: return ($output,$logourl);
9466: }
9467:
9468: sub logo_versioning {
9469: my ($targetdir,$file,$logfile) = @_;
9470: my $target = $targetdir.'/'.$file;
9471: my ($maxversion,$fn,$extn,$output);
9472: $maxversion = 0;
9473: if ($file =~ /^(.+)\.(\w+)$/) {
9474: $fn=$1;
9475: $extn=$2;
9476: }
9477: opendir(DIR,$targetdir);
9478: while (my $filename=readdir(DIR)) {
9479: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
9480: $maxversion=($1>$maxversion)?$1:$maxversion;
9481: }
9482: }
9483: $maxversion++;
9484: print $logfile "\nCreating old version ".$maxversion."\n";
9485: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
9486: if (copy($target,$copyfile)) {
9487: print $logfile "Copied old target to ".$copyfile."\n";
9488: $copyfile=$copyfile.'.meta';
9489: if (copy($target.'.meta',$copyfile)) {
9490: print $logfile "Copied old target metadata to ".$copyfile."\n";
9491: $output = 'ok';
9492: } else {
9493: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
9494: $output = &mt('Failed to copy old meta').", $!, ";
9495: }
9496: } else {
9497: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
9498: $output = &mt('Failed to copy old target').", $!, ";
9499: }
9500: return $output;
9501: }
9502:
9503: sub write_metadata {
9504: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
9505: my (%metadatafields,%metadatakeys,$output);
9506: $metadatafields{'title'}=$formname;
9507: $metadatafields{'creationdate'}=time;
9508: $metadatafields{'lastrevisiondate'}=time;
9509: $metadatafields{'copyright'}='public';
9510: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
9511: $env{'user.domain'};
9512: $metadatafields{'authorspace'}=$confname.':'.$dom;
9513: $metadatafields{'domain'}=$dom;
9514: {
9515: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
9516: my $mfh;
1.160.6.88 raeburn 9517: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 9518: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 9519: unless ($_=~/\./) {
9520: my $unikey=$_;
9521: $unikey=~/^([A-Za-z]+)/;
9522: my $tag=$1;
9523: $tag=~tr/A-Z/a-z/;
9524: print $mfh "\n\<$tag";
9525: foreach (split(/\,/,$metadatakeys{$unikey})) {
9526: my $value=$metadatafields{$unikey.'.'.$_};
9527: $value=~s/\"/\'\'/g;
9528: print $mfh ' '.$_.'="'.$value.'"';
9529: }
9530: print $mfh '>'.
9531: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
9532: .'</'.$tag.'>';
9533: }
9534: }
9535: $output = 'ok';
9536: print $logfile "\nWrote metadata";
9537: close($mfh);
9538: } else {
9539: print $logfile "\nFailed to open metadata file";
1.9 raeburn 9540: $output = &mt('Could not write metadata');
9541: }
9542: }
1.155 raeburn 9543: return $output;
9544: }
9545:
9546: sub notifysubscribed {
9547: foreach my $targetsource (@{$modified_urls}){
9548: next unless (ref($targetsource) eq 'ARRAY');
9549: my ($target,$source)=@{$targetsource};
9550: if ($source ne '') {
1.160.6.88 raeburn 9551: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 9552: print $logfh "\nCleanup phase: Notifications\n";
9553: my @subscribed=&subscribed_hosts($target);
9554: foreach my $subhost (@subscribed) {
9555: print $logfh "\nNotifying host ".$subhost.':';
9556: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
9557: print $logfh $reply;
9558: }
9559: my @subscribedmeta=&subscribed_hosts("$target.meta");
9560: foreach my $subhost (@subscribedmeta) {
9561: print $logfh "\nNotifying host for metadata only ".$subhost.':';
9562: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
9563: $subhost);
9564: print $logfh $reply;
9565: }
9566: print $logfh "\n============ Done ============\n";
1.160 raeburn 9567: close($logfh);
1.155 raeburn 9568: }
9569: }
9570: }
9571: return OK;
9572: }
9573:
9574: sub subscribed_hosts {
9575: my ($target) = @_;
9576: my @subscribed;
1.160.6.88 raeburn 9577: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 9578: while (my $subline=<$fh>) {
9579: if ($subline =~ /^($match_lonid):/) {
9580: my $host = $1;
9581: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
9582: unless (grep(/^\Q$host\E$/,@subscribed)) {
9583: push(@subscribed,$host);
9584: }
9585: }
9586: }
9587: }
9588: }
9589: return @subscribed;
1.9 raeburn 9590: }
9591:
9592: sub check_switchserver {
9593: my ($dom,$confname) = @_;
9594: my ($allowed,$switchserver);
9595: my $home = &Apache::lonnet::homeserver($confname,$dom);
9596: if ($home eq 'no_host') {
9597: $home = &Apache::lonnet::domain($dom,'primary');
9598: }
9599: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 9600: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
9601: if (!$allowed) {
1.160.6.11 raeburn 9602: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 9603: }
9604: return $switchserver;
9605: }
9606:
1.1 raeburn 9607: sub modify_quotas {
1.160.6.30 raeburn 9608: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 9609: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 9610: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 9611: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
9612: $validationfieldsref);
1.86 raeburn 9613: if ($action eq 'quotas') {
9614: $context = 'tools';
1.160.6.26 raeburn 9615: } else {
1.86 raeburn 9616: $context = $action;
9617: }
9618: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 9619: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 9620: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 9621: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
9622: %titles = &courserequest_titles();
9623: $toolregexp = join('|',@usertools);
9624: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 9625: $confname = $dom.'-domainconfig';
9626: my $servadm = $r->dir_config('lonAdmEMail');
9627: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 9628: ($validationitemsref,$validationnamesref,$validationfieldsref) =
9629: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 9630: } elsif ($context eq 'requestauthor') {
9631: @usertools = ('author');
9632: %titles = &authorrequest_titles();
1.86 raeburn 9633: } else {
1.160.6.4 raeburn 9634: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 9635: %titles = &tool_titles();
1.86 raeburn 9636: }
1.160.6.27 raeburn 9637: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 9638: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9639: foreach my $key (keys(%env)) {
1.101 raeburn 9640: if ($context eq 'requestcourses') {
9641: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
9642: my $item = $1;
9643: my $type = $2;
9644: if ($type =~ /^limit_(.+)/) {
9645: $limithash{$item}{$1} = $env{$key};
9646: } else {
9647: $confhash{$item}{$type} = $env{$key};
9648: }
9649: }
1.160.6.5 raeburn 9650: } elsif ($context eq 'requestauthor') {
9651: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
9652: $confhash{$1} = $env{$key};
9653: }
1.101 raeburn 9654: } else {
1.86 raeburn 9655: if ($key =~ /^form\.quota_(.+)$/) {
9656: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 9657: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
9658: $confhash{'authorquota'}{$1} = $env{$key};
9659: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 9660: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
9661: }
1.72 raeburn 9662: }
9663: }
1.160.6.5 raeburn 9664: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 9665: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 9666: @approvalnotify = sort(@approvalnotify);
9667: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 9668: my @crstypes = ('official','unofficial','community','textbook');
9669: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
9670: foreach my $type (@hasuniquecode) {
9671: if (grep(/^\Q$type\E$/,@crstypes)) {
9672: $confhash{'uniquecode'}{$type} = 1;
9673: }
9674: }
1.160.6.46 raeburn 9675: my (%newbook,%allpos);
1.160.6.30 raeburn 9676: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9677: foreach my $type ('textbooks','templates') {
9678: @{$allpos{$type}} = ();
9679: my $invalid;
9680: if ($type eq 'textbooks') {
9681: $invalid = &mt('Invalid LON-CAPA course for textbook');
9682: } else {
9683: $invalid = &mt('Invalid LON-CAPA course for template');
9684: }
9685: if ($env{'form.'.$type.'_addbook'}) {
9686: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
9687: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
9688: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
9689: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
9690: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9691: } else {
9692: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9693: my $position = $env{'form.'.$type.'_addbook_pos'};
9694: $position =~ s/\D+//g;
9695: if ($position ne '') {
9696: $allpos{$type}[$position] = $newbook{$type};
9697: }
1.160.6.30 raeburn 9698: }
1.160.6.46 raeburn 9699: } else {
9700: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 9701: }
9702: }
1.160.6.46 raeburn 9703: }
1.160.6.30 raeburn 9704: }
1.102 raeburn 9705: if (ref($domconfig{$action}) eq 'HASH') {
9706: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
9707: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
9708: $changes{'notify'}{'approval'} = 1;
9709: }
9710: } else {
1.144 raeburn 9711: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9712: $changes{'notify'}{'approval'} = 1;
9713: }
9714: }
1.160.6.30 raeburn 9715: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
9716: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9717: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
9718: unless ($confhash{'uniquecode'}{$crstype}) {
9719: $changes{'uniquecode'} = 1;
9720: }
9721: }
9722: unless ($changes{'uniquecode'}) {
9723: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
9724: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
9725: $changes{'uniquecode'} = 1;
9726: }
9727: }
9728: }
9729: } else {
9730: $changes{'uniquecode'} = 1;
9731: }
9732: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
9733: $changes{'uniquecode'} = 1;
9734: }
9735: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9736: foreach my $type ('textbooks','templates') {
9737: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9738: my %deletions;
9739: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
9740: if (@todelete) {
9741: map { $deletions{$_} = 1; } @todelete;
9742: }
9743: my %imgdeletions;
9744: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
9745: if (@todeleteimages) {
9746: map { $imgdeletions{$_} = 1; } @todeleteimages;
9747: }
9748: my $maxnum = $env{'form.'.$type.'_maxnum'};
9749: for (my $i=0; $i<=$maxnum; $i++) {
9750: my $itemid = $env{'form.'.$type.'_id_'.$i};
9751: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
9752: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
9753: if ($deletions{$key}) {
9754: if ($domconfig{$action}{$type}{$key}{'image'}) {
9755: #FIXME need to obsolete item in RES space
9756: }
9757: next;
9758: } else {
9759: my $newpos = $env{'form.'.$itemid};
9760: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 9761: foreach my $item ('subject','title','publisher','author') {
9762: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9763: ($type eq 'templates'));
1.160.6.46 raeburn 9764: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
9765: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
9766: $changes{$type}{$key} = 1;
9767: }
9768: }
9769: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 9770: }
1.160.6.46 raeburn 9771: if ($imgdeletions{$key}) {
9772: $changes{$type}{$key} = 1;
9773: #FIXME need to obsolete item in RES space
9774: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
9775: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 9776: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9777: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9778: } else {
9779: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
9780: $cdom,$cnum,$type,$configuserok,
9781: $switchserver,$author_ok);
9782: if ($imgurl) {
9783: $confhash{$type}{$key}{'image'} = $imgurl;
9784: $changes{$type}{$key} = 1;
9785: }
9786: if ($error) {
9787: &Apache::lonnet::logthis($error);
9788: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9789: }
1.160.6.46 raeburn 9790: }
9791: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
9792: $confhash{$type}{$key}{'image'} =
9793: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 9794: }
9795: }
9796: }
9797: }
9798: }
9799: }
1.102 raeburn 9800: } else {
1.144 raeburn 9801: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9802: $changes{'notify'}{'approval'} = 1;
9803: }
1.160.6.30 raeburn 9804: if (ref($confhash{'uniquecode'} eq 'HASH')) {
9805: $changes{'uniquecode'} = 1;
9806: }
9807: }
9808: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9809: foreach my $type ('textbooks','templates') {
9810: if ($newbook{$type}) {
9811: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 9812: foreach my $item ('subject','title','publisher','author') {
9813: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9814: ($type eq 'template'));
1.160.6.46 raeburn 9815: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
9816: if ($env{'form.'.$type.'_addbook_'.$item}) {
9817: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
9818: }
9819: }
9820: if ($type eq 'textbooks') {
9821: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
9822: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 9823: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9824: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9825: } else {
9826: my ($imageurl,$error) =
9827: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
9828: $configuserok,$switchserver,$author_ok);
9829: if ($imageurl) {
9830: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
9831: }
9832: if ($error) {
9833: &Apache::lonnet::logthis($error);
9834: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9835: }
1.160.6.46 raeburn 9836: }
9837: }
1.160.6.30 raeburn 9838: }
9839: }
1.160.6.46 raeburn 9840: if (@{$allpos{$type}} > 0) {
9841: my $idx = 0;
9842: foreach my $item (@{$allpos{$type}}) {
9843: if ($item ne '') {
9844: $confhash{$type}{$item}{'order'} = $idx;
9845: if (ref($domconfig{$action}) eq 'HASH') {
9846: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9847: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
9848: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
9849: $changes{$type}{$item} = 1;
9850: }
1.160.6.30 raeburn 9851: }
9852: }
9853: }
1.160.6.46 raeburn 9854: $idx ++;
1.160.6.30 raeburn 9855: }
9856: }
9857: }
9858: }
1.160.6.39 raeburn 9859: if (ref($validationitemsref) eq 'ARRAY') {
9860: foreach my $item (@{$validationitemsref}) {
9861: if ($item eq 'fields') {
9862: my @changed;
9863: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
9864: if (@{$confhash{'validation'}{$item}} > 0) {
9865: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
9866: }
1.160.6.65 raeburn 9867: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9868: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9869: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
9870: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
9871: $domconfig{'requestcourses'}{'validation'}{$item});
9872: } else {
9873: @changed = @{$confhash{'validation'}{$item}};
9874: }
1.160.6.39 raeburn 9875: } else {
9876: @changed = @{$confhash{'validation'}{$item}};
9877: }
9878: } else {
9879: @changed = @{$confhash{'validation'}{$item}};
9880: }
9881: if (@changed) {
9882: if ($confhash{'validation'}{$item}) {
9883: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9884: } else {
9885: $changes{'validation'}{$item} = &mt('None');
9886: }
9887: }
9888: } else {
9889: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9890: if ($item eq 'markup') {
9891: if ($env{'form.requestcourses_validation_'.$item}) {
9892: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9893: }
9894: }
1.160.6.65 raeburn 9895: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9896: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9897: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9898: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9899: }
9900: } else {
9901: if ($confhash{'validation'}{$item} ne '') {
9902: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9903: }
1.160.6.39 raeburn 9904: }
9905: } else {
9906: if ($confhash{'validation'}{$item} ne '') {
9907: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9908: }
9909: }
9910: }
9911: }
9912: }
9913: if ($env{'form.validationdc'}) {
9914: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 9915: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 9916: if (exists($domcoords{$newval})) {
9917: $confhash{'validation'}{'dc'} = $newval;
9918: }
9919: }
9920: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 9921: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9922: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9923: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9924: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9925: if ($confhash{'validation'}{'dc'} eq '') {
9926: $changes{'validation'}{'dc'} = &mt('None');
9927: } else {
9928: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9929: }
1.160.6.39 raeburn 9930: }
1.160.6.65 raeburn 9931: } elsif ($confhash{'validation'}{'dc'} ne '') {
9932: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 9933: }
9934: } elsif ($confhash{'validation'}{'dc'} ne '') {
9935: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9936: }
9937: } elsif ($confhash{'validation'}{'dc'} ne '') {
9938: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9939: }
1.160.6.65 raeburn 9940: } else {
9941: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9942: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9943: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9944: $changes{'validation'}{'dc'} = &mt('None');
9945: }
9946: }
1.160.6.39 raeburn 9947: }
9948: }
1.102 raeburn 9949: }
9950: } else {
1.86 raeburn 9951: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 9952: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9953: }
1.72 raeburn 9954: foreach my $item (@usertools) {
9955: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9956: my $unset;
1.101 raeburn 9957: if ($context eq 'requestcourses') {
1.104 raeburn 9958: $unset = '0';
9959: if ($type eq '_LC_adv') {
9960: $unset = '';
9961: }
1.101 raeburn 9962: if ($confhash{$item}{$type} eq 'autolimit') {
9963: $confhash{$item}{$type} .= '=';
9964: unless ($limithash{$item}{$type} =~ /\D/) {
9965: $confhash{$item}{$type} .= $limithash{$item}{$type};
9966: }
9967: }
1.160.6.5 raeburn 9968: } elsif ($context eq 'requestauthor') {
9969: $unset = '0';
9970: if ($type eq '_LC_adv') {
9971: $unset = '';
9972: }
1.72 raeburn 9973: } else {
1.101 raeburn 9974: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9975: $confhash{$item}{$type} = 1;
9976: } else {
9977: $confhash{$item}{$type} = 0;
9978: }
1.72 raeburn 9979: }
1.86 raeburn 9980: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 9981: if ($action eq 'requestauthor') {
9982: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9983: $changes{$type} = 1;
9984: }
9985: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9986: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9987: $changes{$item}{$type} = 1;
9988: }
9989: } else {
9990: if ($context eq 'requestcourses') {
1.104 raeburn 9991: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9992: $changes{$item}{$type} = 1;
9993: }
9994: } else {
9995: if (!$confhash{$item}{$type}) {
9996: $changes{$item}{$type} = 1;
9997: }
9998: }
9999: }
10000: } else {
10001: if ($context eq 'requestcourses') {
1.104 raeburn 10002: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10003: $changes{$item}{$type} = 1;
10004: }
1.160.6.5 raeburn 10005: } elsif ($context eq 'requestauthor') {
10006: if ($confhash{$type} ne $unset) {
10007: $changes{$type} = 1;
10008: }
1.72 raeburn 10009: } else {
10010: if (!$confhash{$item}{$type}) {
10011: $changes{$item}{$type} = 1;
10012: }
10013: }
10014: }
1.1 raeburn 10015: }
10016: }
1.160.6.5 raeburn 10017: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10018: if (ref($domconfig{'quotas'}) eq 'HASH') {
10019: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10020: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10021: if (exists($confhash{'defaultquota'}{$key})) {
10022: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10023: $changes{'defaultquota'}{$key} = 1;
10024: }
10025: } else {
10026: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10027: }
10028: }
1.86 raeburn 10029: } else {
10030: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10031: if (exists($confhash{'defaultquota'}{$key})) {
10032: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10033: $changes{'defaultquota'}{$key} = 1;
10034: }
10035: } else {
10036: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10037: }
1.1 raeburn 10038: }
10039: }
1.160.6.20 raeburn 10040: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10041: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10042: if (exists($confhash{'authorquota'}{$key})) {
10043: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10044: $changes{'authorquota'}{$key} = 1;
10045: }
10046: } else {
10047: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10048: }
10049: }
10050: }
1.1 raeburn 10051: }
1.86 raeburn 10052: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10053: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10054: if (ref($domconfig{'quotas'}) eq 'HASH') {
10055: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10056: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
10057: $changes{'defaultquota'}{$key} = 1;
10058: }
10059: } else {
10060: if (!exists($domconfig{'quotas'}{$key})) {
10061: $changes{'defaultquota'}{$key} = 1;
10062: }
1.72 raeburn 10063: }
10064: } else {
1.86 raeburn 10065: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 10066: }
1.1 raeburn 10067: }
10068: }
1.160.6.20 raeburn 10069: if (ref($confhash{'authorquota'}) eq 'HASH') {
10070: foreach my $key (keys(%{$confhash{'authorquota'}})) {
10071: if (ref($domconfig{'quotas'}) eq 'HASH') {
10072: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10073: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
10074: $changes{'authorquota'}{$key} = 1;
10075: }
10076: } else {
10077: $changes{'authorquota'}{$key} = 1;
10078: }
10079: } else {
10080: $changes{'authorquota'}{$key} = 1;
10081: }
10082: }
10083: }
1.1 raeburn 10084: }
1.72 raeburn 10085:
1.160.6.5 raeburn 10086: if ($context eq 'requestauthor') {
10087: $domdefaults{'requestauthor'} = \%confhash;
10088: } else {
10089: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 10090: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 10091: $domdefaults{$key} = $confhash{$key};
10092: }
1.160.6.5 raeburn 10093: }
1.72 raeburn 10094: }
1.160.6.5 raeburn 10095:
1.1 raeburn 10096: my %quotahash = (
1.86 raeburn 10097: $action => { %confhash }
1.1 raeburn 10098: );
10099: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
10100: $dom);
10101: if ($putresult eq 'ok') {
10102: if (keys(%changes) > 0) {
1.72 raeburn 10103: my $cachetime = 24*60*60;
10104: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10105: if (ref($lastactref) eq 'HASH') {
10106: $lastactref->{'domdefaults'} = 1;
10107: }
1.1 raeburn 10108: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 10109: unless (($context eq 'requestcourses') ||
10110: ($context eq 'requestauthor')) {
1.86 raeburn 10111: if (ref($changes{'defaultquota'}) eq 'HASH') {
10112: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
10113: foreach my $type (@{$types},'default') {
10114: if (defined($changes{'defaultquota'}{$type})) {
10115: my $typetitle = $usertypes->{$type};
10116: if ($type eq 'default') {
10117: $typetitle = $othertitle;
10118: }
1.160.6.28 raeburn 10119: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 10120: }
10121: }
1.86 raeburn 10122: $resulttext .= '</ul></li>';
1.72 raeburn 10123: }
1.160.6.20 raeburn 10124: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 10125: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 10126: foreach my $type (@{$types},'default') {
10127: if (defined($changes{'authorquota'}{$type})) {
10128: my $typetitle = $usertypes->{$type};
10129: if ($type eq 'default') {
10130: $typetitle = $othertitle;
10131: }
1.160.6.28 raeburn 10132: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 10133: }
10134: }
10135: $resulttext .= '</ul></li>';
10136: }
1.72 raeburn 10137: }
1.80 raeburn 10138: my %newenv;
1.72 raeburn 10139: foreach my $item (@usertools) {
1.160.6.5 raeburn 10140: my (%haschgs,%inconf);
10141: if ($context eq 'requestauthor') {
10142: %haschgs = %changes;
10143: %inconf = %confhash;
10144: } else {
10145: if (ref($changes{$item}) eq 'HASH') {
10146: %haschgs = %{$changes{$item}};
10147: }
10148: if (ref($confhash{$item}) eq 'HASH') {
10149: %inconf = %{$confhash{$item}};
10150: }
10151: }
10152: if (keys(%haschgs) > 0) {
1.80 raeburn 10153: my $newacc =
10154: &Apache::lonnet::usertools_access($env{'user.name'},
10155: $env{'user.domain'},
1.86 raeburn 10156: $item,'reload',$context);
1.160.6.5 raeburn 10157: if (($context eq 'requestcourses') ||
10158: ($context eq 'requestauthor')) {
1.108 raeburn 10159: if ($env{'environment.canrequest.'.$item} ne $newacc) {
10160: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 10161: }
10162: } else {
10163: if ($env{'environment.availabletools.'.$item} ne $newacc) {
10164: $newenv{'environment.availabletools.'.$item} = $newacc;
10165: }
1.80 raeburn 10166: }
1.160.6.5 raeburn 10167: unless ($context eq 'requestauthor') {
10168: $resulttext .= '<li>'.$titles{$item}.'<ul>';
10169: }
1.72 raeburn 10170: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 10171: if ($haschgs{$type}) {
1.72 raeburn 10172: my $typetitle = $usertypes->{$type};
10173: if ($type eq 'default') {
10174: $typetitle = $othertitle;
10175: } elsif ($type eq '_LC_adv') {
10176: $typetitle = 'LON-CAPA Advanced Users';
10177: }
1.160.6.5 raeburn 10178: if ($inconf{$type}) {
1.101 raeburn 10179: if ($context eq 'requestcourses') {
10180: my $cond;
1.160.6.5 raeburn 10181: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 10182: if ($1 eq '') {
10183: $cond = &mt('(Automatic processing of any request).');
10184: } else {
10185: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
10186: }
10187: } else {
1.160.6.5 raeburn 10188: $cond = $conditions{$inconf{$type}};
1.101 raeburn 10189: }
10190: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 10191: } elsif ($context eq 'requestauthor') {
10192: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
10193: $titles{$inconf{$type}},$typetitle);
10194:
1.101 raeburn 10195: } else {
10196: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
10197: }
1.72 raeburn 10198: } else {
1.104 raeburn 10199: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 10200: if ($inconf{$type} eq '0') {
1.104 raeburn 10201: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10202: } else {
10203: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
10204: }
10205: } else {
10206: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10207: }
1.72 raeburn 10208: }
10209: }
1.26 raeburn 10210: }
1.160.6.5 raeburn 10211: unless ($context eq 'requestauthor') {
10212: $resulttext .= '</ul></li>';
10213: }
1.26 raeburn 10214: }
1.1 raeburn 10215: }
1.160.6.5 raeburn 10216: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 10217: if (ref($changes{'notify'}) eq 'HASH') {
10218: if ($changes{'notify'}{'approval'}) {
10219: if (ref($confhash{'notify'}) eq 'HASH') {
10220: if ($confhash{'notify'}{'approval'}) {
10221: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
10222: } else {
1.160.6.5 raeburn 10223: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 10224: }
10225: }
10226: }
10227: }
10228: }
1.160.6.30 raeburn 10229: if ($action eq 'requestcourses') {
10230: my @offon = ('off','on');
10231: if ($changes{'uniquecode'}) {
10232: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10233: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10234: $resulttext .= '<li>'.
10235: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10236: '</li>';
10237: } else {
10238: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10239: '</li>';
10240: }
10241: }
1.160.6.46 raeburn 10242: foreach my $type ('textbooks','templates') {
10243: if (ref($changes{$type}) eq 'HASH') {
10244: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10245: foreach my $key (sort(keys(%{$changes{$type}}))) {
10246: my %coursehash = &Apache::lonnet::coursedescription($key);
10247: my $coursetitle = $coursehash{'description'};
10248: my $position = $confhash{$type}{$key}{'order'} + 1;
10249: $resulttext .= '<li>';
1.160.6.47 raeburn 10250: foreach my $item ('subject','title','publisher','author') {
10251: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10252: ($type eq 'templates'));
1.160.6.46 raeburn 10253: my $name = $item.':';
10254: $name =~ s/^(\w)/\U$1/;
10255: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10256: }
10257: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10258: if ($type eq 'textbooks') {
10259: if ($confhash{$type}{$key}{'image'}) {
10260: $resulttext .= ' '.&mt('Image: [_1]',
10261: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10262: ' alt="Textbook cover" />').'<br />';
10263: }
10264: }
10265: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 10266: }
1.160.6.46 raeburn 10267: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 10268: }
10269: }
1.160.6.39 raeburn 10270: if (ref($changes{'validation'}) eq 'HASH') {
10271: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10272: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10273: foreach my $item (@{$validationitemsref}) {
10274: if (exists($changes{'validation'}{$item})) {
10275: if ($item eq 'markup') {
10276: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10277: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10278: } else {
10279: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10280: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10281: }
10282: }
10283: }
10284: if (exists($changes{'validation'}{'dc'})) {
10285: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
10286: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
10287: }
10288: }
10289: }
1.160.6.30 raeburn 10290: }
1.1 raeburn 10291: $resulttext .= '</ul>';
1.80 raeburn 10292: if (keys(%newenv)) {
10293: &Apache::lonnet::appenv(\%newenv);
10294: }
1.1 raeburn 10295: } else {
1.86 raeburn 10296: if ($context eq 'requestcourses') {
10297: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 10298: } elsif ($context eq 'requestauthor') {
10299: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 10300: } else {
1.90 weissno 10301: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 10302: }
1.1 raeburn 10303: }
10304: } else {
1.11 albertel 10305: $resulttext = '<span class="LC_error">'.
10306: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10307: }
1.160.6.30 raeburn 10308: if ($errors) {
10309: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10310: '<ul>'.$errors.'</ul></p>';
10311: }
1.3 raeburn 10312: return $resulttext;
1.1 raeburn 10313: }
10314:
1.160.6.30 raeburn 10315: sub process_textbook_image {
1.160.6.46 raeburn 10316: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 10317: my $filename = $env{'form.'.$caller.'.filename'};
10318: my ($error,$url);
10319: my ($width,$height) = (50,50);
10320: if ($configuserok eq 'ok') {
10321: if ($switchserver) {
10322: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10323: $switchserver);
10324: } elsif ($author_ok eq 'ok') {
10325: my ($result,$imageurl) =
10326: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 10327: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 10328: if ($result eq 'ok') {
10329: $url = $imageurl;
10330: } else {
10331: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10332: }
10333: } else {
10334: $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);
10335: }
10336: } else {
10337: $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);
10338: }
10339: return ($url,$error);
10340: }
10341:
1.160.6.102.2 1(raebur 10342:0): sub modify_ltitools {
10343:0): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10344:0): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10345:0): my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
10346:0): my $confname = $dom.'-domainconfig';
10347:0): my $servadm = $r->dir_config('lonAdmEMail');
10348:0): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10349:0): my (%posslti,%possfield);
10350:0): my @courseroles = ('cc','in','ta','ep','st');
10351:0): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10352:0): map { $posslti{$_} = 1; } @ltiroles;
10353:0): my @allfields = ('fullname','firstname','lastname','email','user','roles');
10354:0): map { $possfield{$_} = 1; } @allfields;
10355:0): my %lt = <itools_names();
10356:0): if ($env{'form.ltitools_add'}) {
10357:0): my $title = $env{'form.ltitools_add_title'};
10358:0): $title =~ s/(`)/'/g;
10359:0): ($newid,my $error) = &get_ltitools_id($dom,$title);
10360:0): if ($newid) {
10361:0): my $position = $env{'form.ltitools_add_pos'};
10362:0): $position =~ s/\D+//g;
10363:0): if ($position ne '') {
10364:0): $allpos[$position] = $newid;
10365:0): }
10366:0): $changes{$newid} = 1;
10367:0): foreach my $item ('title','url','key','secret') {
10368:0): $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
10369:0): if ($env{'form.ltitools_add_'.$item}) {
10370:0): if (($item eq 'key') || ($item eq 'secret')) {
10371:0): $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10372:0): } else {
10373:0): $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10374:0): }
10375:0): }
10376:0): }
10377:0): if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10378:0): $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10379:0): }
10380:0): if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10381:0): $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10382:0): }
10383:0): foreach my $item ('width','height','linktext','explanation') {
10384:0): $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10385:0): $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
10386:0): if (($item eq 'width') || ($item eq 'height')) {
10387:0): if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10388:0): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10389:0): }
10390:0): } else {
10391:0): if ($env{'form.ltitools_add_'.$item} ne '') {
10392:0): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10393:0): }
10394:0): }
10395:0): }
10396:0): if ($env{'form.ltitools_add_target'} eq 'window') {
10397:0): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
10398:0): } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10399:0): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
10400:0): } else {
10401:0): $confhash{$newid}{'display'}{'target'} = 'iframe';
10402:0): }
10403:0): foreach my $item ('passback','roster') {
10404:0): if ($env{'form.ltitools_add_'.$item}) {
10405:0): $confhash{$newid}{$item} = 1;
10406:0): }
10407:0): }
10408:0): if ($env{'form.ltitools_add_image.filename'} ne '') {
10409:0): my ($imageurl,$error) =
10410:0): &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
10411:0): $configuserok,$switchserver,$author_ok);
10412:0): if ($imageurl) {
10413:0): $confhash{$newid}{'image'} = $imageurl;
10414:0): }
10415:0): if ($error) {
10416:0): &Apache::lonnet::logthis($error);
10417:0): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10418:0): }
10419:0): }
10420:0): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
10421:0): foreach my $field (@fields) {
10422:0): if ($possfield{$field}) {
10423:0): if ($field eq 'roles') {
10424:0): foreach my $role (@courseroles) {
10425:0): my $choice = $env{'form.ltitools_add_roles_'.$role};
10426:0): if (($choice ne '') && ($posslti{$choice})) {
10427:0): $confhash{$newid}{'roles'}{$role} = $choice;
10428:0): if ($role eq 'cc') {
10429:0): $confhash{$newid}{'roles'}{'co'} = $choice;
10430:0): }
10431:0): }
10432:0): }
10433:0): } else {
10434:0): $confhash{$newid}{'fields'}{$field} = 1;
10435:0): }
10436:0): }
10437:0): }
10438:0): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
10439:0): foreach my $item (@courseconfig) {
10440:0): $confhash{$newid}{'crsconf'}{$item} = 1;
10441:0): }
10442:0): if ($env{'form.ltitools_add_custom'}) {
10443:0): my $name = $env{'form.ltitools_add_custom_name'};
10444:0): my $value = $env{'form.ltitools_add_custom_value'};
10445:0): $value =~ s/(`)/'/g;
10446:0): $name =~ s/(`)/'/g;
10447:0): $confhash{$newid}{'custom'}{$name} = $value;
10448:0): }
10449:0): } else {
10450:0): my $error = &mt('Failed to acquire unique ID for new external tool');
10451:0): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10452:0): }
10453:0): }
10454:0): if (ref($domconfig{$action}) eq 'HASH') {
10455:0): my %deletions;
10456:0): my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
10457:0): if (@todelete) {
10458:0): map { $deletions{$_} = 1; } @todelete;
10459:0): }
10460:0): my %customadds;
10461:0): my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
10462:0): if (@newcustom) {
10463:0): map { $customadds{$_} = 1; } @newcustom;
10464:0): }
10465:0): my %imgdeletions;
10466:0): my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
10467:0): if (@todeleteimages) {
10468:0): map { $imgdeletions{$_} = 1; } @todeleteimages;
10469:0): }
10470:0): my $maxnum = $env{'form.ltitools_maxnum'};
10471:0): for (my $i=0; $i<=$maxnum; $i++) {
10472:0): my $itemid = $env{'form.ltitools_id_'.$i};
10473:0): $itemid =~ s/\D+//g;
10474:0): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10475:0): if ($deletions{$itemid}) {
10476:0): if ($domconfig{$action}{$itemid}{'image'}) {
10477:0): #FIXME need to obsolete item in RES space
10478:0): }
10479:0): $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
10480:0): next;
10481:0): } else {
10482:0): my $newpos = $env{'form.ltitools_'.$itemid};
10483:0): $newpos =~ s/\D+//g;
10484:0): foreach my $item ('title','url') {
10485:0): $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10486:0): if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
10487:0): $changes{$itemid} = 1;
10488:0): }
10489:0): }
10490:0): foreach my $item ('key','secret') {
10491:0): $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10492:0): if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
10493:0): $changes{$itemid} = 1;
10494:0): }
10495:0): }
10496:0): if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
10497:0): $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
10498:0): }
10499:0): if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
10500:0): $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
10501:0): }
10502:0): foreach my $size ('width','height') {
10503:0): $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
10504:0): $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
10505:0): if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
10506:0): $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
10507:0): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10508:0): if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
10509:0): $changes{$itemid} = 1;
10510:0): }
10511:0): } else {
10512:0): $changes{$itemid} = 1;
10513:0): }
10514:0): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10515:0): if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
10516:0): $changes{$itemid} = 1;
10517:0): }
10518:0): }
10519:0): }
10520:0): foreach my $item ('linktext','explanation') {
10521:0): $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
10522:0): $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
10523:0): if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
10524:0): $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10525:0): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10526:0): if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
10527:0): $changes{$itemid} = 1;
10528:0): }
10529:0): } else {
10530:0): $changes{$itemid} = 1;
10531:0): }
10532:0): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10533:0): if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
10534:0): $changes{$itemid} = 1;
10535:0): }
10536:0): }
10537:0): }
10538:0): if ($env{'form.ltitools_target_'.$i} eq 'window') {
10539:0): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
10540:0): } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
10541:0): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
10542:0): } else {
10543:0): $confhash{$itemid}{'display'}{'target'} = 'iframe';
10544:0): }
10545:0): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10546:0): if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
10547:0): $changes{$itemid} = 1;
10548:0): }
10549:0): } else {
10550:0): $changes{$itemid} = 1;
10551:0): }
10552:0): foreach my $extra ('passback','roster') {
10553:0): if ($env{'form.ltitools_'.$extra.'_'.$i}) {
10554:0): $confhash{$itemid}{$extra} = 1;
10555:0): }
10556:0): if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
10557:0): $changes{$itemid} = 1;
10558:0): }
10559:0): }
10560:0): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
10561:0): foreach my $item ('label','title','target','linktext','explanation') {
10562:0): if (grep(/^\Q$item\E$/,@courseconfig)) {
10563:0): $confhash{$itemid}{'crsconf'}{$item} = 1;
10564:0): if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
10565:0): if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
10566:0): $changes{$itemid} = 1;
10567:0): }
10568:0): } else {
10569:0): $changes{$itemid} = 1;
10570:0): }
10571:0): }
10572:0): }
10573:0): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
10574:0): foreach my $field (@fields) {
10575:0): if ($possfield{$field}) {
10576:0): if ($field eq 'roles') {
10577:0): foreach my $role (@courseroles) {
10578:0): my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
10579:0): if (($choice ne '') && ($posslti{$choice})) {
10580:0): $confhash{$itemid}{'roles'}{$role} = $choice;
10581:0): if ($role eq 'cc') {
10582:0): $confhash{$itemid}{'roles'}{'co'} = $choice;
10583:0): }
10584:0): }
10585:0): if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
10586:0): if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
10587:0): $changes{$itemid} = 1;
10588:0): }
10589:0): } elsif ($confhash{$itemid}{'roles'}{$role}) {
10590:0): $changes{$itemid} = 1;
10591:0): }
10592:0): }
10593:0): } else {
10594:0): $confhash{$itemid}{'fields'}{$field} = 1;
10595:0): if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
10596:0): if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
10597:0): $changes{$itemid} = 1;
10598:0): }
10599:0): } else {
10600:0): $changes{$itemid} = 1;
10601:0): }
10602:0): }
10603:0): }
10604:0): }
10605:0): $allpos[$newpos] = $itemid;
10606:0): }
10607:0): if ($imgdeletions{$itemid}) {
10608:0): $changes{$itemid} = 1;
10609:0): #FIXME need to obsolete item in RES space
10610:0): } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
10611:0): my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
10612:0): $itemid,$configuserok,$switchserver,
10613:0): $author_ok);
10614:0): if ($imgurl) {
10615:0): $confhash{$itemid}{'image'} = $imgurl;
10616:0): $changes{$itemid} = 1;
10617:0): }
10618:0): if ($error) {
10619:0): &Apache::lonnet::logthis($error);
10620:0): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10621:0): }
10622:0): } elsif ($domconfig{$action}{$itemid}{'image'}) {
10623:0): $confhash{$itemid}{'image'} =
10624:0): $domconfig{$action}{$itemid}{'image'};
10625:0): }
10626:0): if ($customadds{$i}) {
10627:0): my $name = $env{'form.ltitools_custom_name_'.$i};
10628:0): $name =~ s/(`)/'/g;
10629:0): $name =~ s/^\s+//;
10630:0): $name =~ s/\s+$//;
10631:0): my $value = $env{'form.ltitools_custom_value_'.$i};
10632:0): $value =~ s/(`)/'/g;
10633:0): $value =~ s/^\s+//;
10634:0): $value =~ s/\s+$//;
10635:0): if ($name ne '') {
10636:0): $confhash{$itemid}{'custom'}{$name} = $value;
10637:0): $changes{$itemid} = 1;
10638:0): }
10639:0): }
10640:0): my %customdels;
10641:0): my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
10642:0): if (@customdeletions) {
10643:0): $changes{$itemid} = 1;
10644:0): }
10645:0): map { $customdels{$_} = 1; } @customdeletions;
10646:0): if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
10647:0): foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
10648:0): unless ($customdels{$key}) {
10649:0): if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
10650:0): $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
10651:0): }
10652:0): if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
10653:0): $changes{$itemid} = 1;
10654:0): }
10655:0): }
10656:0): }
10657:0): }
10658:0): unless ($changes{$itemid}) {
10659:0): foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
10660:0): if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
10661:0): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
10662:0): foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
10663:0): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
10664:0): $changes{$itemid} = 1;
10665:0): last;
10666:0): }
10667:0): }
10668:0): } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
10669:0): $changes{$itemid} = 1;
10670:0): }
10671:0): }
10672:0): last if ($changes{$itemid});
10673:0): }
10674:0): }
10675:0): }
10676:0): }
10677:0): }
10678:0): if (@allpos > 0) {
10679:0): my $idx = 0;
10680:0): foreach my $itemid (@allpos) {
10681:0): if ($itemid ne '') {
10682:0): $confhash{$itemid}{'order'} = $idx;
10683:0): if (ref($domconfig{$action}) eq 'HASH') {
10684:0): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10685:0): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
10686:0): $changes{$itemid} = 1;
10687:0): }
10688:0): }
10689:0): }
10690:0): $idx ++;
10691:0): }
10692:0): }
10693:0): }
10694:0): my %ltitoolshash = (
10695:0): $action => { %confhash }
10696:0): );
10697:0): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
10698:0): $dom);
10699:0): if ($putresult eq 'ok') {
10700:0): my %ltienchash = (
10701:0): $action => { %encconfig }
10702:0): );
10703:0): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
10704:0): if (keys(%changes) > 0) {
10705:0): my $cachetime = 24*60*60;
10706:0): my %ltiall = %confhash;
10707:0): foreach my $id (keys(%ltiall)) {
10708:0): if (ref($encconfig{$id}) eq 'HASH') {
10709:0): foreach my $item ('key','secret') {
10710:0): $ltiall{$id}{$item} = $encconfig{$id}{$item};
10711:0): }
10712:0): }
10713:0): }
10714:0): &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
10715:0): if (ref($lastactref) eq 'HASH') {
10716:0): $lastactref->{'ltitools'} = 1;
10717:0): }
10718:0): $resulttext = &mt('Changes made:').'<ul>';
10719:0): my %bynum;
10720:0): foreach my $itemid (sort(keys(%changes))) {
10721:0): my $position = $confhash{$itemid}{'order'};
10722:0): $bynum{$position} = $itemid;
10723:0): }
10724:0): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
10725:0): my $itemid = $bynum{$pos};
10726:0): if (ref($confhash{$itemid}) ne 'HASH') {
10727:0): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
10728:0): } else {
10729:0): $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
10730:0): if ($confhash{$itemid}{'image'}) {
10731:0): $resulttext .= ' '.
10732:0): '<img src="'.$confhash{$itemid}{'image'}.'"'.
10733:0): ' alt="'.&mt('Tool Provider icon').'" />';
10734:0): }
10735:0): $resulttext .= '</li><ul>';
10736:0): my $position = $pos + 1;
10737:0): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
10738:0): foreach my $item ('version','msgtype','url') {
10739:0): if ($confhash{$itemid}{$item} ne '') {
10740:0): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
10741:0): }
10742:0): }
10743:0): if ($encconfig{$itemid}{'key'} ne '') {
10744:0): $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
10745:0): }
10746:0): if ($encconfig{$itemid}{'secret'} ne '') {
10747:0): $resulttext .= '<li>'.$lt{'secret'}.': ';
10748:0): my $num = length($encconfig{$itemid}{'secret'});
10749:0): $resulttext .= ('*'x$num).'</li>';
10750:0): }
10751:0): $resulttext .= '<li>'.&mt('Configurable in course:');
10752:0): my @possconfig = ('label','title','target','linktext','explanation');
10753:0): my $numconfig = 0;
10754:0): if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
10755:0): foreach my $item (@possconfig) {
10756:0): if ($confhash{$itemid}{'crsconf'}{$item}) {
10757:0): $numconfig ++;
10758:0): $resulttext .= ' "'.$lt{'crs'.$item}.'"';
10759:0): }
10760:0): }
10761:0): }
10762:0): if (!$numconfig) {
10763:0): $resulttext .= &mt('None');
10764:0): }
10765:0): $resulttext .= '</li>';
10766:0): foreach my $item ('passback','roster') {
10767:0): $resulttext .= '<li>'.$lt{$item}.' ';
10768:0): if ($confhash{$itemid}{$item}) {
10769:0): $resulttext .= &mt('Yes');
10770:0): } else {
10771:0): $resulttext .= &mt('No');
10772:0): }
10773:0): $resulttext .= '</li>';
10774:0): }
10775:0): if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
10776:0): my $displaylist;
10777:0): if ($confhash{$itemid}{'display'}{'target'}) {
10778:0): $displaylist = &mt('Display target').': '.
10779:0): $confhash{$itemid}{'display'}{'target'}.',';
10780:0): }
10781:0): foreach my $size ('width','height') {
10782:0): if ($confhash{$itemid}{'display'}{$size}) {
10783:0): $displaylist .= (' 'x2).$lt{$size}.': '.
10784:0): $confhash{$itemid}{'display'}{$size}.',';
10785:0): }
10786:0): }
10787:0): if ($displaylist) {
10788:0): $displaylist =~ s/,$//;
10789:0): $resulttext .= '<li>'.$displaylist.'</li>';
10790:0): }
10791:0): foreach my $item ('linktext','explanation') {
10792:0): if ($confhash{$itemid}{'display'}{$item}) {
10793:0): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
10794:0): }
10795:0): }
10796:0): }
10797:0): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
10798:0): my $fieldlist;
10799:0): foreach my $field (@allfields) {
10800:0): if ($confhash{$itemid}{'fields'}{$field}) {
10801:0): $fieldlist .= (' 'x2).$lt{$field}.',';
10802:0): }
10803:0): }
10804:0): if ($fieldlist) {
10805:0): $fieldlist =~ s/,$//;
10806:0): $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
10807:0): }
10808:0): }
10809:0): if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
10810:0): my $rolemaps;
10811:0): foreach my $role (@courseroles) {
10812:0): if ($confhash{$itemid}{'roles'}{$role}) {
10813:0): $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
10814:0): $confhash{$itemid}{'roles'}{$role}.',';
10815:0): }
10816:0): }
10817:0): if ($rolemaps) {
10818:0): $rolemaps =~ s/,$//;
10819:0): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
10820:0): }
10821:0): }
10822:0): if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
10823:0): my $customlist;
10824:0): if (keys(%{$confhash{$itemid}{'custom'}})) {
10825:0): foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
10826:0): $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
10827:0): }
10828:0): }
10829:0): if ($customlist) {
10830:0): $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
10831:0): }
10832:0): }
10833:0): $resulttext .= '</ul></li>';
10834:0): }
10835:0): }
10836:0): $resulttext .= '</ul>';
10837:0): } else {
10838:0): $resulttext = &mt('No changes made.');
10839:0): }
10840:0): } else {
10841:0): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
10842:0): }
10843:0): if ($errors) {
10844:0): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10845:0): $errors.'</ul>';
10846:0): }
10847:0): return $resulttext;
10848:0): }
10849:0):
10850:0): sub process_ltitools_image {
10851:0): my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
10852:0): my $filename = $env{'form.'.$caller.'.filename'};
10853:0): my ($error,$url);
10854:0): my ($width,$height) = (21,21);
10855:0): if ($configuserok eq 'ok') {
10856:0): if ($switchserver) {
10857:0): $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
10858:0): $switchserver);
10859:0): } elsif ($author_ok eq 'ok') {
10860:0): my ($result,$imageurl,$madethumb) =
10861:0): &publishlogo($r,'upload',$caller,$dom,$confname,
10862:0): "ltitools/$itemid/icon",$width,$height);
10863:0): if ($result eq 'ok') {
10864:0): if ($madethumb) {
10865:0): my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
10866:0): my $imagethumb = "$path/tn-".$imagefile;
10867:0): $url = $imagethumb;
10868:0): } else {
10869:0): $url = $imageurl;
10870:0): }
10871:0): } else {
10872:0): $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10873:0): }
10874:0): } else {
10875:0): $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);
10876:0): }
10877:0): } else {
10878:0): $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);
10879:0): }
10880:0): return ($url,$error);
10881:0): }
10882:0):
10883:0): sub get_ltitools_id {
10884:0): my ($cdom,$title) = @_;
10885:0): # get lock on ltitools db
10886:0): my $lockhash = {
10887:0): lock => $env{'user.name'}.
10888:0): ':'.$env{'user.domain'},
10889:0): };
10890:0): my $tries = 0;
10891:0): my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10892:0): my ($id,$error);
10893:0):
10894:0): while (($gotlock ne 'ok') && ($tries<10)) {
10895:0): $tries ++;
10896:0): sleep (0.1);
10897:0): $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10898:0): }
10899:0): if ($gotlock eq 'ok') {
10900:0): my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
10901:0): if ($currids{'lock'}) {
10902:0): delete($currids{'lock'});
10903:0): if (keys(%currids)) {
10904:0): my @curr = sort { $a <=> $b } keys(%currids);
10905:0): if ($curr[-1] =~ /^\d+$/) {
10906:0): $id = 1 + $curr[-1];
10907:0): }
10908:0): } else {
10909:0): $id = 1;
10910:0): }
10911:0): if ($id) {
10912:0): unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
10913:0): $error = 'nostore';
10914:0): }
10915:0): } else {
10916:0): $error = 'nonumber';
10917:0): }
10918:0): }
10919:0): my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
10920:0): } else {
10921:0): $error = 'nolock';
10922:0): }
10923:0): return ($id,$error);
10924:0): }
10925:0):
1.3 raeburn 10926: sub modify_autoenroll {
1.160.6.24 raeburn 10927: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 10928: my ($resulttext,%changes);
10929: my %currautoenroll;
10930: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
10931: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
10932: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
10933: }
10934: }
10935: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
10936: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 10937: sender => 'Sender for notification messages',
1.160.6.68 raeburn 10938: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
10939: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 10940: my @offon = ('off','on');
1.17 raeburn 10941: my $sender_uname = $env{'form.sender_uname'};
10942: my $sender_domain = $env{'form.sender_domain'};
10943: if ($sender_domain eq '') {
10944: $sender_uname = '';
10945: } elsif ($sender_uname eq '') {
10946: $sender_domain = '';
10947: }
1.129 raeburn 10948: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 10949: my $failsafe = $env{'form.autoenroll_failsafe'};
10950: $failsafe =~ s{^\s+|\s+$}{}g;
10951: if ($failsafe =~ /\D/) {
10952: undef($failsafe);
10953: }
1.1 raeburn 10954: my %autoenrollhash = (
1.129 raeburn 10955: autoenroll => { 'run' => $env{'form.autoenroll_run'},
10956: 'sender_uname' => $sender_uname,
10957: 'sender_domain' => $sender_domain,
10958: 'co-owners' => $coowners,
1.160.6.68 raeburn 10959: 'autofailsafe' => $failsafe,
1.1 raeburn 10960: }
10961: );
1.4 raeburn 10962: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
10963: $dom);
1.1 raeburn 10964: if ($putresult eq 'ok') {
10965: if (exists($currautoenroll{'run'})) {
10966: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
10967: $changes{'run'} = 1;
10968: }
10969: } elsif ($autorun) {
10970: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 10971: $changes{'run'} = 1;
1.1 raeburn 10972: }
10973: }
1.17 raeburn 10974: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 10975: $changes{'sender'} = 1;
10976: }
1.17 raeburn 10977: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 10978: $changes{'sender'} = 1;
10979: }
1.129 raeburn 10980: if ($currautoenroll{'co-owners'} ne '') {
10981: if ($currautoenroll{'co-owners'} ne $coowners) {
10982: $changes{'coowners'} = 1;
10983: }
10984: } elsif ($coowners) {
10985: $changes{'coowners'} = 1;
1.160.6.68 raeburn 10986: }
10987: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
10988: $changes{'autofailsafe'} = 1;
10989: }
1.1 raeburn 10990: if (keys(%changes) > 0) {
10991: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 10992: if ($changes{'run'}) {
1.1 raeburn 10993: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
10994: }
10995: if ($changes{'sender'}) {
1.17 raeburn 10996: if ($sender_uname eq '' || $sender_domain eq '') {
10997: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
10998: } else {
10999: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
11000: }
1.1 raeburn 11001: }
1.129 raeburn 11002: if ($changes{'coowners'}) {
11003: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
11004: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 11005: if (ref($lastactref) eq 'HASH') {
11006: $lastactref->{'domainconfig'} = 1;
11007: }
1.129 raeburn 11008: }
1.160.6.68 raeburn 11009: if ($changes{'autofailsafe'}) {
11010: if ($failsafe ne '') {
1.160.6.82 raeburn 11011: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 11012: } else {
1.160.6.82 raeburn 11013: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 11014: }
11015: &Apache::lonnet::get_domain_defaults($dom,1);
11016: if (ref($lastactref) eq 'HASH') {
11017: $lastactref->{'domdefaults'} = 1;
11018: }
11019: }
1.1 raeburn 11020: $resulttext .= '</ul>';
11021: } else {
11022: $resulttext = &mt('No changes made to auto-enrollment settings');
11023: }
11024: } else {
1.11 albertel 11025: $resulttext = '<span class="LC_error">'.
11026: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11027: }
1.3 raeburn 11028: return $resulttext;
1.1 raeburn 11029: }
11030:
11031: sub modify_autoupdate {
1.3 raeburn 11032: my ($dom,%domconfig) = @_;
1.1 raeburn 11033: my ($resulttext,%currautoupdate,%fields,%changes);
11034: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
11035: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
11036: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
11037: }
11038: }
11039: my @offon = ('off','on');
11040: my %title = &Apache::lonlocal::texthash (
11041: run => 'Auto-update:',
11042: classlists => 'Updates to user information in classlists?'
11043: );
1.44 raeburn 11044: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11045: my %fieldtitles = &Apache::lonlocal::texthash (
11046: id => 'Student/Employee ID',
1.20 raeburn 11047: permanentemail => 'E-mail address',
1.1 raeburn 11048: lastname => 'Last Name',
11049: firstname => 'First Name',
11050: middlename => 'Middle Name',
1.132 raeburn 11051: generation => 'Generation',
1.1 raeburn 11052: );
1.142 raeburn 11053: $othertitle = &mt('All users');
1.1 raeburn 11054: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 11055: $othertitle = &mt('Other users');
1.1 raeburn 11056: }
11057: foreach my $key (keys(%env)) {
11058: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 11059: my ($usertype,$item) = ($1,$2);
11060: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
11061: if ($usertype eq 'default') {
11062: push(@{$fields{$1}},$2);
11063: } elsif (ref($types) eq 'ARRAY') {
11064: if (grep(/^\Q$usertype\E$/,@{$types})) {
11065: push(@{$fields{$1}},$2);
11066: }
11067: }
11068: }
1.1 raeburn 11069: }
11070: }
1.131 raeburn 11071: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
11072: @lockablenames = sort(@lockablenames);
11073: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
11074: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11075: if (@changed) {
11076: $changes{'lockablenames'} = 1;
11077: }
11078: } else {
11079: if (@lockablenames) {
11080: $changes{'lockablenames'} = 1;
11081: }
11082: }
1.1 raeburn 11083: my %updatehash = (
11084: autoupdate => { run => $env{'form.autoupdate_run'},
11085: classlists => $env{'form.classlists'},
11086: fields => {%fields},
1.131 raeburn 11087: lockablenames => \@lockablenames,
1.1 raeburn 11088: }
11089: );
11090: foreach my $key (keys(%currautoupdate)) {
11091: if (($key eq 'run') || ($key eq 'classlists')) {
11092: if (exists($updatehash{autoupdate}{$key})) {
11093: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
11094: $changes{$key} = 1;
11095: }
11096: }
11097: } elsif ($key eq 'fields') {
11098: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 11099: foreach my $item (@{$types},'default') {
1.1 raeburn 11100: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
11101: my $change = 0;
11102: foreach my $type (@{$currautoupdate{$key}{$item}}) {
11103: if (!exists($fields{$item})) {
11104: $change = 1;
1.132 raeburn 11105: last;
1.1 raeburn 11106: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 11107: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 11108: $change = 1;
1.132 raeburn 11109: last;
1.1 raeburn 11110: }
11111: }
11112: }
11113: if ($change) {
11114: push(@{$changes{$key}},$item);
11115: }
1.26 raeburn 11116: }
1.1 raeburn 11117: }
11118: }
1.131 raeburn 11119: } elsif ($key eq 'lockablenames') {
11120: if (ref($currautoupdate{$key}) eq 'ARRAY') {
11121: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11122: if (@changed) {
11123: $changes{'lockablenames'} = 1;
11124: }
11125: } else {
11126: if (@lockablenames) {
11127: $changes{'lockablenames'} = 1;
11128: }
11129: }
11130: }
11131: }
11132: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
11133: if (@lockablenames) {
11134: $changes{'lockablenames'} = 1;
1.1 raeburn 11135: }
11136: }
1.26 raeburn 11137: foreach my $item (@{$types},'default') {
11138: if (defined($fields{$item})) {
11139: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 11140: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
11141: my $change = 0;
11142: if (ref($fields{$item}) eq 'ARRAY') {
11143: foreach my $type (@{$fields{$item}}) {
11144: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
11145: $change = 1;
11146: last;
11147: }
11148: }
11149: }
11150: if ($change) {
11151: push(@{$changes{'fields'}},$item);
11152: }
11153: } else {
1.26 raeburn 11154: push(@{$changes{'fields'}},$item);
11155: }
11156: } else {
11157: push(@{$changes{'fields'}},$item);
1.1 raeburn 11158: }
11159: }
11160: }
11161: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
11162: $dom);
11163: if ($putresult eq 'ok') {
11164: if (keys(%changes) > 0) {
11165: $resulttext = &mt('Changes made:').'<ul>';
11166: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 11167: if ($key eq 'lockablenames') {
11168: $resulttext .= '<li>';
11169: if (@lockablenames) {
11170: $usertypes->{'default'} = $othertitle;
11171: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
11172: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
11173: } else {
11174: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
11175: }
11176: $resulttext .= '</li>';
11177: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 11178: foreach my $item (@{$changes{$key}}) {
11179: my @newvalues;
11180: foreach my $type (@{$fields{$item}}) {
11181: push(@newvalues,$fieldtitles{$type});
11182: }
1.3 raeburn 11183: my $newvaluestr;
11184: if (@newvalues > 0) {
11185: $newvaluestr = join(', ',@newvalues);
11186: } else {
11187: $newvaluestr = &mt('none');
1.6 raeburn 11188: }
1.1 raeburn 11189: if ($item eq 'default') {
1.26 raeburn 11190: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 11191: } else {
1.26 raeburn 11192: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 11193: }
11194: }
11195: } else {
11196: my $newvalue;
11197: if ($key eq 'run') {
11198: $newvalue = $offon[$env{'form.autoupdate_run'}];
11199: } else {
11200: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 11201: }
1.1 raeburn 11202: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
11203: }
11204: }
11205: $resulttext .= '</ul>';
11206: } else {
1.3 raeburn 11207: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 11208: }
11209: } else {
1.11 albertel 11210: $resulttext = '<span class="LC_error">'.
11211: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11212: }
1.3 raeburn 11213: return $resulttext;
1.1 raeburn 11214: }
11215:
1.125 raeburn 11216: sub modify_autocreate {
11217: my ($dom,%domconfig) = @_;
11218: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
11219: if (ref($domconfig{'autocreate'}) eq 'HASH') {
11220: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
11221: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
11222: }
11223: }
11224: my %title= ( xml => 'Auto-creation of courses in XML course description files',
11225: req => 'Auto-creation of validated requests for official courses',
11226: xmldc => 'Identity of course creator of courses from XML files',
11227: );
11228: my @types = ('xml','req');
11229: foreach my $item (@types) {
11230: $newvals{$item} = $env{'form.autocreate_'.$item};
11231: $newvals{$item} =~ s/\D//g;
11232: $newvals{$item} = 0 if ($newvals{$item} eq '');
11233: }
11234: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 11235: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 11236: unless (exists($domcoords{$newvals{'xmldc'}})) {
11237: $newvals{'xmldc'} = '';
11238: }
11239: %autocreatehash = (
11240: autocreate => { xml => $newvals{'xml'},
11241: req => $newvals{'req'},
11242: }
11243: );
11244: if ($newvals{'xmldc'} ne '') {
11245: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
11246: }
11247: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
11248: $dom);
11249: if ($putresult eq 'ok') {
11250: my @items = @types;
11251: if ($newvals{'xml'}) {
11252: push(@items,'xmldc');
11253: }
11254: foreach my $item (@items) {
11255: if (exists($currautocreate{$item})) {
11256: if ($currautocreate{$item} ne $newvals{$item}) {
11257: $changes{$item} = 1;
11258: }
11259: } elsif ($newvals{$item}) {
11260: $changes{$item} = 1;
11261: }
11262: }
11263: if (keys(%changes) > 0) {
11264: my @offon = ('off','on');
11265: $resulttext = &mt('Changes made:').'<ul>';
11266: foreach my $item (@types) {
11267: if ($changes{$item}) {
11268: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 11269: $resulttext .= '<li>'.
11270: &mt("$title{$item} set to [_1]$newtxt [_2]",
11271: '<b>','</b>').
11272: '</li>';
1.125 raeburn 11273: }
11274: }
11275: if ($changes{'xmldc'}) {
11276: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
11277: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 11278: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 11279: }
11280: $resulttext .= '</ul>';
11281: } else {
11282: $resulttext = &mt('No changes made to auto-creation settings');
11283: }
11284: } else {
11285: $resulttext = '<span class="LC_error">'.
11286: &mt('An error occurred: [_1]',$putresult).'</span>';
11287: }
11288: return $resulttext;
11289: }
11290:
1.23 raeburn 11291: sub modify_directorysrch {
1.160.6.81 raeburn 11292: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 11293: my ($resulttext,%changes);
11294: my %currdirsrch;
11295: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
11296: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
11297: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
11298: }
11299: }
1.160.6.72 raeburn 11300: my %title = ( available => 'Institutional directory search available',
11301: localonly => 'Other domains can search institution',
11302: lcavailable => 'LON-CAPA directory search available',
11303: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 11304: searchby => 'Search types',
11305: searchtypes => 'Search latitude');
11306: my @offon = ('off','on');
1.24 raeburn 11307: my @otherdoms = ('Yes','No');
1.23 raeburn 11308:
1.25 raeburn 11309: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 11310: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
11311: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
11312:
1.44 raeburn 11313: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 11314: if (keys(%{$usertypes}) == 0) {
11315: @cansearch = ('default');
11316: } else {
11317: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
11318: foreach my $type (@{$currdirsrch{'cansearch'}}) {
11319: if (!grep(/^\Q$type\E$/,@cansearch)) {
11320: push(@{$changes{'cansearch'}},$type);
11321: }
1.23 raeburn 11322: }
1.26 raeburn 11323: foreach my $type (@cansearch) {
11324: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
11325: push(@{$changes{'cansearch'}},$type);
11326: }
1.23 raeburn 11327: }
1.26 raeburn 11328: } else {
11329: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 11330: }
11331: }
11332:
11333: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
11334: foreach my $by (@{$currdirsrch{'searchby'}}) {
11335: if (!grep(/^\Q$by\E$/,@searchby)) {
11336: push(@{$changes{'searchby'}},$by);
11337: }
11338: }
11339: foreach my $by (@searchby) {
11340: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
11341: push(@{$changes{'searchby'}},$by);
11342: }
11343: }
11344: } else {
11345: push(@{$changes{'searchby'}},@searchby);
11346: }
1.25 raeburn 11347:
11348: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
11349: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
11350: if (!grep(/^\Q$type\E$/,@searchtypes)) {
11351: push(@{$changes{'searchtypes'}},$type);
11352: }
11353: }
11354: foreach my $type (@searchtypes) {
11355: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
11356: push(@{$changes{'searchtypes'}},$type);
11357: }
11358: }
11359: } else {
11360: if (exists($currdirsrch{'searchtypes'})) {
11361: foreach my $type (@searchtypes) {
11362: if ($type ne $currdirsrch{'searchtypes'}) {
11363: push(@{$changes{'searchtypes'}},$type);
11364: }
11365: }
11366: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
11367: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
11368: }
11369: } else {
11370: push(@{$changes{'searchtypes'}},@searchtypes);
11371: }
11372: }
11373:
1.23 raeburn 11374: my %dirsrch_hash = (
11375: directorysrch => { available => $env{'form.dirsrch_available'},
11376: cansearch => \@cansearch,
1.160.6.72 raeburn 11377: localonly => $env{'form.dirsrch_instlocalonly'},
11378: lclocalonly => $env{'form.dirsrch_domlocalonly'},
11379: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 11380: searchby => \@searchby,
1.25 raeburn 11381: searchtypes => \@searchtypes,
1.23 raeburn 11382: }
11383: );
11384: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
11385: $dom);
11386: if ($putresult eq 'ok') {
11387: if (exists($currdirsrch{'available'})) {
11388: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
11389: $changes{'available'} = 1;
11390: }
11391: } else {
11392: if ($env{'form.dirsrch_available'} eq '1') {
11393: $changes{'available'} = 1;
11394: }
11395: }
1.160.6.72 raeburn 11396: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 11397: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
11398: $changes{'lcavailable'} = 1;
11399: }
1.24 raeburn 11400: } else {
1.160.6.72 raeburn 11401: if ($env{'form.dirsrch_lcavailable'} eq '1') {
11402: $changes{'lcavailable'} = 1;
11403: }
11404: }
11405: if (exists($currdirsrch{'localonly'})) {
11406: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 11407: $changes{'localonly'} = 1;
11408: }
1.160.6.72 raeburn 11409: } else {
11410: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
11411: $changes{'localonly'} = 1;
11412: }
11413: }
11414: if (exists($currdirsrch{'lclocalonly'})) {
11415: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
11416: $changes{'lclocalonly'} = 1;
11417: }
11418: } else {
11419: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
11420: $changes{'lclocalonly'} = 1;
11421: }
1.24 raeburn 11422: }
1.23 raeburn 11423: if (keys(%changes) > 0) {
11424: $resulttext = &mt('Changes made:').'<ul>';
11425: if ($changes{'available'}) {
11426: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
11427: }
1.160.6.72 raeburn 11428: if ($changes{'lcavailable'}) {
11429: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
11430: }
1.24 raeburn 11431: if ($changes{'localonly'}) {
1.160.6.72 raeburn 11432: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
11433: }
11434: if ($changes{'lclocalonly'}) {
11435: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 11436: }
1.23 raeburn 11437: if (ref($changes{'cansearch'}) eq 'ARRAY') {
11438: my $chgtext;
1.26 raeburn 11439: if (ref($usertypes) eq 'HASH') {
11440: if (keys(%{$usertypes}) > 0) {
11441: foreach my $type (@{$types}) {
11442: if (grep(/^\Q$type\E$/,@cansearch)) {
11443: $chgtext .= $usertypes->{$type}.'; ';
11444: }
11445: }
11446: if (grep(/^default$/,@cansearch)) {
11447: $chgtext .= $othertitle;
11448: } else {
11449: $chgtext =~ s/\; $//;
11450: }
1.160.6.13 raeburn 11451: $resulttext .=
11452: '<li>'.
11453: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
11454: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
11455: '</li>';
1.23 raeburn 11456: }
11457: }
11458: }
11459: if (ref($changes{'searchby'}) eq 'ARRAY') {
11460: my ($searchtitles,$titleorder) = &sorted_searchtitles();
11461: my $chgtext;
11462: foreach my $type (@{$titleorder}) {
11463: if (grep(/^\Q$type\E$/,@searchby)) {
11464: if (defined($searchtitles->{$type})) {
11465: $chgtext .= $searchtitles->{$type}.'; ';
11466: }
11467: }
11468: }
11469: $chgtext =~ s/\; $//;
11470: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
11471: }
1.25 raeburn 11472: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
11473: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
11474: my $chgtext;
11475: foreach my $type (@{$srchtypeorder}) {
11476: if (grep(/^\Q$type\E$/,@searchtypes)) {
11477: if (defined($srchtypes_desc->{$type})) {
11478: $chgtext .= $srchtypes_desc->{$type}.'; ';
11479: }
11480: }
11481: }
11482: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 11483: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 11484: }
11485: $resulttext .= '</ul>';
1.160.6.81 raeburn 11486: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
11487: if (ref($lastactref) eq 'HASH') {
11488: $lastactref->{'directorysrch'} = 1;
11489: }
1.23 raeburn 11490: } else {
1.160.6.72 raeburn 11491: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 11492: }
11493: } else {
11494: $resulttext = '<span class="LC_error">'.
1.27 raeburn 11495: &mt('An error occurred: [_1]',$putresult).'</span>';
11496: }
11497: return $resulttext;
11498: }
11499:
1.28 raeburn 11500: sub modify_contacts {
1.160.6.24 raeburn 11501: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 11502: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
11503: if (ref($domconfig{'contacts'}) eq 'HASH') {
11504: foreach my $key (keys(%{$domconfig{'contacts'}})) {
11505: $currsetting{$key} = $domconfig{'contacts'}{$key};
11506: }
11507: }
1.160.6.78 raeburn 11508: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 11509: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 11510: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 11511: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.23 raeburn 11512: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 11513: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 11514: foreach my $type (@mailings) {
11515: @{$newsetting{$type}} =
11516: &Apache::loncommon::get_env_multiple('form.'.$type);
11517: foreach my $item (@contacts) {
11518: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
11519: $contacts_hash{contacts}{$type}{$item} = 1;
11520: } else {
11521: $contacts_hash{contacts}{$type}{$item} = 0;
11522: }
1.160.6.78 raeburn 11523: }
1.28 raeburn 11524: $others{$type} = $env{'form.'.$type.'_others'};
11525: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 11526: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11527: $bcc{$type} = $env{'form.'.$type.'_bcc'};
11528: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 11529: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
11530: $includestr{$type} = $env{'form.'.$type.'_includestr'};
11531: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
11532: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
11533: }
1.134 raeburn 11534: }
1.28 raeburn 11535: }
11536: foreach my $item (@contacts) {
11537: $to{$item} = $env{'form.'.$item};
11538: $contacts_hash{'contacts'}{$item} = $to{$item};
11539: }
1.160.6.23 raeburn 11540: foreach my $item (@toggles) {
11541: if ($env{'form.'.$item} =~ /^(0|1)$/) {
11542: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
11543: }
11544: }
1.160.6.78 raeburn 11545: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
11546: foreach my $field (@{$fields}) {
11547: if (ref($possoptions->{$field}) eq 'ARRAY') {
11548: my $value = $env{'form.helpform_'.$field};
11549: $value =~ s/^\s+|\s+$//g;
11550: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 11551: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 11552: if ($field eq 'screenshot') {
11553: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
11554: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 11555: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 11556: }
11557: }
11558: }
11559: }
11560: }
11561: }
1.160.6.101 raeburn 11562: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11563: my (@statuses,%usertypeshash,@overrides);
11564: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
11565: @statuses = @{$types};
11566: if (ref($usertypes) eq 'HASH') {
11567: %usertypeshash = %{$usertypes};
11568: }
11569: }
11570: if (@statuses) {
11571: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
11572: foreach my $type (@possoverrides) {
11573: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
11574: push(@overrides,$type);
11575: }
11576: }
11577: if (@overrides) {
11578: foreach my $type (@overrides) {
11579: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
11580: foreach my $item (@contacts) {
11581: if (grep(/^\Q$item\E$/,@standard)) {
11582: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
11583: $newsetting{'override_'.$type}{$item} = 1;
11584: } else {
11585: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
11586: $newsetting{'override_'.$type}{$item} = 0;
11587: }
11588: }
11589: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
11590: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
11591: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
11592: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
11593: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
11594: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
11595: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
11596: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
11597: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
11598: }
11599: }
11600: }
11601: }
1.28 raeburn 11602: if (keys(%currsetting) > 0) {
11603: foreach my $item (@contacts) {
11604: if ($to{$item} ne $currsetting{$item}) {
11605: $changes{$item} = 1;
11606: }
11607: }
11608: foreach my $type (@mailings) {
11609: foreach my $item (@contacts) {
11610: if (ref($currsetting{$type}) eq 'HASH') {
11611: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
11612: push(@{$changes{$type}},$item);
11613: }
11614: } else {
11615: push(@{$changes{$type}},@{$newsetting{$type}});
11616: }
11617: }
11618: if ($others{$type} ne $currsetting{$type}{'others'}) {
11619: push(@{$changes{$type}},'others');
11620: }
1.160.6.78 raeburn 11621: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11622: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
11623: push(@{$changes{$type}},'bcc');
11624: }
1.160.6.78 raeburn 11625: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
11626: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
11627: push(@{$changes{$type}},'include');
11628: }
11629: }
11630: }
11631: if (ref($fields) eq 'ARRAY') {
11632: if (ref($currsetting{'helpform'}) eq 'HASH') {
11633: foreach my $field (@{$fields}) {
11634: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
11635: push(@{$changes{'helpform'}},$field);
11636: }
11637: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11638: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
11639: push(@{$changes{'helpform'}},'maxsize');
11640: }
11641: }
11642: }
11643: } else {
11644: foreach my $field (@{$fields}) {
11645: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
11646: push(@{$changes{'helpform'}},$field);
11647: }
11648: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11649: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
11650: push(@{$changes{'helpform'}},'maxsize');
11651: }
11652: }
11653: }
1.134 raeburn 11654: }
1.28 raeburn 11655: }
1.160.6.101 raeburn 11656: if (@statuses) {
11657: if (ref($currsetting{'overrides'}) eq 'HASH') {
11658: foreach my $key (keys(%{$currsetting{'overrides'}})) {
11659: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
11660: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
11661: foreach my $item (@contacts,'bcc','others','include') {
11662: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
11663: push(@{$changes{'overrides'}},$key);
11664: last;
11665: }
11666: }
11667: } else {
11668: push(@{$changes{'overrides'}},$key);
11669: }
11670: }
11671: }
11672: foreach my $key (@overrides) {
11673: unless (exists($currsetting{'overrides'}{$key})) {
11674: push(@{$changes{'overrides'}},$key);
11675: }
11676: }
11677: } else {
11678: foreach my $key (@overrides) {
11679: push(@{$changes{'overrides'}},$key);
11680: }
11681: }
11682: }
1.28 raeburn 11683: } else {
11684: my %default;
11685: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
11686: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
11687: $default{'errormail'} = 'adminemail';
11688: $default{'packagesmail'} = 'adminemail';
11689: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 11690: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 11691: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 11692: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 11693: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 11694: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 11695: foreach my $item (@contacts) {
11696: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 11697: $changes{$item} = 1;
1.160.6.23 raeburn 11698: }
1.28 raeburn 11699: }
11700: foreach my $type (@mailings) {
11701: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
11702: push(@{$changes{$type}},@{$newsetting{$type}});
11703: }
11704: if ($others{$type} ne '') {
11705: push(@{$changes{$type}},'others');
1.134 raeburn 11706: }
1.160.6.78 raeburn 11707: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11708: if ($bcc{$type} ne '') {
11709: push(@{$changes{$type}},'bcc');
11710: }
1.160.6.78 raeburn 11711: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
11712: push(@{$changes{$type}},'include');
11713: }
11714: }
11715: }
11716: if (ref($fields) eq 'ARRAY') {
11717: foreach my $field (@{$fields}) {
11718: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
11719: push(@{$changes{'helpform'}},$field);
11720: }
11721: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11722: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
11723: push(@{$changes{'helpform'}},'maxsize');
11724: }
11725: }
1.134 raeburn 11726: }
1.28 raeburn 11727: }
11728: }
1.160.6.23 raeburn 11729: foreach my $item (@toggles) {
11730: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
11731: $changes{$item} = 1;
11732: } elsif ((!$env{'form.'.$item}) &&
11733: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
11734: $changes{$item} = 1;
11735: }
11736: }
1.28 raeburn 11737: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
11738: $dom);
11739: if ($putresult eq 'ok') {
11740: if (keys(%changes) > 0) {
1.160.6.24 raeburn 11741: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 11742: if (ref($lastactref) eq 'HASH') {
11743: $lastactref->{'domainconfig'} = 1;
11744: }
1.28 raeburn 11745: my ($titles,$short_titles) = &contact_titles();
11746: $resulttext = &mt('Changes made:').'<ul>';
11747: foreach my $item (@contacts) {
11748: if ($changes{$item}) {
11749: $resulttext .= '<li>'.$titles->{$item}.
11750: &mt(' set to: ').
11751: '<span class="LC_cusr_emph">'.
11752: $to{$item}.'</span></li>';
11753: }
11754: }
11755: foreach my $type (@mailings) {
11756: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 11757: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
11758: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
11759: } else {
11760: $resulttext .= '<li>'.$titles->{$type}.': ';
11761: }
1.28 raeburn 11762: my @text;
11763: foreach my $item (@{$newsetting{$type}}) {
11764: push(@text,$short_titles->{$item});
11765: }
11766: if ($others{$type} ne '') {
11767: push(@text,$others{$type});
11768: }
1.160.6.78 raeburn 11769: if (@text) {
11770: $resulttext .= '<span class="LC_cusr_emph">'.
11771: join(', ',@text).'</span>';
11772: }
11773: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11774: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 11775: my $bcctext;
11776: if (@text) {
11777: $bcctext = ' '.&mt('with Bcc to');
11778: } else {
11779: $bcctext = '(Bcc)';
11780: }
11781: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
11782: } elsif (!@text) {
11783: $resulttext .= &mt('No one');
1.134 raeburn 11784: }
1.160.6.78 raeburn 11785: if ($includestr{$type} ne '') {
11786: if ($includeloc{$type} eq 'b') {
11787: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
11788: } elsif ($includeloc{$type} eq 's') {
11789: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
11790: }
11791: }
11792: } elsif (!@text) {
11793: $resulttext .= &mt('No recipients');
1.134 raeburn 11794: }
11795: $resulttext .= '</li>';
1.28 raeburn 11796: }
11797: }
1.160.6.101 raeburn 11798: if (ref($changes{'overrides'}) eq 'ARRAY') {
11799: my @deletions;
11800: foreach my $type (@{$changes{'overrides'}}) {
11801: if ($usertypeshash{$type}) {
11802: if (grep(/^\Q$type\E/,@overrides)) {
11803: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
11804: $usertypeshash{$type}).'<ul><li>';
11805: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
11806: my @text;
11807: foreach my $item (@contacts) {
11808: if ($newsetting{'override_'.$type}{$item}) {
11809: push(@text,$short_titles->{$item});
11810: }
11811: }
11812: if ($newsetting{'override_'.$type}{'others'} ne '') {
11813: push(@text,$newsetting{'override_'.$type}{'others'});
11814: }
11815:
11816: if (@text) {
11817: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
11818: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
11819: }
11820: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
11821: my $bcctext;
11822: if (@text) {
11823: $bcctext = ' '.&mt('with Bcc to');
11824: } else {
11825: $bcctext = '(Bcc)';
11826: }
11827: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
11828: } elsif (!@text) {
11829: $resulttext .= &mt('Helpdesk e-mail sent to no one');
11830: }
11831: $resulttext .= '</li>';
11832: if ($newsetting{'override_'.$type}{'include'} ne '') {
11833: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
11834: if ($loc eq 'b') {
11835: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
11836: } elsif ($loc eq 's') {
11837: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
11838: }
11839: }
11840: }
11841: $resulttext .= '</li></ul></li>';
11842: } else {
11843: push(@deletions,$usertypeshash{$type});
11844: }
11845: }
11846: }
11847: if (@deletions) {
11848: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
11849: join(', ',@deletions)).'</li>';
11850: }
11851: }
1.160.6.23 raeburn 11852: my @offon = ('off','on');
11853: if ($changes{'reporterrors'}) {
11854: $resulttext .= '<li>'.
11855: &mt('E-mail error reports to [_1] set to "'.
11856: $offon[$env{'form.reporterrors'}].'".',
11857: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
11858: &mt('LON-CAPA core group - MSU'),600,500)).
11859: '</li>';
11860: }
11861: if ($changes{'reportupdates'}) {
11862: $resulttext .= '<li>'.
11863: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
11864: $offon[$env{'form.reportupdates'}].'".',
11865: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
11866: &mt('LON-CAPA core group - MSU'),600,500)).
11867: '</li>';
11868: }
1.160.6.78 raeburn 11869: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
11870: my (@optional,@required,@unused,$maxsizechg);
11871: foreach my $field (@{$changes{'helpform'}}) {
11872: if ($field eq 'maxsize') {
11873: $maxsizechg = 1;
11874: next;
11875: }
11876: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
11877: push(@optional,$field);
11878: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
11879: push(@unused,$field);
11880: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
11881: push(@required,$field);
11882: }
11883: }
11884: if (@optional) {
11885: $resulttext .= '<li>'.
11886: &mt('Help form fields changed to "Optional": [_1].',
11887: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
11888: '</li>';
11889: }
11890: if (@required) {
11891: $resulttext .= '<li>'.
11892: &mt('Help form fields changed to "Required": [_1].',
11893: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
11894: '</li>';
11895: }
11896: if (@unused) {
11897: $resulttext .= '<li>'.
11898: &mt('Help form fields changed to "Not shown": [_1].',
11899: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
11900: '</li>';
11901: }
11902: if ($maxsizechg) {
11903: $resulttext .= '<li>'.
11904: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
11905: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
11906: '</li>';
11907: }
11908: }
1.28 raeburn 11909: $resulttext .= '</ul>';
11910: } else {
1.160.6.78 raeburn 11911: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 11912: }
11913: } else {
11914: $resulttext = '<span class="LC_error">'.
11915: &mt('An error occurred: [_1].',$putresult).'</span>';
11916: }
11917: return $resulttext;
11918: }
11919:
1.160.6.98 raeburn 11920: sub modify_passwords {
11921: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
11922: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
11923: $updatedefaults,$updateconf);
11924: my $customfn = 'resetpw.html';
11925: if (ref($domconfig{'passwords'}) eq 'HASH') {
11926: %current = %{$domconfig{'passwords'}};
11927: }
11928: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11929: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11930: if (ref($types) eq 'ARRAY') {
11931: @oktypes = @{$types};
11932: }
11933: push(@oktypes,'default');
11934:
11935: my %titles = &Apache::lonlocal::texthash (
11936: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
11937: intauth_check => 'Check bcrypt cost if authenticated',
11938: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
11939: permanent => 'Permanent e-mail address',
11940: critical => 'Critical notification address',
11941: notify => 'Notification address',
11942: min => 'Minimum password length',
11943: max => 'Maximum password length',
11944: chars => 'Required characters',
11945: numsaved => 'Number of previous passwords to save',
11946: reset => 'Resetting Forgotten Password',
11947: intauth => 'Encryption of Stored Passwords (Internal Auth)',
11948: rules => 'Rules for LON-CAPA Passwords',
11949: crsownerchg => 'Course Owner Changing Student Passwords',
11950: username => 'Username',
11951: email => 'E-mail address',
11952: );
11953:
11954: #
11955: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
11956: #
11957: my (%curr_defaults,%save_defaults);
11958: if (ref($domconfig{'defaults'}) eq 'HASH') {
11959: foreach my $key (keys(%{$domconfig{'defaults'}})) {
11960: if ($key =~ /^intauth_(cost|check|switch)$/) {
11961: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
11962: } else {
11963: $save_defaults{$key} = $domconfig{'defaults'}{$key};
11964: }
11965: }
11966: }
11967: my %staticdefaults = (
11968: 'resetlink' => 2,
11969: 'resetcase' => \@oktypes,
11970: 'resetprelink' => 'both',
11971: 'resetemail' => ['critical','notify','permanent'],
11972: 'intauth_cost' => 10,
11973: 'intauth_check' => 0,
11974: 'intauth_switch' => 0,
11975: );
1.160.6.99 raeburn 11976: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 11977: foreach my $type (@oktypes) {
11978: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
11979: }
11980: my $linklife = $env{'form.passwords_link'};
11981: $linklife =~ s/^\s+|\s+$//g;
11982: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
11983: $newvalues{'resetlink'} = $linklife;
11984: if ($current{'resetlink'}) {
11985: if ($current{'resetlink'} ne $linklife) {
11986: $changes{'reset'} = 1;
11987: }
1.160.6.102 raeburn 11988: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 11989: if ($staticdefaults{'resetlink'} ne $linklife) {
11990: $changes{'reset'} = 1;
11991: }
11992: }
11993: } elsif ($current{'resetlink'}) {
11994: $changes{'reset'} = 1;
11995: }
11996: my @casesens;
11997: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
11998: foreach my $case (sort(@posscase)) {
11999: if (grep(/^\Q$case\E$/,@oktypes)) {
12000: push(@casesens,$case);
12001: }
12002: }
12003: $newvalues{'resetcase'} = \@casesens;
12004: if (ref($current{'resetcase'}) eq 'ARRAY') {
12005: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
12006: if (@diffs > 0) {
12007: $changes{'reset'} = 1;
12008: }
1.160.6.102 raeburn 12009: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12010: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
12011: if (@diffs > 0) {
12012: $changes{'reset'} = 1;
12013: }
12014: }
12015: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
12016: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
12017: if (exists($current{'resetprelink'})) {
12018: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
12019: $changes{'reset'} = 1;
12020: }
1.160.6.102 raeburn 12021: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12022: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
12023: $changes{'reset'} = 1;
12024: }
12025: }
12026: } elsif ($current{'resetprelink'}) {
12027: $changes{'reset'} = 1;
12028: }
12029: foreach my $type (@oktypes) {
12030: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
12031: my @postlink;
12032: foreach my $item (sort(@possplink)) {
12033: if ($item =~ /^(email|username)$/) {
12034: push(@postlink,$item);
12035: }
12036: }
12037: $newvalues{'resetpostlink'}{$type} = \@postlink;
12038: unless ($changes{'reset'}) {
12039: if (ref($current{'resetpostlink'}) eq 'HASH') {
12040: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
12041: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
12042: if (@diffs > 0) {
12043: $changes{'reset'} = 1;
12044: }
12045: } else {
12046: $changes{'reset'} = 1;
12047: }
1.160.6.102 raeburn 12048: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12049: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
12050: if (@diffs > 0) {
12051: $changes{'reset'} = 1;
12052: }
12053: }
12054: }
12055: }
12056: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
12057: my @resetemail;
12058: foreach my $item (sort(@possemailsrc)) {
12059: if ($item =~ /^(permanent|critical|notify)$/) {
12060: push(@resetemail,$item);
12061: }
12062: }
12063: $newvalues{'resetemail'} = \@resetemail;
12064: unless ($changes{'reset'}) {
12065: if (ref($current{'resetemail'}) eq 'ARRAY') {
12066: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
12067: if (@diffs > 0) {
12068: $changes{'reset'} = 1;
12069: }
1.160.6.102 raeburn 12070: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12071: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
12072: if (@diffs > 0) {
12073: $changes{'reset'} = 1;
12074: }
12075: }
12076: }
12077: if ($env{'form.passwords_stdtext'} == 0) {
12078: $newvalues{'resetremove'} = 1;
12079: unless ($current{'resetremove'}) {
12080: $changes{'reset'} = 1;
12081: }
12082: } elsif ($current{'resetremove'}) {
12083: $changes{'reset'} = 1;
12084: }
12085: if ($env{'form.passwords_customfile.filename'} ne '') {
12086: my $servadm = $r->dir_config('lonAdmEMail');
12087: my $servadm = $r->dir_config('lonAdmEMail');
12088: my ($configuserok,$author_ok,$switchserver) =
12089: &config_check($dom,$confname,$servadm);
12090: my $error;
12091: if ($configuserok eq 'ok') {
12092: if ($switchserver) {
12093: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
12094: } else {
12095: if ($author_ok eq 'ok') {
12096: my ($result,$customurl) =
12097: &publishlogo($r,'upload','passwords_customfile',$dom,
12098: $confname,'customtext/resetpw','','',$customfn);
12099: if ($result eq 'ok') {
12100: $newvalues{'resetcustom'} = $customurl;
12101: $changes{'reset'} = 1;
12102: } else {
12103: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
12104: }
12105: } else {
12106: $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].",$customfn,$confname,$dom,$author_ok);
12107: }
12108: }
12109: } else {
12110: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$customfn,$confname,$dom,$configuserok);
12111: }
12112: if ($error) {
12113: &Apache::lonnet::logthis($error);
12114: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12115: }
12116: } elsif ($current{'resetcustom'}) {
12117: if ($env{'form.passwords_custom_del'}) {
12118: $changes{'reset'} = 1;
12119: } else {
12120: $newvalues{'resetcustom'} = $current{'resetcustom'};
12121: }
12122: }
12123: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
12124: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
12125: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
12126: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
12127: $changes{'intauth'} = 1;
12128: }
12129: } else {
12130: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
12131: }
12132: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
12133: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
12134: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
12135: $changes{'intauth'} = 1;
12136: }
12137: } else {
12138: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12139: }
12140: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
12141: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
12142: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
12143: $changes{'intauth'} = 1;
12144: }
12145: } else {
12146: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12147: }
12148: foreach my $item ('cost','check','switch') {
12149: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
12150: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
12151: $updatedefaults = 1;
12152: }
12153: }
12154: foreach my $rule ('min','max','numsaved') {
12155: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.160.6.99 raeburn 12156: my $ruleok;
12157: if ($rule eq 'min') {
12158: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
12159: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
12160: $ruleok = 1;
12161: }
12162: }
12163: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
12164: ($env{'form.passwords_'.$rule} ne '0')) {
12165: $ruleok = 1;
12166: }
12167: if ($ruleok) {
1.160.6.98 raeburn 12168: $newvalues{$rule} = $env{'form.passwords_'.$rule};
12169: if (exists($current{$rule})) {
12170: if ($newvalues{$rule} ne $current{$rule}) {
12171: $changes{'rules'} = 1;
12172: }
12173: } elsif ($rule eq 'min') {
12174: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
12175: $changes{'rules'} = 1;
12176: }
12177: }
12178: } elsif (exists($current{$rule})) {
12179: $changes{'rules'} = 1;
12180: }
12181: }
12182: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
12183: my @chars;
12184: foreach my $item (sort(@posschars)) {
12185: if ($item =~ /^(uc|lc|num|spec)$/) {
12186: push(@chars,$item);
12187: }
12188: }
12189: $newvalues{'chars'} = \@chars;
12190: unless ($changes{'rules'}) {
12191: if (ref($current{'chars'}) eq 'ARRAY') {
12192: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
12193: if (@diffs > 0) {
12194: $changes{'rules'} = 1;
12195: }
12196: } else {
12197: if (@chars > 0) {
12198: $changes{'rules'} = 1;
12199: }
12200: }
12201: }
12202: my %crsownerchg = (
12203: by => [],
12204: for => [],
12205: );
12206: foreach my $item ('by','for') {
12207: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
12208: foreach my $type (sort(@posstypes)) {
12209: if (grep(/^\Q$type\E$/,@oktypes)) {
12210: push(@{$crsownerchg{$item}},$type);
12211: }
12212: }
12213: }
12214: $newvalues{'crsownerchg'} = \%crsownerchg;
12215: if (ref($current{'crsownerchg'}) eq 'HASH') {
12216: foreach my $item ('by','for') {
12217: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
12218: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
12219: if (@diffs > 0) {
12220: $changes{'crsownerchg'} = 1;
12221: last;
12222: }
12223: }
12224: }
1.160.6.102 raeburn 12225: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 12226: foreach my $item ('by','for') {
12227: if (@{$crsownerchg{$item}} > 0) {
12228: $changes{'crsownerchg'} = 1;
12229: last;
12230: }
12231: }
12232: }
12233:
12234: my %confighash = (
12235: defaults => \%save_defaults,
12236: passwords => \%newvalues,
12237: );
12238: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
12239:
12240: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
12241: if ($putresult eq 'ok') {
12242: if (keys(%changes) > 0) {
12243: $resulttext = &mt('Changes made: ').'<ul>';
12244: foreach my $key ('reset','intauth','rules','crsownerchg') {
12245: if ($changes{$key}) {
12246: unless ($key eq 'intauth') {
12247: $updateconf = 1;
12248: }
12249: $resulttext .= '<li>'.$titles{$key}.':<ul>';
12250: if ($key eq 'reset') {
12251: if ($confighash{'passwords'}{'captcha'} eq 'original') {
12252: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
12253: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
12254: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
12255: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />'.
12256: &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchapub'}).'</br>'.
12257: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchapriv'}).'</li>';
12258: } else {
12259: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
12260: }
12261: if ($confighash{'passwords'}{'resetlink'}) {
12262: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
12263: } else {
12264: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
12265: &mt('Will default to 2 hours').'</li>';
12266: }
12267: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
12268: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
12269: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
12270: } else {
12271: my $casesens;
12272: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
12273: if ($type eq 'default') {
12274: $casesens .= $othertitle.', ';
12275: } elsif ($usertypes->{$type} ne '') {
12276: $casesens .= $usertypes->{$type}.', ';
12277: }
12278: }
12279: $casesens =~ s/\Q, \E$//;
12280: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
12281: }
12282: } else {
12283: $resulttext .= '<li>'.&mt('Case-sensitivity not set for "Forgot Password" web form').' '.&mt('Will default to case-sensitive for username and/or e-mail address for all').'</li>';
12284: }
12285: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
12286: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
12287: } else {
12288: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
12289: }
12290: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
12291: my $output;
12292: if (ref($types) eq 'ARRAY') {
12293: foreach my $type (@{$types}) {
12294: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
12295: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
12296: $output .= $usertypes->{$type}.' -- '.&mt('none');
12297: } else {
12298: $output .= $usertypes->{$type}.' -- '.
12299: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
12300: }
12301: }
12302: }
12303: }
12304: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
12305: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
12306: $output .= $othertitle.' -- '.&mt('none');
12307: } else {
12308: $output .= $othertitle.' -- '.
12309: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
12310: }
12311: }
12312: if ($output) {
12313: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
12314: } else {
12315: $resulttext .= '<li>'.&mt('Information required for new password form not set.').' '.&mt('Will default to requiring both the username and an e-mail address').'</li>';
12316: }
12317: } else {
12318: $resulttext .= '<li>'.&mt('Information required for new password form not set.').' '.&mt('Will default to requiring both the username and an e-mail address').'</li>';
12319: }
12320: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
12321: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
12322: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
12323: } else {
12324: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
12325: }
12326: } else {
12327: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
12328: }
12329: if ($confighash{'passwords'}{'resetremove'}) {
12330: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
12331: } else {
12332: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
12333: }
12334: if ($confighash{'passwords'}{'resetcustom'}) {
12335: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
12336: $titles{custom},600,500);
12337: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes [_1]',$customlink).'</li>';
12338: } else {
12339: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
12340: }
12341: } elsif ($key eq 'intauth') {
12342: foreach my $item ('cost','switch','check') {
12343: my $value = $save_defaults{$key.'_'.$item};
12344: if ($item eq 'switch') {
12345: my %optiondesc = &Apache::lonlocal::texthash (
12346: 0 => 'No',
12347: 1 => 'Yes',
12348: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12349: );
12350: if ($value =~ /^(0|1|2)$/) {
12351: $value = $optiondesc{$value};
12352: } else {
12353: $value = &mt('none -- defaults to No');
12354: }
12355: } elsif ($item eq 'check') {
12356: my %optiondesc = &Apache::lonlocal::texthash (
12357: 0 => 'No',
12358: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12359: 2 => 'Yes, disallow login if stored cost is less than domain default',
12360: );
12361: if ($value =~ /^(0|1|2)$/) {
12362: $value = $optiondesc{$value};
12363: } else {
12364: $value = &mt('none -- defaults to No');
12365: }
12366: }
12367: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
12368: }
12369: } elsif ($key eq 'rules') {
12370: foreach my $rule ('min','max','numsaved') {
12371: if ($confighash{'passwords'}{$rule} eq '') {
12372: if ($rule eq 'min') {
12373: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 12374: ' '.&mt('Default of [_1] will be used',
12375: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 12376: } else {
12377: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
12378: }
12379: } else {
12380: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
12381: }
12382: }
12383: } elsif ($key eq 'crsownerchg') {
12384: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
12385: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
12386: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
12387: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
12388: } else {
12389: my %crsownerstr;
12390: foreach my $item ('by','for') {
12391: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
12392: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
12393: if ($type eq 'default') {
12394: $crsownerstr{$item} .= $othertitle.', ';
12395: } elsif ($usertypes->{$type} ne '') {
12396: $crsownerstr{$item} .= $usertypes->{$type}.', ';
12397: }
12398: }
12399: $crsownerstr{$item} =~ s/\Q, \E$//;
12400: }
12401: }
12402: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
12403: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
12404: }
12405: } else {
12406: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
12407: }
12408: }
12409: $resulttext .= '</ul></li>';
12410: }
12411: }
12412: $resulttext .= '</ul>';
12413: } else {
12414: $resulttext = &mt('No changes made to password settings');
12415: }
12416: my $cachetime = 24*60*60;
12417: if ($updatedefaults) {
12418: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12419: if (ref($lastactref) eq 'HASH') {
12420: $lastactref->{'domdefaults'} = 1;
12421: }
12422: }
12423: if ($updateconf) {
12424: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
12425: if (ref($lastactref) eq 'HASH') {
12426: $lastactref->{'passwdconf'} = 1;
12427: }
12428: }
12429: } else {
12430: $resulttext = '<span class="LC_error">'.
12431: &mt('An error occurred: [_1]',$putresult).'</span>';
12432: }
12433: if ($errors) {
12434: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
12435: $errors.'</ul></p>';
12436: }
12437: return $resulttext;
12438: }
12439:
1.28 raeburn 12440: sub modify_usercreation {
1.27 raeburn 12441: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 12442: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 12443: my $warningmsg;
1.27 raeburn 12444: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12445: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 12446: if ($key eq 'cancreate') {
12447: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
12448: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 12449: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 12450: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 12451: } else {
12452: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 12453: }
1.50 raeburn 12454: }
1.43 raeburn 12455: }
1.160.6.34 raeburn 12456: } elsif ($key eq 'email_rule') {
12457: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
12458: } else {
12459: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 12460: }
12461: }
1.34 raeburn 12462: }
1.160.6.34 raeburn 12463: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
12464: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
12465: my @contexts = ('author','course','requestcrs');
12466: foreach my $item(@contexts) {
12467: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 12468: }
1.34 raeburn 12469: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12470: foreach my $item (@contexts) {
1.160.6.34 raeburn 12471: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
12472: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 12473: }
1.27 raeburn 12474: }
1.34 raeburn 12475: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
12476: foreach my $item (@contexts) {
1.43 raeburn 12477: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 12478: if ($cancreate{$item} ne 'any') {
12479: push(@{$changes{'cancreate'}},$item);
12480: }
12481: } else {
12482: if ($cancreate{$item} ne 'none') {
12483: push(@{$changes{'cancreate'}},$item);
12484: }
1.27 raeburn 12485: }
12486: }
12487: } else {
1.43 raeburn 12488: foreach my $item (@contexts) {
1.34 raeburn 12489: push(@{$changes{'cancreate'}},$item);
12490: }
1.27 raeburn 12491: }
1.34 raeburn 12492:
1.27 raeburn 12493: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
12494: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
12495: if (!grep(/^\Q$type\E$/,@username_rule)) {
12496: push(@{$changes{'username_rule'}},$type);
12497: }
12498: }
12499: foreach my $type (@username_rule) {
12500: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
12501: push(@{$changes{'username_rule'}},$type);
12502: }
12503: }
12504: } else {
12505: push(@{$changes{'username_rule'}},@username_rule);
12506: }
12507:
1.32 raeburn 12508: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
12509: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
12510: if (!grep(/^\Q$type\E$/,@id_rule)) {
12511: push(@{$changes{'id_rule'}},$type);
12512: }
12513: }
12514: foreach my $type (@id_rule) {
12515: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
12516: push(@{$changes{'id_rule'}},$type);
12517: }
12518: }
12519: } else {
12520: push(@{$changes{'id_rule'}},@id_rule);
12521: }
12522:
1.43 raeburn 12523: my @authen_contexts = ('author','course','domain');
1.28 raeburn 12524: my @authtypes = ('int','krb4','krb5','loc');
12525: my %authhash;
1.43 raeburn 12526: foreach my $item (@authen_contexts) {
1.28 raeburn 12527: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
12528: foreach my $auth (@authtypes) {
12529: if (grep(/^\Q$auth\E$/,@authallowed)) {
12530: $authhash{$item}{$auth} = 1;
12531: } else {
12532: $authhash{$item}{$auth} = 0;
12533: }
12534: }
12535: }
12536: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 12537: foreach my $item (@authen_contexts) {
1.28 raeburn 12538: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
12539: foreach my $auth (@authtypes) {
12540: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
12541: push(@{$changes{'authtypes'}},$item);
12542: last;
12543: }
12544: }
12545: }
12546: }
12547: } else {
1.43 raeburn 12548: foreach my $item (@authen_contexts) {
1.28 raeburn 12549: push(@{$changes{'authtypes'}},$item);
12550: }
12551: }
12552:
1.160.6.34 raeburn 12553: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
12554: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
12555: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
12556: $save_usercreate{'id_rule'} = \@id_rule;
12557: $save_usercreate{'username_rule'} = \@username_rule,
12558: $save_usercreate{'authtypes'} = \%authhash;
12559:
1.27 raeburn 12560: my %usercreation_hash = (
1.160.6.34 raeburn 12561: usercreation => \%save_usercreate,
12562: );
1.27 raeburn 12563:
12564: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
12565: $dom);
1.50 raeburn 12566:
1.160.6.34 raeburn 12567: if ($putresult eq 'ok') {
12568: if (keys(%changes) > 0) {
12569: $resulttext = &mt('Changes made:').'<ul>';
12570: if (ref($changes{'cancreate'}) eq 'ARRAY') {
12571: my %lt = &usercreation_types();
12572: foreach my $type (@{$changes{'cancreate'}}) {
12573: my $chgtext = $lt{$type}.', ';
12574: if ($cancreate{$type} eq 'none') {
12575: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
12576: } elsif ($cancreate{$type} eq 'any') {
12577: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
12578: } elsif ($cancreate{$type} eq 'official') {
12579: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
12580: } elsif ($cancreate{$type} eq 'unofficial') {
12581: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
12582: }
12583: $resulttext .= '<li>'.$chgtext.'</li>';
12584: }
12585: }
12586: if (ref($changes{'username_rule'}) eq 'ARRAY') {
12587: my ($rules,$ruleorder) =
12588: &Apache::lonnet::inst_userrules($dom,'username');
12589: my $chgtext = '<ul>';
12590: foreach my $type (@username_rule) {
12591: if (ref($rules->{$type}) eq 'HASH') {
12592: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
12593: }
12594: }
12595: $chgtext .= '</ul>';
12596: if (@username_rule > 0) {
12597: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
12598: } else {
12599: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
12600: }
12601: }
12602: if (ref($changes{'id_rule'}) eq 'ARRAY') {
12603: my ($idrules,$idruleorder) =
12604: &Apache::lonnet::inst_userrules($dom,'id');
12605: my $chgtext = '<ul>';
12606: foreach my $type (@id_rule) {
12607: if (ref($idrules->{$type}) eq 'HASH') {
12608: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
12609: }
12610: }
12611: $chgtext .= '</ul>';
12612: if (@id_rule > 0) {
12613: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
12614: } else {
12615: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
12616: }
12617: }
12618: my %authname = &authtype_names();
12619: my %context_title = &context_names();
12620: if (ref($changes{'authtypes'}) eq 'ARRAY') {
12621: my $chgtext = '<ul>';
12622: foreach my $type (@{$changes{'authtypes'}}) {
12623: my @allowed;
12624: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
12625: foreach my $auth (@authtypes) {
12626: if ($authhash{$type}{$auth}) {
12627: push(@allowed,$authname{$auth});
12628: }
12629: }
12630: if (@allowed > 0) {
12631: $chgtext .= join(', ',@allowed).'</li>';
12632: } else {
12633: $chgtext .= &mt('none').'</li>';
12634: }
12635: }
12636: $chgtext .= '</ul>';
12637: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
12638: $resulttext .= '</li>';
12639: }
12640: $resulttext .= '</ul>';
12641: } else {
12642: $resulttext = &mt('No changes made to user creation settings');
12643: }
12644: } else {
12645: $resulttext = '<span class="LC_error">'.
12646: &mt('An error occurred: [_1]',$putresult).'</span>';
12647: }
12648: if ($warningmsg ne '') {
12649: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
12650: }
12651: return $resulttext;
12652: }
12653:
12654: sub modify_selfcreation {
1.160.6.93 raeburn 12655: my ($dom,$lastactref,%domconfig) = @_;
12656: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
12657: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
12658: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12659: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
12660: if (ref($typesref) eq 'ARRAY') {
12661: @types = @{$typesref};
12662: }
12663: if (ref($usertypesref) eq 'HASH') {
12664: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 12665: }
1.160.6.93 raeburn 12666: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 12667: #
12668: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
12669: #
12670: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12671: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
12672: if ($key eq 'cancreate') {
12673: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
12674: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
12675: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 12676: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
12677: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
12678: ($item eq 'emailusername') || ($item eq 'shibenv') ||
12679: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
12680: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 12681: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12682: } else {
12683: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12684: }
12685: }
12686: }
12687: } elsif ($key eq 'email_rule') {
12688: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
12689: } else {
12690: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
12691: }
12692: }
12693: }
12694: #
12695: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
12696: #
12697: if (ref($domconfig{'usermodification'}) eq 'HASH') {
12698: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
12699: if ($key eq 'selfcreate') {
12700: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
12701: } else {
12702: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
12703: }
12704: }
12705: }
1.160.6.93 raeburn 12706: #
12707: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
12708: #
12709: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12710: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
12711: if ($key eq 'inststatusguest') {
12712: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
12713: } else {
12714: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
12715: }
12716: }
12717: }
1.160.6.34 raeburn 12718:
12719: my @contexts = ('selfcreate');
12720: @{$cancreate{'selfcreate'}} = ();
12721: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 12722: if (@types) {
12723: @{$cancreate{'statustocreate'}} = ();
12724: }
1.160.6.40 raeburn 12725: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 12726: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 12727: %{$cancreate{'emailverified'}} = ();
12728: %{$cancreate{'emailoptions'}} = ();
12729: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 12730: my %selfcreatetypes = (
12731: sso => 'users authenticated by institutional single sign on',
12732: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 12733: email => 'users verified by e-mail',
1.50 raeburn 12734: );
1.160.6.34 raeburn 12735: #
12736: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
12737: # is permitted.
12738: #
1.160.6.40 raeburn 12739:
1.160.6.93 raeburn 12740: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 12741:
1.160.6.93 raeburn 12742: my (@statuses,%email_rule);
1.160.6.35 raeburn 12743: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 12744: if ($item eq 'email') {
1.160.6.40 raeburn 12745: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 12746: if (@types) {
12747: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
12748: foreach my $status (@poss_statuses) {
12749: if (grep(/^\Q$status\E$/,(@types,'default'))) {
12750: push(@statuses,$status);
12751: }
12752: }
12753: $save_inststatus{'inststatusguest'} = \@statuses;
12754: } else {
12755: push(@statuses,'default');
12756: }
12757: if (@statuses) {
12758: my %curr_rule;
12759: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
12760: foreach my $type (@statuses) {
12761: $curr_rule{$type} = $curr_usercreation{'email_rule'};
12762: }
12763: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
12764: foreach my $type (@statuses) {
12765: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
12766: }
12767: }
12768: push(@{$cancreate{'selfcreate'}},'email');
12769: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
12770: my %curremaildom;
12771: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
12772: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
12773: }
12774: foreach my $type (@statuses) {
12775: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
12776: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
12777: }
12778: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
12779: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
12780: }
12781: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
12782: #
12783: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
12784: #
12785: my $chosen = $1;
12786: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
12787: my $emaildom;
12788: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
12789: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
12790: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
12791: if (ref($curremaildom{$type}) eq 'HASH') {
12792: if (exists($curremaildom{$type}{$chosen})) {
12793: if ($curremaildom{$type}{$chosen} ne $emaildom) {
12794: push(@{$changes{'cancreate'}},'emaildomain');
12795: }
12796: } elsif ($emaildom ne '') {
12797: push(@{$changes{'cancreate'}},'emaildomain');
12798: }
12799: } elsif ($emaildom ne '') {
12800: push(@{$changes{'cancreate'}},'emaildomain');
12801: }
12802: }
12803: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
12804: } elsif ($chosen eq 'custom') {
12805: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
12806: $email_rule{$type} = [];
12807: if (ref($emailrules) eq 'HASH') {
12808: foreach my $rule (@possemail_rules) {
12809: if (exists($emailrules->{$rule})) {
12810: push(@{$email_rule{$type}},$rule);
12811: }
12812: }
12813: }
12814: if (@{$email_rule{$type}}) {
12815: $cancreate{'emailoptions'}{$type} = 'custom';
12816: if (ref($curr_rule{$type}) eq 'ARRAY') {
12817: if (@{$curr_rule{$type}} > 0) {
12818: foreach my $rule (@{$curr_rule{$type}}) {
12819: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
12820: push(@{$changes{'email_rule'}},$type);
12821: }
12822: }
12823: }
12824: foreach my $type (@{$email_rule{$type}}) {
12825: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
12826: push(@{$changes{'email_rule'}},$type);
12827: }
12828: }
12829: } else {
12830: push(@{$changes{'email_rule'}},$type);
12831: }
12832: }
12833: } else {
12834: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
12835: }
12836: }
12837: }
12838: if (@types) {
12839: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
12840: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
12841: if (@changed) {
12842: push(@{$changes{'inststatus'}},'inststatusguest');
12843: }
12844: } else {
12845: push(@{$changes{'inststatus'}},'inststatusguest');
12846: }
12847: }
12848: } else {
12849: delete($env{'form.cancreate_email'});
12850: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
12851: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
12852: push(@{$changes{'inststatus'}},'inststatusguest');
12853: }
12854: }
12855: }
12856: } else {
12857: $save_inststatus{'inststatusguest'} = [];
12858: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
12859: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
12860: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 12861: }
12862: }
1.160.6.34 raeburn 12863: }
12864: } else {
12865: if ($env{'form.cancreate_'.$item}) {
12866: push(@{$cancreate{'selfcreate'}},$item);
12867: }
12868: }
12869: }
1.160.6.93 raeburn 12870: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 12871: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
12872: #
1.160.6.35 raeburn 12873: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
12874: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.160.6.34 raeburn 12875: #
1.160.6.40 raeburn 12876:
1.160.6.48 raeburn 12877: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 12878: push(@contexts,'emailusername');
1.160.6.93 raeburn 12879: if (@statuses) {
12880: foreach my $type (@statuses) {
1.160.6.35 raeburn 12881: if (ref($infofields) eq 'ARRAY') {
12882: foreach my $field (@{$infofields}) {
12883: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
12884: $cancreate{'emailusername'}{$type}{$field} = $1;
12885: }
12886: }
1.160.6.34 raeburn 12887: }
12888: }
12889: }
12890: #
12891: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 12892: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 12893: #
12894:
12895: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
12896: @approvalnotify = sort(@approvalnotify);
12897: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
12898: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12899: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
12900: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
12901: push(@{$changes{'cancreate'}},'notify');
12902: }
12903: } else {
12904: if ($cancreate{'notify'}{'approval'}) {
12905: push(@{$changes{'cancreate'}},'notify');
12906: }
12907: }
12908: } elsif ($cancreate{'notify'}{'approval'}) {
12909: push(@{$changes{'cancreate'}},'notify');
12910: }
12911:
12912: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
12913: }
12914: #
1.160.6.40 raeburn 12915: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 12916: # institutional log-in.
12917: #
12918: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
12919: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
12920: ($domdefaults{'auth_def'} eq 'localauth'))) {
12921: $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.').' '.
12922: &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.');
12923: }
12924: }
12925: my @fields = ('lastname','firstname','middlename','generation',
12926: 'permanentemail','id');
1.160.6.44 raeburn 12927: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 12928: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12929: #
12930: # Where usernames may created for institutional log-in and/or institutional single sign on:
12931: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
12932: # may self-create accounts
12933: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
12934: # which the user may supply, if institutional data is unavailable.
12935: #
12936: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 12937: if (@types) {
12938: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
12939: push(@contexts,'statustocreate');
12940: foreach my $type (@types) {
1.160.6.34 raeburn 12941: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
12942: foreach my $field (@fields) {
12943: if (grep(/^\Q$field\E$/,@modifiable)) {
12944: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
12945: } else {
12946: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
12947: }
12948: }
12949: }
12950: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 12951: foreach my $type (@types) {
1.160.6.34 raeburn 12952: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
12953: foreach my $field (@fields) {
12954: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
12955: $curr_usermodify{'selfcreate'}{$type}{$field}) {
12956: push(@{$changes{'selfcreate'}},$type);
12957: last;
12958: }
12959: }
12960: }
12961: }
12962: } else {
1.160.6.93 raeburn 12963: foreach my $type (@types) {
1.160.6.34 raeburn 12964: push(@{$changes{'selfcreate'}},$type);
12965: }
12966: }
12967: }
1.160.6.44 raeburn 12968: foreach my $field (@shibfields) {
12969: if ($env{'form.shibenv_'.$field} ne '') {
12970: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
12971: }
12972: }
12973: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12974: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
12975: foreach my $field (@shibfields) {
12976: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
12977: push(@{$changes{'cancreate'}},'shibenv');
12978: }
12979: }
12980: } else {
12981: foreach my $field (@shibfields) {
12982: if ($env{'form.shibenv_'.$field}) {
12983: push(@{$changes{'cancreate'}},'shibenv');
12984: last;
12985: }
12986: }
12987: }
12988: }
1.160.6.34 raeburn 12989: }
12990: foreach my $item (@contexts) {
12991: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
12992: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
12993: if (ref($cancreate{$item}) eq 'ARRAY') {
12994: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
12995: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12996: push(@{$changes{'cancreate'}},$item);
12997: }
12998: }
12999: }
13000: }
13001: if (ref($cancreate{$item}) eq 'ARRAY') {
13002: foreach my $type (@{$cancreate{$item}}) {
13003: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13004: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13005: push(@{$changes{'cancreate'}},$item);
13006: }
13007: }
13008: }
13009: }
13010: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13011: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 13012: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13013: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13014: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13015: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13016: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13017: push(@{$changes{'cancreate'}},$item);
13018: }
13019: }
13020: }
1.160.6.93 raeburn 13021: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13022: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13023: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13024: push(@{$changes{'cancreate'}},$item);
13025: }
1.160.6.34 raeburn 13026: }
13027: }
13028: }
1.160.6.93 raeburn 13029: foreach my $type (keys(%{$cancreate{$item}})) {
13030: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13031: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13032: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13033: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13034: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13035: push(@{$changes{'cancreate'}},$item);
13036: }
13037: }
13038: } else {
13039: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13040: push(@{$changes{'cancreate'}},$item);
13041: }
13042: }
13043: }
1.160.6.93 raeburn 13044: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13045: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13046: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13047: push(@{$changes{'cancreate'}},$item);
13048: }
1.160.6.34 raeburn 13049: }
13050: }
13051: }
13052: }
13053: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13054: if (ref($cancreate{$item}) eq 'ARRAY') {
13055: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13056: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13057: push(@{$changes{'cancreate'}},$item);
13058: }
13059: }
1.160.6.93 raeburn 13060: }
13061: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13062: if (ref($cancreate{$item}) eq 'HASH') {
13063: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13064: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 13065: }
13066: }
13067: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 13068: if (ref($cancreate{$item}) eq 'HASH') {
13069: foreach my $type (keys(%{$cancreate{$item}})) {
13070: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13071: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13072: if ($cancreate{$item}{$type}{$field}) {
13073: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13074: push(@{$changes{'cancreate'}},$item);
13075: }
13076: last;
13077: }
13078: }
13079: }
13080: }
1.160.6.34 raeburn 13081: }
13082: }
13083: }
13084: #
13085: # Populate %save_usercreate hash with updates to self-creation configuration.
13086: #
13087: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13088: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 13089: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 13090: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13091: if (ref($cancreate{'notify'}) eq 'HASH') {
13092: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13093: }
1.160.6.40 raeburn 13094: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13095: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13096: }
1.160.6.93 raeburn 13097: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13098: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13099: }
13100: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13101: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13102: }
13103: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13104: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13105: }
1.160.6.34 raeburn 13106: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13107: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13108: }
1.160.6.44 raeburn 13109: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13110: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13111: }
1.160.6.34 raeburn 13112: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 13113: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 13114:
13115: my %userconfig_hash = (
13116: usercreation => \%save_usercreate,
13117: usermodification => \%save_usermodify,
1.160.6.93 raeburn 13118: inststatus => \%save_inststatus,
1.160.6.34 raeburn 13119: );
1.160.6.93 raeburn 13120:
1.160.6.34 raeburn 13121: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13122: $dom);
13123: #
1.160.6.93 raeburn 13124: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 13125: #
1.27 raeburn 13126: if ($putresult eq 'ok') {
13127: if (keys(%changes) > 0) {
13128: $resulttext = &mt('Changes made:').'<ul>';
13129: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 13130: my %lt = &selfcreation_types();
1.34 raeburn 13131: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 13132: my $chgtext = '';
1.45 raeburn 13133: if ($type eq 'selfcreate') {
1.50 raeburn 13134: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 13135: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13136: } else {
1.160.6.34 raeburn 13137: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13138: '<ul>';
1.50 raeburn 13139: foreach my $case (@{$cancreate{$type}}) {
13140: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13141: }
13142: $chgtext .= '</ul>';
1.100 raeburn 13143: if (ref($cancreate{$type}) eq 'ARRAY') {
13144: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13145: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13146: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 13147: $chgtext .= '<span class="LC_warning">'.
13148: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13149: '</span><br />';
1.100 raeburn 13150: }
13151: }
13152: }
1.160.6.93 raeburn 13153: if (grep(/^email$/,@{$cancreate{$type}})) {
13154: if (!@statuses) {
13155: $chgtext .= '<span class="LC_warning">'.
13156: &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.").
13157: '</span><br />';
13158:
13159: }
13160: }
1.100 raeburn 13161: }
1.43 raeburn 13162: }
1.160.6.44 raeburn 13163: } elsif ($type eq 'shibenv') {
13164: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 13165: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 13166: } else {
13167: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13168: '<ul>';
13169: foreach my $field (@shibfields) {
13170: next if ($cancreate{$type}{$field} eq '');
13171: if ($field eq 'inststatus') {
13172: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13173: } else {
13174: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13175: }
13176: }
13177: $chgtext .= '</ul>';
1.160.6.93 raeburn 13178: }
1.93 raeburn 13179: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13180: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13181: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13182: if (@{$cancreate{'selfcreate'}} > 0) {
13183: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13184: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13185: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 13186: $chgtext .= '<br />'.
13187: '<span class="LC_warning">'.
13188: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13189: '</span>';
13190: }
1.160.6.93 raeburn 13191: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13192: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13193: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13194: } else {
13195: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13196: }
13197: $chgtext .= '<ul>';
13198: foreach my $case (@{$cancreate{$type}}) {
13199: if ($case eq 'default') {
13200: $chgtext .= '<li>'.$othertitle.'</li>';
13201: } else {
1.160.6.93 raeburn 13202: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13203: }
13204: }
1.100 raeburn 13205: $chgtext .= '</ul>';
13206: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 13207: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 13208: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13209: '</span>';
1.100 raeburn 13210: }
13211: }
13212: } else {
13213: if (@{$cancreate{$type}} == 0) {
13214: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13215: } else {
13216: $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 13217: }
13218: }
1.160.6.93 raeburn 13219: $chgtext .= '<br />';
1.93 raeburn 13220: }
1.160.6.40 raeburn 13221: } elsif ($type eq 'selfcreateprocessing') {
13222: my %choices = &Apache::lonlocal::texthash (
13223: automatic => 'Automatic approval',
13224: approval => 'Queued for approval',
13225: );
1.160.6.93 raeburn 13226: if (@types) {
13227: if (@statuses) {
13228: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
13229: '<ul>';
13230: foreach my $status (@statuses) {
13231: if ($status eq 'default') {
13232: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
13233: } else {
13234: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
13235: }
13236: }
13237: $chgtext .= '</ul>';
13238: }
13239: } else {
13240: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13241: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13242: }
13243: } elsif ($type eq 'emailverified') {
13244: my %options = &Apache::lonlocal::texthash (
13245: all => 'Same as e-mail',
13246: first => 'Omit @domain',
13247: free => 'Free to choose',
13248: );
13249: if (@types) {
13250: if (@statuses) {
13251: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13252: '<ul>';
13253: foreach my $status (@statuses) {
13254: if ($status eq 'default') {
13255: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
13256: } else {
13257: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
13258: }
13259: }
13260: $chgtext .= '</ul>';
13261: }
1.160.6.40 raeburn 13262: } else {
1.160.6.93 raeburn 13263: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
13264: $options{$cancreate{'emailverified'}{'default'}});
13265: }
13266: } elsif ($type eq 'emailoptions') {
13267: my %options = &Apache::lonlocal::texthash (
13268: any => 'Any e-mail',
13269: inst => 'Institutional only',
13270: noninst => 'Non-institutional only',
13271: custom => 'Custom restrictions',
13272: );
13273: if (@types) {
13274: if (@statuses) {
13275: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13276: '<ul>';
13277: foreach my $status (@statuses) {
13278: if ($type eq 'default') {
13279: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13280: } else {
13281: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13282: }
13283: }
13284: $chgtext .= '</ul>';
13285: }
13286: } else {
13287: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13288: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13289: } else {
13290: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13291: $options{$cancreate{'emailoptions'}{'default'}});
13292: }
13293: }
13294: } elsif ($type eq 'emaildomain') {
13295: my $output;
13296: if (@statuses) {
13297: foreach my $type (@statuses) {
13298: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13299: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13300: if ($type eq 'default') {
13301: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13302: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13303: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13304: } else {
13305: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13306: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13307: }
13308: } else {
13309: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13310: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13311: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13312: } else {
13313: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13314: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13315: }
13316: }
13317: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13318: if ($type eq 'default') {
13319: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13320: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13321: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13322: } else {
13323: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13324: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13325: }
13326: } else {
13327: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13328: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13329: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13330: } else {
13331: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13332: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13333: }
13334: }
13335: }
13336: }
13337: }
13338: }
13339: if ($output ne '') {
13340: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
13341: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 13342: }
1.160.6.5 raeburn 13343: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 13344: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 13345: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
13346: } else {
13347: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 13348: if ($captchas{$savecaptcha{$type}}) {
13349: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 13350: } else {
13351: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
13352: }
13353: }
13354: } elsif ($type eq 'recaptchakeys') {
13355: my ($privkey,$pubkey);
1.160.6.34 raeburn 13356: if (ref($savecaptcha{$type}) eq 'HASH') {
13357: $pubkey = $savecaptcha{$type}{'public'};
13358: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 13359: }
13360: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
13361: if (!$pubkey) {
13362: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
13363: } else {
13364: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13365: }
13366: if (!$privkey) {
13367: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
13368: } else {
13369: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
13370: }
13371: $chgtext .= '</ul>';
1.160.6.69 raeburn 13372: } elsif ($type eq 'recaptchaversion') {
13373: if ($savecaptcha{'captcha'} eq 'recaptcha') {
13374: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
13375: }
1.160.6.34 raeburn 13376: } elsif ($type eq 'emailusername') {
13377: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 13378: if (@statuses) {
13379: foreach my $type (@statuses) {
1.160.6.35 raeburn 13380: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
13381: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 13382: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.160.6.35 raeburn 13383: '<ul>';
13384: foreach my $field (@{$infofields}) {
13385: if ($cancreate{'emailusername'}{$type}{$field}) {
13386: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
13387: }
13388: }
1.160.6.50 raeburn 13389: $chgtext .= '</ul>';
13390: } else {
1.160.6.93 raeburn 13391: $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.160.6.35 raeburn 13392: }
13393: } else {
1.160.6.93 raeburn 13394: $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.160.6.34 raeburn 13395: }
13396: }
13397: }
13398: }
13399: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 13400: my $numapprove = 0;
1.160.6.34 raeburn 13401: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13402: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
13403: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 13404: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
13405: $numapprove ++;
1.160.6.34 raeburn 13406: }
13407: }
1.43 raeburn 13408: }
1.160.6.93 raeburn 13409: unless ($numapprove) {
13410: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
13411: }
1.34 raeburn 13412: }
1.160.6.34 raeburn 13413: if ($chgtext) {
13414: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 13415: }
13416: }
13417: }
1.160.6.93 raeburn 13418: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 13419: my ($emailrules,$emailruleorder) =
13420: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 13421: foreach my $type (@{$changes{'email_rule'}}) {
13422: if (ref($email_rule{$type}) eq 'ARRAY') {
13423: my $chgtext = '<ul>';
13424: foreach my $rule (@{$email_rule{$type}}) {
13425: if (ref($emailrules->{$rule}) eq 'HASH') {
13426: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
13427: }
13428: }
13429: $chgtext .= '</ul>';
13430: my $typename;
13431: if (@types) {
13432: if ($type eq 'default') {
13433: $typename = $othertitle;
13434: } else {
13435: $typename = $usertypes{$type};
13436: }
13437: $chgtext .= &mt('(Affiliation: [_1])',$typename);
13438: }
13439: if (@{$email_rule{$type}} > 0) {
13440: $resulttext .= '<li>'.
13441: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
13442: $usertypes{$type}).
13443: $chgtext.
13444: '</li>';
13445: } else {
13446: $resulttext .= '<li>'.
13447: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
13448: '</li>'.
13449: &mt('(Affiliation: [_1])',$typename);
13450: }
1.43 raeburn 13451: }
13452: }
1.160.6.93 raeburn 13453: }
13454: if (ref($changes{'inststatus'}) eq 'ARRAY') {
13455: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
13456: if (@{$save_inststatus{'inststatusguest'}} > 0) {
13457: my $chgtext = '<ul>';
13458: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
13459: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
13460: }
13461: $chgtext .= '</ul>';
13462: $resulttext .= '<li>'.
13463: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
13464: $chgtext.
13465: '</li>';
13466: } else {
13467: $resulttext .= '<li>'.
13468: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
13469: '</li>';
13470: }
1.43 raeburn 13471: }
13472: }
1.160.6.34 raeburn 13473: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
13474: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
13475: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13476: foreach my $type (@{$changes{'selfcreate'}}) {
13477: my $typename = $type;
1.160.6.93 raeburn 13478: if (keys(%usertypes) > 0) {
13479: if ($usertypes{$type} ne '') {
13480: $typename = $usertypes{$type};
1.28 raeburn 13481: }
13482: }
1.160.6.34 raeburn 13483: my @modifiable;
13484: $resulttext .= '<li>'.
13485: &mt('Self-creation of account by users with status: [_1]',
13486: '<span class="LC_cusr_emph">'.$typename.'</span>').
13487: ' - '.&mt('modifiable fields (if institutional data blank): ');
13488: foreach my $field (@fields) {
13489: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
13490: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
13491: }
13492: }
13493: if (@modifiable > 0) {
13494: $resulttext .= join(', ',@modifiable);
1.43 raeburn 13495: } else {
1.160.6.34 raeburn 13496: $resulttext .= &mt('none');
1.43 raeburn 13497: }
1.160.6.34 raeburn 13498: $resulttext .= '</li>';
1.28 raeburn 13499: }
1.160.6.34 raeburn 13500: $resulttext .= '</ul></li>';
1.28 raeburn 13501: }
1.27 raeburn 13502: $resulttext .= '</ul>';
1.160.6.93 raeburn 13503: my $cachetime = 24*60*60;
13504: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
13505: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13506: if (ref($lastactref) eq 'HASH') {
13507: $lastactref->{'domdefaults'} = 1;
13508: }
1.27 raeburn 13509: } else {
1.160.6.34 raeburn 13510: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 13511: }
13512: } else {
13513: $resulttext = '<span class="LC_error">'.
1.23 raeburn 13514: &mt('An error occurred: [_1]',$putresult).'</span>';
13515: }
1.43 raeburn 13516: if ($warningmsg ne '') {
13517: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13518: }
1.23 raeburn 13519: return $resulttext;
13520: }
13521:
1.160.6.5 raeburn 13522: sub process_captcha {
13523: my ($container,$changes,$newsettings,$current) = @_;
13524: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
13525: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
13526: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
13527: $newsettings->{'captcha'} = 'original';
13528: }
13529: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
13530: if ($container eq 'cancreate') {
13531: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13532: push(@{$changes->{'cancreate'}},'captcha');
13533: } elsif (!defined($changes->{'cancreate'})) {
13534: $changes->{'cancreate'} = ['captcha'];
13535: }
1.160.6.102 raeburn 13536: } elsif ($container eq 'passwords') {
13537: $changes->{'reset'} = 1;
1.160.6.5 raeburn 13538: } else {
13539: $changes->{'captcha'} = 1;
13540: }
13541: }
1.160.6.69 raeburn 13542: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 13543: if ($newsettings->{'captcha'} eq 'recaptcha') {
13544: $newpub = $env{'form.'.$container.'_recaptchapub'};
13545: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 13546: $newpub =~ s/[^\w\-]//g;
13547: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 13548: $newsettings->{'recaptchakeys'} = {
13549: public => $newpub,
13550: private => $newpriv,
13551: };
1.160.6.69 raeburn 13552: $newversion = $env{'form.'.$container.'_recaptchaversion'};
13553: $newversion =~ s/\D//g;
13554: if ($newversion ne '2') {
13555: $newversion = 1;
13556: }
13557: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 13558: }
13559: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
13560: $currpub = $current->{'recaptchakeys'}{'public'};
13561: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 13562: unless ($newsettings->{'captcha'} eq 'recaptcha') {
13563: $newsettings->{'recaptchakeys'} = {
13564: public => '',
13565: private => '',
13566: }
13567: }
1.160.6.5 raeburn 13568: }
1.160.6.69 raeburn 13569: if ($current->{'captcha'} eq 'recaptcha') {
13570: $currversion = $current->{'recaptchaversion'};
13571: if ($currversion ne '2') {
13572: $currversion = 1;
13573: }
13574: }
13575: if ($currversion ne $newversion) {
13576: if ($container eq 'cancreate') {
13577: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13578: push(@{$changes->{'cancreate'}},'recaptchaversion');
13579: } elsif (!defined($changes->{'cancreate'})) {
13580: $changes->{'cancreate'} = ['recaptchaversion'];
13581: }
1.160.6.102 raeburn 13582: } elsif ($container eq 'passwords') {
13583: $changes->{'reset'} = 1;
1.160.6.69 raeburn 13584: } else {
13585: $changes->{'recaptchaversion'} = 1;
13586: }
13587: }
1.160.6.5 raeburn 13588: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
13589: if ($container eq 'cancreate') {
13590: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13591: push(@{$changes->{'cancreate'}},'recaptchakeys');
13592: } elsif (!defined($changes->{'cancreate'})) {
13593: $changes->{'cancreate'} = ['recaptchakeys'];
13594: }
1.160.6.102 raeburn 13595: } elsif ($container eq 'passwords') {
13596: $changes->{'reset'} = 1;
1.160.6.5 raeburn 13597: } else {
13598: $changes->{'recaptchakeys'} = 1;
13599: }
13600: }
13601: return;
13602: }
13603:
1.33 raeburn 13604: sub modify_usermodification {
13605: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 13606: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 13607: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13608: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 13609: if ($key eq 'selfcreate') {
13610: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
13611: } else {
13612: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
13613: }
1.33 raeburn 13614: }
13615: }
1.160.6.34 raeburn 13616: my @contexts = ('author','course');
1.33 raeburn 13617: my %context_title = (
13618: author => 'In author context',
13619: course => 'In course context',
13620: );
13621: my @fields = ('lastname','firstname','middlename','generation',
13622: 'permanentemail','id');
13623: my %roles = (
13624: author => ['ca','aa'],
13625: course => ['st','ep','ta','in','cr'],
13626: );
13627: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13628: foreach my $context (@contexts) {
13629: foreach my $role (@{$roles{$context}}) {
13630: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
13631: foreach my $item (@fields) {
13632: if (grep(/^\Q$item\E$/,@modifiable)) {
13633: $modifyhash{$context}{$role}{$item} = 1;
13634: } else {
13635: $modifyhash{$context}{$role}{$item} = 0;
13636: }
13637: }
13638: }
13639: if (ref($curr_usermodification{$context}) eq 'HASH') {
13640: foreach my $role (@{$roles{$context}}) {
13641: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
13642: foreach my $field (@fields) {
13643: if ($modifyhash{$context}{$role}{$field} ne
13644: $curr_usermodification{$context}{$role}{$field}) {
13645: push(@{$changes{$context}},$role);
13646: last;
13647: }
13648: }
13649: }
13650: }
13651: } else {
13652: foreach my $context (@contexts) {
13653: foreach my $role (@{$roles{$context}}) {
13654: push(@{$changes{$context}},$role);
13655: }
13656: }
13657: }
13658: }
13659: my %usermodification_hash = (
13660: usermodification => \%modifyhash,
13661: );
13662: my $putresult = &Apache::lonnet::put_dom('configuration',
13663: \%usermodification_hash,$dom);
13664: if ($putresult eq 'ok') {
13665: if (keys(%changes) > 0) {
13666: $resulttext = &mt('Changes made: ').'<ul>';
13667: foreach my $context (@contexts) {
13668: if (ref($changes{$context}) eq 'ARRAY') {
13669: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
13670: if (ref($changes{$context}) eq 'ARRAY') {
13671: foreach my $role (@{$changes{$context}}) {
13672: my $rolename;
1.160.6.34 raeburn 13673: if ($role eq 'cr') {
13674: $rolename = &mt('Custom');
1.33 raeburn 13675: } else {
1.160.6.34 raeburn 13676: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 13677: }
13678: my @modifiable;
1.160.6.34 raeburn 13679: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 13680: foreach my $field (@fields) {
13681: if ($modifyhash{$context}{$role}{$field}) {
13682: push(@modifiable,$fieldtitles{$field});
13683: }
13684: }
13685: if (@modifiable > 0) {
13686: $resulttext .= join(', ',@modifiable);
13687: } else {
13688: $resulttext .= &mt('none');
13689: }
13690: $resulttext .= '</li>';
13691: }
13692: $resulttext .= '</ul></li>';
13693: }
13694: }
13695: }
13696: $resulttext .= '</ul>';
13697: } else {
13698: $resulttext = &mt('No changes made to user modification settings');
13699: }
13700: } else {
13701: $resulttext = '<span class="LC_error">'.
13702: &mt('An error occurred: [_1]',$putresult).'</span>';
13703: }
13704: return $resulttext;
13705: }
13706:
1.43 raeburn 13707: sub modify_defaults {
1.160.6.27 raeburn 13708: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 13709: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 13710: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 13711: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 13712: 'portal_def');
1.43 raeburn 13713: my @authtypes = ('internal','krb4','krb5','localauth');
13714: foreach my $item (@items) {
13715: $newvalues{$item} = $env{'form.'.$item};
13716: if ($item eq 'auth_def') {
13717: if ($newvalues{$item} ne '') {
13718: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
13719: push(@errors,$item);
13720: }
13721: }
13722: } elsif ($item eq 'lang_def') {
13723: if ($newvalues{$item} ne '') {
13724: if ($newvalues{$item} =~ /^(\w+)/) {
13725: my $langcode = $1;
1.103 raeburn 13726: if ($langcode ne 'x_chef') {
13727: if (code2language($langcode) eq '') {
13728: push(@errors,$item);
13729: }
1.43 raeburn 13730: }
13731: } else {
13732: push(@errors,$item);
13733: }
13734: }
1.54 raeburn 13735: } elsif ($item eq 'timezone_def') {
13736: if ($newvalues{$item} ne '') {
1.62 raeburn 13737: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 13738: push(@errors,$item);
13739: }
13740: }
1.68 raeburn 13741: } elsif ($item eq 'datelocale_def') {
13742: if ($newvalues{$item} ne '') {
13743: my @datelocale_ids = DateTime::Locale->ids();
13744: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
13745: push(@errors,$item);
13746: }
13747: }
1.141 raeburn 13748: } elsif ($item eq 'portal_def') {
13749: if ($newvalues{$item} ne '') {
13750: 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])\/?$/) {
13751: push(@errors,$item);
13752: }
13753: }
1.43 raeburn 13754: }
13755: if (grep(/^\Q$item\E$/,@errors)) {
13756: $newvalues{$item} = $domdefaults{$item};
13757: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
13758: $changes{$item} = 1;
13759: }
1.72 raeburn 13760: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 13761: }
1.160.6.98 raeburn 13762: my %staticdefaults = (
13763: 'intauth_cost' => 10,
13764: 'intauth_check' => 0,
13765: 'intauth_switch' => 0,
13766: );
13767: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
13768: if (exists($domdefaults{$item})) {
13769: $newvalues{$item} = $domdefaults{$item};
13770: } else {
13771: $newvalues{$item} = $staticdefaults{$item};
13772: }
13773: }
1.43 raeburn 13774: my %defaults_hash = (
1.72 raeburn 13775: defaults => \%newvalues,
13776: );
1.43 raeburn 13777: my $title = &defaults_titles();
1.160.6.40 raeburn 13778:
13779: my $currinststatus;
13780: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13781: $currinststatus = $domconfig{'inststatus'};
13782: } else {
13783: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13784: $currinststatus = {
13785: inststatustypes => $usertypes,
13786: inststatusorder => $types,
13787: inststatusguest => [],
13788: };
13789: }
13790: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
13791: my @allpos;
13792: my %alltypes;
1.160.6.93 raeburn 13793: my @inststatusguest;
13794: if (ref($currinststatus) eq 'HASH') {
13795: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
13796: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
13797: unless (grep(/^\Q$type\E$/,@todelete)) {
13798: push(@inststatusguest,$type);
13799: }
13800: }
13801: }
13802: }
13803: my ($currtitles,$currorder);
1.160.6.40 raeburn 13804: if (ref($currinststatus) eq 'HASH') {
13805: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
13806: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
13807: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
13808: if ($currinststatus->{inststatustypes}->{$type} ne '') {
13809: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
13810: }
13811: }
13812: unless (grep(/^\Q$type\E$/,@todelete)) {
13813: my $position = $env{'form.inststatus_pos_'.$type};
13814: $position =~ s/\D+//g;
13815: $allpos[$position] = $type;
13816: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
13817: $alltypes{$type} =~ s/`//g;
13818: }
13819: }
13820: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
13821: $currtitles =~ s/,$//;
13822: }
13823: }
13824: if ($env{'form.addinststatus'}) {
13825: my $newtype = $env{'form.addinststatus'};
13826: $newtype =~ s/\W//g;
13827: unless (exists($alltypes{$newtype})) {
13828: $alltypes{$newtype} = $env{'form.addinststatus_title'};
13829: $alltypes{$newtype} =~ s/`//g;
13830: my $position = $env{'form.addinststatus_pos'};
13831: $position =~ s/\D+//g;
13832: if ($position ne '') {
13833: $allpos[$position] = $newtype;
13834: }
13835: }
13836: }
1.160.6.93 raeburn 13837: my @orderedstatus;
1.160.6.40 raeburn 13838: foreach my $type (@allpos) {
13839: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
13840: push(@orderedstatus,$type);
13841: }
13842: }
13843: foreach my $type (keys(%alltypes)) {
13844: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
13845: delete($alltypes{$type});
13846: }
13847: }
13848: $defaults_hash{'inststatus'} = {
13849: inststatustypes => \%alltypes,
13850: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 13851: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 13852: };
13853: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
13854: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
13855: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
13856: }
13857: }
13858: if ($currorder ne join(',',@orderedstatus)) {
13859: $changes{'inststatus'}{'inststatusorder'} = 1;
13860: }
13861: my $newtitles;
13862: foreach my $item (@orderedstatus) {
13863: $newtitles .= $alltypes{$item}.',';
13864: }
13865: $newtitles =~ s/,$//;
13866: if ($currtitles ne $newtitles) {
13867: $changes{'inststatus'}{'inststatustypes'} = 1;
13868: }
1.43 raeburn 13869: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
13870: $dom);
13871: if ($putresult eq 'ok') {
13872: if (keys(%changes) > 0) {
13873: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 13874: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 13875: 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";
13876: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 13877: if ($item eq 'inststatus') {
13878: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 13879: if (@orderedstatus) {
1.160.6.40 raeburn 13880: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
13881: foreach my $type (@orderedstatus) {
13882: $resulttext .= $alltypes{$type}.', ';
13883: }
13884: $resulttext =~ s/, $//;
13885: $resulttext .= '</li>';
1.160.6.93 raeburn 13886: } else {
13887: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 13888: }
13889: }
13890: } else {
13891: my $value = $env{'form.'.$item};
13892: if ($value eq '') {
13893: $value = &mt('none');
13894: } elsif ($item eq 'auth_def') {
13895: my %authnames = &authtype_names();
13896: my %shortauth = (
13897: internal => 'int',
13898: krb4 => 'krb4',
13899: krb5 => 'krb5',
13900: localauth => 'loc',
13901: );
13902: $value = $authnames{$shortauth{$value}};
13903: }
13904: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
13905: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 13906: }
13907: }
13908: $resulttext .= '</ul>';
13909: $mailmsgtext .= "\n";
13910: my $cachetime = 24*60*60;
1.72 raeburn 13911: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 13912: if (ref($lastactref) eq 'HASH') {
13913: $lastactref->{'domdefaults'} = 1;
13914: }
1.68 raeburn 13915: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 13916: my $notify = 1;
13917: if (ref($domconfig{'contacts'}) eq 'HASH') {
13918: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
13919: $notify = 0;
13920: }
13921: }
13922: if ($notify) {
13923: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
13924: "LON-CAPA Domain Settings Change - $dom",
13925: $mailmsgtext);
13926: }
1.54 raeburn 13927: }
1.43 raeburn 13928: } else {
1.54 raeburn 13929: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 13930: }
13931: } else {
13932: $resulttext = '<span class="LC_error">'.
13933: &mt('An error occurred: [_1]',$putresult).'</span>';
13934: }
13935: if (@errors > 0) {
13936: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
13937: foreach my $item (@errors) {
13938: $resulttext .= ' "'.$title->{$item}.'",';
13939: }
13940: $resulttext =~ s/,$//;
13941: }
13942: return $resulttext;
13943: }
13944:
1.46 raeburn 13945: sub modify_scantron {
1.160.6.24 raeburn 13946: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 13947: my ($resulttext,%confhash,%changes,$errors);
13948: my $custom = 'custom.tab';
13949: my $default = 'default.tab';
13950: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 13951: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 13952: &config_check($dom,$confname,$servadm);
13953: if ($env{'form.scantronformat.filename'} ne '') {
13954: my $error;
13955: if ($configuserok eq 'ok') {
13956: if ($switchserver) {
1.130 raeburn 13957: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 13958: } else {
13959: if ($author_ok eq 'ok') {
13960: my ($result,$scantronurl) =
13961: &publishlogo($r,'upload','scantronformat',$dom,
13962: $confname,'scantron','','',$custom);
13963: if ($result eq 'ok') {
13964: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 13965: $changes{'scantronformat'} = 1;
1.46 raeburn 13966: } else {
13967: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
13968: }
13969: } else {
13970: $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);
13971: }
13972: }
13973: } else {
13974: $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);
13975: }
13976: if ($error) {
13977: &Apache::lonnet::logthis($error);
13978: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13979: }
13980: }
1.48 raeburn 13981: if (ref($domconfig{'scantron'}) eq 'HASH') {
13982: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
13983: if ($env{'form.scantronformat_del'}) {
13984: $confhash{'scantron'}{'scantronformat'} = '';
13985: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 13986: } else {
13987: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
13988: }
13989: }
13990: }
13991: my @options = ('hdr','pad','rem');
13992: my @fields = &scantroncsv_fields();
13993: my %titles = &scantronconfig_titles();
13994: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
13995: my ($newdat,$currdat,%newcol,%currcol);
13996: if (grep(/^dat$/,@formats)) {
13997: $confhash{'scantron'}{config}{dat} = 1;
13998: $newdat = 1;
13999: } else {
14000: $newdat = 0;
14001: }
14002: if (grep(/^csv$/,@formats)) {
14003: my %bynum;
14004: foreach my $field (@fields) {
14005: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
14006: my $posscol = $1;
14007: if (($posscol < 20) && (!$bynum{$posscol})) {
14008: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
14009: $bynum{$posscol} = $field;
14010: $newcol{$field} = $posscol;
14011: }
14012: }
14013: }
14014: if (keys(%newcol)) {
14015: foreach my $option (@options) {
14016: if ($env{'form.scantroncsv_'.$option}) {
14017: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
14018: }
14019: }
14020: }
14021: }
14022: $currdat = 1;
14023: if (ref($domconfig{'scantron'}) eq 'HASH') {
14024: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
14025: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
14026: $currdat = 0;
14027: }
14028: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14029: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14030: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
14031: }
14032: }
14033: }
14034: }
14035: if ($currdat != $newdat) {
14036: $changes{'config'} = 1;
14037: } else {
14038: foreach my $field (@fields) {
14039: if ($currcol{$field} ne '') {
14040: if ($currcol{$field} ne $newcol{$field}) {
14041: $changes{'config'} = 1;
14042: last;
14043: }
14044: } elsif ($newcol{$field} ne '') {
14045: $changes{'config'} = 1;
14046: last;
1.46 raeburn 14047: }
14048: }
14049: }
14050: if (keys(%confhash) > 0) {
14051: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14052: $dom);
14053: if ($putresult eq 'ok') {
14054: if (keys(%changes) > 0) {
1.48 raeburn 14055: if (ref($confhash{'scantron'}) eq 'HASH') {
14056: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 14057: if ($changes{'scantronformat'}) {
14058: if ($confhash{'scantron'}{'scantronformat'} eq '') {
14059: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
14060: } else {
14061: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
14062: }
14063: }
14064: if ($changes{'config'}) {
14065: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
14066: if ($confhash{'scantron'}{'config'}{'dat'}) {
14067: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
14068: }
14069: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14070: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14071: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
14072: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
14073: foreach my $field (@fields) {
14074: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
14075: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
14076: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
14077: }
14078: }
14079: $resulttext .= '</ul></li>';
14080: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
14081: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
14082: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
14083: foreach my $option (@options) {
14084: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
14085: $resulttext .= '<li>'.$titles{$option}.'</li>';
14086: }
14087: }
14088: $resulttext .= '</ul></li>';
14089: }
14090: }
14091: }
14092: }
14093: }
14094: } else {
14095: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
14096: }
1.46 raeburn 14097: }
1.48 raeburn 14098: $resulttext .= '</ul>';
14099: } else {
1.130 raeburn 14100: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14101: }
14102: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14103: if (ref($lastactref) eq 'HASH') {
14104: $lastactref->{'domainconfig'} = 1;
14105: }
1.46 raeburn 14106: } else {
1.160.6.97 raeburn 14107: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 14108: }
14109: } else {
14110: $resulttext = '<span class="LC_error">'.
14111: &mt('An error occurred: [_1]',$putresult).'</span>';
14112: }
14113: } else {
1.160.6.97 raeburn 14114: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 14115: }
14116: if ($errors) {
14117: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14118: $errors.'</ul>';
14119: }
14120: return $resulttext;
14121: }
14122:
1.48 raeburn 14123: sub modify_coursecategories {
1.160.6.43 raeburn 14124: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14125: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14126: $cathash);
1.48 raeburn 14127: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 14128: my @catitems = ('unauth','auth');
14129: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14130: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14131: $cathash = $domconfig{'coursecategories'}{'cats'};
14132: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14133: $changes{'togglecats'} = 1;
14134: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14135: }
14136: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14137: $changes{'categorize'} = 1;
14138: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14139: }
1.120 raeburn 14140: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14141: $changes{'togglecatscomm'} = 1;
14142: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14143: }
14144: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14145: $changes{'categorizecomm'} = 1;
14146: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
14147: }
1.160.6.42 raeburn 14148: foreach my $item (@catitems) {
14149: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14150: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14151: $changes{$item} = 1;
14152: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14153: }
14154: }
14155: }
1.57 raeburn 14156: } else {
14157: $changes{'togglecats'} = 1;
14158: $changes{'categorize'} = 1;
1.124 raeburn 14159: $changes{'togglecatscomm'} = 1;
14160: $changes{'categorizecomm'} = 1;
1.87 raeburn 14161: $domconfig{'coursecategories'} = {
14162: togglecats => $env{'form.togglecats'},
14163: categorize => $env{'form.categorize'},
1.124 raeburn 14164: togglecatscomm => $env{'form.togglecatscomm'},
14165: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 14166: };
1.160.6.42 raeburn 14167: foreach my $item (@catitems) {
14168: if ($env{'form.coursecat_'.$item} ne 'std') {
14169: $changes{$item} = 1;
14170: }
14171: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14172: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14173: }
14174: }
1.57 raeburn 14175: }
14176: if (ref($cathash) eq 'HASH') {
14177: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14178: push (@deletecategory,'instcode::0');
14179: }
1.120 raeburn 14180: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14181: push(@deletecategory,'communities::0');
14182: }
1.48 raeburn 14183: }
1.57 raeburn 14184: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14185: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14186: if (@deletecategory > 0) {
14187: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14188: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14189: foreach my $item (@deletecategory) {
1.57 raeburn 14190: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14191: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14192: $deletions{$item} = 1;
1.57 raeburn 14193: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14194: }
14195: }
14196: }
1.57 raeburn 14197: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14198: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14199: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14200: $reorderings{$item} = 1;
1.57 raeburn 14201: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14202: }
14203: if ($env{'form.addcategory_name_'.$item} ne '') {
14204: my $newcat = $env{'form.addcategory_name_'.$item};
14205: my $newdepth = $depth+1;
14206: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14207: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14208: $adds{$newitem} = 1;
14209: }
14210: if ($env{'form.subcat_'.$item} ne '') {
14211: my $newcat = $env{'form.subcat_'.$item};
14212: my $newdepth = $depth+1;
14213: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14214: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14215: $adds{$newitem} = 1;
14216: }
14217: }
14218: }
14219: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14220: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14221: my $newitem = 'instcode::0';
1.57 raeburn 14222: if ($cathash->{$newitem} eq '') {
14223: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14224: $adds{$newitem} = 1;
14225: }
14226: } else {
14227: my $newitem = 'instcode::0';
1.57 raeburn 14228: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14229: $adds{$newitem} = 1;
14230: }
14231: }
1.120 raeburn 14232: if ($env{'form.communities'} eq '1') {
14233: if (ref($cathash) eq 'HASH') {
14234: my $newitem = 'communities::0';
14235: if ($cathash->{$newitem} eq '') {
14236: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14237: $adds{$newitem} = 1;
14238: }
14239: } else {
14240: my $newitem = 'communities::0';
14241: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14242: $adds{$newitem} = 1;
14243: }
14244: }
1.48 raeburn 14245: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14246: if (($env{'form.addcategory_name'} ne 'instcode') &&
14247: ($env{'form.addcategory_name'} ne 'communities')) {
14248: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14249: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14250: $adds{$newitem} = 1;
14251: }
1.48 raeburn 14252: }
1.57 raeburn 14253: my $putresult;
1.48 raeburn 14254: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14255: if (keys(%deletions) > 0) {
14256: foreach my $key (keys(%deletions)) {
14257: if ($predelallitems{$key} ne '') {
14258: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14259: }
14260: }
14261: }
14262: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14263: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14264: if (ref($chkcats[0]) eq 'ARRAY') {
14265: my $depth = 0;
14266: my $chg = 0;
14267: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14268: my $name = $chkcats[0][$i];
14269: my $item;
14270: if ($name eq '') {
14271: $chg ++;
14272: } else {
14273: $item = &escape($name).'::0';
14274: if ($chg) {
1.57 raeburn 14275: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14276: }
14277: $depth ++;
1.57 raeburn 14278: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14279: $depth --;
14280: }
14281: }
14282: }
1.57 raeburn 14283: }
14284: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14285: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14286: if ($putresult eq 'ok') {
1.57 raeburn 14287: my %title = (
1.120 raeburn 14288: togglecats => 'Show/Hide a course in catalog',
14289: categorize => 'Assign a category to a course',
14290: togglecatscomm => 'Show/Hide a community in catalog',
14291: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14292: );
14293: my %level = (
1.120 raeburn 14294: dom => 'set in Domain ("Modify Course/Community")',
14295: crs => 'set in Course ("Course Configuration")',
14296: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 14297: none => 'No catalog',
14298: std => 'Standard catalog',
14299: domonly => 'Domain-only catalog',
14300: codesrch => 'Code search form',
1.57 raeburn 14301: );
1.48 raeburn 14302: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14303: if ($changes{'togglecats'}) {
14304: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14305: }
14306: if ($changes{'categorize'}) {
14307: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14308: }
1.120 raeburn 14309: if ($changes{'togglecatscomm'}) {
14310: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14311: }
14312: if ($changes{'categorizecomm'}) {
14313: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14314: }
1.160.6.42 raeburn 14315: if ($changes{'unauth'}) {
14316: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14317: }
14318: if ($changes{'auth'}) {
14319: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14320: }
1.57 raeburn 14321: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14322: my $cathash;
14323: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14324: $cathash = $domconfig{'coursecategories'}{'cats'};
14325: } else {
14326: $cathash = {};
14327: }
14328: my (@cats,@trails,%allitems);
14329: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
14330: if (keys(%deletions) > 0) {
14331: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
14332: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
14333: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
14334: }
14335: $resulttext .= '</ul></li>';
14336: }
14337: if (keys(%reorderings) > 0) {
14338: my %sort_by_trail;
14339: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
14340: foreach my $key (keys(%reorderings)) {
14341: if ($allitems{$key} ne '') {
14342: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14343: }
1.48 raeburn 14344: }
1.57 raeburn 14345: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14346: $resulttext .= '<li>'.$trails[$trail].'</li>';
14347: }
14348: $resulttext .= '</ul></li>';
1.48 raeburn 14349: }
1.57 raeburn 14350: if (keys(%adds) > 0) {
14351: my %sort_by_trail;
14352: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
14353: foreach my $key (keys(%adds)) {
14354: if ($allitems{$key} ne '') {
14355: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14356: }
14357: }
14358: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14359: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 14360: }
1.57 raeburn 14361: $resulttext .= '</ul></li>';
1.48 raeburn 14362: }
1.160.6.92 raeburn 14363: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
14364: if (ref($lastactref) eq 'HASH') {
14365: $lastactref->{'cats'} = 1;
14366: }
1.48 raeburn 14367: }
14368: $resulttext .= '</ul>';
1.160.6.43 raeburn 14369: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 14370: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14371: if ($changes{'auth'}) {
14372: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
14373: }
14374: if ($changes{'unauth'}) {
14375: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
14376: }
14377: my $cachetime = 24*60*60;
14378: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 14379: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 14380: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 14381: }
14382: }
1.48 raeburn 14383: } else {
14384: $resulttext = '<span class="LC_error">'.
1.57 raeburn 14385: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 14386: }
14387: } else {
1.120 raeburn 14388: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 14389: }
14390: return $resulttext;
14391: }
14392:
1.69 raeburn 14393: sub modify_serverstatuses {
14394: my ($dom,%domconfig) = @_;
14395: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
14396: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
14397: %currserverstatus = %{$domconfig{'serverstatuses'}};
14398: }
14399: my @pages = &serverstatus_pages();
14400: foreach my $type (@pages) {
14401: $newserverstatus{$type}{'namedusers'} = '';
14402: $newserverstatus{$type}{'machines'} = '';
14403: if (defined($env{'form.'.$type.'_namedusers'})) {
14404: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
14405: my @okusers;
14406: foreach my $user (@users) {
14407: my ($uname,$udom) = split(/:/,$user);
14408: if (($udom =~ /^$match_domain$/) &&
14409: (&Apache::lonnet::domain($udom)) &&
14410: ($uname =~ /^$match_username$/)) {
14411: if (!grep(/^\Q$user\E/,@okusers)) {
14412: push(@okusers,$user);
14413: }
14414: }
14415: }
14416: if (@okusers > 0) {
14417: @okusers = sort(@okusers);
14418: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
14419: }
14420: }
14421: if (defined($env{'form.'.$type.'_machines'})) {
14422: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
14423: my @okmachines;
14424: foreach my $ip (@machines) {
14425: my @parts = split(/\./,$ip);
14426: next if (@parts < 4);
14427: my $badip = 0;
14428: for (my $i=0; $i<4; $i++) {
14429: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
14430: $badip = 1;
14431: last;
14432: }
14433: }
14434: if (!$badip) {
14435: push(@okmachines,$ip);
14436: }
14437: }
14438: @okmachines = sort(@okmachines);
14439: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
14440: }
14441: }
14442: my %serverstatushash = (
14443: serverstatuses => \%newserverstatus,
14444: );
14445: foreach my $type (@pages) {
1.83 raeburn 14446: foreach my $setting ('namedusers','machines') {
1.84 raeburn 14447: my (@current,@new);
1.83 raeburn 14448: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 14449: if ($currserverstatus{$type}{$setting} ne '') {
14450: @current = split(/,/,$currserverstatus{$type}{$setting});
14451: }
14452: }
14453: if ($newserverstatus{$type}{$setting} ne '') {
14454: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 14455: }
14456: if (@current > 0) {
14457: if (@new > 0) {
14458: foreach my $item (@current) {
14459: if (!grep(/^\Q$item\E$/,@new)) {
14460: $changes{$type}{$setting} = 1;
1.82 raeburn 14461: last;
14462: }
14463: }
1.84 raeburn 14464: foreach my $item (@new) {
14465: if (!grep(/^\Q$item\E$/,@current)) {
14466: $changes{$type}{$setting} = 1;
14467: last;
1.82 raeburn 14468: }
14469: }
14470: } else {
1.83 raeburn 14471: $changes{$type}{$setting} = 1;
1.69 raeburn 14472: }
1.83 raeburn 14473: } elsif (@new > 0) {
14474: $changes{$type}{$setting} = 1;
1.69 raeburn 14475: }
14476: }
14477: }
14478: if (keys(%changes) > 0) {
1.81 raeburn 14479: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 14480: my $putresult = &Apache::lonnet::put_dom('configuration',
14481: \%serverstatushash,$dom);
14482: if ($putresult eq 'ok') {
14483: $resulttext .= &mt('Changes made:').'<ul>';
14484: foreach my $type (@pages) {
1.84 raeburn 14485: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 14486: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 14487: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 14488: if ($newserverstatus{$type}{'namedusers'} eq '') {
14489: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
14490: } else {
14491: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
14492: }
1.84 raeburn 14493: }
14494: if ($changes{$type}{'machines'}) {
1.69 raeburn 14495: if ($newserverstatus{$type}{'machines'} eq '') {
14496: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
14497: } else {
14498: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
14499: }
14500:
14501: }
14502: $resulttext .= '</ul></li>';
14503: }
14504: }
14505: $resulttext .= '</ul>';
14506: } else {
14507: $resulttext = '<span class="LC_error">'.
14508: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
14509:
14510: }
14511: } else {
14512: $resulttext = &mt('No changes made to access to server status pages');
14513: }
14514: return $resulttext;
14515: }
14516:
1.118 jms 14517: sub modify_helpsettings {
1.160.6.77 raeburn 14518: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 14519: my ($resulttext,$errors,%changes,%helphash);
14520: my %defaultchecked = ('submitbugs' => 'on');
14521: my @offon = ('off','on');
1.118 jms 14522: my @toggles = ('submitbugs');
1.160.6.77 raeburn 14523: my %current = ('submitbugs' => '',
14524: 'adhoc' => {},
14525: );
1.118 jms 14526: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 14527: %current = %{$domconfig{'helpsettings'}};
14528: }
1.160.6.77 raeburn 14529: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 14530: foreach my $item (@toggles) {
14531: if ($defaultchecked{$item} eq 'on') {
14532: if ($current{$item} eq '') {
14533: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 14534: $changes{$item} = 1;
14535: }
1.160.6.73 raeburn 14536: } elsif ($current{$item} ne $env{'form.'.$item}) {
14537: $changes{$item} = 1;
14538: }
14539: } elsif ($defaultchecked{$item} eq 'off') {
14540: if ($current{$item} eq '') {
14541: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 14542: $changes{$item} = 1;
14543: }
1.160.6.73 raeburn 14544: } elsif ($current{$item} ne $env{'form.'.$item}) {
14545: $changes{$item} = 1;
14546: }
14547: }
14548: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
14549: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
14550: }
14551: }
1.160.6.77 raeburn 14552: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 14553: my $confname = $dom.'-domainconfig';
14554: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 14555: my (@allpos,%newsettings,%changedprivs,$newrole);
14556: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 14557: my @accesstypes = ('all','dh','da','none','status','inc','exc');
14558: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 14559: my %lt = &Apache::lonlocal::texthash(
14560: s => 'system',
14561: d => 'domain',
14562: order => 'Display order',
14563: access => 'Role usage',
1.160.6.79 raeburn 14564: all => 'All with domain helpdesk or helpdesk assistant role',
14565: dh => 'All with domain helpdesk role',
14566: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 14567: none => 'None',
14568: status => 'Determined based on institutional status',
14569: inc => 'Include all, but exclude specific personnel',
14570: exc => 'Exclude all, but include specific personnel',
14571: );
14572: for (my $num=0; $num<=$maxnum; $num++) {
14573: my ($prefix,$identifier,$rolename,%curr);
14574: if ($num == $maxnum) {
14575: next unless ($env{'form.newcusthelp'} == $maxnum);
14576: $identifier = 'custhelp'.$num;
14577: $prefix = 'helproles_'.$num;
14578: $rolename = $env{'form.custhelpname'.$num};
14579: $rolename=~s/[^A-Za-z0-9]//gs;
14580: next if ($rolename eq '');
14581: next if (exists($existing{'rolesdef_'.$rolename}));
14582: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
14583: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
14584: $newprivs{'c'},$confname,$dom);
14585: if ($result ne 'ok') {
14586: $errors .= '<li><span class="LC_error">'.
14587: &mt('An error occurred storing the new custom role: [_1]',
14588: $result).'</span></li>';
14589: next;
14590: } else {
14591: $changedprivs{$rolename} = \%newprivs;
14592: $newrole = $rolename;
14593: }
14594: } else {
14595: $prefix = 'helproles_'.$num;
14596: $rolename = $env{'form.'.$prefix};
14597: next if ($rolename eq '');
14598: next unless (exists($existing{'rolesdef_'.$rolename}));
14599: $identifier = 'custhelp'.$num;
14600: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
14601: my %currprivs;
14602: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
14603: split(/\_/,$existing{'rolesdef_'.$rolename});
14604: foreach my $level ('c','d','s') {
14605: if ($newprivs{$level} ne $currprivs{$level}) {
14606: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
14607: $newprivs{'c'},$confname,$dom);
14608: if ($result ne 'ok') {
14609: $errors .= '<li><span class="LC_error">'.
14610: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
14611: $rolename,$result).'</span></li>';
14612: } else {
14613: $changedprivs{$rolename} = \%newprivs;
14614: }
14615: last;
14616: }
14617: }
14618: if (ref($current{'adhoc'}) eq 'HASH') {
14619: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
14620: %curr = %{$current{'adhoc'}{$rolename}};
14621: }
14622: }
14623: }
14624: my $newpos = $env{'form.'.$prefix.'_pos'};
14625: $newpos =~ s/\D+//g;
14626: $allpos[$newpos] = $rolename;
14627: my $newdesc = $env{'form.'.$prefix.'_desc'};
14628: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
14629: if ($curr{'desc'}) {
14630: if ($curr{'desc'} ne $newdesc) {
14631: $changes{'customrole'}{$rolename}{'desc'} = 1;
14632: $newsettings{$rolename}{'desc'} = $newdesc;
14633: }
14634: } elsif ($newdesc ne '') {
14635: $changes{'customrole'}{$rolename}{'desc'} = 1;
14636: $newsettings{$rolename}{'desc'} = $newdesc;
14637: }
14638: my $access = $env{'form.'.$prefix.'_access'};
14639: if (grep(/^\Q$access\E$/,@accesstypes)) {
14640: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
14641: if ($access eq 'status') {
14642: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
14643: if (scalar(@statuses) == 0) {
14644: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
14645: } else {
14646: my (@shownstatus,$numtypes);
14647: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
14648: if (ref($types) eq 'ARRAY') {
14649: $numtypes = scalar(@{$types});
14650: foreach my $type (sort(@statuses)) {
14651: if ($type eq 'default') {
14652: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
14653: } elsif (grep(/^\Q$type\E$/,@{$types})) {
14654: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
14655: push(@shownstatus,$usertypes->{$type});
14656: }
1.160.6.73 raeburn 14657: }
14658: }
1.160.6.77 raeburn 14659: if (grep(/^default$/,@statuses)) {
14660: push(@shownstatus,$othertitle);
14661: }
14662: if (scalar(@shownstatus) == 1+$numtypes) {
14663: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
14664: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
14665: } else {
14666: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
14667: if (ref($curr{'status'}) eq 'ARRAY') {
14668: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
14669: if (@diffs) {
14670: $changes{'customrole'}{$rolename}{$access} = 1;
14671: }
14672: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
14673: $changes{'customrole'}{$rolename}{$access} = 1;
14674: }
14675: }
14676: }
14677: } elsif (($access eq 'inc') || ($access eq 'exc')) {
14678: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
14679: my @newspecstaff;
14680: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
14681: foreach my $person (sort(@personnel)) {
14682: if ($domhelpdesk{$person}) {
14683: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
14684: }
14685: }
14686: if (ref($curr{$access}) eq 'ARRAY') {
14687: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
14688: if (@diffs) {
14689: $changes{'customrole'}{$rolename}{$access} = 1;
14690: }
14691: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
14692: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 14693: }
1.160.6.77 raeburn 14694: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
14695: my ($uname,$udom) = split(/:/,$person);
14696: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
14697: }
14698: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 14699: }
1.160.6.77 raeburn 14700: } else {
14701: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
14702: }
14703: unless ($curr{'access'} eq $access) {
14704: $changes{'customrole'}{$rolename}{'access'} = 1;
14705: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 14706: }
14707: }
1.160.6.77 raeburn 14708: if (@allpos > 0) {
14709: my $idx = 0;
14710: foreach my $rolename (@allpos) {
14711: if ($rolename ne '') {
14712: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
14713: if (ref($current{'adhoc'}) eq 'HASH') {
14714: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
14715: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
14716: $changes{'customrole'}{$rolename}{'order'} = 1;
14717: $newsettings{$rolename}{'order'} = $idx+1;
14718: }
14719: }
1.160.6.73 raeburn 14720: }
1.160.6.77 raeburn 14721: $idx ++;
1.122 jms 14722: }
14723: }
1.118 jms 14724: }
1.123 jms 14725: my $putresult;
14726: if (keys(%changes) > 0) {
1.160.6.5 raeburn 14727: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
14728: if ($putresult eq 'ok') {
1.160.6.77 raeburn 14729: if (ref($helphash{'helpsettings'}) eq 'HASH') {
14730: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
14731: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
14732: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
14733: }
14734: }
14735: my $cachetime = 24*60*60;
14736: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14737: if (ref($lastactref) eq 'HASH') {
14738: $lastactref->{'domdefaults'} = 1;
14739: }
14740: } else {
14741: $errors .= '<li><span class="LC_error">'.
14742: &mt('An error occurred storing the settings: [_1]',
14743: $putresult).'</span></li>';
14744: }
14745: }
14746: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
14747: $resulttext = &mt('Changes made:').'<ul>';
14748: my (%shownprivs,@levelorder);
14749: @levelorder = ('c','d','s');
14750: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 14751: foreach my $item (sort(keys(%changes))) {
14752: if ($item eq 'submitbugs') {
14753: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
14754: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
14755: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 14756: } elsif ($item eq 'customrole') {
14757: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 14758: my @keyorder = ('order','desc','access','status','exc','inc');
14759: my %keytext = &Apache::lonlocal::texthash(
14760: order => 'Order',
14761: desc => 'Role description',
14762: access => 'Role usage',
1.160.6.83 raeburn 14763: status => 'Allowed institutional types',
1.160.6.77 raeburn 14764: exc => 'Allowed personnel',
14765: inc => 'Disallowed personnel',
14766: );
1.160.6.73 raeburn 14767: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 14768: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
14769: if ($role eq $newrole) {
14770: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
14771: $role).'<ul>';
14772: } else {
14773: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
14774: $role).'<ul>';
14775: }
14776: foreach my $key (@keyorder) {
14777: if ($changes{'customrole'}{$role}{$key}) {
14778: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
14779: $keytext{$key},$newsettings{$role}{$key}).
14780: '</li>';
14781: }
14782: }
14783: if (ref($changedprivs{$role}) eq 'HASH') {
14784: $shownprivs{$role} = 1;
14785: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
14786: foreach my $level (@levelorder) {
14787: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
14788: next if ($item eq '');
14789: my ($priv) = split(/\&/,$item,2);
14790: if (&Apache::lonnet::plaintext($priv)) {
14791: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
14792: unless ($level eq 'c') {
14793: $resulttext .= ' ('.$lt{$level}.')';
14794: }
14795: $resulttext .= '</li>';
14796: }
14797: }
14798: }
14799: $resulttext .= '</ul>';
14800: }
14801: $resulttext .= '</ul></li>';
14802: }
1.160.6.73 raeburn 14803: }
14804: }
1.160.6.5 raeburn 14805: }
14806: }
14807: }
1.160.6.77 raeburn 14808: if (keys(%changedprivs)) {
14809: foreach my $role (sort(keys(%changedprivs))) {
14810: unless ($shownprivs{$role}) {
14811: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
14812: $role).'<ul>'.
14813: '<li>'.&mt('Privileges set to :').'<ul>';
14814: foreach my $level (@levelorder) {
14815: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
14816: next if ($item eq '');
14817: my ($priv) = split(/\&/,$item,2);
14818: if (&Apache::lonnet::plaintext($priv)) {
14819: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
14820: unless ($level eq 'c') {
14821: $resulttext .= ' ('.$lt{$level}.')';
14822: }
14823: $resulttext .= '</li>';
14824: }
14825: }
14826: }
14827: $resulttext .= '</ul></li></ul></li>';
14828: }
14829: }
14830: }
14831: $resulttext .= '</ul>';
14832: } else {
14833: $resulttext = &mt('No changes made to help settings');
1.118 jms 14834: }
14835: if ($errors) {
1.160.6.5 raeburn 14836: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 14837: $errors.'</ul>';
1.118 jms 14838: }
14839: return $resulttext;
14840: }
14841:
1.121 raeburn 14842: sub modify_coursedefaults {
1.160.6.27 raeburn 14843: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 14844: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 14845: my %defaultchecked = (
14846: 'uselcmath' => 'on',
14847: 'usejsme' => 'on'
14848: );
14849: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 14850: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 14851: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
14852: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 14853: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 14854: my %staticdefaults = (
14855: anonsurvey_threshold => 10,
14856: uploadquota => 500,
1.160.6.57 raeburn 14857: postsubmit => 60,
1.160.6.70 raeburn 14858: mysqltables => 172800,
1.160.6.21 raeburn 14859: );
1.160.6.90 raeburn 14860: my %texoptions = (
14861: MathJax => 'MathJax',
14862: mimetex => &mt('Convert to Images'),
14863: tth => &mt('TeX to HTML'),
14864: );
1.121 raeburn 14865: $defaultshash{'coursedefaults'} = {};
14866:
14867: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
14868: if ($domconfig{'coursedefaults'} eq '') {
14869: $domconfig{'coursedefaults'} = {};
14870: }
14871: }
14872:
14873: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
14874: foreach my $item (@toggles) {
14875: if ($defaultchecked{$item} eq 'on') {
14876: if (($domconfig{'coursedefaults'}{$item} eq '') &&
14877: ($env{'form.'.$item} eq '0')) {
14878: $changes{$item} = 1;
1.160.6.16 raeburn 14879: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 14880: $changes{$item} = 1;
14881: }
14882: } elsif ($defaultchecked{$item} eq 'off') {
14883: if (($domconfig{'coursedefaults'}{$item} eq '') &&
14884: ($env{'form.'.$item} eq '1')) {
14885: $changes{$item} = 1;
14886: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
14887: $changes{$item} = 1;
14888: }
14889: }
14890: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
14891: }
1.160.6.21 raeburn 14892: foreach my $item (@numbers) {
14893: my ($currdef,$newdef);
1.160.6.26 raeburn 14894: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 14895: if ($item eq 'anonsurvey_threshold') {
14896: $currdef = $domconfig{'coursedefaults'}{$item};
14897: $newdef =~ s/\D//g;
14898: if ($newdef eq '' || $newdef < 1) {
14899: $newdef = 1;
14900: }
14901: $defaultshash{'coursedefaults'}{$item} = $newdef;
14902: } else {
1.160.6.70 raeburn 14903: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
14904: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
14905: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 14906: }
14907: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 14908: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 14909: }
14910: if ($currdef ne $newdef) {
14911: if ($item eq 'anonsurvey_threshold') {
14912: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
14913: $changes{$item} = 1;
14914: }
1.160.6.70 raeburn 14915: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
14916: my $setting = $1;
14917: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
14918: $changes{$setting} = 1;
1.160.6.21 raeburn 14919: }
14920: }
1.139 raeburn 14921: }
14922: }
1.160.6.90 raeburn 14923: my $texengine;
14924: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
14925: $texengine = $env{'form.texengine'};
14926: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
14927: if ($currdef eq '') {
14928: unless ($texengine eq $Apache::lonnet::deftex) {
14929: $changes{'texengine'} = 1;
14930: }
14931: } elsif ($currdef ne $texengine) {
14932: $changes{'texengine'} = 1;
14933: }
14934: }
14935: if ($texengine ne '') {
14936: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
14937: }
1.160.6.64 raeburn 14938: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
14939: my @currclonecode;
14940: if (ref($currclone) eq 'HASH') {
14941: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
14942: @currclonecode = @{$currclone->{'instcode'}};
14943: }
14944: }
14945: my $newclone;
14946: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
14947: $newclone = $env{'form.canclone'};
14948: }
14949: if ($newclone eq 'instcode') {
14950: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
14951: my (%codedefaults,@code_order,@clonecode);
14952: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
14953: \@code_order);
14954: foreach my $item (@code_order) {
14955: if (grep(/^\Q$item\E$/,@newcodes)) {
14956: push(@clonecode,$item);
14957: }
14958: }
14959: if (@clonecode) {
14960: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
14961: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
14962: if (@diffs) {
14963: $changes{'canclone'} = 1;
14964: }
14965: } else {
14966: $newclone eq '';
14967: }
14968: } elsif ($newclone ne '') {
14969: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
14970: }
14971: if ($newclone ne $currclone) {
14972: $changes{'canclone'} = 1;
14973: }
1.160.6.57 raeburn 14974: my %credits;
14975: foreach my $type (@types) {
14976: unless ($type eq 'community') {
14977: $credits{$type} = $env{'form.'.$type.'_credits'};
14978: $credits{$type} =~ s/[^\d.]+//g;
14979: }
14980: }
14981: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
14982: ($env{'form.coursecredits'} eq '1')) {
14983: $changes{'coursecredits'} = 1;
14984: foreach my $type (keys(%credits)) {
14985: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
14986: }
14987: } else {
14988: if ($env{'form.coursecredits'} eq '1') {
14989: foreach my $type (@types) {
14990: unless ($type eq 'community') {
14991: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
14992: $changes{'coursecredits'} = 1;
14993: }
14994: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
14995: }
14996: }
14997: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
14998: foreach my $type (@types) {
14999: unless ($type eq 'community') {
15000: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15001: $changes{'coursecredits'} = 1;
15002: last;
15003: }
15004: }
15005: }
15006: }
15007: }
15008: if ($env{'form.postsubmit'} eq '1') {
15009: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15010: my %currtimeout;
15011: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15012: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15013: $changes{'postsubmit'} = 1;
15014: }
15015: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15016: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15017: }
15018: } else {
15019: $changes{'postsubmit'} = 1;
15020: }
15021: foreach my $type (@types) {
15022: my $timeout = $env{'form.'.$type.'_timeout'};
15023: $timeout =~ s/\D//g;
15024: if ($timeout == $staticdefaults{'postsubmit'}) {
15025: $timeout = '';
15026: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15027: $timeout = '0';
15028: }
15029: unless ($timeout eq '') {
15030: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15031: }
15032: if (exists($currtimeout{$type})) {
15033: if ($timeout ne $currtimeout{$type}) {
15034: $changes{'postsubmit'} = 1;
15035: }
15036: } elsif ($timeout ne '') {
15037: $changes{'postsubmit'} = 1;
15038: }
15039: }
15040: } else {
15041: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15042: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15043: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15044: $changes{'postsubmit'} = 1;
15045: }
15046: } else {
15047: $changes{'postsubmit'} = 1;
15048: }
1.160.6.16 raeburn 15049: }
1.121 raeburn 15050: }
15051: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15052: $dom);
15053: if ($putresult eq 'ok') {
15054: if (keys(%changes) > 0) {
1.160.6.27 raeburn 15055: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 15056: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 15057: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.90 raeburn 15058: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15059: foreach my $item ('uselcmath','usejsme','texengine') {
1.160.6.57 raeburn 15060: if ($changes{$item}) {
15061: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15062: }
1.160.6.16 raeburn 15063: }
15064: if ($changes{'coursecredits'}) {
15065: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 15066: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15067: $domdefaults{$type.'credits'} =
15068: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15069: }
15070: }
15071: }
15072: if ($changes{'postsubmit'}) {
15073: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15074: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15075: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15076: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15077: $domdefaults{$type.'postsubtimeout'} =
15078: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15079: }
15080: }
1.160.6.16 raeburn 15081: }
15082: }
1.160.6.21 raeburn 15083: if ($changes{'uploadquota'}) {
15084: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15085: foreach my $type (@types) {
15086: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15087: }
15088: }
15089: }
1.160.6.64 raeburn 15090: if ($changes{'canclone'}) {
15091: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15092: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15093: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15094: if (@clonecodes) {
15095: $domdefaults{'canclone'} = join('+',@clonecodes);
15096: }
15097: }
15098: } else {
15099: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15100: }
15101: }
1.121 raeburn 15102: my $cachetime = 24*60*60;
15103: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 15104: if (ref($lastactref) eq 'HASH') {
15105: $lastactref->{'domdefaults'} = 1;
15106: }
1.121 raeburn 15107: }
15108: $resulttext = &mt('Changes made:').'<ul>';
15109: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 15110: if ($item eq 'uselcmath') {
1.121 raeburn 15111: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 15112: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 15113: } else {
1.160.6.57 raeburn 15114: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15115: }
15116: } elsif ($item eq 'usejsme') {
15117: if ($env{'form.'.$item} eq '1') {
15118: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15119: } else {
15120: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 15121: }
1.160.6.90 raeburn 15122: } elsif ($item eq 'texengine') {
15123: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15124: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15125: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15126: }
1.139 raeburn 15127: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 15128: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.160.6.21 raeburn 15129: } elsif ($item eq 'uploadquota') {
15130: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15131: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15132: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15133: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 15134: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
15135:
1.160.6.21 raeburn 15136: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15137: '</ul>'.
15138: '</li>';
15139: } else {
15140: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15141: }
1.160.6.70 raeburn 15142: } elsif ($item eq 'mysqltables') {
15143: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15144: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15145: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15146: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15147: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15148: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15149: '</ul>'.
15150: '</li>';
15151: } else {
15152: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15153: }
1.160.6.57 raeburn 15154: } elsif ($item eq 'postsubmit') {
15155: if ($domdefaults{'postsubmit'} eq 'off') {
15156: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15157: } else {
15158: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
15159: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15160: $resulttext .= &mt('durations:').'<ul>';
15161: foreach my $type (@types) {
15162: $resulttext .= '<li>';
15163: my $timeout;
15164: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15165: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15166: }
15167: my $display;
15168: if ($timeout eq '0') {
15169: $display = &mt('unlimited');
15170: } elsif ($timeout eq '') {
15171: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15172: } else {
15173: $display = &mt('[quant,_1,second]',$timeout);
15174: }
15175: if ($type eq 'community') {
15176: $resulttext .= &mt('Communities');
15177: } elsif ($type eq 'official') {
15178: $resulttext .= &mt('Official courses');
15179: } elsif ($type eq 'unofficial') {
15180: $resulttext .= &mt('Unofficial courses');
15181: } elsif ($type eq 'textbook') {
15182: $resulttext .= &mt('Textbook courses');
15183: }
15184: $resulttext .= ' -- '.$display.'</li>';
15185: }
15186: $resulttext .= '</ul>';
15187: }
15188: $resulttext .= '</li>';
15189: }
1.160.6.16 raeburn 15190: } elsif ($item eq 'coursecredits') {
15191: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15192: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 15193: ($domdefaults{'unofficialcredits'} eq '') &&
15194: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 15195: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15196: } else {
15197: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15198: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15199: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 15200: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 15201: '</ul>'.
15202: '</li>';
15203: }
15204: } else {
15205: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15206: }
1.160.6.64 raeburn 15207: } elsif ($item eq 'canclone') {
15208: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15209: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15210: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15211: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15212: }
15213: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15214: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15215: } else {
15216: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
15217: }
1.140 raeburn 15218: }
1.121 raeburn 15219: }
15220: $resulttext .= '</ul>';
15221: } else {
15222: $resulttext = &mt('No changes made to course defaults');
15223: }
15224: } else {
15225: $resulttext = '<span class="LC_error">'.
15226: &mt('An error occurred: [_1]',$putresult).'</span>';
15227: }
15228: return $resulttext;
15229: }
15230:
1.160.6.37 raeburn 15231: sub modify_selfenrollment {
15232: my ($dom,$lastactref,%domconfig) = @_;
15233: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
15234: my @types = ('official','unofficial','community','textbook');
15235: my %titles = &tool_titles();
15236: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15237: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
15238: $ordered{'default'} = ['types','registered','approval','limit'];
15239:
15240: my (%roles,%shown,%toplevel);
15241: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15242:
15243: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15244: if ($domconfig{'selfenrollment'} eq '') {
15245: $domconfig{'selfenrollment'} = {};
15246: }
15247: }
15248: %toplevel = (
15249: admin => 'Configuration Rights',
15250: default => 'Default settings',
15251: validation => 'Validation of self-enrollment requests',
15252: );
15253: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
15254:
15255: if (ref($ordered{'admin'}) eq 'ARRAY') {
15256: foreach my $item (@{$ordered{'admin'}}) {
15257: foreach my $type (@types) {
15258: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15259: $selfenrollhash{'admin'}{$type}{$item} = 1;
15260: } else {
15261: $selfenrollhash{'admin'}{$type}{$item} = 0;
15262: }
15263: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15264: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15265: if ($selfenrollhash{'admin'}{$type}{$item} ne
15266: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15267: push(@{$changes{'admin'}{$type}},$item);
15268: }
15269: } else {
15270: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15271: push(@{$changes{'admin'}{$type}},$item);
15272: }
15273: }
15274: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15275: push(@{$changes{'admin'}{$type}},$item);
15276: }
15277: }
15278: }
15279: }
15280:
15281: foreach my $item (@{$ordered{'default'}}) {
15282: foreach my $type (@types) {
15283: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15284: if ($item eq 'types') {
15285: unless (($value eq 'all') || ($value eq 'dom')) {
15286: $value = '';
15287: }
15288: } elsif ($item eq 'registered') {
15289: unless ($value eq '1') {
15290: $value = 0;
15291: }
15292: } elsif ($item eq 'approval') {
15293: unless ($value =~ /^[012]$/) {
15294: $value = 0;
15295: }
15296: } else {
15297: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15298: $value = 'none';
15299: }
15300: }
15301: $selfenrollhash{'default'}{$type}{$item} = $value;
15302: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15303: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15304: if ($selfenrollhash{'default'}{$type}{$item} ne
15305: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15306: push(@{$changes{'default'}{$type}},$item);
15307: }
15308: } else {
15309: push(@{$changes{'default'}{$type}},$item);
15310: }
15311: } else {
15312: push(@{$changes{'default'}{$type}},$item);
15313: }
15314: if ($item eq 'limit') {
15315: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15316: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15317: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15318: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15319: }
15320: } else {
15321: $selfenrollhash{'default'}{$type}{'cap'} = '';
15322: }
15323: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15324: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15325: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15326: push(@{$changes{'default'}{$type}},'cap');
15327: }
15328: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
15329: push(@{$changes{'default'}{$type}},'cap');
15330: }
15331: }
15332: }
15333: }
15334:
15335: foreach my $item (@{$itemsref}) {
15336: if ($item eq 'fields') {
15337: my @changed;
15338: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
15339: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
15340: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
15341: }
15342: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15343: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
15344: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
15345: $domconfig{'selfenrollment'}{'validation'}{$item});
15346: } else {
15347: @changed = @{$selfenrollhash{'validation'}{$item}};
15348: }
15349: } else {
15350: @changed = @{$selfenrollhash{'validation'}{$item}};
15351: }
15352: if (@changed) {
15353: if ($selfenrollhash{'validation'}{$item}) {
15354: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
15355: } else {
15356: $changes{'validation'}{$item} = &mt('None');
15357: }
15358: }
15359: } else {
15360: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
15361: if ($item eq 'markup') {
15362: if ($env{'form.selfenroll_validation_'.$item}) {
15363: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
15364: }
15365: }
15366: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15367: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
15368: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
15369: }
15370: }
15371: }
15372: }
15373:
15374: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
15375: $dom);
15376: if ($putresult eq 'ok') {
15377: if (keys(%changes) > 0) {
15378: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15379: $resulttext = &mt('Changes made:').'<ul>';
15380: foreach my $key ('admin','default','validation') {
15381: if (ref($changes{$key}) eq 'HASH') {
15382: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
15383: if ($key eq 'validation') {
15384: foreach my $item (@{$itemsref}) {
15385: if (exists($changes{$key}{$item})) {
15386: if ($item eq 'markup') {
15387: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15388: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
15389: } else {
15390: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15391: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
15392: }
15393: }
15394: }
15395: } else {
15396: foreach my $type (@types) {
15397: if ($type eq 'community') {
15398: $roles{'1'} = &mt('Community personnel');
15399: } else {
15400: $roles{'1'} = &mt('Course personnel');
15401: }
15402: if (ref($changes{$key}{$type}) eq 'ARRAY') {
15403: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15404: if ($key eq 'admin') {
15405: my @mgrdc = ();
15406: if (ref($ordered{$key}) eq 'ARRAY') {
15407: foreach my $item (@{$ordered{'admin'}}) {
15408: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15409: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
15410: push(@mgrdc,$item);
15411: }
15412: }
15413: }
15414: if (@mgrdc) {
15415: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
15416: } else {
15417: delete($domdefaults{$type.'selfenrolladmdc'});
15418: }
15419: }
15420: } else {
15421: if (ref($ordered{$key}) eq 'ARRAY') {
15422: foreach my $item (@{$ordered{$key}}) {
15423: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15424: $domdefaults{$type.'selfenroll'.$item} =
15425: $selfenrollhash{$key}{$type}{$item};
15426: }
15427: }
15428: }
15429: }
15430: }
15431: $resulttext .= '<li>'.$titles{$type}.'<ul>';
15432: foreach my $item (@{$ordered{$key}}) {
15433: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15434: $resulttext .= '<li>';
15435: if ($key eq 'admin') {
15436: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
15437: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
15438: } else {
15439: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
15440: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
15441: }
15442: $resulttext .= '</li>';
15443: }
15444: }
15445: $resulttext .= '</ul></li>';
15446: }
15447: }
15448: $resulttext .= '</ul></li>';
15449: }
15450: }
1.160.6.93 raeburn 15451: }
15452: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
15453: my $cachetime = 24*60*60;
15454: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15455: if (ref($lastactref) eq 'HASH') {
15456: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 15457: }
15458: }
15459: $resulttext .= '</ul>';
15460: } else {
15461: $resulttext = &mt('No changes made to self-enrollment settings');
15462: }
15463: } else {
15464: $resulttext = '<span class="LC_error">'.
15465: &mt('An error occurred: [_1]',$putresult).'</span>';
15466: }
15467: return $resulttext;
15468: }
15469:
1.137 raeburn 15470: sub modify_usersessions {
1.160.6.27 raeburn 15471: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 15472: my @hostingtypes = ('version','excludedomain','includedomain');
15473: my @offloadtypes = ('primary','default');
15474: my %types = (
15475: remote => \@hostingtypes,
15476: hosted => \@hostingtypes,
15477: spares => \@offloadtypes,
15478: );
15479: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 15480: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 15481: my (%by_ip,%by_location,@intdoms);
15482: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
15483: my @locations = sort(keys(%by_location));
1.137 raeburn 15484: my (%defaultshash,%changes);
15485: foreach my $prefix (@prefixes) {
15486: $defaultshash{'usersessions'}{$prefix} = {};
15487: }
1.160.6.27 raeburn 15488: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 15489: my $resulttext;
1.138 raeburn 15490: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 15491: foreach my $prefix (@prefixes) {
1.145 raeburn 15492: next if ($prefix eq 'spares');
15493: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 15494: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
15495: if ($type eq 'version') {
15496: my $value = $env{'form.'.$prefix.'_'.$type};
15497: my $okvalue;
15498: if ($value ne '') {
15499: if (grep(/^\Q$value\E$/,@lcversions)) {
15500: $okvalue = $value;
15501: }
15502: }
15503: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15504: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15505: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
15506: if ($inuse == 0) {
15507: $changes{$prefix}{$type} = 1;
15508: } else {
15509: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
15510: $changes{$prefix}{$type} = 1;
15511: }
15512: if ($okvalue ne '') {
15513: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15514: }
15515: }
15516: } else {
15517: if (($inuse == 1) && ($okvalue ne '')) {
15518: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15519: $changes{$prefix}{$type} = 1;
15520: }
15521: }
15522: } else {
15523: if (($inuse == 1) && ($okvalue ne '')) {
15524: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15525: $changes{$prefix}{$type} = 1;
15526: }
15527: }
15528: } else {
15529: if (($inuse == 1) && ($okvalue ne '')) {
15530: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15531: $changes{$prefix}{$type} = 1;
15532: }
15533: }
15534: } else {
15535: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
15536: my @okvals;
15537: foreach my $val (@vals) {
1.138 raeburn 15538: if ($val =~ /:/) {
15539: my @items = split(/:/,$val);
15540: foreach my $item (@items) {
15541: if (ref($by_location{$item}) eq 'ARRAY') {
15542: push(@okvals,$item);
15543: }
15544: }
15545: } else {
15546: if (ref($by_location{$val}) eq 'ARRAY') {
15547: push(@okvals,$val);
15548: }
1.137 raeburn 15549: }
15550: }
15551: @okvals = sort(@okvals);
15552: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15553: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15554: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
15555: if ($inuse == 0) {
15556: $changes{$prefix}{$type} = 1;
15557: } else {
15558: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15559: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
15560: if (@changed > 0) {
15561: $changes{$prefix}{$type} = 1;
15562: }
15563: }
15564: } else {
15565: if ($inuse == 1) {
15566: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15567: $changes{$prefix}{$type} = 1;
15568: }
15569: }
15570: } else {
15571: if ($inuse == 1) {
15572: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15573: $changes{$prefix}{$type} = 1;
15574: }
15575: }
15576: } else {
15577: if ($inuse == 1) {
15578: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15579: $changes{$prefix}{$type} = 1;
15580: }
15581: }
15582: }
15583: }
15584: }
1.145 raeburn 15585:
15586: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 15587: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 15588: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
15589: my $savespares;
15590:
15591: foreach my $lonhost (sort(keys(%servers))) {
15592: my $serverhomeID =
15593: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 15594: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 15595: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
15596: my %spareschg;
15597: foreach my $type (@{$types{'spares'}}) {
15598: my @okspares;
15599: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
15600: foreach my $server (@checked) {
1.152 raeburn 15601: if (&Apache::lonnet::hostname($server) ne '') {
15602: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
15603: unless (grep(/^\Q$server\E$/,@okspares)) {
15604: push(@okspares,$server);
15605: }
1.145 raeburn 15606: }
15607: }
15608: }
15609: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
15610: my $newspare;
1.152 raeburn 15611: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
15612: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 15613: $newspare = $new;
15614: }
15615: }
1.152 raeburn 15616: my @spares;
15617: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
15618: @spares = sort(@okspares,$newspare);
15619: } else {
15620: @spares = sort(@okspares);
15621: }
15622: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 15623: if (ref($spareid{$lonhost}) eq 'HASH') {
15624: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 15625: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 15626: if (@diffs > 0) {
15627: $spareschg{$type} = 1;
15628: }
15629: }
15630: }
15631: }
15632: if (keys(%spareschg) > 0) {
15633: $changes{'spares'}{$lonhost} = \%spareschg;
15634: }
15635: }
1.160.6.61 raeburn 15636: $defaultshash{'usersessions'}{'offloadnow'} = {};
15637: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
15638: my @okoffload;
15639: if (@offloadnow) {
15640: foreach my $server (@offloadnow) {
15641: if (&Apache::lonnet::hostname($server) ne '') {
15642: unless (grep(/^\Q$server\E$/,@okoffload)) {
15643: push(@okoffload,$server);
15644: }
15645: }
15646: }
15647: if (@okoffload) {
15648: foreach my $lonhost (@okoffload) {
15649: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
15650: }
15651: }
15652: }
1.145 raeburn 15653: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15654: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
15655: if (ref($changes{'spares'}) eq 'HASH') {
15656: if (keys(%{$changes{'spares'}}) > 0) {
15657: $savespares = 1;
15658: }
15659: }
15660: } else {
15661: $savespares = 1;
15662: }
1.160.6.61 raeburn 15663: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
15664: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
15665: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
15666: $changes{'offloadnow'} = 1;
15667: last;
15668: }
15669: }
15670: unless ($changes{'offloadnow'}) {
15671: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
15672: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
15673: $changes{'offloadnow'} = 1;
15674: last;
15675: }
15676: }
15677: }
15678: } elsif (@okoffload) {
15679: $changes{'offloadnow'} = 1;
15680: }
15681: } elsif (@okoffload) {
15682: $changes{'offloadnow'} = 1;
1.145 raeburn 15683: }
1.147 raeburn 15684: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
15685: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 15686: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15687: $dom);
15688: if ($putresult eq 'ok') {
15689: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
15690: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
15691: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
15692: }
15693: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
15694: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
15695: }
1.160.6.61 raeburn 15696: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
15697: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
15698: }
1.137 raeburn 15699: }
15700: my $cachetime = 24*60*60;
15701: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 15702: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 15703: if (ref($lastactref) eq 'HASH') {
15704: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 15705: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 15706: }
1.147 raeburn 15707: if (keys(%changes) > 0) {
15708: my %lt = &usersession_titles();
15709: $resulttext = &mt('Changes made:').'<ul>';
15710: foreach my $prefix (@prefixes) {
15711: if (ref($changes{$prefix}) eq 'HASH') {
15712: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
15713: if ($prefix eq 'spares') {
15714: if (ref($changes{$prefix}) eq 'HASH') {
15715: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
15716: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 15717: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 15718: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
15719: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 15720: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
15721: foreach my $type (@{$types{$prefix}}) {
15722: if ($changes{$prefix}{$lonhost}{$type}) {
15723: my $offloadto = &mt('None');
15724: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
15725: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
15726: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
15727: }
1.145 raeburn 15728: }
1.147 raeburn 15729: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 15730: }
1.137 raeburn 15731: }
15732: }
1.147 raeburn 15733: $resulttext .= '</li>';
1.137 raeburn 15734: }
15735: }
1.147 raeburn 15736: } else {
15737: foreach my $type (@{$types{$prefix}}) {
15738: if (defined($changes{$prefix}{$type})) {
15739: my $newvalue;
15740: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
15741: if (ref($defaultshash{'usersessions'}{$prefix})) {
15742: if ($type eq 'version') {
15743: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
15744: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
15745: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
15746: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
15747: }
1.145 raeburn 15748: }
15749: }
15750: }
1.147 raeburn 15751: if ($newvalue eq '') {
15752: if ($type eq 'version') {
15753: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
15754: } else {
15755: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
15756: }
1.145 raeburn 15757: } else {
1.147 raeburn 15758: if ($type eq 'version') {
15759: $newvalue .= ' '.&mt('(or later)');
15760: }
15761: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 15762: }
1.137 raeburn 15763: }
15764: }
15765: }
1.147 raeburn 15766: $resulttext .= '</ul>';
1.137 raeburn 15767: }
15768: }
1.160.6.61 raeburn 15769: if ($changes{'offloadnow'}) {
15770: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
15771: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
15772: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
15773: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
15774: $resulttext .= '<li>'.$lonhost.'</li>';
15775: }
15776: $resulttext .= '</ul>';
15777: } else {
15778: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
15779: }
15780: } else {
15781: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
15782: }
15783: }
1.147 raeburn 15784: $resulttext .= '</ul>';
15785: } else {
15786: $resulttext = $nochgmsg;
1.137 raeburn 15787: }
15788: } else {
15789: $resulttext = '<span class="LC_error">'.
15790: &mt('An error occurred: [_1]',$putresult).'</span>';
15791: }
15792: } else {
1.147 raeburn 15793: $resulttext = $nochgmsg;
1.137 raeburn 15794: }
15795: return $resulttext;
15796: }
15797:
1.150 raeburn 15798: sub modify_loadbalancing {
15799: my ($dom,%domconfig) = @_;
15800: my $primary_id = &Apache::lonnet::domain($dom,'primary');
15801: my $intdom = &Apache::lonnet::internet_dom($primary_id);
15802: my ($othertitle,$usertypes,$types) =
15803: &Apache::loncommon::sorted_inst_types($dom);
15804: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 15805: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 15806: my @sparestypes = ('primary','default');
15807: my %typetitles = &sparestype_titles();
15808: my $resulttext;
1.160.6.94 raeburn 15809: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 15810: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
15811: %existing = %{$domconfig{'loadbalancing'}};
15812: }
15813: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 15814: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 15815: my ($saveloadbalancing,%defaultshash,%changes);
15816: my ($alltypes,$othertypes,$titles) =
15817: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
15818: my %ruletitles = &offloadtype_text();
15819: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
15820: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
15821: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
15822: if ($balancer eq '') {
15823: next;
15824: }
15825: if (!exists($servers{$balancer})) {
15826: if (exists($currbalancer{$balancer})) {
15827: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 15828: }
1.160.6.7 raeburn 15829: next;
15830: }
15831: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
15832: push(@{$changes{'delete'}},$balancer);
15833: next;
15834: }
15835: if (!exists($currbalancer{$balancer})) {
15836: push(@{$changes{'add'}},$balancer);
15837: }
15838: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
15839: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
15840: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
15841: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
15842: $saveloadbalancing = 1;
15843: }
15844: foreach my $sparetype (@sparestypes) {
15845: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
15846: my @offloadto;
15847: foreach my $target (@targets) {
15848: if (($servers{$target}) && ($target ne $balancer)) {
15849: if ($sparetype eq 'default') {
15850: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
15851: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 15852: }
15853: }
1.160.6.7 raeburn 15854: unless(grep(/^\Q$target\E$/,@offloadto)) {
15855: push(@offloadto,$target);
15856: }
1.150 raeburn 15857: }
15858: }
1.160.6.76 raeburn 15859: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
15860: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
15861: push(@offloadto,$balancer);
15862: }
15863: }
15864: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 15865: }
1.160.6.94 raeburn 15866: if ($env{'form.loadbalancing_cookie_'.$i}) {
15867: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
15868: if (exists($currbalancer{$balancer})) {
15869: unless ($currcookies{$balancer}) {
15870: $changes{'curr'}{$balancer}{'cookie'} = 1;
15871: }
15872: }
15873: } elsif (exists($currbalancer{$balancer})) {
15874: if ($currcookies{$balancer}) {
15875: $changes{'curr'}{$balancer}{'cookie'} = 1;
15876: }
15877: }
1.160.6.7 raeburn 15878: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 15879: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 15880: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
15881: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 15882: if (@targetdiffs > 0) {
1.160.6.7 raeburn 15883: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 15884: }
1.160.6.7 raeburn 15885: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15886: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
15887: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 15888: }
15889: }
15890: }
15891: } else {
1.160.6.7 raeburn 15892: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
15893: foreach my $sparetype (@sparestypes) {
15894: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15895: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
15896: $changes{'curr'}{$balancer}{'targets'} = 1;
15897: }
1.150 raeburn 15898: }
15899: }
1.160.6.7 raeburn 15900: }
1.150 raeburn 15901: }
15902: my $ishomedom;
1.160.6.7 raeburn 15903: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
15904: $ishomedom = 1;
1.150 raeburn 15905: }
15906: if (ref($alltypes) eq 'ARRAY') {
15907: foreach my $type (@{$alltypes}) {
15908: my $rule;
1.160.6.7 raeburn 15909: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 15910: (!$ishomedom)) {
1.160.6.7 raeburn 15911: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
15912: }
15913: if ($rule eq 'specific') {
1.160.6.55 raeburn 15914: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
15915: if (exists($servers{$specifiedhost})) {
15916: $rule = $specifiedhost;
15917: }
1.150 raeburn 15918: }
1.160.6.7 raeburn 15919: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
15920: if (ref($currrules{$balancer}) eq 'HASH') {
15921: if ($rule ne $currrules{$balancer}{$type}) {
15922: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 15923: }
15924: } elsif ($rule ne '') {
1.160.6.7 raeburn 15925: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 15926: }
15927: }
15928: }
1.160.6.7 raeburn 15929: }
15930: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
15931: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
15932: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
15933: $defaultshash{'loadbalancing'} = {};
15934: }
15935: my $putresult = &Apache::lonnet::put_dom('configuration',
15936: \%defaultshash,$dom);
15937: if ($putresult eq 'ok') {
15938: if (keys(%changes) > 0) {
1.160.6.54 raeburn 15939: my %toupdate;
1.160.6.7 raeburn 15940: if (ref($changes{'delete'}) eq 'ARRAY') {
15941: foreach my $balancer (sort(@{$changes{'delete'}})) {
15942: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 15943: $toupdate{$balancer} = 1;
1.150 raeburn 15944: }
1.160.6.7 raeburn 15945: }
15946: if (ref($changes{'add'}) eq 'ARRAY') {
15947: foreach my $balancer (sort(@{$changes{'add'}})) {
15948: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 15949: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 15950: }
15951: }
15952: if (ref($changes{'curr'}) eq 'HASH') {
15953: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 15954: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 15955: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
15956: if ($changes{'curr'}{$balancer}{'targets'}) {
15957: my %offloadstr;
15958: foreach my $sparetype (@sparestypes) {
15959: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15960: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
15961: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
15962: }
15963: }
1.150 raeburn 15964: }
1.160.6.7 raeburn 15965: if (keys(%offloadstr) == 0) {
15966: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 15967: } else {
1.160.6.7 raeburn 15968: my $showoffload;
15969: foreach my $sparetype (@sparestypes) {
15970: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
15971: if (defined($offloadstr{$sparetype})) {
15972: $showoffload .= $offloadstr{$sparetype};
15973: } else {
15974: $showoffload .= &mt('None');
15975: }
15976: $showoffload .= (' 'x3);
15977: }
15978: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 15979: }
15980: }
15981: }
1.160.6.7 raeburn 15982: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
15983: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
15984: foreach my $type (@{$alltypes}) {
15985: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
15986: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
15987: my $balancetext;
15988: if ($rule eq '') {
15989: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 15990: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 15991: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
15992: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 15993: foreach my $sparetype (@sparestypes) {
15994: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15995: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
15996: }
15997: }
1.160.6.55 raeburn 15998: foreach my $item (@{$alltypes}) {
15999: next if ($item =~ /^_LC_ipchange/);
16000: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
16001: if ($hasrule eq 'homeserver') {
16002: map { $toupdate{$_} = 1; } (keys(%libraryservers));
16003: } else {
16004: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
16005: if ($servers{$hasrule}) {
16006: $toupdate{$hasrule} = 1;
16007: }
16008: }
16009: }
16010: }
16011: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
16012: $balancetext = $ruletitles{$rule};
16013: } else {
16014: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16015: $balancetext = $ruletitles{'particular'}.' '.$receiver;
16016: if ($receiver) {
16017: $toupdate{$receiver};
16018: }
16019: }
16020: } else {
16021: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 16022: }
1.160.6.7 raeburn 16023: } else {
16024: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
16025: }
1.160.6.26 raeburn 16026: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 16027: }
16028: }
16029: }
16030: }
1.160.6.94 raeburn 16031: if ($changes{'curr'}{$balancer}{'cookie'}) {
16032: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
16033: $balancer).'</li>';
16034: }
1.160.6.54 raeburn 16035: if (keys(%toupdate)) {
16036: my %thismachine;
16037: my $updatedhere;
16038: my $cachetime = 60*60*24;
16039: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
16040: foreach my $lonhost (keys(%toupdate)) {
16041: if ($thismachine{$lonhost}) {
16042: unless ($updatedhere) {
16043: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
16044: $defaultshash{'loadbalancing'},
16045: $cachetime);
16046: $updatedhere = 1;
16047: }
16048: } else {
16049: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
16050: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
16051: }
16052: }
16053: }
1.150 raeburn 16054: }
1.160.6.7 raeburn 16055: }
16056: if ($resulttext ne '') {
16057: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 16058: } else {
16059: $resulttext = $nochgmsg;
16060: }
16061: } else {
1.160.6.7 raeburn 16062: $resulttext = $nochgmsg;
1.150 raeburn 16063: }
16064: } else {
1.160.6.7 raeburn 16065: $resulttext = '<span class="LC_error">'.
16066: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 16067: }
16068: } else {
1.160.6.7 raeburn 16069: $resulttext = $nochgmsg;
1.150 raeburn 16070: }
16071: return $resulttext;
16072: }
16073:
1.48 raeburn 16074: sub recurse_check {
16075: my ($chkcats,$categories,$depth,$name) = @_;
16076: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
16077: my $chg = 0;
16078: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
16079: my $category = $chkcats->[$depth]{$name}[$j];
16080: my $item;
16081: if ($category eq '') {
16082: $chg ++;
16083: } else {
16084: my $deeper = $depth + 1;
16085: $item = &escape($category).':'.&escape($name).':'.$depth;
16086: if ($chg) {
16087: $categories->{$item} -= $chg;
16088: }
16089: &recurse_check($chkcats,$categories,$deeper,$category);
16090: $deeper --;
16091: }
16092: }
16093: }
16094: return;
16095: }
16096:
16097: sub recurse_cat_deletes {
16098: my ($item,$coursecategories,$deletions) = @_;
16099: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16100: my $subdepth = $depth + 1;
16101: if (ref($coursecategories) eq 'HASH') {
16102: foreach my $subitem (keys(%{$coursecategories})) {
16103: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
16104: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
16105: delete($coursecategories->{$subitem});
16106: $deletions->{$subitem} = 1;
16107: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 16108: }
1.48 raeburn 16109: }
16110: }
16111: return;
16112: }
16113:
1.125 raeburn 16114: sub active_dc_picker {
1.160.6.16 raeburn 16115: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 16116: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 16117: my @domcoord = keys(%domcoords);
16118: if (keys(%currhash)) {
16119: foreach my $dc (keys(%currhash)) {
16120: unless (exists($domcoords{$dc})) {
16121: push(@domcoord,$dc);
16122: }
16123: }
16124: }
16125: @domcoord = sort(@domcoord);
16126: my $numdcs = scalar(@domcoord);
16127: my $rows = 0;
16128: my $table;
1.125 raeburn 16129: if ($numdcs > 1) {
1.160.6.16 raeburn 16130: $table = '<table>';
16131: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 16132: my $rem = $i%($numinrow);
16133: if ($rem == 0) {
16134: if ($i > 0) {
1.160.6.16 raeburn 16135: $table .= '</tr>';
1.125 raeburn 16136: }
1.160.6.16 raeburn 16137: $table .= '<tr>';
16138: $rows ++;
1.125 raeburn 16139: }
1.160.6.16 raeburn 16140: my $check = '';
16141: if ($inputtype eq 'radio') {
16142: if (keys(%currhash) == 0) {
16143: if (!$i) {
16144: $check = ' checked="checked"';
16145: }
16146: } elsif (exists($currhash{$domcoord[$i]})) {
16147: $check = ' checked="checked"';
16148: }
16149: } else {
16150: if (exists($currhash{$domcoord[$i]})) {
16151: $check = ' checked="checked"';
1.125 raeburn 16152: }
16153: }
1.160.6.16 raeburn 16154: if ($i == @domcoord - 1) {
1.125 raeburn 16155: my $colsleft = $numinrow - $rem;
16156: if ($colsleft > 1) {
1.160.6.16 raeburn 16157: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 16158: } else {
1.160.6.16 raeburn 16159: $table .= '<td class="LC_left_item">';
1.125 raeburn 16160: }
16161: } else {
1.160.6.16 raeburn 16162: $table .= '<td class="LC_left_item">';
16163: }
16164: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
16165: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
16166: $table .= '<span class="LC_nobreak"><label>'.
16167: '<input type="'.$inputtype.'" name="'.$name.'"'.
16168: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
16169: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 16170: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 16171: }
1.160.6.33 raeburn 16172: $table .= '</label></span></td>';
1.125 raeburn 16173: }
1.160.6.16 raeburn 16174: $table .= '</tr></table>';
16175: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 16176: my ($dcname,$dcdom) = split(':',$domcoord[0]);
16177: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 16178: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 16179: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 16180: if ($user ne $dcname.':'.$dcdom) {
16181: $table .= ' ('.$dcname.':'.$dcdom.')';
16182: }
1.160.6.16 raeburn 16183: } else {
16184: my $check;
16185: if (exists($currhash{$domcoord[0]})) {
16186: $check = ' checked="checked"';
16187: }
1.160.6.50 raeburn 16188: $table = '<span class="LC_nobreak"><label>'.
16189: '<input type="checkbox" name="'.$name.'" '.
16190: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 16191: if ($user ne $dcname.':'.$dcdom) {
16192: $table .= ' ('.$dcname.':'.$dcdom.')';
16193: }
16194: $table .= '</label></span>';
1.160.6.16 raeburn 16195: $rows ++;
16196: }
1.125 raeburn 16197: }
1.160.6.16 raeburn 16198: return ($numdcs,$table,$rows);
1.125 raeburn 16199: }
16200:
1.137 raeburn 16201: sub usersession_titles {
16202: return &Apache::lonlocal::texthash(
16203: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
16204: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 16205: spares => 'Servers offloaded to, when busy',
1.137 raeburn 16206: version => 'LON-CAPA version requirement',
1.138 raeburn 16207: excludedomain => 'Allow all, but exclude specific domains',
16208: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 16209: primary => 'Primary (checked first)',
1.154 raeburn 16210: default => 'Default',
1.137 raeburn 16211: );
16212: }
16213:
1.152 raeburn 16214: sub id_for_thisdom {
16215: my (%servers) = @_;
16216: my %altids;
16217: foreach my $server (keys(%servers)) {
16218: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
16219: if ($serverhome ne $server) {
16220: $altids{$serverhome} = $server;
16221: }
16222: }
16223: return %altids;
16224: }
16225:
1.150 raeburn 16226: sub count_servers {
16227: my ($currbalancer,%servers) = @_;
16228: my (@spares,$numspares);
16229: foreach my $lonhost (sort(keys(%servers))) {
16230: next if ($currbalancer eq $lonhost);
16231: push(@spares,$lonhost);
16232: }
16233: if ($currbalancer) {
16234: $numspares = scalar(@spares);
16235: } else {
16236: $numspares = scalar(@spares) - 1;
16237: }
16238: return ($numspares,@spares);
16239: }
16240:
16241: sub lonbalance_targets_js {
1.160.6.7 raeburn 16242: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 16243: my $select = &mt('Select');
16244: my ($alltargets,$allishome,$allinsttypes,@alltypes);
16245: if (ref($servers) eq 'HASH') {
16246: $alltargets = join("','",sort(keys(%{$servers})));
16247: my @homedoms;
16248: foreach my $server (sort(keys(%{$servers}))) {
16249: if (&Apache::lonnet::host_domain($server) eq $dom) {
16250: push(@homedoms,'1');
16251: } else {
16252: push(@homedoms,'0');
16253: }
16254: }
16255: $allishome = join("','",@homedoms);
16256: }
16257: if (ref($types) eq 'ARRAY') {
16258: if (@{$types} > 0) {
16259: @alltypes = @{$types};
16260: }
16261: }
16262: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
16263: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 16264: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 16265: if (ref($settings) eq 'HASH') {
16266: %existing = %{$settings};
16267: }
16268: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 16269: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 16270: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 16271: return <<"END";
16272:
16273: <script type="text/javascript">
16274: // <![CDATA[
16275:
1.160.6.7 raeburn 16276: currBalancers = new Array('$balancers');
16277:
16278: function toggleTargets(balnum) {
16279: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
16280: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
16281: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
16282: var prevbalancer = prevhostitem.value;
16283: var baltotal = document.getElementById('loadbalancing_total').value;
16284: prevhostitem.value = balancer;
16285: if (prevbalancer != '') {
16286: var prevIdx = currBalancers.indexOf(prevbalancer);
16287: if (prevIdx != -1) {
16288: currBalancers.splice(prevIdx,1);
16289: }
16290: }
1.150 raeburn 16291: if (balancer == '') {
1.160.6.7 raeburn 16292: hideSpares(balnum);
1.150 raeburn 16293: } else {
1.160.6.7 raeburn 16294: var currIdx = currBalancers.indexOf(balancer);
16295: if (currIdx == -1) {
16296: currBalancers.push(balancer);
16297: }
1.150 raeburn 16298: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 16299: var ishomedom = homedoms[lonhostitem.selectedIndex];
16300: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 16301: }
1.160.6.7 raeburn 16302: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 16303: return;
16304: }
16305:
1.160.6.7 raeburn 16306: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 16307: var alltargets = new Array('$alltargets');
16308: var insttypes = new Array('$allinsttypes');
1.151 raeburn 16309: var offloadtypes = new Array('primary','default');
16310:
1.160.6.7 raeburn 16311: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
16312: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 16313:
1.151 raeburn 16314: for (var i=0; i<offloadtypes.length; i++) {
16315: var count = 0;
16316: for (var j=0; j<alltargets.length; j++) {
16317: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 16318: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
16319: item.value = alltargets[j];
16320: item.style.textAlign='left';
16321: item.style.textFace='normal';
16322: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
16323: if (currBalancers.indexOf(alltargets[j]) == -1) {
16324: item.disabled = '';
16325: } else {
16326: item.disabled = 'disabled';
16327: item.checked = false;
16328: }
1.151 raeburn 16329: count ++;
16330: }
1.150 raeburn 16331: }
16332: }
1.151 raeburn 16333: for (var k=0; k<insttypes.length; k++) {
16334: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 16335: if (ishomedom == 1) {
1.160.6.7 raeburn 16336: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
16337: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 16338: } else {
1.160.6.7 raeburn 16339: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
16340: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 16341: }
16342: } else {
1.160.6.7 raeburn 16343: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
16344: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 16345: }
1.151 raeburn 16346: if ((insttypes[k] != '_LC_external') &&
16347: ((insttypes[k] != '_LC_internetdom') ||
16348: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 16349: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
16350: item.options.length = 0;
16351: item.options[0] = new Option("","",true,true);
16352: var idx = 0;
1.151 raeburn 16353: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 16354: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
16355: idx ++;
16356: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 16357: }
16358: }
16359: }
16360: }
16361: return;
16362: }
16363:
1.160.6.7 raeburn 16364: function hideSpares(balnum) {
1.150 raeburn 16365: var alltargets = new Array('$alltargets');
16366: var insttypes = new Array('$allinsttypes');
16367: var offloadtypes = new Array('primary','default');
16368:
1.160.6.7 raeburn 16369: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
16370: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 16371:
16372: var total = alltargets.length - 1;
16373: for (var i=0; i<offloadtypes; i++) {
16374: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 16375: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
16376: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
16377: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 16378: }
1.150 raeburn 16379: }
16380: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 16381: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
16382: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 16383: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 16384: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
16385: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 16386: }
16387: }
16388: return;
16389: }
16390:
1.160.6.7 raeburn 16391: function checkOffloads(item,balnum,type) {
1.150 raeburn 16392: var alltargets = new Array('$alltargets');
16393: var offloadtypes = new Array('primary','default');
16394: if (item.checked) {
16395: var total = alltargets.length - 1;
16396: var other;
16397: if (type == offloadtypes[0]) {
1.151 raeburn 16398: other = offloadtypes[1];
1.150 raeburn 16399: } else {
1.151 raeburn 16400: other = offloadtypes[0];
1.150 raeburn 16401: }
16402: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 16403: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 16404: if (server == item.value) {
1.160.6.7 raeburn 16405: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
16406: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 16407: }
16408: }
16409: }
16410: }
16411: return;
16412: }
16413:
1.160.6.7 raeburn 16414: function singleServerToggle(balnum,type) {
16415: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 16416: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 16417: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
16418: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 16419:
16420: } else {
1.160.6.7 raeburn 16421: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
16422: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 16423: }
16424: return;
16425: }
16426:
1.160.6.7 raeburn 16427: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 16428: if (type == '_LC_external') {
1.160.6.26 raeburn 16429: return;
1.150 raeburn 16430: }
1.160.6.7 raeburn 16431: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 16432: for (var i=0; i<typesRules.length; i++) {
16433: if (formname.elements[typesRules[i]].checked) {
16434: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 16435: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
16436: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 16437: } else {
1.160.6.7 raeburn 16438: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
16439: }
16440: }
16441: }
16442: return;
16443: }
16444:
16445: function balancerDeleteChange(balnum) {
16446: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
16447: var baltotal = document.getElementById('loadbalancing_total').value;
16448: var addtarget;
16449: var removetarget;
16450: var action = 'delete';
16451: if (document.getElementById('loadbalancing_delete_'+balnum)) {
16452: var lonhost = hostitem.value;
16453: var currIdx = currBalancers.indexOf(lonhost);
16454: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
16455: if (currIdx != -1) {
16456: currBalancers.splice(currIdx,1);
16457: }
16458: addtarget = lonhost;
16459: } else {
16460: if (currIdx == -1) {
16461: currBalancers.push(lonhost);
16462: }
16463: removetarget = lonhost;
16464: action = 'undelete';
16465: }
16466: balancerChange(balnum,baltotal,action,addtarget,removetarget);
16467: }
16468: return;
16469: }
16470:
16471: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
16472: if (baltotal > 1) {
16473: var offloadtypes = new Array('primary','default');
16474: var alltargets = new Array('$alltargets');
16475: var insttypes = new Array('$allinsttypes');
16476: for (var i=0; i<baltotal; i++) {
16477: if (i != balnum) {
16478: for (var j=0; j<offloadtypes.length; j++) {
16479: var total = alltargets.length - 1;
16480: for (var k=0; k<total; k++) {
16481: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
16482: var server = serveritem.value;
16483: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16484: if (server == addtarget) {
16485: serveritem.disabled = '';
16486: }
16487: }
16488: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16489: if (server == removetarget) {
16490: serveritem.disabled = 'disabled';
16491: serveritem.checked = false;
16492: }
16493: }
16494: }
16495: }
16496: for (var j=0; j<insttypes.length; j++) {
16497: if (insttypes[j] != '_LC_external') {
16498: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
16499: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
16500: var currSel = singleserver.selectedIndex;
16501: var currVal = singleserver.options[currSel].value;
16502: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16503: var numoptions = singleserver.options.length;
16504: var needsnew = 1;
16505: for (var k=0; k<numoptions; k++) {
16506: if (singleserver.options[k] == addtarget) {
16507: needsnew = 0;
16508: break;
16509: }
16510: }
16511: if (needsnew == 1) {
16512: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
16513: }
16514: }
16515: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16516: singleserver.options.length = 0;
16517: if ((currVal) && (currVal != removetarget)) {
16518: singleserver.options[0] = new Option("","",false,false);
16519: } else {
16520: singleserver.options[0] = new Option("","",true,true);
16521: }
16522: var idx = 0;
16523: for (var m=0; m<alltargets.length; m++) {
16524: if (currBalancers.indexOf(alltargets[m]) == -1) {
16525: idx ++;
16526: if (currVal == alltargets[m]) {
16527: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
16528: } else {
16529: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
16530: }
16531: }
16532: }
16533: }
16534: }
16535: }
16536: }
1.150 raeburn 16537: }
16538: }
16539: }
16540: return;
16541: }
16542:
1.152 raeburn 16543: // ]]>
16544: </script>
16545:
16546: END
16547: }
16548:
16549: sub new_spares_js {
16550: my @sparestypes = ('primary','default');
16551: my $types = join("','",@sparestypes);
16552: my $select = &mt('Select');
16553: return <<"END";
16554:
16555: <script type="text/javascript">
16556: // <![CDATA[
16557:
16558: function updateNewSpares(formname,lonhost) {
16559: var types = new Array('$types');
16560: var include = new Array();
16561: var exclude = new Array();
16562: for (var i=0; i<types.length; i++) {
16563: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
16564: for (var j=0; j<spareboxes.length; j++) {
16565: if (formname.elements[spareboxes[j]].checked) {
16566: exclude.push(formname.elements[spareboxes[j]].value);
16567: } else {
16568: include.push(formname.elements[spareboxes[j]].value);
16569: }
16570: }
16571: }
16572: for (var i=0; i<types.length; i++) {
16573: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
16574: var selIdx = newSpare.selectedIndex;
16575: var currnew = newSpare.options[selIdx].value;
16576: var okSpares = new Array();
16577: for (var j=0; j<newSpare.options.length; j++) {
16578: var possible = newSpare.options[j].value;
16579: if (possible != '') {
16580: if (exclude.indexOf(possible) == -1) {
16581: okSpares.push(possible);
16582: } else {
16583: if (currnew == possible) {
16584: selIdx = 0;
16585: }
16586: }
16587: }
16588: }
16589: for (var k=0; k<include.length; k++) {
16590: if (okSpares.indexOf(include[k]) == -1) {
16591: okSpares.push(include[k]);
16592: }
16593: }
16594: okSpares.sort();
16595: newSpare.options.length = 0;
16596: if (selIdx == 0) {
16597: newSpare.options[0] = new Option("$select","",true,true);
16598: } else {
16599: newSpare.options[0] = new Option("$select","",false,false);
16600: }
16601: for (var m=0; m<okSpares.length; m++) {
16602: var idx = m+1;
16603: var selThis = 0;
16604: if (selIdx != 0) {
16605: if (okSpares[m] == currnew) {
16606: selThis = 1;
16607: }
16608: }
16609: if (selThis == 1) {
16610: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
16611: } else {
16612: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
16613: }
16614: }
16615: }
16616: return;
16617: }
16618:
16619: function checkNewSpares(lonhost,type) {
16620: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
16621: var chosen = newSpare.options[newSpare.selectedIndex].value;
16622: if (chosen != '') {
16623: var othertype;
16624: var othernewSpare;
16625: if (type == 'primary') {
16626: othernewSpare = document.getElementById('newspare_default_'+lonhost);
16627: }
16628: if (type == 'default') {
16629: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
16630: }
16631: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
16632: othernewSpare.selectedIndex = 0;
16633: }
16634: }
16635: return;
16636: }
16637:
16638: // ]]>
16639: </script>
16640:
16641: END
16642:
16643: }
16644:
16645: sub common_domprefs_js {
16646: return <<"END";
16647:
16648: <script type="text/javascript">
16649: // <![CDATA[
16650:
1.150 raeburn 16651: function getIndicesByName(formname,item) {
1.152 raeburn 16652: var group = new Array();
1.150 raeburn 16653: for (var i=0;i<formname.elements.length;i++) {
16654: if (formname.elements[i].name == item) {
1.152 raeburn 16655: group.push(formname.elements[i].id);
1.150 raeburn 16656: }
16657: }
1.152 raeburn 16658: return group;
1.150 raeburn 16659: }
16660:
16661: // ]]>
16662: </script>
16663:
16664: END
1.152 raeburn 16665:
1.150 raeburn 16666: }
16667:
1.160.6.5 raeburn 16668: sub recaptcha_js {
16669: my %lt = &captcha_phrases();
16670: return <<"END";
16671:
16672: <script type="text/javascript">
16673: // <![CDATA[
16674:
16675: function updateCaptcha(caller,context) {
16676: var privitem;
16677: var pubitem;
16678: var privtext;
16679: var pubtext;
1.160.6.69 raeburn 16680: var versionitem;
16681: var versiontext;
1.160.6.5 raeburn 16682: if (document.getElementById(context+'_recaptchapub')) {
16683: pubitem = document.getElementById(context+'_recaptchapub');
16684: } else {
16685: return;
16686: }
16687: if (document.getElementById(context+'_recaptchapriv')) {
16688: privitem = document.getElementById(context+'_recaptchapriv');
16689: } else {
16690: return;
16691: }
16692: if (document.getElementById(context+'_recaptchapubtxt')) {
16693: pubtext = document.getElementById(context+'_recaptchapubtxt');
16694: } else {
16695: return;
16696: }
16697: if (document.getElementById(context+'_recaptchaprivtxt')) {
16698: privtext = document.getElementById(context+'_recaptchaprivtxt');
16699: } else {
16700: return;
16701: }
1.160.6.69 raeburn 16702: if (document.getElementById(context+'_recaptchaversion')) {
16703: versionitem = document.getElementById(context+'_recaptchaversion');
16704: } else {
16705: return;
16706: }
16707: if (document.getElementById(context+'_recaptchavertxt')) {
16708: versiontext = document.getElementById(context+'_recaptchavertxt');
16709: } else {
16710: return;
16711: }
1.160.6.5 raeburn 16712: if (caller.checked) {
16713: if (caller.value == 'recaptcha') {
16714: pubitem.type = 'text';
16715: privitem.type = 'text';
16716: pubitem.size = '40';
16717: privitem.size = '40';
16718: pubtext.innerHTML = "$lt{'pub'}";
16719: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 16720: versionitem.type = 'text';
16721: versionitem.size = '3';
16722: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 16723: } else {
16724: pubitem.type = 'hidden';
16725: privitem.type = 'hidden';
1.160.6.69 raeburn 16726: versionitem.type = 'hidden';
1.160.6.5 raeburn 16727: pubtext.innerHTML = '';
16728: privtext.innerHTML = '';
1.160.6.69 raeburn 16729: versiontext.innerHTML = '';
1.160.6.5 raeburn 16730: }
16731: }
16732: return;
16733: }
16734:
16735: // ]]>
16736: </script>
16737:
16738: END
16739:
16740: }
16741:
1.160.6.40 raeburn 16742: sub toggle_display_js {
1.160.6.16 raeburn 16743: return <<"END";
16744:
16745: <script type="text/javascript">
16746: // <![CDATA[
16747:
1.160.6.40 raeburn 16748: function toggleDisplay(domForm,caller) {
16749: if (document.getElementById(caller)) {
16750: var divitem = document.getElementById(caller);
16751: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 16752: var checkval = 1;
16753: var dispval = 'block';
1.160.6.93 raeburn 16754: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 16755: if (caller == 'emailoptions') {
16756: optionsElement = domForm.cancreate_email;
16757: }
1.160.6.57 raeburn 16758: if (caller == 'studentsubmission') {
16759: optionsElement = domForm.postsubmit;
16760: }
1.160.6.64 raeburn 16761: if (caller == 'cloneinstcode') {
16762: optionsElement = domForm.canclone;
16763: checkval = 'instcode';
16764: }
1.160.6.93 raeburn 16765: if (selfcreateRegExp.test(caller)) {
16766: optionsElement = domForm.elements[caller];
16767: checkval = 'other';
16768: dispval = 'inline'
16769: }
1.160.6.40 raeburn 16770: if (optionsElement.length) {
1.160.6.16 raeburn 16771: var currval;
1.160.6.40 raeburn 16772: for (var i=0; i<optionsElement.length; i++) {
16773: if (optionsElement[i].checked) {
16774: currval = optionsElement[i].value;
1.160.6.16 raeburn 16775: }
16776: }
1.160.6.64 raeburn 16777: if (currval == checkval) {
16778: divitem.style.display = dispval;
1.160.6.16 raeburn 16779: } else {
1.160.6.40 raeburn 16780: divitem.style.display = 'none';
1.160.6.16 raeburn 16781: }
16782: }
16783: }
16784: return;
16785: }
16786:
16787: // ]]>
16788: </script>
16789:
16790: END
16791:
16792: }
16793:
1.160.6.5 raeburn 16794: sub captcha_phrases {
16795: return &Apache::lonlocal::texthash (
16796: priv => 'Private key',
16797: pub => 'Public key',
16798: original => 'original (CAPTCHA)',
16799: recaptcha => 'successor (ReCAPTCHA)',
16800: notused => 'unused',
1.160.6.69 raeburn 16801: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 16802: );
16803: }
16804:
1.160.6.24 raeburn 16805: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 16806: my ($dom,$cachekeys) = @_;
16807: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 16808: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16809: my %thismachine;
16810: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.98 raeburn 16811: my @posscached = ('domainconfig','domdefaults','usersessions',
1.160.6.102.2 1(raebur 16812:0): 'ltitools','directorysrch','passwdconf','cats');
1.160.6.61 raeburn 16813: if (keys(%servers)) {
1.160.6.24 raeburn 16814: foreach my $server (keys(%servers)) {
16815: next if ($thismachine{$server});
1.160.6.27 raeburn 16816: my @cached;
16817: foreach my $name (@posscached) {
16818: if ($cachekeys->{$name}) {
16819: push(@cached,&escape($name).':'.&escape($dom));
16820: }
16821: }
16822: if (@cached) {
16823: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
16824: }
1.160.6.24 raeburn 16825: }
16826: }
16827: return;
16828: }
16829:
1.3 raeburn 16830: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>