Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.102.2.9
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.102.2 9(raebur 4:1): # $Id: domainprefs.pm,v 1.160.6.102.2.8 2021/02/01 16:26:54 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',},
1.160.6.102.2 7(raebur 352:1): {col1 => 'Nightly status check e-mail',
353:1): col2 => 'Settings',},
1.160.6.78 raeburn 354: {col1 => 'Ask helpdesk form settings',
355: col2 => 'Value',},],
1.160.6.37 raeburn 356: print => \&print_contacts,
357: modify => \&modify_contacts,
1.30 raeburn 358: },
359: 'usercreation' =>
360: { text => 'User creation',
1.67 raeburn 361: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 362: header => [{col1 => 'Format rule type',
363: col2 => 'Format rules in force'},
1.34 raeburn 364: {col1 => 'User account creation',
365: col2 => 'Usernames which may be created',},
1.30 raeburn 366: {col1 => 'Context',
1.43 raeburn 367: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 368: print => \&print_usercreation,
369: modify => \&modify_usercreation,
1.30 raeburn 370: },
1.160.6.34 raeburn 371: 'selfcreation' =>
372: { text => 'Users self-creating accounts',
373: help => 'Domain_Configuration_Self_Creation',
374: header => [{col1 => 'Self-creation with institutional username',
375: col2 => 'Enabled?'},
376: {col1 => 'Institutional user type (login/SSO self-creation)',
377: col2 => 'Information user can enter'},
1.160.6.93 raeburn 378: {col1 => 'Self-creation with e-mail verification',
1.160.6.34 raeburn 379: col2 => 'Settings'}],
1.160.6.37 raeburn 380: print => \&print_selfcreation,
381: modify => \&modify_selfcreation,
1.160.6.34 raeburn 382: },
1.69 raeburn 383: 'usermodification' =>
1.33 raeburn 384: { text => 'User modification',
1.67 raeburn 385: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 386: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 387: col2 => 'User information updatable in author context'},
1.33 raeburn 388: {col1 => 'Target user has role',
1.160.6.35 raeburn 389: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 390: print => \&print_usermodification,
391: modify => \&modify_usermodification,
1.33 raeburn 392: },
1.69 raeburn 393: 'scantron' =>
1.160.6.97 raeburn 394: { text => 'Bubblesheet format',
1.67 raeburn 395: help => 'Domain_Configuration_Scantron_Format',
1.160.6.97 raeburn 396: header => [ {col1 => 'Bubblesheet format file',
397: col2 => ''},
398: {col1 => 'Bubblesheet data upload formats',
399: col2 => 'Settings'}],
1.160.6.37 raeburn 400: print => \&print_scantron,
401: modify => \&modify_scantron,
1.46 raeburn 402: },
1.86 raeburn 403: 'requestcourses' =>
404: {text => 'Request creation of courses',
405: help => 'Domain_Configuration_Request_Courses',
406: header => [{col1 => 'User affiliation',
1.102 raeburn 407: col2 => 'Availability/Processing of requests',},
408: {col1 => 'Setting',
1.160.6.30 raeburn 409: col2 => 'Value'},
410: {col1 => 'Available textbooks',
1.160.6.39 raeburn 411: col2 => ''},
1.160.6.46 raeburn 412: {col1 => 'Available templates',
413: col2 => ''},
1.160.6.39 raeburn 414: {col1 => 'Validation (not official courses)',
415: col2 => 'Value'},],
1.160.6.37 raeburn 416: print => \&print_quotas,
417: modify => \&modify_quotas,
1.86 raeburn 418: },
1.160.6.5 raeburn 419: 'requestauthor' =>
1.160.6.34 raeburn 420: {text => 'Request Authoring Space',
1.160.6.5 raeburn 421: help => 'Domain_Configuration_Request_Author',
422: header => [{col1 => 'User affiliation',
423: col2 => 'Availability/Processing of requests',},
424: {col1 => 'Setting',
425: col2 => 'Value'}],
1.160.6.37 raeburn 426: print => \&print_quotas,
427: modify => \&modify_quotas,
1.160.6.5 raeburn 428: },
1.69 raeburn 429: 'coursecategories' =>
1.120 raeburn 430: { text => 'Cataloging of courses/communities',
1.67 raeburn 431: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 432: header => [{col1 => 'Catalog type/availability',
433: col2 => '',},
434: {col1 => 'Category settings for standard catalog',
1.57 raeburn 435: col2 => '',},
436: {col1 => 'Categories',
437: col2 => '',
438: }],
1.160.6.37 raeburn 439: print => \&print_coursecategories,
440: modify => \&modify_coursecategories,
1.69 raeburn 441: },
442: 'serverstatuses' =>
1.77 raeburn 443: {text => 'Access to server status pages',
1.69 raeburn 444: help => 'Domain_Configuration_Server_Status',
445: header => [{col1 => 'Status Page',
446: col2 => 'Other named users',
447: col3 => 'Specific IPs',
448: }],
1.160.6.37 raeburn 449: print => \&print_serverstatuses,
450: modify => \&modify_serverstatuses,
1.69 raeburn 451: },
1.160.6.73 raeburn 452: 'helpsettings' =>
453: {text => 'Support settings',
454: help => 'Domain_Configuration_Help_Settings',
455: header => [{col1 => 'Help Page Settings (logged-in users)',
456: col2 => 'Value'},
457: {col1 => 'Helpdesk Roles',
458: col2 => 'Settings'},],
459: print => \&print_helpsettings,
460: modify => \&modify_helpsettings,
461: },
1.160.6.39 raeburn 462: 'coursedefaults' =>
1.160.6.16 raeburn 463: {text => 'Course/Community defaults',
464: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 465: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
466: col2 => 'Value',},
467: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 468: col2 => 'Value',},],
1.160.6.37 raeburn 469: print => \&print_coursedefaults,
470: modify => \&modify_coursedefaults,
471: },
1.160.6.39 raeburn 472: 'selfenrollment' =>
1.160.6.37 raeburn 473: {text => 'Self-enrollment in Course/Community',
474: help => 'Domain_Configuration_Selfenrollment',
475: header => [{col1 => 'Configuration Rights',
476: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
477: {col1 => 'Defaults',
478: col2 => 'Value'},
479: {col1 => 'Self-enrollment validation (optional)',
480: col2 => 'Value'},],
481: print => \&print_selfenrollment,
482: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 483: },
1.141 raeburn 484: 'usersessions' =>
1.145 raeburn 485: {text => 'User session hosting/offloading',
1.137 raeburn 486: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 487: header => [{col1 => 'Domain server',
488: col2 => 'Servers to offload sessions to when busy'},
489: {col1 => 'Hosting of users from other domains',
1.137 raeburn 490: col2 => 'Rules'},
491: {col1 => "Hosting domain's own users elsewhere",
492: col2 => 'Rules'}],
1.160.6.37 raeburn 493: print => \&print_usersessions,
494: modify => \&modify_usersessions,
1.137 raeburn 495: },
1.160.6.78 raeburn 496: 'loadbalancing' =>
1.160.6.7 raeburn 497: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 498: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 499: header => [{col1 => 'Balancers',
1.150 raeburn 500: col2 => 'Default destinations',
1.160.6.13 raeburn 501: col3 => 'User affiliation',
1.150 raeburn 502: col4 => 'Overrides'},
503: ],
1.160.6.37 raeburn 504: print => \&print_loadbalancing,
505: modify => \&modify_loadbalancing,
1.150 raeburn 506: },
1.160.6.102.2 1(raebur 507:0): 'ltitools' =>
508:0): {text => 'External Tools (LTI)',
509:0): help => 'Domain_Configuration_LTI_Tools',
510:0): header => [{col1 => 'Setting',
511:0): col2 => 'Value',}],
512:0): print => \&print_ltitools,
513:0): modify => \&modify_ltitools,
514:0): },
1.3 raeburn 515: );
1.110 raeburn 516: if (keys(%servers) > 1) {
517: $prefs{'login'} = { text => 'Log-in page options',
518: help => 'Domain_Configuration_Login_Page',
519: header => [{col1 => 'Log-in Service',
520: col2 => 'Server Setting',},
521: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 522: col2 => ''},
523: {col1 => 'Log-in Help',
1.160.6.56 raeburn 524: col2 => 'Value'},
525: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 526: col2 => 'Value'}],
1.160.6.37 raeburn 527: print => \&print_login,
528: modify => \&modify_login,
1.110 raeburn 529: };
530: }
1.160.6.13 raeburn 531:
1.6 raeburn 532: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 533: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 534: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 535: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 536: text=>"Settings to display/modify"});
1.9 raeburn 537: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 538:
1.3 raeburn 539: if ($phase eq 'process') {
1.160.6.27 raeburn 540: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
541: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 542: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 543: $r->rflush();
1.160.6.27 raeburn 544: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 545: }
1.30 raeburn 546: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 547: my $js = &recaptcha_js().
1.160.6.40 raeburn 548: &toggle_display_js();
1.160.6.7 raeburn 549: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 550: my ($othertitle,$usertypes,$types) =
551: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 552: $js .= &lonbalance_targets_js($dom,$types,\%servers,
553: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 554: &new_spares_js().
555: &common_domprefs_js().
556: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 557: }
1.160.6.30 raeburn 558: if (grep(/^requestcourses$/,@actions)) {
559: my $javascript_validations;
560: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
561: $js .= <<END;
562: <script type="text/javascript">
563: $javascript_validations
564: </script>
565: $coursebrowserjs
566: END
567: }
1.160.6.93 raeburn 568: if (grep(/^selfcreation$/,@actions)) {
569: $js .= &selfcreate_javascript();
570: }
1.160.6.78 raeburn 571: if (grep(/^contacts$/,@actions)) {
572: $js .= &contacts_javascript();
573: }
1.160.6.97 raeburn 574: if (grep(/^scantron$/,@actions)) {
575: $js .= &scantron_javascript();
576: }
1.150 raeburn 577: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 578: } else {
1.160.6.11 raeburn 579: # check if domconfig user exists for the domain.
580: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 581: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 582: &config_check($dom,$confname,$servadm);
583: unless ($configuserok eq 'ok') {
584: &Apache::lonconfigsettings::print_header($r,$phase,$context);
585: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
586: $confname).
587: '<br />'
588: );
589: if ($switchserver) {
590: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
591: '<br />'.
592: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
593: '<br />'.
594: &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).
595: '<br />'.
596: &mt('To do that now, use the following link: [_1]',$switchserver)
597: );
598: } else {
599: $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.').
600: '<br />'.
601: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
602: );
603: }
604: $r->print(&Apache::loncommon::end_page());
605: return OK;
606: }
1.21 raeburn 607: if (keys(%domconfig) == 0) {
608: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 609: my @ids=&Apache::lonnet::current_machine_ids();
610: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 611: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 612: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 613: my $custom_img_count = 0;
614: foreach my $img (@loginimages) {
615: if ($designhash{$dom.'.login.'.$img} ne '') {
616: $custom_img_count ++;
617: }
618: }
619: foreach my $role (@roles) {
620: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
621: $custom_img_count ++;
622: }
623: }
624: if ($custom_img_count > 0) {
1.94 raeburn 625: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 626: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 627: $r->print(
628: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
629: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
630: &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 />'.
631: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
632: if ($switch_server) {
1.30 raeburn 633: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 634: }
1.91 raeburn 635: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 636: return OK;
637: }
638: }
639: }
1.91 raeburn 640: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 641: }
642: return OK;
643: }
644:
645: sub process_changes {
1.160.6.24 raeburn 646: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 647: my %domconfig;
648: if (ref($values) eq 'HASH') {
649: %domconfig = %{$values};
650: }
1.3 raeburn 651: my $output;
652: if ($action eq 'login') {
1.160.6.24 raeburn 653: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 654: } elsif ($action eq 'rolecolors') {
1.9 raeburn 655: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 656: $lastactref,%domconfig);
1.3 raeburn 657: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 658: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 659: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 660: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 661: } elsif ($action eq 'autoupdate') {
662: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 663: } elsif ($action eq 'autocreate') {
664: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 665: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 666: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 667: } elsif ($action eq 'usercreation') {
1.28 raeburn 668: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 669: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 670: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 671: } elsif ($action eq 'usermodification') {
672: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 673: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 674: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 675: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 676: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 677: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 678: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 679: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 680: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 681: } elsif ($action eq 'serverstatuses') {
682: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 683: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 684: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 685: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 686: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 687: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 688: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 689: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 690: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 691: } elsif ($action eq 'selfenrollment') {
692: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 693: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 694: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 695: } elsif ($action eq 'loadbalancing') {
696: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.98 raeburn 697: } elsif ($action eq 'passwords') {
698: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.102.2 1(raebur 699:0): } elsif ($action eq 'ltitools') {
700:0): $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 701: }
702: return $output;
703: }
704:
705: sub print_config_box {
1.9 raeburn 706: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 707: my $rowtotal = 0;
1.49 raeburn 708: my $output;
709: if ($action eq 'coursecategories') {
710: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 711: } elsif ($action eq 'defaults') {
712: $output = &defaults_javascript($settings);
1.160.6.98 raeburn 713: } elsif ($action eq 'passwords') {
714: $output = &passwords_javascript();
1.160.6.73 raeburn 715: } elsif ($action eq 'helpsettings') {
716: my (%privs,%levelscurrent);
717: my %full=();
718: my %levels=(
719: course => {},
720: domain => {},
721: system => {},
722: );
723: my $context = 'domain';
724: my $crstype = 'Course';
725: my $formname = 'display';
726: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
727: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
728: $output =
729: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
730: \@templateroles);
1.160.6.102.2 5(raebur 731:0): } elsif ($action eq 'ltitools') {
732:0): $output .= <itools_javascript($settings);
1.91 raeburn 733: }
1.160.6.40 raeburn 734: $output .=
1.30 raeburn 735: '<table class="LC_nested_outer">
1.3 raeburn 736: <tr>
1.66 raeburn 737: <th align="left" valign="middle"><span class="LC_nobreak">'.
738: &mt($item->{text}).' '.
739: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
740: '</tr>';
1.30 raeburn 741: $rowtotal ++;
1.110 raeburn 742: my $numheaders = 1;
743: if (ref($item->{'header'}) eq 'ARRAY') {
744: $numheaders = scalar(@{$item->{'header'}});
745: }
746: if ($numheaders > 1) {
1.64 raeburn 747: my $colspan = '';
1.145 raeburn 748: my $rightcolspan = '';
1.160.6.102.2 3(raebur 749:0): my $leftnobr = '';
1.160.6.42 raeburn 750: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 751: ($action eq 'directorysrch') ||
1.160.6.56 raeburn 752: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 753: $colspan = ' colspan="2"';
754: }
1.145 raeburn 755: if ($action eq 'usersessions') {
756: $rightcolspan = ' colspan="3"';
757: }
1.160.6.102.2 3(raebur 758:0): if ($action eq 'passwords') {
759:0): $leftnobr = ' LC_nobreak';
760:0): }
1.30 raeburn 761: $output .= '
1.3 raeburn 762: <tr>
763: <td>
764: <table class="LC_nested">
765: <tr class="LC_info_row">
1.160.6.102.2 3(raebur 766:0): <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 767: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 768: </tr>';
1.69 raeburn 769: $rowtotal ++;
1.160.6.37 raeburn 770: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 771: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 772: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78 raeburn 773: ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37 raeburn 774: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98 raeburn 775: } elsif ($action eq 'passwords') {
776: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 777: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 778: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97 raeburn 779: } elsif ($action eq 'scantron') {
780: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 781: } elsif ($action eq 'login') {
1.160.6.56 raeburn 782: if ($numheaders == 4) {
1.160.6.5 raeburn 783: $colspan = ' colspan="2"';
784: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
785: } else {
786: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
787: }
1.160.6.37 raeburn 788: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 789: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 790: } elsif ($action eq 'rolecolors') {
1.30 raeburn 791: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 792: }
1.30 raeburn 793: $output .= '
1.6 raeburn 794: </table>
795: </td>
796: </tr>
797: <tr>
798: <td>
799: <table class="LC_nested">
800: <tr class="LC_info_row">
1.160.6.37 raeburn 801: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 802: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 803: </tr>';
804: $rowtotal ++;
1.160.6.37 raeburn 805: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
806: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 807: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.98 raeburn 808: ($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.42 raeburn 809: if ($action eq 'coursecategories') {
810: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
811: $colspan = ' colspan="2"';
1.160.6.98 raeburn 812: } elsif ($action eq 'passwords') {
813: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.42 raeburn 814: } else {
815: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
816: }
817: $output .= '
1.63 raeburn 818: </table>
819: </td>
820: </tr>
821: <tr>
822: <td>
823: <table class="LC_nested">
824: <tr class="LC_info_row">
1.160.6.102.2 3(raebur 825:0): <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 826: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 827: </tr>'."\n";
828: if ($action eq 'coursecategories') {
829: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.102.2 7(raebur 830:1): } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
831:1): if ($action eq 'passwords') {
832:1): $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
833:1): } else {
834:1): $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
835:1): }
836:1): $output .= '
1.160.6.98 raeburn 837: </tr>
838: </table>
839: </td>
840: </tr>
841: <tr>
842: <td>
843: <table class="LC_nested">
844: <tr class="LC_info_row">
845: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.160.6.102.2 7(raebur 846:1): <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
847:1): if ($action eq 'passwords') {
848:1): $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
849:1): } else {
850:1): $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
851:1): }
852:1): $output .= '
1.160.6.98 raeburn 853: </table>
854: </td>
855: </tr>
856: <tr>';
1.160.6.42 raeburn 857: } else {
858: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
859: }
1.63 raeburn 860: $rowtotal ++;
1.160.6.57 raeburn 861: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 862: ($action eq 'defaults') || ($action eq 'directorysrch') ||
863: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 864: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97 raeburn 865: } elsif ($action eq 'scantron') {
866: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 867: } elsif ($action eq 'login') {
1.160.6.56 raeburn 868: if ($numheaders == 4) {
1.160.6.5 raeburn 869: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
870: </table>
871: </td>
872: </tr>
873: <tr>
874: <td>
875: <table class="LC_nested">
876: <tr class="LC_info_row">
877: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 878: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 879: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
880: $rowtotal ++;
881: } else {
882: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
883: }
1.160.6.56 raeburn 884: $output .= '
885: </table>
886: </td>
887: </tr>
888: <tr>
889: <td>
890: <table class="LC_nested">
891: <tr class="LC_info_row">';
892: if ($numheaders == 4) {
893: $output .= '
894: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
895: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
896: </tr>';
897: } else {
898: $output .= '
899: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
900: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
901: </tr>';
902: }
903: $rowtotal ++;
904: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 905: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 906: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
907: $rowtotal ++;
908: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 909: </table>
910: </td>
911: </tr>
912: <tr>
913: <td>
914: <table class="LC_nested">
915: <tr class="LC_info_row">
916: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
917: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 918: &textbookcourses_javascript($settings).
919: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
920: </table>
921: </td>
922: </tr>
923: <tr>
924: <td>
925: <table class="LC_nested">
926: <tr class="LC_info_row">
927: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
928: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
929: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 930: </table>
931: </td>
932: </tr>
933: <tr>
934: <td>
935: <table class="LC_nested">
936: <tr class="LC_info_row">
1.160.6.46 raeburn 937: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
938: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 939: </tr>'.
940: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 941: } elsif ($action eq 'requestauthor') {
942: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 943: $rowtotal ++;
1.122 jms 944: } elsif ($action eq 'rolecolors') {
1.30 raeburn 945: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 946: </table>
947: </td>
948: </tr>
949: <tr>
950: <td>
951: <table class="LC_nested">
952: <tr class="LC_info_row">
1.69 raeburn 953: <td class="LC_left_item"'.$colspan.' valign="top">'.
954: &mt($item->{'header'}->[2]->{'col1'}).'</td>
955: <td class="LC_right_item" valign="top">'.
956: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 957: </tr>'.
1.30 raeburn 958: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 959: </table>
960: </td>
961: </tr>
962: <tr>
963: <td>
964: <table class="LC_nested">
965: <tr class="LC_info_row">
1.59 bisitz 966: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
967: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 968: </tr>'.
1.30 raeburn 969: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
970: $rowtotal += 2;
1.6 raeburn 971: }
1.3 raeburn 972: } else {
1.30 raeburn 973: $output .= '
1.3 raeburn 974: <tr>
975: <td>
976: <table class="LC_nested">
1.30 raeburn 977: <tr class="LC_info_row">';
1.160.6.72 raeburn 978: if ($action eq 'login') {
1.30 raeburn 979: $output .= '
1.59 bisitz 980: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 981: } elsif ($action eq 'serverstatuses') {
982: $output .= '
983: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
984: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
985:
1.6 raeburn 986: } else {
1.30 raeburn 987: $output .= '
1.69 raeburn 988: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
989: }
1.72 raeburn 990: if (defined($item->{'header'}->[0]->{'col3'})) {
991: $output .= '<td class="LC_left_item" valign="top">'.
992: &mt($item->{'header'}->[0]->{'col2'});
993: if ($action eq 'serverstatuses') {
994: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
995: }
1.69 raeburn 996: } else {
997: $output .= '<td class="LC_right_item" valign="top">'.
998: &mt($item->{'header'}->[0]->{'col2'});
999: }
1000: $output .= '</td>';
1001: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1002: if (defined($item->{'header'}->[0]->{'col4'})) {
1003: $output .= '<td class="LC_left_item" valign="top">'.
1004: &mt($item->{'header'}->[0]->{'col3'});
1005: } else {
1006: $output .= '<td class="LC_right_item" valign="top">'.
1007: &mt($item->{'header'}->[0]->{'col3'});
1008: }
1.69 raeburn 1009: if ($action eq 'serverstatuses') {
1010: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1011: }
1012: $output .= '</td>';
1.6 raeburn 1013: }
1.150 raeburn 1014: if ($item->{'header'}->[0]->{'col4'}) {
1015: $output .= '<td class="LC_right_item" valign="top">'.
1016: &mt($item->{'header'}->[0]->{'col4'});
1017: }
1.69 raeburn 1018: $output .= '</tr>';
1.48 raeburn 1019: $rowtotal ++;
1.160.6.5 raeburn 1020: if ($action eq 'quotas') {
1.86 raeburn 1021: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 1022: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.102.2 1(raebur 1023:0): ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1024:0): ($action eq 'ltitools')) {
1.160.6.37 raeburn 1025: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1026: }
1.3 raeburn 1027: }
1.30 raeburn 1028: $output .= '
1.3 raeburn 1029: </table>
1030: </td>
1031: </tr>
1.30 raeburn 1032: </table><br />';
1033: return ($output,$rowtotal);
1.1 raeburn 1034: }
1035:
1.3 raeburn 1036: sub print_login {
1.160.6.5 raeburn 1037: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1038: my ($css_class,$datatable);
1.6 raeburn 1039: my %choices = &login_choices();
1.110 raeburn 1040:
1.160.6.5 raeburn 1041: if ($caller eq 'service') {
1.149 raeburn 1042: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1043: my $choice = $choices{'disallowlogin'};
1044: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1045: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1046: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1047: '<th>'.$choices{'server'}.'</th>'.
1048: '<th>'.$choices{'serverpath'}.'</th>'.
1049: '<th>'.$choices{'custompath'}.'</th>'.
1050: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1051: my %disallowed;
1052: if (ref($settings) eq 'HASH') {
1053: if (ref($settings->{'loginvia'}) eq 'HASH') {
1054: %disallowed = %{$settings->{'loginvia'}};
1055: }
1056: }
1057: foreach my $lonhost (sort(keys(%servers))) {
1058: my $direct = 'selected="selected"';
1.128 raeburn 1059: if (ref($disallowed{$lonhost}) eq 'HASH') {
1060: if ($disallowed{$lonhost}{'server'} ne '') {
1061: $direct = '';
1062: }
1.110 raeburn 1063: }
1.115 raeburn 1064: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1065: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1066: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1067: '</option>';
1.160.6.13 raeburn 1068: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1069: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1070: my $selected = '';
1.128 raeburn 1071: if (ref($disallowed{$lonhost}) eq 'HASH') {
1072: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1073: $selected = 'selected="selected"';
1074: }
1.110 raeburn 1075: }
1076: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1077: $servers{$hostid}.'</option>';
1078: }
1.128 raeburn 1079: $datatable .= '</select></td>'.
1080: '<td><select name="'.$lonhost.'_serverpath">';
1081: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1082: my $pathname = $path;
1083: if ($path eq 'custom') {
1084: $pathname = &mt('Custom Path').' ->';
1085: }
1086: my $selected = '';
1087: if (ref($disallowed{$lonhost}) eq 'HASH') {
1088: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1089: $selected = 'selected="selected"';
1090: }
1091: } elsif ($path eq '') {
1092: $selected = 'selected="selected"';
1093: }
1094: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1095: }
1096: $datatable .= '</select></td>';
1097: my ($custom,$exempt);
1098: if (ref($disallowed{$lonhost}) eq 'HASH') {
1099: $custom = $disallowed{$lonhost}{'custompath'};
1100: $exempt = $disallowed{$lonhost}{'exempt'};
1101: }
1102: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1103: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1104: '</tr>';
1.110 raeburn 1105: }
1106: $datatable .= '</table></td></tr>';
1107: return $datatable;
1.160.6.5 raeburn 1108: } elsif ($caller eq 'page') {
1109: my %defaultchecked = (
1110: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1111: 'helpdesk' => 'on',
1.160.6.5 raeburn 1112: 'adminmail' => 'off',
1113: 'newuser' => 'off',
1114: );
1.160.6.14 raeburn 1115: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1116: my (%checkedon,%checkedoff);
1.42 raeburn 1117: foreach my $item (@toggles) {
1.160.6.5 raeburn 1118: if ($defaultchecked{$item} eq 'on') {
1119: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1120: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1121: } elsif ($defaultchecked{$item} eq 'off') {
1122: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1123: $checkedon{$item} = ' ';
1124: }
1.1 raeburn 1125: }
1.160.6.5 raeburn 1126: my @images = ('img','logo','domlogo','login');
1127: my @logintext = ('textcol','bgcol');
1128: my @bgs = ('pgbg','mainbg','sidebg');
1129: my @links = ('link','alink','vlink');
1130: my %designhash = &Apache::loncommon::get_domainconf($dom);
1131: my %defaultdesign = %Apache::loncommon::defaultdesign;
1132: my (%is_custom,%designs);
1133: my %defaults = (
1134: font => $defaultdesign{'login.font'},
1135: );
1.6 raeburn 1136: foreach my $item (@images) {
1.160.6.5 raeburn 1137: $defaults{$item} = $defaultdesign{'login.'.$item};
1138: $defaults{'showlogo'}{$item} = 1;
1139: }
1140: foreach my $item (@bgs) {
1141: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1142: }
1.41 raeburn 1143: foreach my $item (@logintext) {
1.160.6.5 raeburn 1144: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1145: }
1.160.6.5 raeburn 1146: foreach my $item (@links) {
1147: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1148: }
1.160.6.5 raeburn 1149: if (ref($settings) eq 'HASH') {
1150: foreach my $item (@toggles) {
1151: if ($settings->{$item} eq '1') {
1152: $checkedon{$item} = ' checked="checked" ';
1153: $checkedoff{$item} = ' ';
1154: } elsif ($settings->{$item} eq '0') {
1155: $checkedoff{$item} = ' checked="checked" ';
1156: $checkedon{$item} = ' ';
1157: }
1.6 raeburn 1158: }
1.160.6.5 raeburn 1159: foreach my $item (@images) {
1160: if (defined($settings->{$item})) {
1161: $designs{$item} = $settings->{$item};
1162: $is_custom{$item} = 1;
1163: }
1164: if (defined($settings->{'showlogo'}{$item})) {
1165: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1166: }
1167: }
1168: foreach my $item (@logintext) {
1169: if ($settings->{$item} ne '') {
1170: $designs{'logintext'}{$item} = $settings->{$item};
1171: $is_custom{$item} = 1;
1172: }
1173: }
1174: if ($settings->{'font'} ne '') {
1175: $designs{'font'} = $settings->{'font'};
1176: $is_custom{'font'} = 1;
1177: }
1178: foreach my $item (@bgs) {
1179: if ($settings->{$item} ne '') {
1180: $designs{'bgs'}{$item} = $settings->{$item};
1181: $is_custom{$item} = 1;
1182: }
1183: }
1184: foreach my $item (@links) {
1185: if ($settings->{$item} ne '') {
1186: $designs{'links'}{$item} = $settings->{$item};
1187: $is_custom{$item} = 1;
1188: }
1189: }
1190: } else {
1191: if ($designhash{$dom.'.login.font'} ne '') {
1192: $designs{'font'} = $designhash{$dom.'.login.font'};
1193: $is_custom{'font'} = 1;
1194: }
1195: foreach my $item (@images) {
1196: if ($designhash{$dom.'.login.'.$item} ne '') {
1197: $designs{$item} = $designhash{$dom.'.login.'.$item};
1198: $is_custom{$item} = 1;
1199: }
1200: }
1201: foreach my $item (@bgs) {
1202: if ($designhash{$dom.'.login.'.$item} ne '') {
1203: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1204: $is_custom{$item} = 1;
1205: }
1206: }
1207: foreach my $item (@links) {
1208: if ($designhash{$dom.'.login.'.$item} ne '') {
1209: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1210: $is_custom{$item} = 1;
1211: }
1.6 raeburn 1212: }
1213: }
1.160.6.5 raeburn 1214: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1215: logo => 'Institution Logo',
1216: domlogo => 'Domain Logo',
1217: login => 'Login box');
1218: my $itemcount = 1;
1219: foreach my $item (@toggles) {
1220: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1221: $datatable .=
1222: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1223: '</td><td>'.
1224: '<span class="LC_nobreak"><label><input type="radio" name="'.
1225: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1226: '</label> <label><input type="radio" name="'.$item.'"'.
1227: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1228: '</tr>';
1229: $itemcount ++;
1.6 raeburn 1230: }
1.160.6.5 raeburn 1231: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1232: $datatable .= '</tr></table></td></tr>';
1233: } elsif ($caller eq 'help') {
1234: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1235: my $switchserver = &check_switchserver($dom,$confname);
1236: my $itemcount = 1;
1237: $defaulturl = '/adm/loginproblems.html';
1238: $defaulttype = 'default';
1239: %lt = &Apache::lonlocal::texthash (
1240: del => 'Delete?',
1241: rep => 'Replace:',
1242: upl => 'Upload:',
1243: default => 'Default',
1244: custom => 'Custom',
1245: );
1246: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1247: my @currlangs;
1248: if (ref($settings) eq 'HASH') {
1249: if (ref($settings->{'helpurl'}) eq 'HASH') {
1250: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1251: next if ($settings->{'helpurl'}{$key} eq '');
1252: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1253: $type{$key} = 'custom';
1254: unless ($key eq 'nolang') {
1255: push(@currlangs,$key);
1256: }
1257: }
1258: } elsif ($settings->{'helpurl'} ne '') {
1259: $type{'nolang'} = 'custom';
1260: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1261: }
1262: }
1.160.6.5 raeburn 1263: foreach my $lang ('nolang',sort(@currlangs)) {
1264: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1265: $datatable .= '<tr'.$css_class.'>';
1266: if ($url{$lang} eq '') {
1267: $url{$lang} = $defaulturl;
1268: }
1269: if ($type{$lang} eq '') {
1270: $type{$lang} = $defaulttype;
1271: }
1272: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1273: if ($lang eq 'nolang') {
1274: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1275: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1276: } else {
1277: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1278: $langchoices{$lang},
1279: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1280: }
1281: $datatable .= '</span></td>'."\n".
1282: '<td class="LC_left_item">';
1283: if ($type{$lang} eq 'custom') {
1284: $datatable .= '<span class="LC_nobreak"><label>'.
1285: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1286: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1287: } else {
1288: $datatable .= $lt{'upl'};
1289: }
1290: $datatable .='<br />';
1291: if ($switchserver) {
1292: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1293: } else {
1294: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1295: }
1.160.6.5 raeburn 1296: $datatable .= '</td></tr>';
1297: $itemcount ++;
1.6 raeburn 1298: }
1.160.6.5 raeburn 1299: my @addlangs;
1300: foreach my $lang (sort(keys(%langchoices))) {
1301: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1302: push(@addlangs,$lang);
1303: }
1304: if (@addlangs > 0) {
1305: my %toadd;
1306: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1307: $toadd{''} = &mt('Select');
1308: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1309: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1310: &mt('Add log-in help page for a specific language:').' '.
1311: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1312: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1313: if ($switchserver) {
1314: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1315: } else {
1316: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1317: }
1.160.6.5 raeburn 1318: $datatable .= '</td></tr>';
1319: $itemcount ++;
1.6 raeburn 1320: }
1.160.6.5 raeburn 1321: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1322: } elsif ($caller eq 'headtag') {
1323: my %domservers = &Apache::lonnet::get_servers($dom);
1324: my $choice = $choices{'headtag'};
1325: $css_class = ' class="LC_odd_row"';
1326: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1327: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1328: '<th>'.$choices{'current'}.'</th>'.
1329: '<th>'.$choices{'action'}.'</th>'.
1330: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1331: my (%currurls,%currexempt);
1332: if (ref($settings) eq 'HASH') {
1333: if (ref($settings->{'headtag'}) eq 'HASH') {
1334: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1335: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1336: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1337: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1338: }
1339: }
1340: }
1341: }
1342: my %lt = &Apache::lonlocal::texthash(
1343: del => 'Delete?',
1344: rep => 'Replace:',
1345: upl => 'Upload:',
1346: curr => 'View contents',
1347: none => 'None',
1348: );
1349: my $switchserver = &check_switchserver($dom,$confname);
1350: foreach my $lonhost (sort(keys(%domservers))) {
1351: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1352: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1353: if ($currurls{$lonhost}) {
1354: $datatable .= '<td class="LC_right_item"><a href="'.
1355: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1356: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1357: '">'.$lt{'curr'}.'</a></td>'.
1358: '<td><span class="LC_nobreak"><label>'.
1359: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1360: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1361: } else {
1362: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1363: }
1364: $datatable .='<br />';
1365: if ($switchserver) {
1366: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1367: } else {
1368: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1369: }
1.160.6.87 raeburn 1370: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1371: }
1372: $datatable .= '</table></td></tr>';
1.1 raeburn 1373: }
1.6 raeburn 1374: return $datatable;
1375: }
1376:
1377: sub login_choices {
1378: my %choices =
1379: &Apache::lonlocal::texthash (
1.116 bisitz 1380: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1381: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1382: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1383: disallowlogin => "Login page requests redirected",
1384: hostid => "Server",
1.128 raeburn 1385: server => "Redirect to:",
1386: serverpath => "Path",
1387: custompath => "Custom",
1388: exempt => "Exempt IP(s)",
1.110 raeburn 1389: directlogin => "No redirect",
1390: newuser => "Link to create a user account",
1391: img => "Header",
1392: logo => "Main Logo",
1393: domlogo => "Domain Logo",
1394: login => "Log-in Header",
1395: textcol => "Text color",
1396: bgcol => "Box color",
1397: bgs => "Background colors",
1398: links => "Link colors",
1399: font => "Font color",
1400: pgbg => "Header",
1401: mainbg => "Page",
1402: sidebg => "Login box",
1403: link => "Link",
1404: alink => "Active link",
1405: vlink => "Visited link",
1.160.6.56 raeburn 1406: headtag => "Custom markup",
1407: action => "Action",
1408: current => "Current",
1.6 raeburn 1409: );
1410: return %choices;
1411: }
1412:
1413: sub print_rolecolors {
1.30 raeburn 1414: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1415: my %choices = &color_font_choices();
1416: my @bgs = ('pgbg','tabbg','sidebg');
1417: my @links = ('link','alink','vlink');
1418: my @images = ('img');
1419: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1420: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1421: my %defaultdesign = %Apache::loncommon::defaultdesign;
1422: my (%is_custom,%designs);
1.160.6.22 raeburn 1423: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1424: if (ref($settings) eq 'HASH') {
1425: if (ref($settings->{$role}) eq 'HASH') {
1426: if ($settings->{$role}->{'img'} ne '') {
1427: $designs{'img'} = $settings->{$role}->{'img'};
1428: $is_custom{'img'} = 1;
1429: }
1430: if ($settings->{$role}->{'font'} ne '') {
1431: $designs{'font'} = $settings->{$role}->{'font'};
1432: $is_custom{'font'} = 1;
1433: }
1.97 tempelho 1434: if ($settings->{$role}->{'fontmenu'} ne '') {
1435: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1436: $is_custom{'fontmenu'} = 1;
1437: }
1.6 raeburn 1438: foreach my $item (@bgs) {
1439: if ($settings->{$role}->{$item} ne '') {
1440: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1441: $is_custom{$item} = 1;
1442: }
1443: }
1444: foreach my $item (@links) {
1445: if ($settings->{$role}->{$item} ne '') {
1446: $designs{'links'}{$item} = $settings->{$role}->{$item};
1447: $is_custom{$item} = 1;
1448: }
1449: }
1450: }
1451: } else {
1452: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1453: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1454: $is_custom{'img'} = 1;
1455: }
1.97 tempelho 1456: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1457: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1458: $is_custom{'fontmenu'} = 1;
1459: }
1.6 raeburn 1460: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1461: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1462: $is_custom{'font'} = 1;
1463: }
1464: foreach my $item (@bgs) {
1465: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1466: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1467: $is_custom{$item} = 1;
1468:
1469: }
1470: }
1471: foreach my $item (@links) {
1472: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1473: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1474: $is_custom{$item} = 1;
1475: }
1476: }
1477: }
1478: my $itemcount = 1;
1.30 raeburn 1479: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1480: $datatable .= '</tr></table></td></tr>';
1481: return $datatable;
1482: }
1483:
1.160.6.22 raeburn 1484: sub role_defaults {
1485: my ($role,$bgs,$links,$images,$logintext) = @_;
1486: my %defaults;
1487: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1488: return %defaults;
1489: }
1490: my %defaultdesign = %Apache::loncommon::defaultdesign;
1491: if ($role eq 'login') {
1492: %defaults = (
1493: font => $defaultdesign{$role.'.font'},
1494: );
1495: if (ref($logintext) eq 'ARRAY') {
1496: foreach my $item (@{$logintext}) {
1497: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1498: }
1499: }
1500: foreach my $item (@{$images}) {
1501: $defaults{'showlogo'}{$item} = 1;
1502: }
1503: } else {
1504: %defaults = (
1505: img => $defaultdesign{$role.'.img'},
1506: font => $defaultdesign{$role.'.font'},
1507: fontmenu => $defaultdesign{$role.'.fontmenu'},
1508: );
1509: }
1510: foreach my $item (@{$bgs}) {
1511: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1512: }
1513: foreach my $item (@{$links}) {
1514: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1515: }
1516: foreach my $item (@{$images}) {
1517: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1518: }
1519: return %defaults;
1520: }
1521:
1.6 raeburn 1522: sub display_color_options {
1.9 raeburn 1523: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1524: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1525: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1526: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1527: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1528: '<td>'.$choices->{'font'}.'</td>';
1529: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1530: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1531: } else {
1532: $datatable .= '<td> </td>';
1533: }
1.160.6.9 raeburn 1534: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1535:
1.8 raeburn 1536: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1537: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1538: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1539: ' </span></td></tr>';
1.107 raeburn 1540: unless ($role eq 'login') {
1541: $datatable .= '<tr'.$css_class.'>'.
1542: '<td>'.$choices->{'fontmenu'}.'</td>';
1543: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1544: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1545: } else {
1546: $datatable .= '<td> </td>';
1547: }
1.160.6.22 raeburn 1548: $current_color = $designs->{'fontmenu'} ?
1549: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1550: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1551: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1552: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1553: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1554: ' </span></td></tr>';
1.97 tempelho 1555: }
1.9 raeburn 1556: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1557: foreach my $img (@{$images}) {
1.18 albertel 1558: $itemcount ++;
1.6 raeburn 1559: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1560: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1561: '<td>'.$choices->{$img};
1.41 raeburn 1562: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1563: if ($role eq 'login') {
1564: if ($img eq 'login') {
1565: $login_hdr_pick =
1.135 bisitz 1566: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1567: $logincolors =
1568: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1569: $designs,$defaults);
1.70 raeburn 1570: } elsif ($img ne 'domlogo') {
1571: $datatable.= &logo_display_options($img,$defaults,$designs);
1572: }
1573: }
1574: $datatable .= '</td>';
1.6 raeburn 1575: if ($designs->{$img} ne '') {
1576: $imgfile = $designs->{$img};
1.18 albertel 1577: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1578: } else {
1579: $imgfile = $defaults->{$img};
1580: }
1581: if ($imgfile) {
1.9 raeburn 1582: my ($showfile,$fullsize);
1583: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1584: my $urldir = $1;
1585: my $filename = $2;
1586: my @info = &Apache::lonnet::stat_file($designs->{$img});
1587: if (@info) {
1588: my $thumbfile = 'tn-'.$filename;
1589: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1590: if (@thumb) {
1591: $showfile = $urldir.'/'.$thumbfile;
1592: } else {
1593: $showfile = $imgfile;
1594: }
1595: } else {
1596: $showfile = '';
1597: }
1598: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1599: $showfile = $imgfile;
1.6 raeburn 1600: my $imgdir = $1;
1601: my $filename = $2;
1.159 raeburn 1602: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1603: $showfile = "/$imgdir/tn-".$filename;
1604: } else {
1.159 raeburn 1605: my $input = $londocroot.$imgfile;
1606: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1607: if (!-e $output) {
1.9 raeburn 1608: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1609: my ($fullwidth,$fullheight) = &check_dimensions($input);
1610: if ($fullwidth ne '' && $fullheight ne '') {
1611: if ($fullwidth > $width && $fullheight > $height) {
1612: my $size = $width.'x'.$height;
1.160.6.88 raeburn 1613: my @args = ('convert','-sample',$size,$input,$output);
1614: system({$args[0]} @args);
1.159 raeburn 1615: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1616: }
1617: }
1.6 raeburn 1618: }
1619: }
1.16 raeburn 1620: }
1.6 raeburn 1621: if ($showfile) {
1.40 raeburn 1622: if ($showfile =~ m{^/(adm|res)/}) {
1623: if ($showfile =~ m{^/res/}) {
1624: my $local_showfile =
1625: &Apache::lonnet::filelocation('',$showfile);
1626: &Apache::lonnet::repcopy($local_showfile);
1627: }
1628: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1629: }
1630: if ($imgfile) {
1631: if ($imgfile =~ m{^/(adm|res)/}) {
1632: if ($imgfile =~ m{^/res/}) {
1633: my $local_imgfile =
1634: &Apache::lonnet::filelocation('',$imgfile);
1635: &Apache::lonnet::repcopy($local_imgfile);
1636: }
1637: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1638: } else {
1639: $fullsize = $imgfile;
1640: }
1641: }
1.41 raeburn 1642: $datatable .= '<td>';
1643: if ($img eq 'login') {
1.135 bisitz 1644: $datatable .= $login_hdr_pick;
1645: }
1.41 raeburn 1646: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1647: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1648: } else {
1.160.6.22 raeburn 1649: $datatable .= '<td> </td><td class="LC_left_item">'.
1650: &mt('Upload:').'<br />';
1.6 raeburn 1651: }
1652: } else {
1.160.6.22 raeburn 1653: $datatable .= '<td> </td><td class="LC_left_item">'.
1654: &mt('Upload:').'<br />';
1.6 raeburn 1655: }
1.9 raeburn 1656: if ($switchserver) {
1657: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1658: } else {
1.135 bisitz 1659: if ($img ne 'login') { # suppress file selection for Log-in header
1660: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1661: }
1.9 raeburn 1662: }
1663: $datatable .= '</td></tr>';
1.6 raeburn 1664: }
1665: $itemcount ++;
1666: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1667: $datatable .= '<tr'.$css_class.'>'.
1668: '<td>'.$choices->{'bgs'}.'</td>';
1669: my $bgs_def;
1670: foreach my $item (@{$bgs}) {
1671: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1672: $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 1673: }
1674: }
1675: if ($bgs_def) {
1.8 raeburn 1676: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1677: } else {
1678: $datatable .= '<td> </td>';
1679: }
1680: $datatable .= '<td class="LC_right_item">'.
1681: '<table border="0"><tr>';
1.160.6.13 raeburn 1682:
1.6 raeburn 1683: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1684: $datatable .= '<td align="center">'.$choices->{$item};
1685: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1686: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1687: $datatable .= ' ';
1.6 raeburn 1688: }
1.160.6.9 raeburn 1689: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1690: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1691: }
1692: $datatable .= '</tr></table></td></tr>';
1693: $itemcount ++;
1694: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1695: $datatable .= '<tr'.$css_class.'>'.
1696: '<td>'.$choices->{'links'}.'</td>';
1697: my $links_def;
1698: foreach my $item (@{$links}) {
1699: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1700: $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 1701: }
1702: }
1703: if ($links_def) {
1.8 raeburn 1704: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1705: } else {
1706: $datatable .= '<td> </td>';
1707: }
1708: $datatable .= '<td class="LC_right_item">'.
1709: '<table border="0"><tr>';
1710: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1711: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1712: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1713: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1714: $datatable.=' ';
1.6 raeburn 1715: }
1.160.6.9 raeburn 1716: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1717: '" /></td>';
1718: }
1.30 raeburn 1719: $$rowtotal += $itemcount;
1.3 raeburn 1720: return $datatable;
1721: }
1722:
1.70 raeburn 1723: sub logo_display_options {
1724: my ($img,$defaults,$designs) = @_;
1725: my $checkedon;
1726: if (ref($defaults) eq 'HASH') {
1727: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1728: if ($defaults->{'showlogo'}{$img}) {
1729: $checkedon = 'checked="checked" ';
1730: }
1731: }
1732: }
1733: if (ref($designs) eq 'HASH') {
1734: if (ref($designs->{'showlogo'}) eq 'HASH') {
1735: if (defined($designs->{'showlogo'}{$img})) {
1736: if ($designs->{'showlogo'}{$img} == 0) {
1737: $checkedon = '';
1738: } elsif ($designs->{'showlogo'}{$img} == 1) {
1739: $checkedon = 'checked="checked" ';
1740: }
1741: }
1742: }
1743: }
1744: return '<br /><label> <input type="checkbox" name="'.
1745: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1746: &mt('show').'</label>'."\n";
1747: }
1748:
1.41 raeburn 1749: sub login_header_options {
1.135 bisitz 1750: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1751: my $output = '';
1.41 raeburn 1752: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1753: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1754: if (!$is_custom->{'textcol'}) {
1755: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1756: ' ';
1757: }
1758: if (!$is_custom->{'bgcol'}) {
1759: $output .= $choices->{'bgcol'}.': '.
1760: '<span id="css_'.$role.'_font" style="background-color: '.
1761: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1762: }
1763: $output .= '<br />';
1764: }
1765: $output .='<br />';
1766: return $output;
1767: }
1768:
1769: sub login_text_colors {
1.160.6.22 raeburn 1770: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1771: my $color_menu = '<table border="0"><tr>';
1772: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1773: $color_menu .= '<td align="center">'.$choices->{$item};
1774: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1775: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1776: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1777: }
1778: $color_menu .= '</tr></table><br />';
1779: return $color_menu;
1780: }
1781:
1782: sub image_changes {
1783: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1784: my $output;
1.135 bisitz 1785: if ($img eq 'login') {
1.160.6.87 raeburn 1786: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1787: } elsif (!$is_custom) {
1.70 raeburn 1788: if ($img ne 'domlogo') {
1.160.6.87 raeburn 1789: $output = &mt('Default image:').'<br />';
1.41 raeburn 1790: } else {
1.160.6.87 raeburn 1791: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1792: }
1793: }
1.160.6.87 raeburn 1794: if ($img ne 'login') {
1.135 bisitz 1795: if ($img_import) {
1796: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1797: }
1798: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1799: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1800: if ($is_custom) {
1801: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1802: '<input type="checkbox" name="'.
1803: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1804: '</label> '.&mt('Replace:').'</span><br />';
1805: } else {
1.160.6.22 raeburn 1806: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1807: }
1.41 raeburn 1808: }
1809: return $output;
1810: }
1811:
1.3 raeburn 1812: sub print_quotas {
1.86 raeburn 1813: my ($dom,$settings,$rowtotal,$action) = @_;
1814: my $context;
1815: if ($action eq 'quotas') {
1816: $context = 'tools';
1817: } else {
1818: $context = $action;
1819: }
1.160.6.20 raeburn 1820: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1821: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1822: my $typecount = 0;
1.101 raeburn 1823: my ($css_class,%titles);
1.86 raeburn 1824: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1825: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1826: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1827: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1828: %titles = &courserequest_titles();
1.160.6.5 raeburn 1829: } elsif ($context eq 'requestauthor') {
1830: @usertools = ('author');
1831: @options = ('norequest','approval','automatic');
1832: %titles = &authorrequest_titles();
1.86 raeburn 1833: } else {
1.160.6.4 raeburn 1834: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1835: %titles = &tool_titles();
1.86 raeburn 1836: }
1.26 raeburn 1837: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1838: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1839: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1840: unless (($context eq 'requestcourses') ||
1841: ($context eq 'requestauthor')) {
1.86 raeburn 1842: if (ref($settings) eq 'HASH') {
1843: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1844: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1845: } else {
1846: $currdefquota = $settings->{$type};
1847: }
1.160.6.20 raeburn 1848: if (ref($settings->{authorquota}) eq 'HASH') {
1849: $currauthorquota = $settings->{authorquota}->{$type};
1850: }
1.78 raeburn 1851: }
1.72 raeburn 1852: }
1.3 raeburn 1853: if (defined($usertypes->{$type})) {
1854: $typecount ++;
1855: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1856: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1857: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1858: '<td class="LC_left_item">';
1.101 raeburn 1859: if ($context eq 'requestcourses') {
1860: $datatable .= '<table><tr>';
1861: }
1862: my %cell;
1.72 raeburn 1863: foreach my $item (@usertools) {
1.101 raeburn 1864: if ($context eq 'requestcourses') {
1865: my ($curroption,$currlimit);
1866: if (ref($settings) eq 'HASH') {
1867: if (ref($settings->{$item}) eq 'HASH') {
1868: $curroption = $settings->{$item}->{$type};
1869: if ($curroption =~ /^autolimit=(\d*)$/) {
1870: $currlimit = $1;
1871: }
1872: }
1873: }
1874: if (!$curroption) {
1875: $curroption = 'norequest';
1876: }
1877: $datatable .= '<th>'.$titles{$item}.'</th>';
1878: foreach my $option (@options) {
1879: my $val = $option;
1880: if ($option eq 'norequest') {
1881: $val = 0;
1882: }
1883: if ($option eq 'validate') {
1884: my $canvalidate = 0;
1885: if (ref($validations{$item}) eq 'HASH') {
1886: if ($validations{$item}{$type}) {
1887: $canvalidate = 1;
1888: }
1889: }
1890: next if (!$canvalidate);
1891: }
1892: my $checked = '';
1893: if ($option eq $curroption) {
1894: $checked = ' checked="checked"';
1895: } elsif ($option eq 'autolimit') {
1896: if ($curroption =~ /^autolimit/) {
1897: $checked = ' checked="checked"';
1898: }
1899: }
1900: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1901: '<input type="radio" name="crsreq_'.$item.
1902: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1903: $titles{$option}.'</label>';
1.101 raeburn 1904: if ($option eq 'autolimit') {
1.127 raeburn 1905: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1906: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1907: 'value="'.$currlimit.'" />';
1.101 raeburn 1908: }
1.127 raeburn 1909: $cell{$item} .= '</span> ';
1.103 raeburn 1910: if ($option eq 'autolimit') {
1.127 raeburn 1911: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1912: }
1.101 raeburn 1913: }
1.160.6.5 raeburn 1914: } elsif ($context eq 'requestauthor') {
1915: my $curroption;
1916: if (ref($settings) eq 'HASH') {
1917: $curroption = $settings->{$type};
1918: }
1919: if (!$curroption) {
1920: $curroption = 'norequest';
1921: }
1922: foreach my $option (@options) {
1923: my $val = $option;
1924: if ($option eq 'norequest') {
1925: $val = 0;
1926: }
1927: my $checked = '';
1928: if ($option eq $curroption) {
1929: $checked = ' checked="checked"';
1930: }
1931: $datatable .= '<span class="LC_nobreak"><label>'.
1932: '<input type="radio" name="authorreq_'.$type.
1933: '" value="'.$val.'"'.$checked.' />'.
1934: $titles{$option}.'</label></span> ';
1935: }
1.101 raeburn 1936: } else {
1937: my $checked = 'checked="checked" ';
1938: if (ref($settings) eq 'HASH') {
1939: if (ref($settings->{$item}) eq 'HASH') {
1940: if ($settings->{$item}->{$type} == 0) {
1941: $checked = '';
1942: } elsif ($settings->{$item}->{$type} == 1) {
1943: $checked = 'checked="checked" ';
1944: }
1.78 raeburn 1945: }
1.72 raeburn 1946: }
1.101 raeburn 1947: $datatable .= '<span class="LC_nobreak"><label>'.
1948: '<input type="checkbox" name="'.$context.'_'.$item.
1949: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1950: '</label></span> ';
1.72 raeburn 1951: }
1.101 raeburn 1952: }
1953: if ($context eq 'requestcourses') {
1954: $datatable .= '</tr><tr>';
1955: foreach my $item (@usertools) {
1.106 raeburn 1956: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1957: }
1958: $datatable .= '</tr></table>';
1.72 raeburn 1959: }
1.86 raeburn 1960: $datatable .= '</td>';
1.160.6.5 raeburn 1961: unless (($context eq 'requestcourses') ||
1962: ($context eq 'requestauthor')) {
1.86 raeburn 1963: $datatable .=
1.160.6.20 raeburn 1964: '<td class="LC_right_item">'.
1965: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1966: '<input type="text" name="quota_'.$type.
1.72 raeburn 1967: '" value="'.$currdefquota.
1.160.6.20 raeburn 1968: '" size="5" /></span>'.(' ' x 2).
1969: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1970: '<input type="text" name="authorquota_'.$type.
1971: '" value="'.$currauthorquota.
1972: '" size="5" /></span></td>';
1.86 raeburn 1973: }
1974: $datatable .= '</tr>';
1.3 raeburn 1975: }
1976: }
1977: }
1.160.6.5 raeburn 1978: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1979: $defaultquota = '20';
1.160.6.20 raeburn 1980: $authorquota = '500';
1.86 raeburn 1981: if (ref($settings) eq 'HASH') {
1982: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1983: $defaultquota = $settings->{'defaultquota'}->{'default'};
1984: } elsif (defined($settings->{'default'})) {
1985: $defaultquota = $settings->{'default'};
1986: }
1.160.6.20 raeburn 1987: if (ref($settings->{'authorquota'}) eq 'HASH') {
1988: $authorquota = $settings->{'authorquota'}->{'default'};
1989: }
1.3 raeburn 1990: }
1991: }
1992: $typecount ++;
1993: $css_class = $typecount%2?' class="LC_odd_row"':'';
1994: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1995: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1996: '<td class="LC_left_item">';
1.101 raeburn 1997: if ($context eq 'requestcourses') {
1998: $datatable .= '<table><tr>';
1999: }
2000: my %defcell;
1.72 raeburn 2001: foreach my $item (@usertools) {
1.101 raeburn 2002: if ($context eq 'requestcourses') {
2003: my ($curroption,$currlimit);
2004: if (ref($settings) eq 'HASH') {
2005: if (ref($settings->{$item}) eq 'HASH') {
2006: $curroption = $settings->{$item}->{'default'};
2007: if ($curroption =~ /^autolimit=(\d*)$/) {
2008: $currlimit = $1;
2009: }
2010: }
2011: }
2012: if (!$curroption) {
2013: $curroption = 'norequest';
2014: }
2015: $datatable .= '<th>'.$titles{$item}.'</th>';
2016: foreach my $option (@options) {
2017: my $val = $option;
2018: if ($option eq 'norequest') {
2019: $val = 0;
2020: }
2021: if ($option eq 'validate') {
2022: my $canvalidate = 0;
2023: if (ref($validations{$item}) eq 'HASH') {
2024: if ($validations{$item}{'default'}) {
2025: $canvalidate = 1;
2026: }
2027: }
2028: next if (!$canvalidate);
2029: }
2030: my $checked = '';
2031: if ($option eq $curroption) {
2032: $checked = ' checked="checked"';
2033: } elsif ($option eq 'autolimit') {
2034: if ($curroption =~ /^autolimit/) {
2035: $checked = ' checked="checked"';
2036: }
2037: }
2038: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2039: '<input type="radio" name="crsreq_'.$item.
2040: '_default" value="'.$val.'"'.$checked.' />'.
2041: $titles{$option}.'</label>';
2042: if ($option eq 'autolimit') {
1.127 raeburn 2043: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2044: $item.'_limit_default" size="1" '.
2045: 'value="'.$currlimit.'" />';
2046: }
1.127 raeburn 2047: $defcell{$item} .= '</span> ';
1.104 raeburn 2048: if ($option eq 'autolimit') {
1.127 raeburn 2049: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2050: }
1.101 raeburn 2051: }
1.160.6.5 raeburn 2052: } elsif ($context eq 'requestauthor') {
2053: my $curroption;
2054: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2055: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2056: }
2057: if (!$curroption) {
2058: $curroption = 'norequest';
2059: }
2060: foreach my $option (@options) {
2061: my $val = $option;
2062: if ($option eq 'norequest') {
2063: $val = 0;
2064: }
2065: my $checked = '';
2066: if ($option eq $curroption) {
2067: $checked = ' checked="checked"';
2068: }
2069: $datatable .= '<span class="LC_nobreak"><label>'.
2070: '<input type="radio" name="authorreq_default"'.
2071: ' value="'.$val.'"'.$checked.' />'.
2072: $titles{$option}.'</label></span> ';
2073: }
1.101 raeburn 2074: } else {
2075: my $checked = 'checked="checked" ';
2076: if (ref($settings) eq 'HASH') {
2077: if (ref($settings->{$item}) eq 'HASH') {
2078: if ($settings->{$item}->{'default'} == 0) {
2079: $checked = '';
2080: } elsif ($settings->{$item}->{'default'} == 1) {
2081: $checked = 'checked="checked" ';
2082: }
1.78 raeburn 2083: }
1.72 raeburn 2084: }
1.101 raeburn 2085: $datatable .= '<span class="LC_nobreak"><label>'.
2086: '<input type="checkbox" name="'.$context.'_'.$item.
2087: '" value="default" '.$checked.'/>'.$titles{$item}.
2088: '</label></span> ';
2089: }
2090: }
2091: if ($context eq 'requestcourses') {
2092: $datatable .= '</tr><tr>';
2093: foreach my $item (@usertools) {
1.106 raeburn 2094: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2095: }
1.101 raeburn 2096: $datatable .= '</tr></table>';
1.72 raeburn 2097: }
1.86 raeburn 2098: $datatable .= '</td>';
1.160.6.5 raeburn 2099: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2100: $datatable .= '<td class="LC_right_item">'.
2101: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2102: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2103: $defaultquota.'" size="5" /></span>'.(' ' x2).
2104: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2105: '<input type="text" name="authorquota" value="'.
2106: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2107: }
2108: $datatable .= '</tr>';
1.72 raeburn 2109: $typecount ++;
2110: $css_class = $typecount%2?' class="LC_odd_row"':'';
2111: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2112: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2113: if ($context eq 'requestcourses') {
1.109 raeburn 2114: $datatable .= &mt('(overrides affiliation, if set)').
2115: '</td>'.
2116: '<td class="LC_left_item">'.
2117: '<table><tr>';
1.101 raeburn 2118: } else {
1.109 raeburn 2119: $datatable .= &mt('(overrides affiliation, if checked)').
2120: '</td>'.
2121: '<td class="LC_left_item" colspan="2">'.
2122: '<br />';
1.101 raeburn 2123: }
2124: my %advcell;
1.72 raeburn 2125: foreach my $item (@usertools) {
1.101 raeburn 2126: if ($context eq 'requestcourses') {
2127: my ($curroption,$currlimit);
2128: if (ref($settings) eq 'HASH') {
2129: if (ref($settings->{$item}) eq 'HASH') {
2130: $curroption = $settings->{$item}->{'_LC_adv'};
2131: if ($curroption =~ /^autolimit=(\d*)$/) {
2132: $currlimit = $1;
2133: }
2134: }
2135: }
2136: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2137: my $checked = '';
2138: if ($curroption eq '') {
2139: $checked = ' checked="checked"';
2140: }
2141: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2142: '<input type="radio" name="crsreq_'.$item.
2143: '__LC_adv" value=""'.$checked.' />'.
2144: &mt('No override set').'</label></span> ';
1.101 raeburn 2145: foreach my $option (@options) {
2146: my $val = $option;
2147: if ($option eq 'norequest') {
2148: $val = 0;
2149: }
2150: if ($option eq 'validate') {
2151: my $canvalidate = 0;
2152: if (ref($validations{$item}) eq 'HASH') {
2153: if ($validations{$item}{'_LC_adv'}) {
2154: $canvalidate = 1;
2155: }
2156: }
2157: next if (!$canvalidate);
2158: }
2159: my $checked = '';
1.104 raeburn 2160: if ($val eq $curroption) {
1.101 raeburn 2161: $checked = ' checked="checked"';
2162: } elsif ($option eq 'autolimit') {
2163: if ($curroption =~ /^autolimit/) {
2164: $checked = ' checked="checked"';
2165: }
2166: }
2167: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2168: '<input type="radio" name="crsreq_'.$item.
2169: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2170: $titles{$option}.'</label>';
2171: if ($option eq 'autolimit') {
1.127 raeburn 2172: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2173: $item.'_limit__LC_adv" size="1" '.
2174: 'value="'.$currlimit.'" />';
2175: }
1.127 raeburn 2176: $advcell{$item} .= '</span> ';
1.104 raeburn 2177: if ($option eq 'autolimit') {
1.127 raeburn 2178: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2179: }
1.101 raeburn 2180: }
1.160.6.5 raeburn 2181: } elsif ($context eq 'requestauthor') {
2182: my $curroption;
2183: if (ref($settings) eq 'HASH') {
2184: $curroption = $settings->{'_LC_adv'};
2185: }
2186: my $checked = '';
2187: if ($curroption eq '') {
2188: $checked = ' checked="checked"';
2189: }
2190: $datatable .= '<span class="LC_nobreak"><label>'.
2191: '<input type="radio" name="authorreq__LC_adv"'.
2192: ' value=""'.$checked.' />'.
2193: &mt('No override set').'</label></span> ';
2194: foreach my $option (@options) {
2195: my $val = $option;
2196: if ($option eq 'norequest') {
2197: $val = 0;
2198: }
2199: my $checked = '';
2200: if ($val eq $curroption) {
2201: $checked = ' checked="checked"';
2202: }
2203: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2204: '<input type="radio" name="authorreq__LC_adv"'.
2205: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2206: $titles{$option}.'</label></span> ';
2207: }
1.101 raeburn 2208: } else {
2209: my $checked = 'checked="checked" ';
2210: if (ref($settings) eq 'HASH') {
2211: if (ref($settings->{$item}) eq 'HASH') {
2212: if ($settings->{$item}->{'_LC_adv'} == 0) {
2213: $checked = '';
2214: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2215: $checked = 'checked="checked" ';
2216: }
1.79 raeburn 2217: }
1.72 raeburn 2218: }
1.101 raeburn 2219: $datatable .= '<span class="LC_nobreak"><label>'.
2220: '<input type="checkbox" name="'.$context.'_'.$item.
2221: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2222: '</label></span> ';
2223: }
2224: }
2225: if ($context eq 'requestcourses') {
2226: $datatable .= '</tr><tr>';
2227: foreach my $item (@usertools) {
1.106 raeburn 2228: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2229: }
1.101 raeburn 2230: $datatable .= '</tr></table>';
1.72 raeburn 2231: }
1.98 raeburn 2232: $datatable .= '</td></tr>';
1.30 raeburn 2233: $$rowtotal += $typecount;
1.3 raeburn 2234: return $datatable;
2235: }
2236:
1.160.6.5 raeburn 2237: sub print_requestmail {
1.160.6.93 raeburn 2238: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2239: my ($now,$datatable,%currapp);
1.102 raeburn 2240: $now = time;
2241: if (ref($settings) eq 'HASH') {
2242: if (ref($settings->{'notify'}) eq 'HASH') {
2243: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2244: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2245: }
2246: }
2247: }
1.160.6.16 raeburn 2248: my $numinrow = 2;
1.160.6.34 raeburn 2249: my $css_class;
1.160.6.93 raeburn 2250: if ($$rowtotal%2) {
2251: $css_class = 'LC_odd_row';
2252: }
2253: if ($customcss) {
2254: $css_class .= " $customcss";
2255: }
2256: $css_class =~ s/^\s+//;
2257: if ($css_class) {
2258: $css_class = ' class="'.$css_class.'"';
2259: }
2260: if ($rowstyle) {
2261: $css_class .= ' style="'.$rowstyle.'"';
2262: }
1.160.6.5 raeburn 2263: my $text;
2264: if ($action eq 'requestcourses') {
2265: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2266: } elsif ($action eq 'requestauthor') {
2267: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2268: } else {
1.160.6.34 raeburn 2269: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2270: }
1.160.6.34 raeburn 2271: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2272: ' <td>'.$text.'</td>'.
1.102 raeburn 2273: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2274: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2275: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2276: if ($numdc > 0) {
2277: $datatable .= $table;
1.102 raeburn 2278: } else {
2279: $datatable .= &mt('There are no active Domain Coordinators');
2280: }
2281: $datatable .='</td></tr>';
2282: return $datatable;
2283: }
2284:
1.160.6.30 raeburn 2285: sub print_studentcode {
2286: my ($settings,$rowtotal) = @_;
2287: my $rownum = 0;
2288: my ($output,%current);
2289: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2290: if (ref($settings) eq 'HASH') {
2291: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2292: foreach my $type (@crstypes) {
2293: $current{$type} = $settings->{'uniquecode'}{$type};
2294: }
1.160.6.30 raeburn 2295: }
2296: }
2297: $output .= '<tr>'.
2298: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2299: '<td class="LC_left_item">';
2300: foreach my $type (@crstypes) {
2301: my $check = ' ';
2302: if ($current{$type}) {
2303: $check = ' checked="checked" ';
2304: }
2305: $output .= '<span class="LC_nobreak"><label>'.
2306: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2307: &mt($type).'</label></span>'.(' 'x2).' ';
2308: }
2309: $output .= '</td></tr>';
2310: $$rowtotal ++;
2311: return $output;
2312: }
2313:
2314: sub print_textbookcourses {
1.160.6.46 raeburn 2315: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2316: my $rownum = 0;
2317: my $css_class;
2318: my $itemcount = 1;
2319: my $maxnum = 0;
2320: my $bookshash;
2321: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2322: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2323: }
2324: my %ordered;
2325: if (ref($bookshash) eq 'HASH') {
2326: foreach my $item (keys(%{$bookshash})) {
2327: if (ref($bookshash->{$item}) eq 'HASH') {
2328: my $num = $bookshash->{$item}{'order'};
2329: $ordered{$num} = $item;
2330: }
2331: }
2332: }
2333: my $confname = $dom.'-domainconfig';
2334: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2335: my $maxnum = scalar(keys(%ordered));
2336: my $datatable;
1.160.6.30 raeburn 2337: if (keys(%ordered)) {
2338: my @items = sort { $a <=> $b } keys(%ordered);
2339: for (my $i=0; $i<@items; $i++) {
2340: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2341: my $key = $ordered{$items[$i]};
2342: my %coursehash=&Apache::lonnet::coursedescription($key);
2343: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2344: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2345: if (ref($bookshash->{$key}) eq 'HASH') {
2346: $subject = $bookshash->{$key}->{'subject'};
2347: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2348: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2349: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2350: $author = $bookshash->{$key}->{'author'};
2351: $image = $bookshash->{$key}->{'image'};
2352: if ($image ne '') {
2353: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2354: my $imagethumb = "$path/tn-".$imagefile;
2355: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2356: }
1.160.6.30 raeburn 2357: }
2358: }
1.160.6.46 raeburn 2359: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2360: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2361: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2362: for (my $k=0; $k<=$maxnum; $k++) {
2363: my $vpos = $k+1;
2364: my $selstr;
2365: if ($k == $i) {
2366: $selstr = ' selected="selected" ';
2367: }
2368: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2369: }
2370: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2371: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2372: &mt('Delete?').'</label></span></td>'.
2373: '<td colspan="2">'.
1.160.6.46 raeburn 2374: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2375: (' 'x2).
1.160.6.46 raeburn 2376: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2377: if ($type eq 'textbooks') {
2378: $datatable .= (' 'x2).
1.160.6.47 raeburn 2379: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2380: (' 'x2).
1.160.6.46 raeburn 2381: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2382: (' 'x2).
2383: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2384: if ($image) {
2385: $datatable .= '<span class="LC_nobreak">'.
2386: $imgsrc.
2387: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2388: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2389: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2390: }
2391: if ($switchserver) {
2392: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2393: } else {
2394: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2395: }
1.160.6.30 raeburn 2396: }
1.160.6.46 raeburn 2397: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2398: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2399: $coursetitle.'</span></td></tr>'."\n";
2400: $itemcount ++;
2401: }
2402: }
2403: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2404: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2405: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2406: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2407: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2408: for (my $k=0; $k<$maxnum+1; $k++) {
2409: my $vpos = $k+1;
2410: my $selstr;
2411: if ($k == $maxnum) {
2412: $selstr = ' selected="selected" ';
2413: }
2414: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2415: }
2416: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2417: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2418: '<td colspan="2">'.
1.160.6.46 raeburn 2419: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2420: (' 'x2).
1.160.6.46 raeburn 2421: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2422: (' 'x2);
2423: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2424: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2425: (' 'x2).
2426: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2427: (' 'x2).
2428: '<span class="LC_nobreak">'.&mt('Image:').' ';
2429: if ($switchserver) {
2430: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2431: } else {
2432: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2433: }
1.160.6.87 raeburn 2434: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2435: }
1.160.6.87 raeburn 2436: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2437: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2438: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2439: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2440: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2441: '</span></td>'."\n".
2442: '</tr>'."\n";
2443: $itemcount ++;
2444: return $datatable;
2445: }
2446:
2447: sub textbookcourses_javascript {
1.160.6.46 raeburn 2448: my ($settings) = @_;
2449: return unless(ref($settings) eq 'HASH');
2450: my (%ordered,%total,%jstext);
2451: foreach my $type ('textbooks','templates') {
2452: $total{$type} = 0;
2453: if (ref($settings->{$type}) eq 'HASH') {
2454: foreach my $item (keys(%{$settings->{$type}})) {
2455: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2456: my $num = $settings->{$type}->{$item}{'order'};
2457: $ordered{$type}{$num} = $item;
2458: }
2459: }
2460: $total{$type} = scalar(keys(%{$settings->{$type}}));
2461: }
2462: my @jsarray = ();
2463: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2464: push(@jsarray,$ordered{$type}{$item});
2465: }
2466: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2467: }
2468: return <<"ENDSCRIPT";
2469: <script type="text/javascript">
2470: // <![CDATA[
1.160.6.46 raeburn 2471: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2472: var changedVal;
1.160.6.46 raeburn 2473: $jstext{'textbooks'};
2474: $jstext{'templates'};
2475: var newpos;
2476: var maxh;
2477: if (caller == 'textbooks') {
2478: newpos = 'textbooks_addbook_pos';
2479: maxh = 1 + $total{'textbooks'};
2480: } else {
2481: newpos = 'templates_addbook_pos';
2482: maxh = 1 + $total{'templates'};
2483: }
1.160.6.30 raeburn 2484: var current = new Array;
2485: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2486: if (item == newpos) {
2487: changedVal = newitemVal;
2488: } else {
2489: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2490: current[newitemVal] = newpos;
2491: }
1.160.6.46 raeburn 2492: if (caller == 'textbooks') {
2493: for (var i=0; i<textbooks.length; i++) {
2494: var elementName = 'textbooks_'+textbooks[i];
2495: if (elementName != item) {
2496: if (form.elements[elementName]) {
2497: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2498: current[currVal] = elementName;
2499: }
2500: }
2501: }
2502: }
2503: if (caller == 'templates') {
2504: for (var i=0; i<templates.length; i++) {
2505: var elementName = 'templates_'+templates[i];
2506: if (elementName != item) {
2507: if (form.elements[elementName]) {
2508: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2509: current[currVal] = elementName;
2510: }
1.160.6.30 raeburn 2511: }
2512: }
2513: }
2514: var oldVal;
2515: for (var j=0; j<maxh; j++) {
2516: if (current[j] == undefined) {
2517: oldVal = j;
2518: }
2519: }
2520: if (oldVal < changedVal) {
2521: for (var k=oldVal+1; k<=changedVal ; k++) {
2522: var elementName = current[k];
2523: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2524: }
2525: } else {
2526: for (var k=changedVal; k<oldVal; k++) {
2527: var elementName = current[k];
2528: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2529: }
2530: }
2531: return;
2532: }
2533:
2534: // ]]>
2535: </script>
2536:
2537: ENDSCRIPT
2538: }
2539:
1.160.6.102.2 1(raebur 2540:0): sub ltitools_javascript {
2541:0): my ($settings) = @_;
5(raebur 2542:0): my $togglejs = <itools_toggle_js();
2543:0): unless (ref($settings) eq 'HASH') {
2544:0): return $togglejs;
2545:0): }
1(raebur 2546:0): my (%ordered,$total,%jstext);
2547:0): $total = 0;
2548:0): foreach my $item (keys(%{$settings})) {
2549:0): if (ref($settings->{$item}) eq 'HASH') {
2550:0): my $num = $settings->{$item}{'order'};
2551:0): $ordered{$num} = $item;
2552:0): }
2553:0): }
2554:0): $total = scalar(keys(%{$settings}));
2555:0): my @jsarray = ();
2556:0): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2557:0): push(@jsarray,$ordered{$item});
2558:0): }
2559:0): my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2560:0): return <<"ENDSCRIPT";
2561:0): <script type="text/javascript">
2562:0): // <![CDATA[
5(raebur 2563:0): function reorderLTITools(form,item) {
1(raebur 2564:0): var changedVal;
2565:0): $jstext
2566:0): var newpos = 'ltitools_add_pos';
2567:0): var maxh = 1 + $total;
2568:0): var current = new Array;
2569:0): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2570:0): if (item == newpos) {
2571:0): changedVal = newitemVal;
2572:0): } else {
2573:0): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2574:0): current[newitemVal] = newpos;
2575:0): }
2576:0): for (var i=0; i<ltitools.length; i++) {
2577:0): var elementName = 'ltitools_'+ltitools[i];
2578:0): if (elementName != item) {
2579:0): if (form.elements[elementName]) {
2580:0): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2581:0): current[currVal] = elementName;
2582:0): }
2583:0): }
2584:0): }
2585:0): var oldVal;
2586:0): for (var j=0; j<maxh; j++) {
2587:0): if (current[j] == undefined) {
2588:0): oldVal = j;
2589:0): }
2590:0): }
2591:0): if (oldVal < changedVal) {
2592:0): for (var k=oldVal+1; k<=changedVal ; k++) {
2593:0): var elementName = current[k];
2594:0): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2595:0): }
2596:0): } else {
2597:0): for (var k=changedVal; k<oldVal; k++) {
2598:0): var elementName = current[k];
2599:0): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2600:0): }
2601:0): }
2602:0): return;
2603:0): }
2604:0):
2605:0): // ]]>
2606:0): </script>
2607:0):
5(raebur 2608:0): $togglejs
2609:0):
2610:0): ENDSCRIPT
2611:0): }
2612:0):
2613:0): sub ltitools_toggle_js {
2614:0): return <<"ENDSCRIPT";
2615:0): <script type="text/javascript">
2616:0): // <![CDATA[
2617:0):
2618:0): function toggleLTITools(form,setting,item) {
2619:0): var radioname = '';
2620:0): var divid = '';
2621:0): if (setting == 'user') {
2622:0): divid = 'ltitools_'+setting+'_div_'+item;
2623:0): var checkid = 'ltitools_'+setting+'_field_'+item;
2624:0): if (document.getElementById(divid)) {
2625:0): if (document.getElementById(checkid)) {
2626:0): if (document.getElementById(checkid).checked) {
2627:0): document.getElementById(divid).style.display = 'inline-block';
2628:0): } else {
2629:0): document.getElementById(divid).style.display = 'none';
2630:0): }
2631:0): }
2632:0): }
2633:0): }
2634:0): return;
2635:0): }
2636:0): // ]]>
2637:0): </script>
2638:0):
1(raebur 2639:0): ENDSCRIPT
2640:0): }
2641:0):
1.3 raeburn 2642: sub print_autoenroll {
1.30 raeburn 2643: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2644: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2645: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2646: if (ref($settings) eq 'HASH') {
2647: if (exists($settings->{'run'})) {
2648: if ($settings->{'run'} eq '0') {
2649: $runoff = ' checked="checked" ';
2650: $runon = ' ';
2651: } else {
2652: $runon = ' checked="checked" ';
2653: $runoff = ' ';
2654: }
2655: } else {
2656: if ($autorun) {
2657: $runon = ' checked="checked" ';
2658: $runoff = ' ';
2659: } else {
2660: $runoff = ' checked="checked" ';
2661: $runon = ' ';
2662: }
2663: }
1.129 raeburn 2664: if (exists($settings->{'co-owners'})) {
2665: if ($settings->{'co-owners'} eq '0') {
2666: $coownersoff = ' checked="checked" ';
2667: $coownerson = ' ';
2668: } else {
2669: $coownerson = ' checked="checked" ';
2670: $coownersoff = ' ';
2671: }
2672: } else {
2673: $coownersoff = ' checked="checked" ';
2674: $coownerson = ' ';
2675: }
1.3 raeburn 2676: if (exists($settings->{'sender_domain'})) {
2677: $defdom = $settings->{'sender_domain'};
2678: }
1.160.6.68 raeburn 2679: if (exists($settings->{'autofailsafe'})) {
2680: $failsafe = $settings->{'autofailsafe'};
2681: }
1.14 raeburn 2682: } else {
2683: if ($autorun) {
2684: $runon = ' checked="checked" ';
2685: $runoff = ' ';
2686: } else {
2687: $runoff = ' checked="checked" ';
2688: $runon = ' ';
2689: }
1.3 raeburn 2690: }
2691: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2692: my $notif_sender;
2693: if (ref($settings) eq 'HASH') {
2694: $notif_sender = $settings->{'sender_uname'};
2695: }
1.3 raeburn 2696: my $datatable='<tr class="LC_odd_row">'.
2697: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2698: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2699: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2700: $runon.' value="1" />'.&mt('Yes').'</label> '.
2701: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2702: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2703: '</tr><tr>'.
2704: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2705: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2706: &mt('username').': '.
2707: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2708: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2709: ': '.$domform.'</span></td></tr>'.
2710: '<tr class="LC_odd_row">'.
2711: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2712: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2713: '<input type="radio" name="autoassign_coowners"'.
2714: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2715: '<label><input type="radio" name="autoassign_coowners"'.
2716: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2717: '</tr><tr>'.
2718: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2719: '<td class="LC_right_item"><span class="LC_nobreak">'.
2720: '<input type="text" name="autoenroll_failsafe"'.
1.160.6.87 raeburn 2721: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.160.6.68 raeburn 2722: $$rowtotal += 4;
1.3 raeburn 2723: return $datatable;
2724: }
2725:
2726: sub print_autoupdate {
1.30 raeburn 2727: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2728: my $datatable;
2729: if ($position eq 'top') {
2730: my $updateon = ' ';
2731: my $updateoff = ' checked="checked" ';
2732: my $classlistson = ' ';
2733: my $classlistsoff = ' checked="checked" ';
2734: if (ref($settings) eq 'HASH') {
2735: if ($settings->{'run'} eq '1') {
2736: $updateon = $updateoff;
2737: $updateoff = ' ';
2738: }
2739: if ($settings->{'classlists'} eq '1') {
2740: $classlistson = $classlistsoff;
2741: $classlistsoff = ' ';
2742: }
2743: }
2744: my %title = (
2745: run => 'Auto-update active?',
2746: classlists => 'Update information in classlists?',
2747: );
2748: $datatable = '<tr class="LC_odd_row">'.
2749: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2750: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2751: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2752: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2753: '<label><input type="radio" name="autoupdate_run"'.
2754: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2755: '</tr><tr>'.
2756: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2757: '<td class="LC_right_item"><span class="LC_nobreak">'.
2758: '<label><input type="radio" name="classlists"'.
2759: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2760: '<label><input type="radio" name="classlists"'.
2761: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2762: '</tr>';
1.30 raeburn 2763: $$rowtotal += 2;
1.131 raeburn 2764: } elsif ($position eq 'middle') {
2765: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2766: my $numinrow = 3;
2767: my $locknamesettings;
2768: $datatable .= &insttypes_row($settings,$types,$usertypes,
2769: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 2770: 'lockablenames',$rowtotal);
1.131 raeburn 2771: $$rowtotal ++;
1.3 raeburn 2772: } else {
1.44 raeburn 2773: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2774: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2775: 'permanentemail','id');
1.33 raeburn 2776: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2777: my $numrows = 0;
1.26 raeburn 2778: if (ref($types) eq 'ARRAY') {
2779: if (@{$types} > 0) {
2780: $datatable =
2781: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2782: \@fields,$types,\$numrows);
1.30 raeburn 2783: $$rowtotal += @{$types};
1.26 raeburn 2784: }
1.3 raeburn 2785: }
2786: $datatable .=
2787: &usertype_update_row($settings,{'default' => $othertitle},
2788: \%fieldtitles,\@fields,['default'],
2789: \$numrows);
1.30 raeburn 2790: $$rowtotal ++;
1.3 raeburn 2791: }
2792: return $datatable;
2793: }
2794:
1.125 raeburn 2795: sub print_autocreate {
2796: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2797: my (%createon,%createoff,%currhash);
1.125 raeburn 2798: my @types = ('xml','req');
2799: if (ref($settings) eq 'HASH') {
2800: foreach my $item (@types) {
2801: $createoff{$item} = ' checked="checked" ';
2802: $createon{$item} = ' ';
2803: if (exists($settings->{$item})) {
2804: if ($settings->{$item}) {
2805: $createon{$item} = ' checked="checked" ';
2806: $createoff{$item} = ' ';
2807: }
2808: }
2809: }
1.160.6.16 raeburn 2810: if ($settings->{'xmldc'} ne '') {
2811: $currhash{$settings->{'xmldc'}} = 1;
2812: }
1.125 raeburn 2813: } else {
2814: foreach my $item (@types) {
2815: $createoff{$item} = ' checked="checked" ';
2816: $createon{$item} = ' ';
2817: }
2818: }
2819: $$rowtotal += 2;
1.160.6.16 raeburn 2820: my $numinrow = 2;
1.125 raeburn 2821: my $datatable='<tr class="LC_odd_row">'.
2822: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2823: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2824: '<input type="radio" name="autocreate_xml"'.
2825: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2826: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2827: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2828: '</td></tr><tr>'.
2829: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2830: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2831: '<input type="radio" name="autocreate_req"'.
2832: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2833: '<label><input type="radio" name="autocreate_req"'.
2834: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2835: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2836: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2837: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2838: if ($numdc > 1) {
1.160.6.50 raeburn 2839: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2840: '</td><td class="LC_left_item">';
1.125 raeburn 2841: } else {
1.160.6.50 raeburn 2842: $datatable .= &mt('Course creation processed as:').
2843: '</td><td class="LC_right_item">';
1.125 raeburn 2844: }
1.160.6.50 raeburn 2845: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2846: $$rowtotal += $rows;
1.125 raeburn 2847: return $datatable;
2848: }
2849:
1.23 raeburn 2850: sub print_directorysrch {
1.160.6.72 raeburn 2851: my ($position,$dom,$settings,$rowtotal) = @_;
2852: my $datatable;
2853: if ($position eq 'top') {
2854: my $instsrchon = ' ';
2855: my $instsrchoff = ' checked="checked" ';
2856: my ($exacton,$containson,$beginson);
2857: my $instlocalon = ' ';
2858: my $instlocaloff = ' checked="checked" ';
2859: if (ref($settings) eq 'HASH') {
2860: if ($settings->{'available'} eq '1') {
2861: $instsrchon = $instsrchoff;
2862: $instsrchoff = ' ';
2863: }
2864: if ($settings->{'localonly'} eq '1') {
2865: $instlocalon = $instlocaloff;
2866: $instlocaloff = ' ';
2867: }
2868: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2869: foreach my $type (@{$settings->{'searchtypes'}}) {
2870: if ($type eq 'exact') {
2871: $exacton = ' checked="checked" ';
2872: } elsif ($type eq 'contains') {
2873: $containson = ' checked="checked" ';
2874: } elsif ($type eq 'begins') {
2875: $beginson = ' checked="checked" ';
2876: }
2877: }
2878: } else {
2879: if ($settings->{'searchtypes'} eq 'exact') {
2880: $exacton = ' checked="checked" ';
2881: } elsif ($settings->{'searchtypes'} eq 'contains') {
2882: $containson = ' checked="checked" ';
2883: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2884: $exacton = ' checked="checked" ';
2885: $containson = ' checked="checked" ';
2886: }
2887: }
1.23 raeburn 2888: }
1.160.6.72 raeburn 2889: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2890: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2891:
1.160.6.72 raeburn 2892: my $numinrow = 4;
2893: my $cansrchrow = 0;
2894: $datatable='<tr class="LC_odd_row">'.
2895: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2896: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2897: '<input type="radio" name="dirsrch_available"'.
2898: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2899: '<label><input type="radio" name="dirsrch_available"'.
2900: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2901: '</tr><tr>'.
2902: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2903: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2904: '<input type="radio" name="dirsrch_instlocalonly"'.
2905: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2906: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2907: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2908: '</tr>';
2909: $$rowtotal += 2;
2910: if (ref($usertypes) eq 'HASH') {
2911: if (keys(%{$usertypes}) > 0) {
2912: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 2913: $numinrow,$othertitle,'cansearch',
2914: $rowtotal);
1.160.6.72 raeburn 2915: $cansrchrow = 1;
2916: }
1.26 raeburn 2917: }
1.160.6.72 raeburn 2918: if ($cansrchrow) {
2919: $$rowtotal ++;
2920: $datatable .= '<tr>';
2921: } else {
2922: $datatable .= '<tr class="LC_odd_row">';
2923: }
2924: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2925: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2926: foreach my $title (@{$titleorder}) {
2927: if (defined($searchtitles->{$title})) {
2928: my $check = ' ';
2929: if (ref($settings) eq 'HASH') {
2930: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2931: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2932: $check = ' checked="checked" ';
2933: }
1.39 raeburn 2934: }
1.25 raeburn 2935: }
1.160.6.72 raeburn 2936: $datatable .= '<td class="LC_left_item">'.
2937: '<span class="LC_nobreak"><label>'.
2938: '<input type="checkbox" name="searchby" '.
2939: 'value="'.$title.'"'.$check.'/>'.
2940: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2941: }
2942: }
1.160.6.72 raeburn 2943: $datatable .= '</tr></table></td></tr>';
2944: $$rowtotal ++;
2945: if ($cansrchrow) {
2946: $datatable .= '<tr class="LC_odd_row">';
2947: } else {
2948: $datatable .= '<tr>';
2949: }
2950: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2951: '<td class="LC_left_item" colspan="2">'.
2952: '<span class="LC_nobreak"><label>'.
2953: '<input type="checkbox" name="searchtypes" '.
2954: $exacton.' value="exact" />'.&mt('Exact match').
2955: '</label> '.
2956: '<label><input type="checkbox" name="searchtypes" '.
2957: $beginson.' value="begins" />'.&mt('Begins with').
2958: '</label> '.
2959: '<label><input type="checkbox" name="searchtypes" '.
2960: $containson.' value="contains" />'.&mt('Contains').
2961: '</label></span></td></tr>';
2962: $$rowtotal ++;
1.26 raeburn 2963: } else {
1.160.6.72 raeburn 2964: my $domsrchon = ' checked="checked" ';
2965: my $domsrchoff = ' ';
2966: my $domlocalon = ' ';
2967: my $domlocaloff = ' checked="checked" ';
2968: if (ref($settings) eq 'HASH') {
2969: if ($settings->{'lclocalonly'} eq '1') {
2970: $domlocalon = $domlocaloff;
2971: $domlocaloff = ' ';
2972: }
2973: if ($settings->{'lcavailable'} eq '0') {
2974: $domsrchoff = $domsrchon;
2975: $domsrchon = ' ';
2976: }
2977: }
2978: $datatable='<tr class="LC_odd_row">'.
2979: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2980: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2981: '<input type="radio" name="dirsrch_domavailable"'.
2982: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2983: '<label><input type="radio" name="dirsrch_domavailable"'.
2984: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2985: '</tr><tr>'.
2986: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2987: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2988: '<input type="radio" name="dirsrch_domlocalonly"'.
2989: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2990: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2991: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2992: '</tr>';
2993: $$rowtotal += 2;
1.26 raeburn 2994: }
1.25 raeburn 2995: return $datatable;
2996: }
2997:
1.28 raeburn 2998: sub print_contacts {
1.160.6.78 raeburn 2999: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3000: my $datatable;
3001: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 3002: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.102.2 7(raebur 3003:1): $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 3004: if ($position eq 'top') {
3005: if (ref($settings) eq 'HASH') {
3006: foreach my $item (@contacts) {
3007: if (exists($settings->{$item})) {
3008: $to{$item} = $settings->{$item};
3009: }
1.28 raeburn 3010: }
3011: }
1.160.6.78 raeburn 3012: } elsif ($position eq 'middle') {
3013: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 3014: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 3015: foreach my $type (@mailings) {
1.160.6.78 raeburn 3016: $otheremails{$type} = '';
3017: }
1.160.6.102.2 7(raebur 3018:1): } elsif ($position eq 'lower') {
3019:1): if (ref($settings) eq 'HASH') {
3020:1): if (ref($settings->{'lonstatus'}) eq 'HASH') {
3021:1): %lonstatus = %{$settings->{'lonstatus'}};
3022:1): }
3023:1): }
1.160.6.78 raeburn 3024: } else {
3025: @mailings = ('helpdeskmail','otherdomsmail');
3026: foreach my $type (@mailings) {
3027: $otheremails{$type} = '';
3028: }
3029: $bccemails{'helpdeskmail'} = '';
3030: $bccemails{'otherdomsmail'} = '';
3031: $includestr{'helpdeskmail'} = '';
3032: $includestr{'otherdomsmail'} = '';
3033: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3034: }
3035: if (ref($settings) eq 'HASH') {
1.160.6.102.2 7(raebur 3036:1): unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3037: foreach my $type (@mailings) {
3038: if (exists($settings->{$type})) {
3039: if (ref($settings->{$type}) eq 'HASH') {
3040: foreach my $item (@contacts) {
3041: if ($settings->{$type}{$item}) {
3042: $checked{$type}{$item} = ' checked="checked" ';
3043: }
1.28 raeburn 3044: }
1.160.6.78 raeburn 3045: $otheremails{$type} = $settings->{$type}{'others'};
3046: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3047: $bccemails{$type} = $settings->{$type}{'bcc'};
3048: if ($settings->{$type}{'include'} ne '') {
3049: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3050: $includestr{$type} = &unescape($includestr{$type});
3051: }
3052: }
3053: }
3054: } elsif ($type eq 'lonstatusmail') {
3055: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3056: }
3057: }
3058: }
3059: if ($position eq 'bottom') {
3060: foreach my $type (@mailings) {
3061: $bccemails{$type} = $settings->{$type}{'bcc'};
3062: if ($settings->{$type}{'include'} ne '') {
3063: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3064: $includestr{$type} = &unescape($includestr{$type});
3065: }
3066: }
3067: if (ref($settings->{'helpform'}) eq 'HASH') {
3068: if (ref($fields) eq 'ARRAY') {
3069: foreach my $field (@{$fields}) {
3070: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3071: }
1.160.6.78 raeburn 3072: }
3073: if (exists($settings->{'helpform'}{'maxsize'})) {
3074: $maxsize = $settings->{'helpform'}{'maxsize'};
3075: } else {
3076: $maxsize = '1.0';
3077: }
3078: } else {
3079: if (ref($fields) eq 'ARRAY') {
3080: foreach my $field (@{$fields}) {
3081: $currfield{$field} = 'yes';
1.134 raeburn 3082: }
1.28 raeburn 3083: }
1.160.6.78 raeburn 3084: $maxsize = '1.0';
1.28 raeburn 3085: }
3086: }
3087: } else {
1.160.6.78 raeburn 3088: if ($position eq 'top') {
3089: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3090: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3091: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3092: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3093: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3094: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3095: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3096: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 3097: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 3098: } elsif ($position eq 'bottom') {
3099: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3100: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3101: if (ref($fields) eq 'ARRAY') {
3102: foreach my $field (@{$fields}) {
3103: $currfield{$field} = 'yes';
3104: }
3105: }
3106: $maxsize = '1.0';
3107: }
1.28 raeburn 3108: }
3109: my ($titles,$short_titles) = &contact_titles();
3110: my $rownum = 0;
3111: my $css_class;
1.160.6.78 raeburn 3112: if ($position eq 'top') {
3113: foreach my $item (@contacts) {
3114: $css_class = $rownum%2?' class="LC_odd_row"':'';
3115: $datatable .= '<tr'.$css_class.'>'.
3116: '<td><span class="LC_nobreak">'.$titles->{$item}.
3117: '</span></td><td class="LC_right_item">'.
3118: '<input type="text" name="'.$item.'" value="'.
3119: $to{$item}.'" /></td></tr>';
3120: $rownum ++;
3121: }
1.160.6.101 raeburn 3122: } elsif ($position eq 'bottom') {
3123: $css_class = $rownum%2?' class="LC_odd_row"':'';
3124: $datatable .= '<tr'.$css_class.'>'.
3125: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3126: &mt('(e-mail, subject, and description always shown)').
3127: '</td><td class="LC_left_item">';
3128: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3129: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3130: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3131: foreach my $field (@{$fields}) {
3132: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3133: if (($field eq 'screenshot') || ($field eq 'cc')) {
3134: $datatable .= ' '.&mt('(logged-in users)');
3135: }
3136: $datatable .='</td><td>';
3137: my $clickaction;
3138: if ($field eq 'screenshot') {
3139: $clickaction = ' onclick="screenshotSize(this);"';
3140: }
3141: if (ref($possoptions->{$field}) eq 'ARRAY') {
3142: foreach my $option (@{$possoptions->{$field}}) {
3143: my $checked;
3144: if ($currfield{$field} eq $option) {
3145: $checked = ' checked="checked"';
3146: }
3147: $datatable .= '<span class="LC_nobreak"><label>'.
3148: '<input type="radio" name="helpform_'.$field.'" '.
3149: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3150: '</label></span>'.(' 'x2);
3151: }
3152: }
3153: if ($field eq 'screenshot') {
3154: my $display;
3155: if ($currfield{$field} eq 'no') {
3156: $display = ' style="display:none"';
3157: }
3158: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
3159: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3160: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3161: }
3162: $datatable .= '</td></tr>';
3163: }
3164: $datatable .= '</table>';
3165: }
3166: $datatable .= '</td></tr>'."\n";
3167: $rownum ++;
3168: }
1.160.6.102.2 7(raebur 3169:1): unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3170: foreach my $type (@mailings) {
3171: $css_class = $rownum%2?' class="LC_odd_row"':'';
3172: $datatable .= '<tr'.$css_class.'>'.
3173: '<td><span class="LC_nobreak">'.
3174: $titles->{$type}.': </span></td>'.
3175: '<td class="LC_left_item">';
3176: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3177: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3178: }
3179: $datatable .= '<span class="LC_nobreak">';
3180: foreach my $item (@contacts) {
3181: $datatable .= '<label>'.
3182: '<input type="checkbox" name="'.$type.'"'.
3183: $checked{$type}{$item}.
3184: ' value="'.$item.'" />'.$short_titles->{$item}.
3185: '</label> ';
3186: }
3187: $datatable .= '</span><br />'.&mt('Others').': '.
3188: '<input type="text" name="'.$type.'_others" '.
3189: 'value="'.$otheremails{$type}.'" />';
3190: my %locchecked;
3191: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3192: foreach my $loc ('s','b') {
3193: if ($includeloc{$type} eq $loc) {
3194: $locchecked{$loc} = ' checked="checked"';
3195: last;
3196: }
3197: }
3198: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3199: '<input type="text" name="'.$type.'_bcc" '.
3200: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3201: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3202: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 3203: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 3204: '<span class="LC_nobreak">'.&mt('Location:').' '.
3205: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3206: (' 'x2).
3207: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3208: '</span></fieldset>';
3209: }
3210: $datatable .= '</td></tr>'."\n";
3211: $rownum ++;
3212: }
1.28 raeburn 3213: }
1.160.6.78 raeburn 3214: if ($position eq 'middle') {
3215: my %choices;
1.160.6.102.2 7(raebur 3216:1): my $corelink = &core_link_msu();
3217:1): $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 3218: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.102.2 7(raebur 3219:1): $corelink);
3220:1): $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3221:1): my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 3222: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.102.2 7(raebur 3223:1): 'reportupdates' => 'on',
3224:1): 'reportstatus' => 'on');
1.160.6.78 raeburn 3225: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3226: \%choices,$rownum);
3227: $datatable .= $reports;
1.160.6.102.2 7(raebur 3228:1): } elsif ($position eq 'lower') {
8(raebur 3229:1): my (%current,%excluded,%weights);
7(raebur 3230:1): my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3231:1): if ($lonstatus{'threshold'} =~ /^\d+$/) {
8(raebur 3232:1): $current{'errorthreshold'} = $lonstatus{'threshold'};
7(raebur 3233:1): } else {
8(raebur 3234:1): $current{'errorthreshold'} = $defaults->{'threshold'};
7(raebur 3235:1): }
3236:1): if ($lonstatus{'sysmail'} =~ /^\d+$/) {
8(raebur 3237:1): $current{'errorsysmail'} = $lonstatus{'sysmail'};
7(raebur 3238:1): } else {
8(raebur 3239:1): $current{'errorsysmail'} = $defaults->{'sysmail'};
7(raebur 3240:1): }
3241:1): if (ref($lonstatus{'weights'}) eq 'HASH') {
3242:1): foreach my $type ('E','W','N','U') {
3243:1): if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3244:1): $weights{$type} = $lonstatus{'weights'}{$type};
3245:1): } else {
3246:1): $weights{$type} = $defaults->{$type};
3247:1): }
3248:1): }
3249:1): } else {
3250:1): foreach my $type ('E','W','N','U') {
3251:1): $weights{$type} = $defaults->{$type};
3252:1): }
3253:1): }
3254:1): if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3255:1): if (@{$lonstatus{'excluded'}} > 0) {
3256:1): map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3257:1): }
3258:1): }
8(raebur 3259:1): foreach my $item ('errorthreshold','errorsysmail') {
3260:1): $css_class = $rownum%2?' class="LC_odd_row"':'';
3261:1): $datatable .= '<tr'.$css_class.'>'.
3262:1): '<td class="LC_left_item"><span class="LC_nobreak">'.
3263:1): $titles->{$item}.
3264:1): '</span></td><td class="LC_left_item">'.
3265:1): '<input type="text" name="'.$item.'" value="'.
9(raebur 3266:1): $current{$item}.'" size="5" /></td></tr>';
8(raebur 3267:1): $rownum ++;
3268:1): }
7(raebur 3269:1): $css_class = $rownum%2?' class="LC_odd_row"':'';
3270:1): $datatable .= '<tr'.$css_class.'>'.
3271:1): '<td class="LC_left_item">'.
3272:1): '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3273:1): '</span></td><td class="LC_left_item"><table><tr>';
3274:1): foreach my $type ('E','W','N','U') {
3275:1): $datatable .= '<td>'.$names->{$type}.'<br />'.
3276:1): '<input type="text" name="errorweights_'.$type.'" value="'.
3277:1): $weights{$type}.'" size="5" /></td>';
3278:1): }
3279:1): $datatable .= '</tr></table></tr>';
3280:1): $rownum ++;
3281:1): $css_class = $rownum%2?' class="LC_odd_row"':'';
3282:1): $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3283:1): $titles->{'errorexcluded'}.'</td>'.
3284:1): '<td class="LC_left_item"><table>';
3285:1): my $numinrow = 4;
3286:1): my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3287:1): for (my $i=0; $i<@ids; $i++) {
3288:1): my $rem = $i%($numinrow);
3289:1): if ($rem == 0) {
3290:1): if ($i > 0) {
3291:1): $datatable .= '</tr>';
3292:1): }
3293:1): $datatable .= '<tr>';
3294:1): }
3295:1): my $check;
3296:1): if ($excluded{$ids[$i]}) {
3297:1): $check = ' checked="checked" ';
3298:1): }
3299:1): $datatable .= '<td class="LC_left_item">'.
3300:1): '<span class="LC_nobreak"><label>'.
3301:1): '<input type="checkbox" name="errorexcluded" '.
3302:1): 'value="'.$ids[$i].'"'.$check.' />'.
3303:1): $ids[$i].'</label></span></td>';
3304:1): }
3305:1): my $colsleft = $numinrow - @ids%($numinrow);
3306:1): if ($colsleft > 1 ) {
3307:1): $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3308:1): ' </td>';
3309:1): } elsif ($colsleft == 1) {
3310:1): $datatable .= '<td class="LC_left_item"> </td>';
3311:1): }
3312:1): $datatable .= '</tr></table></td></tr>';
3313:1): $rownum ++;
1.160.6.78 raeburn 3314: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 3315: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3316: my (@posstypes,%usertypeshash);
3317: if (ref($types) eq 'ARRAY') {
3318: @posstypes = @{$types};
3319: }
3320: if (@posstypes) {
3321: if (ref($usertypes) eq 'HASH') {
3322: %usertypeshash = %{$usertypes};
3323: }
3324: my @overridden;
3325: my $numinrow = 4;
3326: if (ref($settings) eq 'HASH') {
3327: if (ref($settings->{'overrides'}) eq 'HASH') {
3328: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3329: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3330: push(@overridden,$key);
3331: foreach my $item (@contacts) {
3332: if ($settings->{'overrides'}{$key}{$item}) {
3333: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3334: }
3335: }
3336: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3337: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3338: $includeloc{'override_'.$key} = '';
3339: $includestr{'override_'.$key} = '';
3340: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3341: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3342: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3343: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3344: }
1.160.6.78 raeburn 3345: }
3346: }
3347: }
1.160.6.101 raeburn 3348: }
3349: my $customclass = 'LC_helpdesk_override';
3350: my $optionsprefix = 'LC_options_helpdesk_';
3351:
3352: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3353:
3354: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3355: $numinrow,$othertitle,'overrides',
3356: \$rownum,$onclicktypes,$customclass);
3357: $rownum ++;
3358: $usertypeshash{'default'} = $othertitle;
3359: foreach my $status (@posstypes) {
3360: my $css_class;
3361: if ($rownum%2) {
3362: $css_class = 'LC_odd_row ';
3363: }
3364: $css_class .= $customclass;
3365: my $rowid = $optionsprefix.$status;
3366: my $hidden = 1;
3367: my $currstyle = 'display:none';
3368: if (grep(/^\Q$status\E$/,@overridden)) {
3369: $currstyle = 'display:table-row';
3370: $hidden = 0;
3371: }
3372: my $key = 'override_'.$status;
3373: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3374: $includeloc{$key},$includestr{$key},$status,$rowid,
3375: $usertypeshash{$status},$css_class,$currstyle,
3376: \@contacts,$short_titles);
3377: unless ($hidden) {
3378: $rownum ++;
1.160.6.78 raeburn 3379: }
3380: }
1.134 raeburn 3381: }
1.28 raeburn 3382: }
1.30 raeburn 3383: $$rowtotal += $rownum;
1.28 raeburn 3384: return $datatable;
3385: }
3386:
1.160.6.102.2 7(raebur 3387:1): sub core_link_msu {
3388:1): return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3389:1): &mt('LON-CAPA core group - MSU'),600,500);
3390:1): }
3391:1):
1.160.6.101 raeburn 3392: sub overridden_helpdesk {
3393: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3394: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3395: my $class = 'LC_left_item';
3396: if ($css_class) {
3397: $css_class = ' class="'.$css_class.'"';
3398: }
3399: if ($rowid) {
3400: $rowid = ' id="'.$rowid.'"';
3401: }
3402: if ($rowstyle) {
3403: $rowstyle = ' style="'.$rowstyle.'"';
3404: }
3405: my ($output,$description);
3406: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3407: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3408: "<td>$description</td>\n".
3409: '<td class="'.$class.'" colspan="2">'.
3410: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3411: '<span class="LC_nobreak">';
3412: if (ref($contacts) eq 'ARRAY') {
3413: foreach my $item (@{$contacts}) {
3414: my $check;
3415: if (ref($checked) eq 'HASH') {
3416: $check = $checked->{$item};
3417: }
3418: my $title;
3419: if (ref($short_titles) eq 'HASH') {
3420: $title = $short_titles->{$item};
3421: }
3422: $output .= '<label>'.
3423: '<input type="checkbox" name="override_'.$type.'"'.$check.
3424: ' value="'.$item.'" />'.$title.'</label> ';
3425: }
3426: }
3427: $output .= '</span><br />'.&mt('Others').': '.
3428: '<input type="text" name="override_'.$type.'_others" '.
3429: 'value="'.$otheremails.'" />';
3430: my %locchecked;
3431: foreach my $loc ('s','b') {
3432: if ($includeloc eq $loc) {
3433: $locchecked{$loc} = ' checked="checked"';
3434: last;
3435: }
3436: }
3437: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3438: '<input type="text" name="override_'.$type.'_bcc" '.
3439: 'value="'.$bccemails.'" /></fieldset>'.
3440: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3441: &mt('Text automatically added to e-mail:').' '.
3442: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
3443: '<span class="LC_nobreak">'.&mt('Location:').' '.
3444: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3445: (' 'x2).
3446: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3447: '</span></fieldset>'.
3448: '</td></tr>'."\n";
3449: return $output;
3450: }
3451:
1.160.6.78 raeburn 3452: sub contacts_javascript {
3453: return <<"ENDSCRIPT";
3454:
3455: <script type="text/javascript">
3456: // <![CDATA[
3457:
3458: function screenshotSize(field) {
3459: if (document.getElementById('help_screenshotsize')) {
3460: if (field.value == 'no') {
3461: document.getElementById('help_screenshotsize').style.display="none";
3462: } else {
3463: document.getElementById('help_screenshotsize').style.display="";
3464: }
3465: }
3466: return;
3467: }
3468:
1.160.6.101 raeburn 3469: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3470: if (form.elements[checkbox].length != undefined) {
3471: var count = 0;
3472: if (docount) {
3473: for (var i=0; i<form.elements[checkbox].length; i++) {
3474: if (form.elements[checkbox][i].checked) {
3475: count ++;
3476: }
3477: }
3478: }
3479: for (var i=0; i<form.elements[checkbox].length; i++) {
3480: var type = form.elements[checkbox][i].value;
3481: if (document.getElementById(prefix+type)) {
3482: if (form.elements[checkbox][i].checked) {
3483: document.getElementById(prefix+type).style.display = 'table-row';
3484: if (count % 2 == 1) {
3485: document.getElementById(prefix+type).className = target+' LC_odd_row';
3486: } else {
3487: document.getElementById(prefix+type).className = target;
3488: }
3489: count ++;
3490: } else {
3491: document.getElementById(prefix+type).style.display = 'none';
3492: }
3493: }
3494: }
3495: }
3496: return;
3497: }
3498:
1.160.6.78 raeburn 3499: // ]]>
3500: </script>
3501:
3502: ENDSCRIPT
3503: }
3504:
1.118 jms 3505: sub print_helpsettings {
1.160.6.73 raeburn 3506: my ($position,$dom,$settings,$rowtotal) = @_;
3507: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3508: my $formname = 'display';
1.160.6.5 raeburn 3509: my ($datatable,$itemcount);
1.160.6.73 raeburn 3510: if ($position eq 'top') {
3511: $itemcount = 1;
3512: my (%choices,%defaultchecked,@toggles);
3513: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3514: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3515: &mt('LON-CAPA bug tracker'),600,500));
3516: %defaultchecked = ('submitbugs' => 'on');
3517: @toggles = ('submitbugs');
3518: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3519: \%choices,$itemcount);
3520: $$rowtotal ++;
3521: } else {
3522: my $css_class;
3523: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3524: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 3525: if (ref($settings) eq 'HASH') {
3526: if (ref($settings->{'adhoc'}) eq 'HASH') {
3527: %current = %{$settings->{'adhoc'}};
3528: }
1.160.6.77 raeburn 3529: }
3530: my $count = 0;
3531: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3532: if ($key=~/^rolesdef\_(\w+)$/) {
3533: my $rolename = $1;
1.160.6.77 raeburn 3534: my (%privs,$order);
1.160.6.73 raeburn 3535: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3536: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3537: if (ref($current{$rolename}) eq 'HASH') {
3538: $order = $current{$rolename}{'order'};
3539: }
3540: if ($order eq '') {
3541: $order = $count;
3542: }
3543: $ordered{$order} = $rolename;
3544: $count++;
1.160.6.73 raeburn 3545: }
3546: }
1.160.6.77 raeburn 3547: my $maxnum = scalar(keys(%ordered));
3548: my @roles_by_num = ();
3549: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3550: push(@roles_by_num,$item);
3551: }
3552: my $context = 'domprefs';
3553: my $crstype = 'Course';
3554: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3555: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3556: my ($numstatustypes,@jsarray);
3557: if (ref($types) eq 'ARRAY') {
3558: if (@{$types} > 0) {
3559: $numstatustypes = scalar(@{$types});
3560: push(@accesstypes,'status');
3561: @jsarray = ('bystatus');
3562: }
3563: }
1.160.6.86 raeburn 3564: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3565: if (keys(%domhelpdesk)) {
3566: push(@accesstypes,('inc','exc'));
3567: push(@jsarray,('notinc','notexc'));
3568: }
3569: my $hiddenstr = join("','",@jsarray);
3570: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3571: my $context = 'domprefs';
3572: my $crstype = 'Course';
1.160.6.77 raeburn 3573: my $prefix = 'helproles_';
3574: my $add_class = 'LC_hidden';
3575: foreach my $num (@roles_by_num) {
3576: my $role = $ordered{$num};
3577: my ($desc,$access,@statuses);
3578: if (ref($current{$role}) eq 'HASH') {
3579: $desc = $current{$role}{'desc'};
3580: $access = $current{$role}{'access'};
3581: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3582: @statuses = @{$current{$role}{'insttypes'}};
3583: }
3584: }
3585: if ($desc eq '') {
3586: $desc = $role;
3587: }
3588: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3589: my %full=();
3590: my %levels= (
3591: course => {},
3592: domain => {},
3593: system => {},
3594: );
3595: my %levelscurrent=(
3596: course => {},
3597: domain => {},
3598: system => {},
3599: );
3600: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3601: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3602: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3603: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3604: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3605: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3606: for (my $k=0; $k<=$maxnum; $k++) {
3607: my $vpos = $k+1;
3608: my $selstr;
3609: if ($k == $num) {
3610: $selstr = ' selected="selected" ';
3611: }
3612: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3613: }
3614: $datatable .= '</select>'.(' 'x2).
3615: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3616: '</td>'.
3617: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3618: &mt('Name shown to users:').
3619: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3620: '</fieldset>'.
3621: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3622: $othertitle,$usertypes,$types,\%domhelpdesk).
3623: '<fieldset>'.
3624: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3625: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3626: \%levelscurrent,$identifier,
3627: 'LC_hidden',$prefix.$num.'_privs').
3628: '</fieldset></td>';
1.160.6.73 raeburn 3629: $itemcount ++;
3630: }
3631: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3632: my $newcust = 'custhelp'.$count;
3633: my (%privs,%levelscurrent);
3634: my %full=();
3635: my %levels= (
3636: course => {},
3637: domain => {},
3638: system => {},
3639: );
3640: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3641: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3642: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3643: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3644: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3645: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3646: for (my $k=0; $k<$maxnum+1; $k++) {
3647: my $vpos = $k+1;
3648: my $selstr;
3649: if ($k == $maxnum) {
3650: $selstr = ' selected="selected" ';
3651: }
3652: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3653: }
3654: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3655: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3656: '</label></span></td>'.
1.160.6.77 raeburn 3657: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3658: '<span class="LC_nobreak">'.
3659: &mt('Internal name:').
3660: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3661: '</span>'.(' 'x4).
3662: '<span class="LC_nobreak">'.
3663: &mt('Name shown to users:').
3664: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3665: '</span></fieldset>'.
3666: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3667: $usertypes,$types,\%domhelpdesk).
3668: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3669: &Apache::lonuserutils::custom_role_header($context,$crstype,
3670: \@templateroles,$newcust).
3671: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3672: \%levelscurrent,$newcust).
1.160.6.87 raeburn 3673: '</fieldset>'.
3674: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
3675: '</td></tr>';
1.160.6.73 raeburn 3676: $count ++;
3677: $$rowtotal += $count;
3678: }
1.160.6.5 raeburn 3679: return $datatable;
1.121 raeburn 3680: }
3681:
1.160.6.77 raeburn 3682: sub adhocbutton {
3683: my ($prefix,$num,$field,$visibility) = @_;
3684: my %lt = &Apache::lonlocal::texthash(
3685: show => 'Show details',
3686: hide => 'Hide details',
3687: );
3688: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3689: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3690: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3691: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3692: }
3693:
3694: sub helpsettings_javascript {
3695: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3696: return unless(ref($roles_by_num) eq 'ARRAY');
3697: my %html_js_lt = &Apache::lonlocal::texthash(
3698: show => 'Show details',
3699: hide => 'Hide details',
3700: );
3701: &html_escape(\%html_js_lt);
3702: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3703: return <<"ENDSCRIPT";
3704: <script type="text/javascript">
3705: // <![CDATA[
3706:
3707: function reorderHelpRoles(form,item) {
3708: var changedVal;
3709: $jstext
3710: var newpos = 'helproles_${total}_pos';
3711: var maxh = 1 + $total;
3712: var current = new Array();
3713: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3714: if (item == newpos) {
3715: changedVal = newitemVal;
3716: } else {
3717: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3718: current[newitemVal] = newpos;
3719: }
3720: for (var i=0; i<helproles.length; i++) {
3721: var elementName = 'helproles_'+helproles[i]+'_pos';
3722: if (elementName != item) {
3723: if (form.elements[elementName]) {
3724: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3725: current[currVal] = elementName;
3726: }
3727: }
3728: }
3729: var oldVal;
3730: for (var j=0; j<maxh; j++) {
3731: if (current[j] == undefined) {
3732: oldVal = j;
3733: }
3734: }
3735: if (oldVal < changedVal) {
3736: for (var k=oldVal+1; k<=changedVal ; k++) {
3737: var elementName = current[k];
3738: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3739: }
3740: } else {
3741: for (var k=changedVal; k<oldVal; k++) {
3742: var elementName = current[k];
3743: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3744: }
3745: }
3746: return;
3747: }
3748:
3749: function helpdeskAccess(num) {
3750: var curraccess = null;
3751: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3752: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3753: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3754: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3755: }
3756: }
3757: }
3758: var shown = Array();
3759: var hidden = Array();
3760: if (curraccess == 'none') {
3761: hidden = Array('$hiddenstr');
3762: } else {
3763: if (curraccess == 'status') {
3764: shown = Array('bystatus');
3765: hidden = Array('notinc','notexc');
3766: } else {
3767: if (curraccess == 'exc') {
3768: shown = Array('notexc');
3769: hidden = Array('notinc','bystatus');
3770: }
3771: if (curraccess == 'inc') {
3772: shown = Array('notinc');
3773: hidden = Array('notexc','bystatus');
3774: }
1.160.6.79 raeburn 3775: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3776: hidden = Array('notinc','notexc','bystatus');
3777: }
3778: }
3779: }
3780: if (hidden.length > 0) {
3781: for (var i=0; i<hidden.length; i++) {
3782: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3783: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3784: }
3785: }
3786: }
3787: if (shown.length > 0) {
3788: for (var i=0; i<shown.length; i++) {
3789: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3790: if (shown[i] == 'privs') {
3791: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3792: } else {
3793: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3794: }
3795: }
3796: }
3797: }
3798: return;
3799: }
3800:
3801: function toggleHelpdeskItem(num,field) {
3802: if (document.getElementById('helproles_'+num+'_'+field)) {
3803: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3804: document.getElementById('helproles_'+num+'_'+field).className =
3805: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3806: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3807: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3808: }
3809: } else {
3810: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3811: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3812: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3813: }
3814: }
3815: }
3816: return;
3817: }
3818:
3819: // ]]>
3820: </script>
3821:
3822: ENDSCRIPT
3823: }
3824:
3825: sub helpdeskroles_access {
3826: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3827: $usertypes,$types,$domhelpdesk) = @_;
3828: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3829: my %lt = &Apache::lonlocal::texthash(
3830: 'rou' => 'Role usage',
3831: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3832: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3833: 'dh' => 'All with domain helpdesk role',
3834: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3835: 'none' => 'None',
3836: 'status' => 'Determined based on institutional status',
3837: 'inc' => 'Include all, but exclude specific personnel',
3838: 'exc' => 'Exclude all, but include specific personnel',
3839: );
3840: my %usecheck = (
3841: all => ' checked="checked"',
3842: );
3843: my %displaydiv = (
3844: status => 'none',
3845: inc => 'none',
3846: exc => 'none',
3847: priv => 'block',
3848: );
3849: my $output;
3850: if (ref($current) eq 'HASH') {
3851: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3852: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3853: $usecheck{$current->{access}} = $usecheck{'all'};
3854: delete($usecheck{'all'});
3855: if ($current->{access} =~ /^(status|inc|exc)$/) {
3856: my $access = $1;
3857: $displaydiv{$access} = 'inline';
3858: } elsif ($current->{access} eq 'none') {
3859: $displaydiv{'priv'} = 'none';
3860: }
3861: }
3862: }
3863: }
3864: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3865: '<p>'.$lt{'whi'}.'</p>';
3866: foreach my $access (@{$accesstypes}) {
3867: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3868: ' onclick="helpdeskAccess('."'$num'".');" />'.
3869: $lt{$access}.'</label>';
3870: if ($access eq 'status') {
3871: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3872: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3873: $othertitle,$usertypes,$types).
3874: '</div>';
3875: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3876: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3877: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3878: '</div>';
3879: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3880: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3881: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3882: '</div>';
3883: }
3884: $output .= '</p>';
3885: }
3886: $output .= '</fieldset>';
3887: return $output;
3888: }
3889:
1.121 raeburn 3890: sub radiobutton_prefs {
1.160.6.16 raeburn 3891: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3892: $additional,$align) = @_;
1.121 raeburn 3893: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3894: (ref($choices) eq 'HASH'));
3895:
3896: my (%checkedon,%checkedoff,$datatable,$css_class);
3897:
3898: foreach my $item (@{$toggles}) {
3899: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3900: $checkedon{$item} = ' checked="checked" ';
3901: $checkedoff{$item} = ' ';
1.121 raeburn 3902: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3903: $checkedoff{$item} = ' checked="checked" ';
3904: $checkedon{$item} = ' ';
3905: }
3906: }
3907: if (ref($settings) eq 'HASH') {
1.121 raeburn 3908: foreach my $item (@{$toggles}) {
1.118 jms 3909: if ($settings->{$item} eq '1') {
3910: $checkedon{$item} = ' checked="checked" ';
3911: $checkedoff{$item} = ' ';
3912: } elsif ($settings->{$item} eq '0') {
3913: $checkedoff{$item} = ' checked="checked" ';
3914: $checkedon{$item} = ' ';
3915: }
3916: }
1.121 raeburn 3917: }
1.160.6.16 raeburn 3918: if ($onclick) {
3919: $onclick = ' onclick="'.$onclick.'"';
3920: }
1.121 raeburn 3921: foreach my $item (@{$toggles}) {
1.118 jms 3922: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3923: $datatable .=
1.160.6.16 raeburn 3924: '<tr'.$css_class.'><td valign="top">'.
3925: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3926: '</span></td>';
3927: if ($align eq 'left') {
3928: $datatable .= '<td class="LC_left_item">';
3929: } else {
3930: $datatable .= '<td class="LC_right_item">';
3931: }
3932: $datatable .=
3933: '<span class="LC_nobreak">'.
1.118 jms 3934: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3935: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3936: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3937: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3938: '</span>'.$additional.
3939: '</td>'.
1.118 jms 3940: '</tr>';
3941: $itemcount ++;
1.121 raeburn 3942: }
3943: return ($datatable,$itemcount);
3944: }
3945:
1.160.6.102.2 1(raebur 3946:0): sub print_ltitools {
3947:0): my ($dom,$settings,$rowtotal) = @_;
3948:0): my $rownum = 0;
3949:0): my $css_class;
3950:0): my $itemcount = 1;
3951:0): my $maxnum = 0;
3952:0): my %ordered;
3953:0): if (ref($settings) eq 'HASH') {
3954:0): foreach my $item (keys(%{$settings})) {
3955:0): if (ref($settings->{$item}) eq 'HASH') {
3956:0): my $num = $settings->{$item}{'order'};
3957:0): $ordered{$num} = $item;
3958:0): }
3959:0): }
3960:0): }
3961:0): my $confname = $dom.'-domainconfig';
3962:0): my $switchserver = &check_switchserver($dom,$confname);
3963:0): my $maxnum = scalar(keys(%ordered));
5(raebur 3964:0): my $datatable;
1(raebur 3965:0): my %lt = <itools_names();
3966:0): my @courseroles = ('cc','in','ta','ep','st');
3967:0): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
5(raebur 3968:0): my @fields = ('fullname','firstname','lastname','email','roles','user');
1(raebur 3969:0): if (keys(%ordered)) {
3970:0): my @items = sort { $a <=> $b } keys(%ordered);
3971:0): for (my $i=0; $i<@items; $i++) {
3972:0): $css_class = $itemcount%2?' class="LC_odd_row"':'';
3973:0): my $item = $ordered{$items[$i]};
5(raebur 3974:0): my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1(raebur 3975:0): if (ref($settings->{$item}) eq 'HASH') {
3976:0): $title = $settings->{$item}->{'title'};
3977:0): $url = $settings->{$item}->{'url'};
3978:0): $key = $settings->{$item}->{'key'};
3979:0): $secret = $settings->{$item}->{'secret'};
5(raebur 3980:0): $lifetime = $settings->{$item}->{'lifetime'};
1(raebur 3981:0): my $image = $settings->{$item}->{'image'};
3982:0): if ($image ne '') {
3983:0): $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3984:0): }
5(raebur 3985:0): if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
3986:0): $sigsel{'HMAC-256'} = ' selected="selected"';
3987:0): } else {
3988:0): $sigsel{'HMAC-SHA1'} = ' selected="selected"';
3989:0): }
1(raebur 3990:0): }
5(raebur 3991:0): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1(raebur 3992:0): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3993:0): .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3994:0): for (my $k=0; $k<=$maxnum; $k++) {
3995:0): my $vpos = $k+1;
3996:0): my $selstr;
3997:0): if ($k == $i) {
3998:0): $selstr = ' selected="selected" ';
3999:0): }
4000:0): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4001:0): }
4002:0): $datatable .= '</select>'.(' 'x2).
4003:0): '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4004:0): &mt('Delete?').'</label></span></td>'.
4005:0): '<td colspan="2">'.
4006:0): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5(raebur 4007:0): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1(raebur 4008:0): (' 'x2).
4009:0): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4010:0): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4011:0): (' 'x2).
4012:0): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4013:0): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
5(raebur 4014:0): (' 'x2).
4015:0): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4016:0): '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4017:0): '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1(raebur 4018:0): '<br /><br />'.
5(raebur 4019:0): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1(raebur 4020:0): ' value="'.$url.'" /></span>'.
4021:0): (' 'x2).
5(raebur 4022:0): '<span class="LC_nobreak">'.$lt{'key'}.':'.
1(raebur 4023:0): '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4024:0): (' 'x2).
5(raebur 4025:0): '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4026:0): '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4027:0): (' 'x2).
1(raebur 4028:0): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4029:0): '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4030: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>'.
4031:0): '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4032:0): '</fieldset>'.
4033:0): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4034:0): '<span class="LC_nobreak">'.&mt('Display target:');
4035:0): my %currdisp;
4036:0): if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4037:0): if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4038:0): $currdisp{'window'} = ' checked="checked"';
4039:0): } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4040:0): $currdisp{'tab'} = ' checked="checked"';
4041:0): } else {
4042:0): $currdisp{'iframe'} = ' checked="checked"';
4043:0): }
4044:0): if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4045:0): $currdisp{'width'} = $1;
4046:0): }
4047:0): if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4048:0): $currdisp{'height'} = $1;
4049:0): }
4050:0): $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4051:0): $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
4052:0): } else {
4053:0): $currdisp{'iframe'} = ' checked="checked"';
4054:0): }
4055:0): foreach my $disp ('iframe','tab','window') {
4056:0): $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4057:0): $lt{$disp}.'</label>'.(' 'x2);
4058:0): }
4059:0): $datatable .= (' 'x4);
4060:0): foreach my $dimen ('width','height') {
4061:0): $datatable .= '<label>'.$lt{$dimen}.' '.
4062:0): '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4063:0): (' 'x2);
4064:0): }
5(raebur 4065:0): $datatable .= '</span><br />'.
1(raebur 4066:0): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
5(raebur 4067:0): '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1(raebur 4068:0): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4069:0): '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
5(raebur 4070:0): '</textarea></div><div style=""></div>'.
4071:0): '<div style="padding:0;clear:both;margin:0;border:0"></div>';
4072:0): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1(raebur 4073:0): if ($imgsrc) {
4074:0): $datatable .= $imgsrc.
4075:0): '<label><input type="checkbox" name="ltitools_image_del"'.
4076:0): ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4077:0): '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4078:0): } else {
4079:0): $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4080:0): }
4081:0): if ($switchserver) {
4082:0): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4083:0): } else {
4084:0): $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4085:0): }
4086:0): $datatable .= '</span></fieldset>';
5(raebur 4087:0): my (%checkedfields,%rolemaps,$userincdom);
1(raebur 4088:0): if (ref($settings->{$item}) eq 'HASH') {
4089:0): if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4090:0): %checkedfields = %{$settings->{$item}->{'fields'}};
4091:0): }
5(raebur 4092:0): $userincdom = $settings->{$item}->{'incdom'};
1(raebur 4093:0): if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4094:0): %rolemaps = %{$settings->{$item}->{'roles'}};
4095:0): $checkedfields{'roles'} = 1;
4096:0): }
4097:0): }
4098:0): $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4099:0): '<span class="LC_nobreak">';
5(raebur 4100:0): my $userfieldstyle = 'display:none;';
4101:0): my $seluserdom = '';
4102:0): my $unseluserdom = ' selected="selected"';
1(raebur 4103:0): foreach my $field (@fields) {
5(raebur 4104:0): my ($checked,$onclick,$id,$spacer);
1(raebur 4105:0): if ($checkedfields{$field}) {
4106:0): $checked = ' checked="checked"';
4107:0): }
5(raebur 4108:0): if ($field eq 'user') {
4109:0): $id = ' id="ltitools_user_field_'.$i.'"';
4110:0): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4111:0): if ($checked) {
4112:0): $userfieldstyle = 'display:inline-block';
4113:0): if ($userincdom) {
4114:0): $seluserdom = $unseluserdom;
4115:0): $unseluserdom = '';
4116:0): }
4117:0): }
4118:0): } else {
4119:0): $spacer = (' ' x2);
4120:0): }
1(raebur 4121:0): $datatable .= '<label>'.
5(raebur 4122:0): '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4123:0): $lt{$field}.'</label>'.$spacer;
1(raebur 4124:0): }
5(raebur 4125:0): $datatable .= '</span>';
4126:0): $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4127:0): '<span class="LC_nobreak"> : '.
4128:0): '<select name="ltitools_userincdom_'.$i.'">'.
4129:0): '<option value="">'.&mt('Select').'</option>'.
4130:0): '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4131:0): '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4132:0): '</select></span></div>';
4133:0): $datatable .= '</fieldset>'.
1(raebur 4134:0): '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4135:0): foreach my $role (@courseroles) {
4136:0): my ($selected,$selectnone);
4137:0): if (!$rolemaps{$role}) {
4138:0): $selectnone = ' selected="selected"';
4139:0): }
4140:0): $datatable .= '<td align="center">'.
4141:0): &Apache::lonnet::plaintext($role,'Course').'<br />'.
4142:0): '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4143:0): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4144:0): foreach my $ltirole (@ltiroles) {
4145:0): unless ($selectnone) {
4146:0): if ($rolemaps{$role} eq $ltirole) {
4147:0): $selected = ' selected="selected"';
4148:0): } else {
4149:0): $selected = '';
4150:0): }
4151:0): }
4152:0): $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4153:0): }
4154:0): $datatable .= '</select></td>';
4155:0): }
4156:0): $datatable .= '</tr></table></fieldset>';
4157:0): my %courseconfig;
4158:0): if (ref($settings->{$item}) eq 'HASH') {
4159:0): if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4160:0): %courseconfig = %{$settings->{$item}->{'crsconf'}};
4161:0): }
4162:0): }
4163:0): $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
5(raebur 4164:0): foreach my $item ('label','title','target','linktext','explanation','append') {
1(raebur 4165:0): my $checked;
4166:0): if ($courseconfig{$item}) {
4167:0): $checked = ' checked="checked"';
4168:0): }
4169:0): $datatable .= '<label>'.
4170:0): '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4171:0): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4172:0): }
4173:0): $datatable .= '</span></fieldset>'.
4174:0): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4175:0): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4176:0): if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4177:0): my %custom = %{$settings->{$item}->{'custom'}};
4178:0): if (keys(%custom) > 0) {
4179:0): foreach my $key (sort(keys(%custom))) {
4180:0): $datatable .= '<tr><td><span class="LC_nobreak">'.
4181:0): '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4182:0): $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4183:0): '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4184:0): ' value="'.$custom{$key}.'" /></td></tr>';
4185:0): }
4186:0): }
4187:0): }
4188:0): $datatable .= '<tr><td><span class="LC_nobreak">'.
4189:0): '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4190:0): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4191:0): '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4192:0): $datatable .= '</table></fieldset></td></tr>'."\n";
4193:0): $itemcount ++;
4194:0): }
4195:0): }
4196:0): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5(raebur 4197:0): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1(raebur 4198:0): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4199:0): '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4200:0): '<select name="ltitools_add_pos"'.$chgstr.'>';
4201:0): for (my $k=0; $k<$maxnum+1; $k++) {
4202:0): my $vpos = $k+1;
4203:0): my $selstr;
4204:0): if ($k == $maxnum) {
4205:0): $selstr = ' selected="selected" ';
4206:0): }
4207:0): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4208:0): }
4209:0): $datatable .= '</select> '."\n".
5(raebur 4210:0): '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1(raebur 4211:0): '<td colspan="2">'.
4212:0): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5(raebur 4213:0): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1(raebur 4214:0): (' 'x2).
4215:0): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4216:0): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4217:0): (' 'x2).
4218:0): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4219:0): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
5(raebur 4220:0): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4221:0): '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4222:0): '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1(raebur 4223:0): '<br />'.
5(raebur 4224:0): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1(raebur 4225:0): (' 'x2).
4226:0): '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4227:0): (' 'x2).
5(raebur 4228:0): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4229:0): (' 'x2).
1(raebur 4230:0): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4231: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".
4232:0): '</fieldset>'.
4233:0): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4234:0): '<span class="LC_nobreak">'.&mt('Display target:');
4235:0): my %defaultdisp;
4236:0): $defaultdisp{'iframe'} = ' checked="checked"';
4237:0): foreach my $disp ('iframe','tab','window') {
4238:0): $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4239:0): $lt{$disp}.'</label>'.(' 'x2);
4240:0): }
4241:0): $datatable .= (' 'x4);
4242:0): foreach my $dimen ('width','height') {
4243:0): $datatable .= '<label>'.$lt{$dimen}.' '.
4244:0): '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4245:0): (' 'x2);
4246:0): }
5(raebur 4247:0): $datatable .= '</span><br />'.
1(raebur 4248:0): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
5(raebur 4249:0): '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1(raebur 4250:0): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
5(raebur 4251:0): '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4252:0): '</div><div style=""></div>'.
4253:0): '<div style="padding:0;clear:both;margin:0;border:0"></div>';
4254:0): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1(raebur 4255:0): '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4256:0): if ($switchserver) {
4257:0): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4258:0): } else {
4259:0): $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4260:0): }
4261:0): $datatable .= '</span></fieldset>'.
4262:0): '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4263:0): '<span class="LC_nobreak">';
4264:0): foreach my $field (@fields) {
5(raebur 4265:0): my ($id,$onclick,$spacer);
4266:0): if ($field eq 'user') {
4267:0): $id = ' id="ltitools_user_field_add"';
4268:0): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4269:0): } else {
4270:0): $spacer = (' ' x2);
4271:0): }
1(raebur 4272:0): $datatable .= '<label>'.
5(raebur 4273:0): '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4274:0): $lt{$field}.'</label>'.$spacer;
1(raebur 4275:0): }
5(raebur 4276:0): $datatable .= '</span>'.
4277:0): '<div style="display:none;" id="ltitools_user_div_add">'.
4278:0): '<span class="LC_nobreak"> : '.
4279:0): '<select name="ltitools_userincdom_add">'.
4280:0): '<option value="" selected="selected">'.&mt('Select').'</option>'.
4281:0): '<option value="0">'.&mt('username').'</option>'.
4282:0): '<option value="1">'.&mt('username:domain').'</option>'.
4283:0): '</select></span></div></fieldset>';
4284:0): $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1(raebur 4285:0): foreach my $role (@courseroles) {
4286:0): my ($checked,$checkednone);
4287:0): $datatable .= '<td align="center">'.
4288:0): &Apache::lonnet::plaintext($role,'Course').'<br />'.
4289:0): '<select name="ltitools_add_roles_'.$role.'">'.
4290:0): '<option value="" selected="selected">'.&mt('Select').'</option>';
4291:0): foreach my $ltirole (@ltiroles) {
4292:0): $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4293:0): }
4294:0): $datatable .= '</select></td>';
4295:0): }
4296:0): $datatable .= '</tr></table></fieldset>'.
4297:0): '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
5(raebur 4298:0): foreach my $item ('label','title','target','linktext','explanation','append') {
1(raebur 4299:0): $datatable .= '<label>'.
4300:0): '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4301:0): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4302:0): }
4303:0): $datatable .= '</span></fieldset>'.
4304:0): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4305:0): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4306:0): '<tr><td><span class="LC_nobreak">'.
4307:0): '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4308:0): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4309:0): '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
5(raebur 4310:0): '</table></fieldset>'."\n".
1(raebur 4311:0): '</td>'."\n".
4312:0): '</tr>'."\n";
4313:0): $itemcount ++;
4314:0): return $datatable;
4315:0): }
4316:0):
4317:0): sub ltitools_names {
4318:0): my %lt = &Apache::lonlocal::texthash(
4319:0): 'title' => 'Title',
4320:0): 'version' => 'Version',
4321:0): 'msgtype' => 'Message Type',
5(raebur 4322:0): 'sigmethod' => 'Signature Method',
1(raebur 4323:0): 'url' => 'URL',
4324:0): 'key' => 'Key',
5(raebur 4325:0): 'lifetime' => 'Nonce lifetime (s)',
1(raebur 4326:0): 'secret' => 'Secret',
4327:0): 'icon' => 'Icon',
5(raebur 4328:0): 'user' => 'User',
1(raebur 4329:0): 'fullname' => 'Full Name',
4330:0): 'firstname' => 'First Name',
4331:0): 'lastname' => 'Last Name',
4332:0): 'email' => 'E-mail',
4333:0): 'roles' => 'Role',
4334:0): 'window' => 'Window',
4335:0): 'tab' => 'Tab',
4336:0): 'iframe' => 'iFrame',
4337:0): 'height' => 'Height',
4338:0): 'width' => 'Width',
4339:0): 'linktext' => 'Default Link Text',
4340:0): 'explanation' => 'Default Explanation',
4341:0): 'crstarget' => 'Display target',
4342:0): 'crslabel' => 'Course label',
4343:0): 'crstitle' => 'Course title',
4344:0): 'crslinktext' => 'Link Text',
4345:0): 'crsexplanation' => 'Explanation',
5(raebur 4346:0): 'crsappend' => 'Provider URL',
1(raebur 4347:0): );
4348:0):
4349:0): return %lt;
4350:0): }
4351:0):
1.121 raeburn 4352: sub print_coursedefaults {
1.139 raeburn 4353: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 4354: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4355: my $itemcount = 1;
1.160.6.16 raeburn 4356: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 4357: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 4358: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4359: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 4360: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4361: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.90 raeburn 4362: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 4363: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 4364: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 4365: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 4366: );
1.160.6.21 raeburn 4367: my %staticdefaults = (
4368: anonsurvey_threshold => 10,
4369: uploadquota => 500,
1.160.6.57 raeburn 4370: postsubmit => 60,
1.160.6.70 raeburn 4371: mysqltables => 172800,
1.160.6.21 raeburn 4372: );
1.139 raeburn 4373: if ($position eq 'top') {
1.160.6.57 raeburn 4374: %defaultchecked = (
4375: 'uselcmath' => 'on',
4376: 'usejsme' => 'on',
1.160.6.64 raeburn 4377: 'canclone' => 'none',
1.160.6.57 raeburn 4378: );
4379: @toggles = ('uselcmath','usejsme');
1.160.6.90 raeburn 4380: my $deftex = $Apache::lonnet::deftex;
4381: if (ref($settings) eq 'HASH') {
4382: if ($settings->{'texengine'}) {
4383: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4384: $deftex = $settings->{'texengine'};
4385: }
4386: }
4387: }
4388: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4389: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4390: '<span class="LC_nobreak">'.$choices{'texengine'}.
4391: '</span></td><td class="LC_right_item">'.
4392: '<select name="texengine">'."\n";
4393: my %texoptions = (
4394: MathJax => 'MathJax',
4395: mimetex => &mt('Convert to Images'),
4396: tth => &mt('TeX to HTML'),
4397: );
4398: foreach my $renderer ('MathJax','mimetex','tth') {
4399: my $selected = '';
4400: if ($renderer eq $deftex) {
4401: $selected = ' selected="selected"';
4402: }
4403: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
4404: }
4405: $mathdisp .= '</select></td></tr>'."\n";
4406: $itemcount ++;
1.139 raeburn 4407: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4408: \%choices,$itemcount);
1.160.6.90 raeburn 4409: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 4410: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4411: $datatable .=
4412: '<tr'.$css_class.'><td valign="top">'.
4413: '<span class="LC_nobreak">'.$choices{'canclone'}.
4414: '</span></td><td class="LC_left_item">';
4415: my $currcanclone = 'none';
4416: my $onclick;
4417: my @cloneoptions = ('none','domain');
4418: my %clonetitles = (
4419: none => 'No additional course requesters',
4420: domain => "Any course requester in course's domain",
4421: instcode => 'Course requests for official courses ...',
4422: );
4423: my (%codedefaults,@code_order,@posscodes);
4424: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4425: \@code_order) eq 'ok') {
4426: if (@code_order > 0) {
4427: push(@cloneoptions,'instcode');
4428: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4429: }
4430: }
4431: if (ref($settings) eq 'HASH') {
4432: if ($settings->{'canclone'}) {
4433: if (ref($settings->{'canclone'}) eq 'HASH') {
4434: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4435: if (@code_order > 0) {
4436: $currcanclone = 'instcode';
4437: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4438: }
4439: }
4440: } elsif ($settings->{'canclone'} eq 'domain') {
4441: $currcanclone = $settings->{'canclone'};
4442: }
4443: }
4444: }
4445: foreach my $option (@cloneoptions) {
4446: my ($checked,$additional);
4447: if ($currcanclone eq $option) {
4448: $checked = ' checked="checked"';
4449: }
4450: if ($option eq 'instcode') {
4451: if (@code_order) {
4452: my $show = 'none';
4453: if ($checked) {
4454: $show = 'block';
4455: }
4456: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4457: &mt('Institutional codes for new and cloned course have identical:').
4458: '<br />';
4459: foreach my $item (@code_order) {
4460: my $codechk;
4461: if ($checked) {
4462: if (grep(/^\Q$item\E$/,@posscodes)) {
4463: $codechk = ' checked="checked"';
4464: }
4465: }
4466: $additional .= '<label>'.
4467: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4468: $item.'</label>';
4469: }
4470: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4471: }
4472: }
4473: $datatable .=
4474: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4475: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4476: '</label> '.$additional.'</span><br />';
4477: }
4478: $datatable .= '</td>'.
4479: '</tr>';
4480: $itemcount ++;
1.139 raeburn 4481: } else {
4482: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 4483: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 4484: my $currusecredits = 0;
1.160.6.57 raeburn 4485: my $postsubmitclient = 1;
1.160.6.30 raeburn 4486: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 4487: if (ref($settings) eq 'HASH') {
4488: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 4489: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4490: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4491: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4492: }
4493: }
1.160.6.16 raeburn 4494: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 4495: foreach my $type (@types) {
4496: next if ($type eq 'community');
4497: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4498: if ($defcredits{$type} ne '') {
4499: $currusecredits = 1;
4500: }
4501: }
4502: }
4503: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4504: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4505: $postsubmitclient = 0;
4506: foreach my $type (@types) {
4507: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4508: }
4509: } else {
4510: foreach my $type (@types) {
4511: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4512: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4513: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4514: } else {
4515: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4516: }
4517: } else {
4518: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4519: }
4520: }
4521: }
4522: } else {
4523: foreach my $type (@types) {
4524: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 4525: }
4526: }
1.160.6.70 raeburn 4527: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4528: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4529: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4530: }
4531: } else {
4532: foreach my $type (@types) {
4533: $currmysql{$type} = $staticdefaults{'mysqltables'};
4534: }
4535: }
1.160.6.58 raeburn 4536: } else {
4537: foreach my $type (@types) {
4538: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4539: }
1.139 raeburn 4540: }
4541: if (!$currdefresponder) {
1.160.6.21 raeburn 4542: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4543: } elsif ($currdefresponder < 1) {
4544: $currdefresponder = 1;
4545: }
1.160.6.21 raeburn 4546: foreach my $type (@types) {
4547: if ($curruploadquota{$type} eq '') {
4548: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4549: }
4550: }
1.139 raeburn 4551: $datatable .=
1.160.6.16 raeburn 4552: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4553: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4554: '</span></td>'.
4555: '<td class="LC_right_item"><span class="LC_nobreak">'.
4556: '<input type="text" name="anonsurvey_threshold"'.
4557: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 4558: '</td></tr>'."\n";
4559: $itemcount ++;
4560: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4561: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4562: $choices{'uploadquota'}.
4563: '</span></td>'.
4564: '<td align="right" class="LC_right_item">'.
4565: '<table><tr>';
1.160.6.21 raeburn 4566: foreach my $type (@types) {
4567: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4568: '<input type="text" name="uploadquota_'.$type.'"'.
4569: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4570: }
4571: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 4572: $itemcount ++;
1.160.6.40 raeburn 4573: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 4574: my $display = 'none';
4575: if ($currusecredits) {
4576: $display = 'block';
4577: }
4578: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 4579: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4580: foreach my $type (@types) {
4581: next if ($type eq 'community');
4582: $additional .= '<td align="center">'.&mt($type).'<br />'.
4583: '<input type="text" name="'.$type.'_credits"'.
4584: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4585: }
4586: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 4587: %defaultchecked = ('coursecredits' => 'off');
4588: @toggles = ('coursecredits');
4589: my $current = {
4590: 'coursecredits' => $currusecredits,
4591: };
4592: (my $table,$itemcount) =
4593: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4594: \%choices,$itemcount,$onclick,$additional,'left');
4595: $datatable .= $table;
4596: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4597: my $display = 'none';
4598: if ($postsubmitclient) {
4599: $display = 'block';
4600: }
4601: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 4602: &mt('Number of seconds submit is disabled').'<br />'.
4603: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4604: '<table><tr>';
1.160.6.57 raeburn 4605: foreach my $type (@types) {
4606: $additional .= '<td align="center">'.&mt($type).'<br />'.
4607: '<input type="text" name="'.$type.'_timeout" value="'.
4608: $deftimeout{$type}.'" size="5" /></td>';
4609: }
4610: $additional .= '</tr></table></div>'."\n";
4611: %defaultchecked = ('postsubmit' => 'on');
4612: @toggles = ('postsubmit');
1.160.6.70 raeburn 4613: $current = {
4614: 'postsubmit' => $postsubmitclient,
4615: };
1.160.6.57 raeburn 4616: ($table,$itemcount) =
4617: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4618: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 4619: $datatable .= $table;
1.160.6.70 raeburn 4620: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4621: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4622: $choices{'mysqltables'}.
4623: '</span></td>'.
4624: '<td align="right" class="LC_right_item">'.
4625: '<table><tr>';
4626: foreach my $type (@types) {
4627: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4628: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 4629: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 4630: }
4631: $datatable .= '</tr></table></td></tr>'."\n";
4632: $itemcount ++;
4633:
1.160.6.37 raeburn 4634: }
4635: $$rowtotal += $itemcount;
4636: return $datatable;
4637: }
4638:
4639: sub print_selfenrollment {
4640: my ($position,$dom,$settings,$rowtotal) = @_;
4641: my ($css_class,$datatable);
4642: my $itemcount = 1;
4643: my @types = ('official','unofficial','community','textbook');
4644: if (($position eq 'top') || ($position eq 'middle')) {
4645: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4646: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4647: my @rows;
4648: my $key;
4649: if ($position eq 'top') {
4650: $key = 'admin';
4651: if (ref($rowsref) eq 'ARRAY') {
4652: @rows = @{$rowsref};
4653: }
4654: } elsif ($position eq 'middle') {
4655: $key = 'default';
4656: @rows = ('types','registered','approval','limit');
4657: }
4658: foreach my $row (@rows) {
4659: if (defined($titlesref->{$row})) {
4660: $itemcount ++;
4661: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4662: $datatable .= '<tr'.$css_class.'>'.
4663: '<td>'.$titlesref->{$row}.'</td>'.
4664: '<td class="LC_left_item">'.
4665: '<table><tr>';
4666: my (%current,%currentcap);
4667: if (ref($settings) eq 'HASH') {
4668: if (ref($settings->{$key}) eq 'HASH') {
4669: foreach my $type (@types) {
4670: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4671: $current{$type} = $settings->{$key}->{$type}->{$row};
4672: }
4673: if (($row eq 'limit') && ($key eq 'default')) {
4674: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4675: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4676: }
4677: }
4678: }
4679: }
4680: }
4681: my %roles = (
4682: '0' => &Apache::lonnet::plaintext('dc'),
4683: );
4684:
4685: foreach my $type (@types) {
4686: unless (($row eq 'registered') && ($key eq 'default')) {
4687: $datatable .= '<th>'.&mt($type).'</th>';
4688: }
4689: }
4690: unless (($row eq 'registered') && ($key eq 'default')) {
4691: $datatable .= '</tr><tr>';
4692: }
4693: foreach my $type (@types) {
4694: if ($type eq 'community') {
4695: $roles{'1'} = &mt('Community personnel');
4696: } else {
4697: $roles{'1'} = &mt('Course personnel');
4698: }
4699: $datatable .= '<td style="vertical-align: top">';
4700: if ($position eq 'top') {
4701: my %checked;
4702: if ($current{$type} eq '0') {
4703: $checked{'0'} = ' checked="checked"';
4704: } else {
4705: $checked{'1'} = ' checked="checked"';
4706: }
4707: foreach my $role ('1','0') {
4708: $datatable .= '<span class="LC_nobreak"><label>'.
4709: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4710: 'value="'.$role.'"'.$checked{$role}.' />'.
4711: $roles{$role}.'</label></span> ';
4712: }
4713: } else {
4714: if ($row eq 'types') {
4715: my %checked;
4716: if ($current{$type} =~ /^(all|dom)$/) {
4717: $checked{$1} = ' checked="checked"';
4718: } else {
4719: $checked{''} = ' checked="checked"';
4720: }
4721: foreach my $val ('','dom','all') {
4722: $datatable .= '<span class="LC_nobreak"><label>'.
4723: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4724: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4725: }
4726: } elsif ($row eq 'registered') {
4727: my %checked;
4728: if ($current{$type} eq '1') {
4729: $checked{'1'} = ' checked="checked"';
4730: } else {
4731: $checked{'0'} = ' checked="checked"';
4732: }
4733: foreach my $val ('0','1') {
4734: $datatable .= '<span class="LC_nobreak"><label>'.
4735: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4736: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4737: }
4738: } elsif ($row eq 'approval') {
4739: my %checked;
4740: if ($current{$type} =~ /^([12])$/) {
4741: $checked{$1} = ' checked="checked"';
4742: } else {
4743: $checked{'0'} = ' checked="checked"';
4744: }
4745: for my $val (0..2) {
4746: $datatable .= '<span class="LC_nobreak"><label>'.
4747: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4748: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4749: }
4750: } elsif ($row eq 'limit') {
4751: my %checked;
4752: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4753: $checked{$1} = ' checked="checked"';
4754: } else {
4755: $checked{'none'} = ' checked="checked"';
4756: }
4757: my $cap;
4758: if ($currentcap{$type} =~ /^\d+$/) {
4759: $cap = $currentcap{$type};
4760: }
4761: foreach my $val ('none','allstudents','selfenrolled') {
4762: $datatable .= '<span class="LC_nobreak"><label>'.
4763: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4764: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4765: }
4766: $datatable .= '<br />'.
4767: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4768: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4769: '</span>';
4770: }
4771: }
4772: $datatable .= '</td>';
4773: }
4774: $datatable .= '</tr>';
4775: }
4776: $datatable .= '</table></td></tr>';
4777: }
4778: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 4779: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4780: }
4781: $$rowtotal += $itemcount;
4782: return $datatable;
4783: }
4784:
4785: sub print_validation_rows {
4786: my ($caller,$dom,$settings,$rowtotal) = @_;
4787: my ($itemsref,$namesref,$fieldsref);
4788: if ($caller eq 'selfenroll') {
4789: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4790: } elsif ($caller eq 'requestcourses') {
4791: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4792: }
4793: my %currvalidation;
4794: if (ref($settings) eq 'HASH') {
4795: if (ref($settings->{'validation'}) eq 'HASH') {
4796: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 4797: }
1.160.6.39 raeburn 4798: }
4799: my $datatable;
4800: my $itemcount = 0;
4801: foreach my $item (@{$itemsref}) {
4802: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4803: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4804: $namesref->{$item}.
4805: '</span></td>'.
4806: '<td class="LC_left_item">';
4807: if (($item eq 'url') || ($item eq 'button')) {
4808: $datatable .= '<span class="LC_nobreak">'.
4809: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4810: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4811: } elsif ($item eq 'fields') {
4812: my @currfields;
4813: if (ref($currvalidation{$item}) eq 'ARRAY') {
4814: @currfields = @{$currvalidation{$item}};
4815: }
4816: foreach my $field (@{$fieldsref}) {
4817: my $check = '';
4818: if (grep(/^\Q$field\E$/,@currfields)) {
4819: $check = ' checked="checked"';
4820: }
4821: $datatable .= '<span class="LC_nobreak"><label>'.
4822: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4823: ' value="'.$field.'"'.$check.' />'.$field.
4824: '</label></span> ';
4825: }
4826: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 4827: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 4828: $currvalidation{$item}.
1.160.6.37 raeburn 4829: '</textarea>';
1.160.6.39 raeburn 4830: }
4831: $datatable .= '</td></tr>'."\n";
4832: if (ref($rowtotal)) {
1.160.6.37 raeburn 4833: $itemcount ++;
4834: }
1.139 raeburn 4835: }
1.160.6.39 raeburn 4836: if ($caller eq 'requestcourses') {
4837: my %currhash;
1.160.6.51 raeburn 4838: if (ref($settings) eq 'HASH') {
4839: if (ref($settings->{'validation'}) eq 'HASH') {
4840: if ($settings->{'validation'}{'dc'} ne '') {
4841: $currhash{$settings->{'validation'}{'dc'}} = 1;
4842: }
1.160.6.39 raeburn 4843: }
4844: }
4845: my $numinrow = 2;
4846: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4847: 'validationdc',%currhash);
1.160.6.50 raeburn 4848: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 4849: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 4850: if ($numdc > 1) {
1.160.6.50 raeburn 4851: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 4852: } else {
1.160.6.50 raeburn 4853: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 4854: }
1.160.6.50 raeburn 4855: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 4856: $itemcount ++;
4857: }
4858: if (ref($rowtotal)) {
4859: $$rowtotal += $itemcount;
4860: }
1.121 raeburn 4861: return $datatable;
1.118 jms 4862: }
4863:
1.160.6.98 raeburn 4864: sub print_passwords {
4865: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
4866: my ($datatable,$css_class);
4867: my $itemcount = 0;
4868: my %titles = &Apache::lonlocal::texthash (
4869: captcha => '"Forgot Password" CAPTCHA validation',
4870: link => 'Reset link expiration (hours)',
4871: case => 'Case-sensitive usernames/e-mail',
4872: prelink => 'Information required (form 1)',
4873: postlink => 'Information required (form 2)',
4874: emailsrc => 'LON-CAPA e-mail address type(s)',
4875: customtext => 'Domain specific text (HTML)',
4876: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
4877: intauth_check => 'Check bcrypt cost if authenticated',
4878: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
4879: permanent => 'Permanent e-mail address',
4880: critical => 'Critical notification address',
4881: notify => 'Notification address',
4882: min => 'Minimum password length',
4883: max => 'Maximum password length',
4884: chars => 'Required characters',
4885: numsaved => 'Number of previous passwords to save and disallow reuse',
4886: );
4887: if ($position eq 'top') {
4888: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4889: my $shownlinklife = 2;
4890: my $prelink = 'both';
4891: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
4892: if (ref($settings) eq 'HASH') {
4893: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
4894: $shownlinklife = $settings->{resetlink};
4895: }
4896: if (ref($settings->{resetcase}) eq 'ARRAY') {
4897: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
4898: }
4899: if ($settings->{resetprelink} =~ /^(both|either)$/) {
4900: $prelink = $settings->{resetprelink};
4901: }
4902: if (ref($settings->{resetpostlink}) eq 'HASH') {
4903: %postlink = %{$settings->{resetpostlink}};
4904: }
4905: if (ref($settings->{resetemail}) eq 'ARRAY') {
4906: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
4907: }
4908: if ($settings->{resetremove}) {
4909: $nostdtext = 1;
4910: }
4911: if ($settings->{resetcustom}) {
4912: $customurl = $settings->{resetcustom};
4913: }
4914: } else {
4915: if (ref($types) eq 'ARRAY') {
4916: foreach my $item (@{$types}) {
4917: $casesens{$item} = 1;
4918: $postlink{$item} = ['username','email'];
4919: }
4920: }
4921: $casesens{'default'} = 1;
4922: $postlink{'default'} = ['username','email'];
4923: $prelink = 'both';
4924: %emailsrc = (
4925: permanent => 1,
4926: critical => 1,
4927: notify => 1,
4928: );
4929: }
4930: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
4931: $itemcount ++;
4932: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4933: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
4934: '<td class="LC_left_item">'.
4935: '<input type="textbox" value="'.$shownlinklife.'" '.
4936: 'name="passwords_link" size="3" /></td></tr>';
4937: $itemcount ++;
4938: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4939: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
4940: '<td class="LC_left_item">';
4941: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4942: foreach my $item (@{$types}) {
4943: my $checkedcase;
4944: if ($casesens{$item}) {
4945: $checkedcase = ' checked="checked"';
4946: }
4947: $datatable .= '<span class="LC_nobreak"><label>'.
4948: '<input type="checkbox" name="passwords_case_sensitive" value="'.
4949: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.102.2 3(raebur 4950:0): '</span> ';
1.160.6.98 raeburn 4951: }
4952: }
4953: my $checkedcase;
4954: if ($casesens{'default'}) {
4955: $checkedcase = ' checked="checked"';
4956: }
4957: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
4958: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
4959: $othertitle.'</label></span></td>';
4960: $itemcount ++;
4961: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4962: my %checkedpre = (
4963: both => ' checked="checked"',
4964: either => '',
4965: );
4966: if ($prelink eq 'either') {
4967: $checkedpre{either} = ' checked="checked"';
4968: $checkedpre{both} = '';
4969: }
4970: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
4971: '<td class="LC_left_item"><span class="LC_nobreak">'.
4972: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
4973: &mt('Both username and e-mail address').'</label></span> '.
4974: '<span class="LC_nobreak"><label>'.
4975: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
4976: &mt('Either username or e-mail address').'</label></span></td></tr>';
4977: $itemcount ++;
4978: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4979: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
4980: '<td class="LC_left_item">';
4981: my %postlinked;
4982: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4983: foreach my $item (@{$types}) {
4984: undef(%postlinked);
4985: $datatable .= '<fieldset style="display: inline-block;">'.
4986: '<legend>'.$usertypes->{$item}.'</legend>';
4987: if (ref($postlink{$item}) eq 'ARRAY') {
4988: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
4989: }
4990: foreach my $field ('email','username') {
4991: my $checked;
4992: if ($postlinked{$field}) {
4993: $checked = ' checked="checked"';
4994: }
4995: $datatable .= '<span class="LC_nobreak"><label>'.
4996: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
4997: $field.'"'.$checked.' />'.$field.'</label>'.
4998: '<span> ';
4999: }
5000: $datatable .= '</fieldset>';
5001: }
5002: }
5003: if (ref($postlink{'default'}) eq 'ARRAY') {
5004: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
5005: }
5006: $datatable .= '<fieldset style="display: inline-block;">'.
5007: '<legend>'.$othertitle.'</legend>';
5008: foreach my $field ('email','username') {
5009: my $checked;
5010: if ($postlinked{$field}) {
5011: $checked = ' checked="checked"';
5012: }
5013: $datatable .= '<span class="LC_nobreak"><label>'.
5014: '<input type="checkbox" name="passwords_postlink_default" value="'.
5015: $field.'"'.$checked.' />'.$field.'</label>'.
5016: '<span> ';
5017: }
5018: $datatable .= '</fieldset></td></tr>';
5019: $itemcount ++;
5020: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5021: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
5022: '<td class="LC_left_item">';
5023: foreach my $type ('permanent','critical','notify') {
5024: my $checkedemail;
5025: if ($emailsrc{$type}) {
5026: $checkedemail = ' checked="checked"';
5027: }
5028: $datatable .= '<span class="LC_nobreak"><label>'.
5029: '<input type="checkbox" name="passwords_emailsrc" value="'.
5030: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
5031: '<span> ';
5032: }
5033: $datatable .= '</td></tr>';
5034: $itemcount ++;
5035: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5036: my $switchserver = &check_switchserver($dom,$confname);
5037: my ($showstd,$noshowstd);
5038: if ($nostdtext) {
5039: $noshowstd = ' checked="checked"';
5040: } else {
5041: $showstd = ' checked="checked"';
5042: }
5043: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
5044: '<td class="LC_left_item"><span class="LC_nobreak">'.
5045: &mt('Retain standard text:').
5046: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
5047: &mt('Yes').'</label>'.' '.
5048: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
5049: &mt('No').'</label></span><br />'.
5050: '<span class="LC_fontsize_small">'.
5051: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
5052: &mt('Include custom text:');
5053: if ($customurl) {
1.160.6.102.2 3(raebur 5054:0): my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 5055: undef,undef,undef,undef,'background-color:#ffffff');
5056: $datatable .= '<span class="LC_nobreak"> '.$link.
5057: '<label><input type="checkbox" name="passwords_custom_del"'.
5058: ' value="1" />'.&mt('Delete?').'</label></span>'.
5059: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
5060: }
5061: if ($switchserver) {
5062: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
5063: } else {
5064: $datatable .='<span class="LC_nobreak"> '.
5065: '<input type="file" name="passwords_customfile" /></span>';
5066: }
5067: $datatable .= '</td></tr>';
5068: } elsif ($position eq 'middle') {
5069: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
5070: my @items = ('intauth_cost','intauth_check','intauth_switch');
5071: my %defaults;
5072: if (ref($domconf{'defaults'}) eq 'HASH') {
5073: %defaults = %{$domconf{'defaults'}};
5074: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5075: $defaults{'intauth_cost'} = 10;
5076: }
5077: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5078: $defaults{'intauth_check'} = 0;
5079: }
5080: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5081: $defaults{'intauth_switch'} = 0;
5082: }
5083: } else {
5084: %defaults = (
5085: 'intauth_cost' => 10,
5086: 'intauth_check' => 0,
5087: 'intauth_switch' => 0,
5088: );
5089: }
5090: foreach my $item (@items) {
5091: if ($itemcount%2) {
5092: $css_class = '';
5093: } else {
5094: $css_class = ' class="LC_odd_row" ';
5095: }
5096: $datatable .= '<tr'.$css_class.'>'.
5097: '<td><span class="LC_nobreak">'.$titles{$item}.
5098: '</span></td><td class="LC_left_item" colspan="3">';
5099: if ($item eq 'intauth_switch') {
5100: my @options = (0,1,2);
5101: my %optiondesc = &Apache::lonlocal::texthash (
5102: 0 => 'No',
5103: 1 => 'Yes',
5104: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5105: );
5106: $datatable .= '<table width="100%">';
5107: foreach my $option (@options) {
5108: my $checked = ' ';
5109: if ($defaults{$item} eq $option) {
5110: $checked = ' checked="checked"';
5111: }
5112: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5113: '<label><input type="radio" name="'.$item.
5114: '" value="'.$option.'"'.$checked.' />'.
5115: $optiondesc{$option}.'</label></span></td></tr>';
5116: }
5117: $datatable .= '</table>';
5118: } elsif ($item eq 'intauth_check') {
5119: my @options = (0,1,2);
5120: my %optiondesc = &Apache::lonlocal::texthash (
5121: 0 => 'No',
5122: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5123: 2 => 'Yes, disallow login if stored cost is less than domain default',
5124: );
5125: $datatable .= '<table width="100%">';
5126: foreach my $option (@options) {
5127: my $checked = ' ';
5128: my $onclick;
5129: if ($defaults{$item} eq $option) {
5130: $checked = ' checked="checked"';
5131: }
5132: if ($option == 2) {
5133: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5134: }
5135: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5136: '<label><input type="radio" name="'.$item.
5137: '" value="'.$option.'"'.$checked.$onclick.' />'.
5138: $optiondesc{$option}.'</label></span></td></tr>';
5139: }
5140: $datatable .= '</table>';
5141: } else {
5142: $datatable .= '<input type="text" name="'.$item.'" value="'.
5143: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5144: }
5145: $datatable .= '</td></tr>';
5146: $itemcount ++;
5147: }
5148: } elsif ($position eq 'lower') {
5149: my ($min,$max,%chars,$numsaved);
1.160.6.99 raeburn 5150: $min = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 5151: if (ref($settings) eq 'HASH') {
5152: if ($settings->{min}) {
5153: $min = $settings->{min};
5154: }
5155: if ($settings->{max}) {
5156: $max = $settings->{max};
5157: }
5158: if (ref($settings->{chars}) eq 'ARRAY') {
5159: map { $chars{$_} = 1; } (@{$settings->{chars}});
5160: }
5161: if ($settings->{numsaved}) {
5162: $numsaved = $settings->{numsaved};
5163: }
5164: }
5165: my %rulenames = &Apache::lonlocal::texthash(
5166: uc => 'At least one upper case letter',
5167: lc => 'At least one lower case letter',
5168: num => 'At least one number',
5169: spec => 'At least one non-alphanumeric',
5170: );
5171: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5172: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
5173: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5174: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
5175: 'onblur="javascript:warnIntPass(this);" />'.
5176: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.160.6.98 raeburn 5177: '</span></td></tr>';
5178: $itemcount ++;
5179: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5180: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
5181: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5182: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
5183: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5184: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
5185: '</span></td></tr>';
5186: $itemcount ++;
5187: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5188: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
5189: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
5190: '</span></td>';
5191: my $numinrow = 2;
5192: my @possrules = ('uc','lc','num','spec');
5193: $datatable .= '<td class="LC_left_item"><table>';
5194: for (my $i=0; $i<@possrules; $i++) {
5195: my ($rem,$checked);
5196: if ($chars{$possrules[$i]}) {
5197: $checked = ' checked="checked"';
5198: }
5199: $rem = $i%($numinrow);
5200: if ($rem == 0) {
5201: if ($i > 0) {
5202: $datatable .= '</tr>';
5203: }
5204: $datatable .= '<tr>';
5205: }
5206: $datatable .= '<td><span class="LC_nobreak"><label>'.
5207: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
5208: $rulenames{$possrules[$i]}.'</label></span></td>';
5209: }
5210: my $rem = @possrules%($numinrow);
5211: my $colsleft = $numinrow - $rem;
5212: if ($colsleft > 1 ) {
5213: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5214: ' </td>';
5215: } elsif ($colsleft == 1) {
5216: $datatable .= '<td class="LC_left_item"> </td>';
5217: }
5218: $datatable .='</table></td></tr>';
5219: $itemcount ++;
5220: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5221: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
5222: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.100 raeburn 5223: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
1.160.6.99 raeburn 5224: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5225: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
5226: '</span></td></tr>';
5227: } else {
5228: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5229: my %ownerchg = (
5230: by => {},
5231: for => {},
5232: );
5233: my %ownertitles = &Apache::lonlocal::texthash (
5234: by => 'Course owner status(es) allowed',
5235: for => 'Student status(es) allowed',
5236: );
5237: if (ref($settings) eq 'HASH') {
5238: if (ref($settings->{crsownerchg}) eq 'HASH') {
5239: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
5240: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
5241: }
5242: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
5243: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
5244: }
5245: }
5246: }
5247: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5248: $datatable .= '<tr '.$css_class.'>'.
5249: '<td>'.
5250: &mt('Requirements').'<ul>'.
5251: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
5252: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
5253: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
5254: '<li>'.&mt('User, course, and student share same domain').'</li>'.
5255: '</ul>'.
5256: '</td>'.
5257: '<td class="LC_left_item">';
5258: foreach my $item ('by','for') {
5259: $datatable .= '<fieldset style="display: inline-block;">'.
5260: '<legend>'.$ownertitles{$item}.'</legend>';
5261: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5262: foreach my $type (@{$types}) {
5263: my $checked;
5264: if ($ownerchg{$item}{$type}) {
5265: $checked = ' checked="checked"';
5266: }
5267: $datatable .= '<span class="LC_nobreak"><label>'.
5268: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
5269: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.102.2 3(raebur 5270:0): '</span> ';
1.160.6.98 raeburn 5271: }
5272: }
5273: my $checked;
5274: if ($ownerchg{$item}{'default'}) {
5275: $checked = ' checked="checked"';
5276: }
5277: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5278: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
5279: $othertitle.'</label></span></fieldset>';
5280: }
5281: $datatable .= '</td></tr>';
5282: }
5283: return $datatable;
5284: }
5285:
1.137 raeburn 5286: sub print_usersessions {
5287: my ($position,$dom,$settings,$rowtotal) = @_;
5288: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 5289: my (%by_ip,%by_location,@intdoms);
5290: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 5291:
5292: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5293: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5294: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5295: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5296: my $itemcount = 1;
5297: if ($position eq 'top') {
1.152 raeburn 5298: if (keys(%serverhomes) > 1) {
1.145 raeburn 5299: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.102.2 4(raebur 5300:0): my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 5301: if (ref($settings) eq 'HASH') {
5302: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5303: $curroffloadnow = $settings->{'offloadnow'};
5304: }
1.160.6.102.2 4(raebur 5305:0): if (ref($settings->{'offloadoth'}) eq 'HASH') {
5306:0): $curroffloadoth = $settings->{'offloadoth'};
5307:0): }
1.160.6.61 raeburn 5308: }
1.160.6.102.2 4(raebur 5309:0): my $other_insts = scalar(keys(%by_location));
5310:0): $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
5311:0): $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 5312: } else {
1.140 raeburn 5313: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 5314: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 5315: }
1.137 raeburn 5316: } else {
1.145 raeburn 5317: if (keys(%by_location) == 0) {
5318: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 5319: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 5320: } else {
5321: my %lt = &usersession_titles();
5322: my $numinrow = 5;
5323: my $prefix;
5324: my @types;
5325: if ($position eq 'bottom') {
5326: $prefix = 'remote';
5327: @types = ('version','excludedomain','includedomain');
5328: } else {
5329: $prefix = 'hosted';
5330: @types = ('excludedomain','includedomain');
5331: }
5332: my (%current,%checkedon,%checkedoff);
5333: my @lcversions = &Apache::lonnet::all_loncaparevs();
5334: my @locations = sort(keys(%by_location));
5335: foreach my $type (@types) {
5336: $checkedon{$type} = '';
5337: $checkedoff{$type} = ' checked="checked"';
5338: }
5339: if (ref($settings) eq 'HASH') {
5340: if (ref($settings->{$prefix}) eq 'HASH') {
5341: foreach my $key (keys(%{$settings->{$prefix}})) {
5342: $current{$key} = $settings->{$prefix}{$key};
5343: if ($key eq 'version') {
5344: if ($current{$key} ne '') {
5345: $checkedon{$key} = ' checked="checked"';
5346: $checkedoff{$key} = '';
5347: }
5348: } elsif (ref($current{$key}) eq 'ARRAY') {
5349: $checkedon{$key} = ' checked="checked"';
5350: $checkedoff{$key} = '';
5351: }
1.137 raeburn 5352: }
5353: }
5354: }
1.145 raeburn 5355: foreach my $type (@types) {
5356: next if ($type ne 'version' && !@locations);
5357: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5358: $datatable .= '<tr'.$css_class.'>
5359: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
5360: <span class="LC_nobreak">
5361: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5362: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5363: if ($type eq 'version') {
5364: my $selector = '<select name="'.$prefix.'_version">';
5365: foreach my $version (@lcversions) {
5366: my $selected = '';
5367: if ($current{'version'} eq $version) {
5368: $selected = ' selected="selected"';
5369: }
5370: $selector .= ' <option value="'.$version.'"'.
5371: $selected.'>'.$version.'</option>';
5372: }
5373: $selector .= '</select> ';
5374: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5375: } else {
5376: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5377: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5378: ' />'.(' 'x2).
5379: '<input type="button" value="'.&mt('uncheck all').'" '.
5380: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5381: "\n".
5382: '</div><div><table>';
5383: my $rem;
5384: for (my $i=0; $i<@locations; $i++) {
5385: my ($showloc,$value,$checkedtype);
5386: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
5387: my $ip = $by_location{$locations[$i]}->[0];
5388: if (ref($by_ip{$ip}) eq 'ARRAY') {
5389: $value = join(':',@{$by_ip{$ip}});
5390: $showloc = join(', ',@{$by_ip{$ip}});
5391: if (ref($current{$type}) eq 'ARRAY') {
5392: foreach my $loc (@{$by_ip{$ip}}) {
5393: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5394: $checkedtype = ' checked="checked"';
5395: last;
5396: }
5397: }
1.138 raeburn 5398: }
5399: }
5400: }
1.145 raeburn 5401: $rem = $i%($numinrow);
5402: if ($rem == 0) {
5403: if ($i > 0) {
5404: $datatable .= '</tr>';
5405: }
5406: $datatable .= '<tr>';
5407: }
5408: $datatable .= '<td class="LC_left_item">'.
5409: '<span class="LC_nobreak"><label>'.
5410: '<input type="checkbox" name="'.$prefix.'_'.$type.
5411: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5412: '</label></span></td>';
1.137 raeburn 5413: }
1.145 raeburn 5414: $rem = @locations%($numinrow);
5415: my $colsleft = $numinrow - $rem;
5416: if ($colsleft > 1 ) {
5417: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5418: ' </td>';
5419: } elsif ($colsleft == 1) {
5420: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5421: }
1.145 raeburn 5422: $datatable .= '</tr></table>';
1.137 raeburn 5423: }
1.145 raeburn 5424: $datatable .= '</td></tr>';
5425: $itemcount ++;
1.137 raeburn 5426: }
5427: }
5428: }
5429: $$rowtotal += $itemcount;
5430: return $datatable;
5431: }
5432:
1.138 raeburn 5433: sub build_location_hashes {
5434: my ($intdoms,$by_ip,$by_location) = @_;
5435: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
5436: (ref($by_location) eq 'HASH'));
5437: my %iphost = &Apache::lonnet::get_iphost();
5438: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5439: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5440: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5441: foreach my $id (@{$iphost{$primary_ip}}) {
5442: my $intdom = &Apache::lonnet::internet_dom($id);
5443: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5444: push(@{$intdoms},$intdom);
5445: }
5446: }
5447: }
5448: foreach my $ip (keys(%iphost)) {
5449: if (ref($iphost{$ip}) eq 'ARRAY') {
5450: foreach my $id (@{$iphost{$ip}}) {
5451: my $location = &Apache::lonnet::internet_dom($id);
5452: if ($location) {
5453: next if (grep(/^\Q$location\E$/,@{$intdoms}));
5454: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5455: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5456: push(@{$by_ip->{$ip}},$location);
5457: }
5458: } else {
5459: $by_ip->{$ip} = [$location];
5460: }
5461: }
5462: }
5463: }
5464: }
5465: foreach my $ip (sort(keys(%{$by_ip}))) {
5466: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5467: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5468: my $first = $by_ip->{$ip}->[0];
5469: if (ref($by_location->{$first}) eq 'ARRAY') {
5470: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5471: push(@{$by_location->{$first}},$ip);
5472: }
5473: } else {
5474: $by_location->{$first} = [$ip];
5475: }
5476: }
5477: }
5478: return;
5479: }
5480:
1.145 raeburn 5481: sub current_offloads_to {
5482: my ($dom,$settings,$servers) = @_;
5483: my (%spareid,%otherdomconfigs);
1.152 raeburn 5484: if (ref($servers) eq 'HASH') {
1.145 raeburn 5485: foreach my $lonhost (sort(keys(%{$servers}))) {
5486: my $gotspares;
1.152 raeburn 5487: if (ref($settings) eq 'HASH') {
5488: if (ref($settings->{'spares'}) eq 'HASH') {
5489: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5490: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5491: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5492: $gotspares = 1;
5493: }
1.145 raeburn 5494: }
5495: }
5496: unless ($gotspares) {
5497: my $gotspares;
5498: my $serverhomeID =
5499: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5500: my $serverhomedom =
5501: &Apache::lonnet::host_domain($serverhomeID);
5502: if ($serverhomedom ne $dom) {
5503: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5504: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5505: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5506: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5507: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5508: $gotspares = 1;
5509: }
5510: }
5511: } else {
5512: $otherdomconfigs{$serverhomedom} =
5513: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5514: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5515: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5516: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5517: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5518: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5519: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5520: $gotspares = 1;
5521: }
5522: }
5523: }
5524: }
5525: }
5526: }
5527: }
5528: unless ($gotspares) {
5529: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5530: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5531: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5532: } else {
5533: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5534: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5535: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5536: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5537: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5538: } else {
1.150 raeburn 5539: my %what = (
5540: spareid => 1,
5541: );
5542: my ($result,$returnhash) =
5543: &Apache::lonnet::get_remote_globals($lonhost,\%what);
5544: if ($result eq 'ok') {
5545: if (ref($returnhash) eq 'HASH') {
5546: if (ref($returnhash->{'spareid'}) eq 'HASH') {
5547: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5548: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5549: }
5550: }
1.145 raeburn 5551: }
5552: }
5553: }
5554: }
5555: }
5556: }
5557: return %spareid;
5558: }
5559:
5560: sub spares_row {
1.160.6.102.2 4(raebur 5561:0): my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
5562:0): $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 5563: my $css_class;
5564: my $numinrow = 4;
5565: my $itemcount = 1;
5566: my $datatable;
1.152 raeburn 5567: my %typetitles = &sparestype_titles();
5568: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5569: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5570: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5571: my ($othercontrol,$serverdom);
5572: if ($serverhome ne $server) {
5573: $serverdom = &Apache::lonnet::host_domain($serverhome);
5574: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5575: } else {
5576: $serverdom = &Apache::lonnet::host_domain($server);
5577: if ($serverdom ne $dom) {
5578: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5579: }
5580: }
5581: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.102.2 4(raebur 5582:0): my ($checkednow,$checkedoth);
1.160.6.61 raeburn 5583: if (ref($curroffloadnow) eq 'HASH') {
5584: if ($curroffloadnow->{$server}) {
5585: $checkednow = ' checked="checked"';
5586: }
5587: }
1.160.6.102.2 4(raebur 5588:0): if (ref($curroffloadoth) eq 'HASH') {
5589:0): if ($curroffloadoth->{$server}) {
5590:0): $checkedoth = ' checked="checked"';
5591:0): }
5592:0): }
1.145 raeburn 5593: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5594: $datatable .= '<tr'.$css_class.'>
5595: <td rowspan="2">
1.160.6.13 raeburn 5596: <span class="LC_nobreak">'.
5597: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 5598: ,'<b>'.$server.'</b>').'</span><br />'.
5599: '<span class="LC_nobreak">'."\n".
5600: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.102.2 4(raebur 5601:0): ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 5602: "\n";
1.160.6.102.2 4(raebur 5603:0): if ($other_insts) {
5604:0): $datatable .= '<br />'.
5605:0): '<span class="LC_nobreak">'."\n".
5606:0): '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
5607:0): ' '.&mt('Switch other institutions on next access').'</label></span>'.
5608:0): "\n";
5609:0): }
1.145 raeburn 5610: my (%current,%canselect);
1.152 raeburn 5611: my @choices =
5612: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5613: foreach my $type ('primary','default') {
5614: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5615: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5616: my @spares = @{$spareid->{$server}{$type}};
5617: if (@spares > 0) {
1.152 raeburn 5618: if ($othercontrol) {
5619: $current{$type} = join(', ',@spares);
5620: } else {
5621: $current{$type} .= '<table>';
5622: my $numspares = scalar(@spares);
5623: for (my $i=0; $i<@spares; $i++) {
5624: my $rem = $i%($numinrow);
5625: if ($rem == 0) {
5626: if ($i > 0) {
5627: $current{$type} .= '</tr>';
5628: }
5629: $current{$type} .= '<tr>';
1.145 raeburn 5630: }
1.152 raeburn 5631: $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'".');" /> '.
5632: $spareid->{$server}{$type}[$i].
5633: '</label></td>'."\n";
5634: }
5635: my $rem = @spares%($numinrow);
5636: my $colsleft = $numinrow - $rem;
5637: if ($colsleft > 1 ) {
5638: $current{$type} .= '<td colspan="'.$colsleft.
5639: '" class="LC_left_item">'.
5640: ' </td>';
5641: } elsif ($colsleft == 1) {
5642: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5643: }
1.152 raeburn 5644: $current{$type} .= '</tr></table>';
1.150 raeburn 5645: }
1.145 raeburn 5646: }
5647: }
5648: if ($current{$type} eq '') {
5649: $current{$type} = &mt('None specified');
5650: }
1.152 raeburn 5651: if ($othercontrol) {
5652: if ($type eq 'primary') {
5653: $canselect{$type} = $othercontrol;
5654: }
5655: } else {
5656: $canselect{$type} =
5657: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5658: '<select name="newspare_'.$type.'_'.$server.'" '.
5659: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5660: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5661: if (@choices > 0) {
5662: foreach my $lonhost (@choices) {
5663: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5664: }
5665: }
5666: $canselect{$type} .= '</select>'."\n";
5667: }
5668: } else {
5669: $current{$type} = &mt('Could not be determined');
5670: if ($type eq 'primary') {
5671: $canselect{$type} = $othercontrol;
5672: }
1.145 raeburn 5673: }
1.152 raeburn 5674: if ($type eq 'default') {
5675: $datatable .= '<tr'.$css_class.'>';
5676: }
5677: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5678: '<td>'.$current{$type}.'</td>'."\n".
5679: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5680: }
5681: $itemcount ++;
5682: }
5683: }
5684: $$rowtotal += $itemcount;
5685: return $datatable;
5686: }
5687:
1.152 raeburn 5688: sub possible_newspares {
5689: my ($server,$currspares,$serverhomes,$altids) = @_;
5690: my $serverhostname = &Apache::lonnet::hostname($server);
5691: my %excluded;
5692: if ($serverhostname ne '') {
5693: %excluded = (
5694: $serverhostname => 1,
5695: );
5696: }
5697: if (ref($currspares) eq 'HASH') {
5698: foreach my $type (keys(%{$currspares})) {
5699: if (ref($currspares->{$type}) eq 'ARRAY') {
5700: if (@{$currspares->{$type}} > 0) {
5701: foreach my $curr (@{$currspares->{$type}}) {
5702: my $hostname = &Apache::lonnet::hostname($curr);
5703: $excluded{$hostname} = 1;
5704: }
5705: }
5706: }
5707: }
5708: }
5709: my @choices;
5710: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5711: if (keys(%{$serverhomes}) > 1) {
5712: foreach my $name (sort(keys(%{$serverhomes}))) {
5713: unless ($excluded{$name}) {
5714: if (exists($altids->{$serverhomes->{$name}})) {
5715: push(@choices,$altids->{$serverhomes->{$name}});
5716: } else {
5717: push(@choices,$serverhomes->{$name});
1.145 raeburn 5718: }
5719: }
5720: }
5721: }
5722: }
1.152 raeburn 5723: return sort(@choices);
1.145 raeburn 5724: }
5725:
1.150 raeburn 5726: sub print_loadbalancing {
5727: my ($dom,$settings,$rowtotal) = @_;
5728: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5729: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5730: my $numinrow = 1;
5731: my $datatable;
5732: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 5733: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 5734: if (ref($settings) eq 'HASH') {
5735: %existing = %{$settings};
5736: }
5737: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5738: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 5739: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 5740: } else {
5741: return;
5742: }
5743: my ($othertitle,$usertypes,$types) =
5744: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 5745: my $rownum = 8;
1.150 raeburn 5746: if (ref($types) eq 'ARRAY') {
5747: $rownum += scalar(@{$types});
5748: }
1.160.6.7 raeburn 5749: my @css_class = ('LC_odd_row','LC_even_row');
5750: my $balnum = 0;
5751: my $islast;
5752: my (@toshow,$disabledtext);
5753: if (keys(%currbalancer) > 0) {
5754: @toshow = sort(keys(%currbalancer));
5755: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5756: push(@toshow,'');
5757: }
5758: } else {
5759: @toshow = ('');
5760: $disabledtext = &mt('No existing load balancer');
5761: }
5762: foreach my $lonhost (@toshow) {
5763: if ($balnum == scalar(@toshow)-1) {
5764: $islast = 1;
5765: } else {
5766: $islast = 0;
5767: }
5768: my $cssidx = $balnum%2;
5769: my $targets_div_style = 'display: none';
5770: my $disabled_div_style = 'display: block';
5771: my $homedom_div_style = 'display: none';
5772: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5773: '<td rowspan="'.$rownum.'" valign="top">'.
5774: '<p>';
5775: if ($lonhost eq '') {
5776: $datatable .= '<span class="LC_nobreak">';
5777: if (keys(%currbalancer) > 0) {
5778: $datatable .= &mt('Add balancer:');
5779: } else {
5780: $datatable .= &mt('Enable balancer:');
5781: }
5782: $datatable .= ' '.
5783: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5784: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5785: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5786: '<option value="" selected="selected">'.&mt('None').
5787: '</option>'."\n";
5788: foreach my $server (sort(keys(%servers))) {
5789: next if ($currbalancer{$server});
5790: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5791: }
5792: $datatable .=
5793: '</select>'."\n".
5794: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5795: } else {
5796: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5797: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5798: &mt('Stop balancing').'</label>'.
5799: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5800: $targets_div_style = 'display: block';
5801: $disabled_div_style = 'display: none';
5802: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5803: $homedom_div_style = 'display: block';
5804: }
5805: }
5806: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5807: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5808: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5809: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5810: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5811: my @sparestypes = ('primary','default');
5812: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 5813: my %hostherechecked = (
5814: no => ' checked="checked"',
5815: );
1.160.6.94 raeburn 5816: my %balcookiechecked = (
5817: no => ' checked="checked"',
5818: );
1.160.6.7 raeburn 5819: foreach my $sparetype (@sparestypes) {
5820: my $targettable;
5821: for (my $i=0; $i<$numspares; $i++) {
5822: my $checked;
5823: if (ref($currtargets{$lonhost}) eq 'HASH') {
5824: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5825: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5826: $checked = ' checked="checked"';
5827: }
5828: }
5829: }
5830: my ($chkboxval,$disabled);
5831: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5832: $chkboxval = $spares[$i];
5833: }
5834: if (exists($currbalancer{$spares[$i]})) {
5835: $disabled = ' disabled="disabled"';
5836: }
5837: $targettable .=
1.160.6.55 raeburn 5838: '<td><span class="LC_nobreak"><label>'.
5839: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 5840: $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 5841: '</span></label></span></td>';
1.160.6.7 raeburn 5842: my $rem = $i%($numinrow);
5843: if ($rem == 0) {
5844: if (($i > 0) && ($i < $numspares-1)) {
5845: $targettable .= '</tr>';
5846: }
5847: if ($i < $numspares-1) {
5848: $targettable .= '<tr>';
1.150 raeburn 5849: }
5850: }
5851: }
1.160.6.7 raeburn 5852: if ($targettable ne '') {
5853: my $rem = $numspares%($numinrow);
5854: my $colsleft = $numinrow - $rem;
5855: if ($colsleft > 1 ) {
5856: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5857: ' </td>';
5858: } elsif ($colsleft == 1) {
5859: $targettable .= '<td class="LC_left_item"> </td>';
5860: }
5861: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5862: '<table><tr>'.$targettable.'</tr></table><br />';
5863: }
1.160.6.76 raeburn 5864: $hostherechecked{$sparetype} = '';
5865: if (ref($currtargets{$lonhost}) eq 'HASH') {
5866: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5867: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5868: $hostherechecked{$sparetype} = ' checked="checked"';
5869: $hostherechecked{'no'} = '';
5870: }
5871: }
5872: }
5873: }
1.160.6.94 raeburn 5874: if ($currcookies{$lonhost}) {
5875: %balcookiechecked = (
5876: yes => ' checked="checked"',
5877: );
5878: }
1.160.6.76 raeburn 5879: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5880: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5881: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5882: foreach my $sparetype (@sparestypes) {
5883: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5884: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5885: '</i></label><br />';
1.160.6.7 raeburn 5886: }
1.160.6.94 raeburn 5887: $datatable .= &mt('Use balancer cookie').'<br />'.
5888: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
5889: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
5890: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
5891: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
5892: '</div></td></tr>'.
1.160.6.7 raeburn 5893: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5894: $othertitle,$usertypes,$types,\%servers,
5895: \%currbalancer,$lonhost,
5896: $targets_div_style,$homedom_div_style,
5897: $css_class[$cssidx],$balnum,$islast);
5898: $$rowtotal += $rownum;
5899: $balnum ++;
5900: }
5901: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5902: return $datatable;
5903: }
5904:
5905: sub get_loadbalancers_config {
1.160.6.94 raeburn 5906: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 5907: return unless ((ref($servers) eq 'HASH') &&
5908: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 5909: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
5910: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 5911: if (keys(%{$existing}) > 0) {
5912: my $oldlonhost;
5913: foreach my $key (sort(keys(%{$existing}))) {
5914: if ($key eq 'lonhost') {
5915: $oldlonhost = $existing->{'lonhost'};
5916: $currbalancer->{$oldlonhost} = 1;
5917: } elsif ($key eq 'targets') {
5918: if ($oldlonhost) {
5919: $currtargets->{$oldlonhost} = $existing->{'targets'};
5920: }
5921: } elsif ($key eq 'rules') {
5922: if ($oldlonhost) {
5923: $currrules->{$oldlonhost} = $existing->{'rules'};
5924: }
5925: } elsif (ref($existing->{$key}) eq 'HASH') {
5926: $currbalancer->{$key} = 1;
5927: $currtargets->{$key} = $existing->{$key}{'targets'};
5928: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 5929: if ($existing->{$key}{'cookie'}) {
5930: $currcookies->{$key} = 1;
5931: }
1.150 raeburn 5932: }
5933: }
1.160.6.7 raeburn 5934: } else {
5935: my ($balancerref,$targetsref) =
5936: &Apache::lonnet::get_lonbalancer_config($servers);
5937: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5938: foreach my $server (sort(keys(%{$balancerref}))) {
5939: $currbalancer->{$server} = 1;
5940: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5941: }
5942: }
5943: }
1.160.6.7 raeburn 5944: return;
1.150 raeburn 5945: }
5946:
5947: sub loadbalancing_rules {
5948: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 5949: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5950: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5951: my $output;
1.160.6.7 raeburn 5952: my $num = 0;
5953: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5954: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5955: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5956: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 5957: $num ++;
1.150 raeburn 5958: my $current;
5959: if (ref($currrules) eq 'HASH') {
5960: $current = $currrules->{$type};
5961: }
1.160.6.55 raeburn 5962: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 5963: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5964: $current = '';
5965: }
5966: }
5967: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 5968: $servers,$currbalancer,$lonhost,$dom,
5969: $targets_div_style,$homedom_div_style,
5970: $css_class,$balnum,$num,$islast);
1.150 raeburn 5971: }
5972: }
5973: return $output;
5974: }
5975:
5976: sub loadbalancing_titles {
5977: my ($dom,$intdom,$usertypes,$types) = @_;
5978: my %othertypes = (
5979: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5980: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5981: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5982: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 5983: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5984: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5985: );
1.160.6.26 raeburn 5986: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 5987: my @available;
1.150 raeburn 5988: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 5989: @available = @{$types};
1.150 raeburn 5990: }
1.160.6.89 raeburn 5991: unless (grep(/^default$/,@available)) {
5992: push(@available,'default');
5993: }
5994: unshift(@alltypes,@available);
1.150 raeburn 5995: my %titles;
5996: foreach my $type (@alltypes) {
5997: if ($type =~ /^_LC_/) {
5998: $titles{$type} = $othertypes{$type};
5999: } elsif ($type eq 'default') {
6000: $titles{$type} = &mt('All users from [_1]',$dom);
6001: if (ref($types) eq 'ARRAY') {
6002: if (@{$types} > 0) {
6003: $titles{$type} = &mt('Other users from [_1]',$dom);
6004: }
6005: }
6006: } elsif (ref($usertypes) eq 'HASH') {
6007: $titles{$type} = $usertypes->{$type};
6008: }
6009: }
6010: return (\@alltypes,\%othertypes,\%titles);
6011: }
6012:
6013: sub loadbalance_rule_row {
1.160.6.7 raeburn 6014: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6015: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 6016: my @rulenames;
1.150 raeburn 6017: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 6018: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 6019: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6020: } else {
1.160.6.26 raeburn 6021: @rulenames = ('default','homeserver');
6022: if ($type eq '_LC_external') {
6023: push(@rulenames,'externalbalancer');
6024: } else {
6025: push(@rulenames,'specific');
6026: }
6027: push(@rulenames,'none');
1.150 raeburn 6028: }
6029: my $style = $targets_div_style;
1.160.6.55 raeburn 6030: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6031: $style = $homedom_div_style;
6032: }
1.160.6.7 raeburn 6033: my $space;
6034: if ($islast && $num == 1) {
6035: $space = '<div display="inline-block"> </div>';
6036: }
6037: my $output =
6038: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
6039: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6040: '<td valaign="top">'.$space.
6041: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6042: for (my $i=0; $i<@rulenames; $i++) {
6043: my $rule = $rulenames[$i];
6044: my ($checked,$extra);
6045: if ($rulenames[$i] eq 'default') {
6046: $rule = '';
6047: }
6048: if ($rulenames[$i] eq 'specific') {
6049: if (ref($servers) eq 'HASH') {
6050: my $default;
6051: if (($current ne '') && (exists($servers->{$current}))) {
6052: $checked = ' checked="checked"';
6053: }
6054: unless ($checked) {
6055: $default = ' selected="selected"';
6056: }
1.160.6.7 raeburn 6057: $extra =
6058: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6059: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6060: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6061: '<option value=""'.$default.'></option>'."\n";
6062: foreach my $server (sort(keys(%{$servers}))) {
6063: if (ref($currbalancer) eq 'HASH') {
6064: next if (exists($currbalancer->{$server}));
6065: }
1.150 raeburn 6066: my $selected;
1.160.6.7 raeburn 6067: if ($server eq $current) {
1.150 raeburn 6068: $selected = ' selected="selected"';
6069: }
1.160.6.7 raeburn 6070: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6071: }
6072: $extra .= '</select>';
6073: }
6074: } elsif ($rule eq $current) {
6075: $checked = ' checked="checked"';
6076: }
6077: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 6078: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6079: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6080: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 6081: ')"'.$checked.' /> ';
1.160.6.56 raeburn 6082: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 6083: $output .= $ruletitles{'particular'};
6084: } else {
6085: $output .= $ruletitles{$rulenames[$i]};
6086: }
6087: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6088: }
6089: $output .= '</div></td></tr>'."\n";
6090: return $output;
6091: }
6092:
6093: sub offloadtype_text {
6094: my %ruletitles = &Apache::lonlocal::texthash (
6095: 'default' => 'Offloads to default destinations',
6096: 'homeserver' => "Offloads to user's home server",
6097: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6098: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 6099: 'none' => 'No offload',
1.160.6.26 raeburn 6100: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6101: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 6102: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6103: );
6104: return %ruletitles;
6105: }
6106:
6107: sub sparestype_titles {
6108: my %typestitles = &Apache::lonlocal::texthash (
6109: 'primary' => 'primary',
6110: 'default' => 'default',
6111: );
6112: return %typestitles;
6113: }
6114:
1.28 raeburn 6115: sub contact_titles {
6116: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 6117: 'supportemail' => 'Support E-mail address',
6118: 'adminemail' => 'Default Server Admin E-mail address',
6119: 'errormail' => 'Error reports to be e-mailed to',
6120: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 6121: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6122: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 6123: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6124: 'requestsmail' => 'E-mail from course requests requiring approval',
6125: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 6126: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 6127: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.102.2 8(raebur 6128:1): 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
6129:1): 'errorsysmail' => 'Error count threshold for e-mail to developer group',
7(raebur 6130:1): 'errorweights' => 'Weights used to compute error count',
6131:1): 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 6132: );
6133: my %short_titles = &Apache::lonlocal::texthash (
6134: adminemail => 'Admin E-mail address',
6135: supportemail => 'Support E-mail',
6136: );
6137: return (\%titles,\%short_titles);
6138: }
6139:
1.160.6.78 raeburn 6140: sub helpform_fields {
6141: my %titles = &Apache::lonlocal::texthash (
6142: 'username' => 'Name',
6143: 'user' => 'Username/domain',
6144: 'phone' => 'Phone',
6145: 'cc' => 'Cc e-mail',
6146: 'course' => 'Course Details',
6147: 'section' => 'Sections',
6148: 'screenshot' => 'File upload',
6149: );
6150: my @fields = ('username','phone','user','course','section','cc','screenshot');
6151: my %possoptions = (
6152: username => ['yes','no','req'],
6153: phone => ['yes','no','req'],
6154: user => ['yes','no'],
6155: cc => ['yes','no'],
6156: course => ['yes','no'],
6157: section => ['yes','no'],
6158: screenshot => ['yes','no'],
6159: );
6160: my %fieldoptions = &Apache::lonlocal::texthash (
6161: 'yes' => 'Optional',
6162: 'req' => 'Required',
6163: 'no' => "Not shown",
6164: );
6165: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6166: }
6167:
1.72 raeburn 6168: sub tool_titles {
6169: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 6170: aboutme => 'Personal web page',
1.86 raeburn 6171: blog => 'Blog',
1.160.6.4 raeburn 6172: webdav => 'WebDAV',
1.86 raeburn 6173: portfolio => 'Portfolio',
1.88 bisitz 6174: official => 'Official courses (with institutional codes)',
6175: unofficial => 'Unofficial courses',
1.98 raeburn 6176: community => 'Communities',
1.160.6.30 raeburn 6177: textbook => 'Textbook courses',
1.86 raeburn 6178: );
1.72 raeburn 6179: return %titles;
6180: }
6181:
1.101 raeburn 6182: sub courserequest_titles {
6183: my %titles = &Apache::lonlocal::texthash (
6184: official => 'Official',
6185: unofficial => 'Unofficial',
6186: community => 'Communities',
1.160.6.30 raeburn 6187: textbook => 'Textbook',
1.101 raeburn 6188: norequest => 'Not allowed',
1.104 raeburn 6189: approval => 'Approval by Dom. Coord.',
1.101 raeburn 6190: validate => 'With validation',
6191: autolimit => 'Numerical limit',
1.103 raeburn 6192: unlimited => '(blank for unlimited)',
1.101 raeburn 6193: );
6194: return %titles;
6195: }
6196:
1.160.6.5 raeburn 6197: sub authorrequest_titles {
6198: my %titles = &Apache::lonlocal::texthash (
6199: norequest => 'Not allowed',
6200: approval => 'Approval by Dom. Coord.',
6201: automatic => 'Automatic approval',
6202: );
6203: return %titles;
6204: }
6205:
1.101 raeburn 6206: sub courserequest_conditions {
6207: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6208: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 6209: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6210: );
6211: return %conditions;
6212: }
6213:
6214:
1.27 raeburn 6215: sub print_usercreation {
1.30 raeburn 6216: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6217: my $numinrow = 4;
1.28 raeburn 6218: my $datatable;
6219: if ($position eq 'top') {
1.30 raeburn 6220: $$rowtotal ++;
1.34 raeburn 6221: my $rowcount = 0;
1.32 raeburn 6222: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6223: if (ref($rules) eq 'HASH') {
6224: if (keys(%{$rules}) > 0) {
1.32 raeburn 6225: $datatable .= &user_formats_row('username',$settings,$rules,
6226: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6227: $$rowtotal ++;
1.32 raeburn 6228: $rowcount ++;
6229: }
6230: }
6231: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6232: if (ref($idrules) eq 'HASH') {
6233: if (keys(%{$idrules}) > 0) {
6234: $datatable .= &user_formats_row('id',$settings,$idrules,
6235: $idruleorder,$numinrow,$rowcount);
6236: $$rowtotal ++;
6237: $rowcount ++;
1.28 raeburn 6238: }
6239: }
1.39 raeburn 6240: if ($rowcount == 0) {
6241: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6242: $$rowtotal ++;
6243: $rowcount ++;
6244: }
1.34 raeburn 6245: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 6246: my @creators = ('author','course','requestcrs');
1.37 raeburn 6247: my ($rules,$ruleorder) =
6248: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6249: my %lt = &usercreation_types();
6250: my %checked;
6251: if (ref($settings) eq 'HASH') {
6252: if (ref($settings->{'cancreate'}) eq 'HASH') {
6253: foreach my $item (@creators) {
6254: $checked{$item} = $settings->{'cancreate'}{$item};
6255: }
6256: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6257: foreach my $item (@creators) {
6258: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6259: $checked{$item} = 'none';
6260: }
6261: }
6262: }
6263: }
6264: my $rownum = 0;
6265: foreach my $item (@creators) {
6266: $rownum ++;
1.160.6.34 raeburn 6267: if ($checked{$item} eq '') {
6268: $checked{$item} = 'any';
1.34 raeburn 6269: }
6270: my $css_class;
6271: if ($rownum%2) {
6272: $css_class = '';
6273: } else {
6274: $css_class = ' class="LC_odd_row" ';
6275: }
6276: $datatable .= '<tr'.$css_class.'>'.
6277: '<td><span class="LC_nobreak">'.$lt{$item}.
6278: '</span></td><td align="right">';
1.160.6.34 raeburn 6279: my @options = ('any');
6280: if (ref($rules) eq 'HASH') {
6281: if (keys(%{$rules}) > 0) {
6282: push(@options,('official','unofficial'));
1.37 raeburn 6283: }
6284: }
1.160.6.34 raeburn 6285: push(@options,'none');
1.37 raeburn 6286: foreach my $option (@options) {
1.50 raeburn 6287: my $type = 'radio';
1.34 raeburn 6288: my $check = ' ';
1.160.6.34 raeburn 6289: if ($checked{$item} eq $option) {
6290: $check = ' checked="checked" ';
1.34 raeburn 6291: }
6292: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6293: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6294: $item.'" value="'.$option.'"'.$check.'/> '.
6295: $lt{$option}.'</label> </span>';
6296: }
6297: $datatable .= '</td></tr>';
6298: }
1.28 raeburn 6299: } else {
6300: my @contexts = ('author','course','domain');
6301: my @authtypes = ('int','krb4','krb5','loc');
6302: my %checked;
6303: if (ref($settings) eq 'HASH') {
6304: if (ref($settings->{'authtypes'}) eq 'HASH') {
6305: foreach my $item (@contexts) {
6306: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6307: foreach my $auth (@authtypes) {
6308: if ($settings->{'authtypes'}{$item}{$auth}) {
6309: $checked{$item}{$auth} = ' checked="checked" ';
6310: }
6311: }
6312: }
6313: }
1.27 raeburn 6314: }
1.35 raeburn 6315: } else {
6316: foreach my $item (@contexts) {
1.36 raeburn 6317: foreach my $auth (@authtypes) {
1.35 raeburn 6318: $checked{$item}{$auth} = ' checked="checked" ';
6319: }
6320: }
1.27 raeburn 6321: }
1.28 raeburn 6322: my %title = &context_names();
6323: my %authname = &authtype_names();
6324: my $rownum = 0;
6325: my $css_class;
6326: foreach my $item (@contexts) {
6327: if ($rownum%2) {
6328: $css_class = '';
6329: } else {
6330: $css_class = ' class="LC_odd_row" ';
6331: }
1.30 raeburn 6332: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6333: '<td>'.$title{$item}.
6334: '</td><td class="LC_left_item">'.
6335: '<span class="LC_nobreak">';
6336: foreach my $auth (@authtypes) {
6337: $datatable .= '<label>'.
6338: '<input type="checkbox" name="'.$item.'_auth" '.
6339: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6340: $authname{$auth}.'</label> ';
6341: }
6342: $datatable .= '</span></td></tr>';
6343: $rownum ++;
1.27 raeburn 6344: }
1.30 raeburn 6345: $$rowtotal += $rownum;
1.27 raeburn 6346: }
6347: return $datatable;
6348: }
6349:
1.160.6.34 raeburn 6350: sub print_selfcreation {
6351: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 6352: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6353: $emaildomain,$datatable);
1.160.6.34 raeburn 6354: if (ref($settings) eq 'HASH') {
6355: if (ref($settings->{'cancreate'}) eq 'HASH') {
6356: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 6357: if (ref($createsettings) eq 'HASH') {
6358: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6359: @selfcreate = @{$createsettings->{'selfcreate'}};
6360: } elsif ($createsettings->{'selfcreate'} ne '') {
6361: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6362: @selfcreate = ('email','login','sso');
6363: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6364: @selfcreate = ($createsettings->{'selfcreate'});
6365: }
6366: }
6367: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6368: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 6369: }
1.160.6.93 raeburn 6370: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6371: $emailoptions = $createsettings->{'emailoptions'};
6372: }
6373: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6374: $emailverified = $createsettings->{'emailverified'};
6375: }
6376: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6377: $emaildomain = $createsettings->{'emaildomain'};
6378: }
1.160.6.34 raeburn 6379: }
6380: }
6381: }
6382: my %radiohash;
6383: my $numinrow = 4;
6384: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 6385: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 6386: if ($position eq 'top') {
6387: my %choices = &Apache::lonlocal::texthash (
6388: cancreate_login => 'Institutional Login',
6389: cancreate_sso => 'Institutional Single Sign On',
6390: );
6391: my @toggles = sort(keys(%choices));
6392: my %defaultchecked = (
6393: 'cancreate_login' => 'off',
6394: 'cancreate_sso' => 'off',
6395: );
1.160.6.35 raeburn 6396: my ($onclick,$itemcount);
1.160.6.34 raeburn 6397: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6398: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 6399: $$rowtotal += $itemcount;
1.160.6.34 raeburn 6400:
6401: if (ref($usertypes) eq 'HASH') {
6402: if (keys(%{$usertypes}) > 0) {
6403: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6404: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 6405: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 6406: $$rowtotal ++;
6407: }
6408: }
1.160.6.44 raeburn 6409: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6410: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6411: $fieldtitles{'inststatus'} = &mt('Institutional status');
6412: my $rem;
6413: my $numperrow = 2;
6414: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6415: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 6416: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 6417: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 6418: '<table>'."\n";
1.160.6.44 raeburn 6419: for (my $i=0; $i<@fields; $i++) {
6420: $rem = $i%($numperrow);
6421: if ($rem == 0) {
6422: if ($i > 0) {
6423: $datatable .= '</tr>';
6424: }
6425: $datatable .= '<tr>';
6426: }
6427: my $currval;
1.160.6.51 raeburn 6428: if (ref($createsettings) eq 'HASH') {
6429: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6430: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6431: }
1.160.6.44 raeburn 6432: }
6433: $datatable .= '<td class="LC_left_item">'.
6434: '<span class="LC_nobreak">'.
6435: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6436: 'value="'.$currval.'" size="10" /> '.
6437: $fieldtitles{$fields[$i]}.'</span></td>';
6438: }
6439: my $colsleft = $numperrow - $rem;
6440: if ($colsleft > 1 ) {
6441: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6442: ' </td>';
6443: } elsif ($colsleft == 1) {
6444: $datatable .= '<td class="LC_left_item"> </td>';
6445: }
6446: $datatable .= '</tr></table></td></tr>';
6447: $$rowtotal ++;
1.160.6.34 raeburn 6448: } elsif ($position eq 'middle') {
6449: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 6450: my @posstypes;
1.160.6.34 raeburn 6451: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 6452: @posstypes = @{$types};
6453: }
6454: unless (grep(/^default$/,@posstypes)) {
6455: push(@posstypes,'default');
6456: }
6457: my %usertypeshash;
6458: if (ref($usertypes) eq 'HASH') {
6459: %usertypeshash = %{$usertypes};
6460: }
6461: $usertypeshash{'default'} = $othertitle;
6462: foreach my $status (@posstypes) {
6463: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6464: $numinrow,$$rowtotal,\%usertypeshash);
6465: $$rowtotal ++;
1.160.6.34 raeburn 6466: }
6467: } else {
1.160.6.40 raeburn 6468: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 6469: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 6470: );
6471: my @toggles = sort(keys(%choices));
6472: my %defaultchecked = (
6473: 'cancreate_email' => 'off',
6474: );
1.160.6.93 raeburn 6475: my $customclass = 'LC_selfcreate_email';
6476: my $classprefix = 'LC_canmodify_emailusername_';
6477: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 6478: my $display = 'none';
1.160.6.93 raeburn 6479: my $rowstyle = 'display:none';
1.160.6.40 raeburn 6480: if (grep(/^\Qemail\E$/,@selfcreate)) {
6481: $display = 'block';
1.160.6.93 raeburn 6482: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 6483: }
1.160.6.93 raeburn 6484: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6485: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6486: \%choices,$$rowtotal,$onclick);
6487: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6488: $rowstyle);
6489: $$rowtotal ++;
6490: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6491: $rowstyle);
6492: $$rowtotal ++;
6493: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 6494: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 6495: my ($emailrules,$emailruleorder) =
6496: &Apache::lonnet::inst_userrules($dom,'email');
6497: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6498: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6499: if (ref($types) eq 'ARRAY') {
6500: @posstypes = @{$types};
6501: }
6502: if (@posstypes) {
6503: unless (grep(/^default$/,@posstypes)) {
6504: push(@posstypes,'default');
1.160.6.89 raeburn 6505: }
6506: if (ref($usertypes) eq 'HASH') {
6507: %usertypeshash = %{$usertypes};
6508: }
1.160.6.93 raeburn 6509: my $currassign;
6510: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6511: $currassign = {
6512: selfassign => $domdefaults{'inststatusguest'},
6513: };
6514: @ordered = @{$domdefaults{'inststatusguest'}};
6515: } else {
6516: $currassign = { selfassign => [] };
6517: }
6518: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6519: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6520: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6521: $numinrow,$othertitle,'selfassign',
6522: $rowtotal,$onclicktypes,$customclass,
6523: $rowstyle);
6524: $$rowtotal ++;
1.160.6.89 raeburn 6525: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 6526: foreach my $status (@posstypes) {
6527: my $css_class;
6528: if ($$rowtotal%2) {
6529: $css_class = 'LC_odd_row ';
6530: }
6531: $css_class .= $customclass;
6532: my $rowid = $optionsprefix.$status;
6533: my $hidden = 1;
6534: my $currstyle = 'display:none';
6535: if (grep(/^\Q$status\E$/,@ordered)) {
6536: $currstyle = $rowstyle;
6537: $hidden = 0;
6538: }
6539: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6540: $emailrules,$emailruleorder,$settings,$status,$rowid,
6541: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6542: unless ($hidden) {
6543: $$rowtotal ++;
6544: }
1.160.6.89 raeburn 6545: }
6546: } else {
1.160.6.93 raeburn 6547: my $css_class;
6548: if ($$rowtotal%2) {
6549: $css_class = 'LC_odd_row ';
6550: }
6551: $css_class .= $customclass;
1.160.6.89 raeburn 6552: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 6553: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6554: $emailrules,$emailruleorder,$settings,'default','',
6555: $othertitle,$css_class,$rowstyle,$intdom);
6556: $$rowtotal ++;
1.160.6.34 raeburn 6557: }
1.160.6.35 raeburn 6558: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
6559: $numinrow = 1;
1.160.6.93 raeburn 6560: if (@posstypes) {
6561: foreach my $status (@posstypes) {
6562: my $rowid = $classprefix.$status;
6563: my $datarowstyle = 'display:none';
6564: if (grep(/^\Q$status\E$/,@ordered)) {
6565: $datarowstyle = $rowstyle;
6566: }
6567: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6568: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6569: $infotitles,$rowid,$customclass,$datarowstyle);
6570: unless ($datarowstyle eq 'display:none') {
6571: $$rowtotal ++;
6572: }
1.160.6.34 raeburn 6573: }
1.160.6.93 raeburn 6574: } else {
6575: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
6576: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6577: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 6578: }
6579: }
6580: return $datatable;
6581: }
6582:
1.160.6.93 raeburn 6583: sub selfcreate_javascript {
6584: return <<"ENDSCRIPT";
6585:
6586: <script type="text/javascript">
6587: // <![CDATA[
6588:
6589: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6590: var x = document.getElementsByClassName(target);
6591: var insttypes = 0;
6592: var insttypeRegExp = new RegExp(prefix);
6593: if ((x.length != undefined) && (x.length > 0)) {
6594: if (form.elements[radio].length != undefined) {
6595: for (var i=0; i<form.elements[radio].length; i++) {
6596: if (form.elements[radio][i].checked) {
6597: if (form.elements[radio][i].value == 1) {
6598: for (var j=0; j<x.length; j++) {
6599: if (x[j].id == 'undefined') {
6600: x[j].style.display = 'table-row';
6601: } else if (insttypeRegExp.test(x[j].id)) {
6602: insttypes ++;
6603: } else {
6604: x[j].style.display = 'table-row';
6605: }
6606: }
6607: } else {
6608: for (var j=0; j<x.length; j++) {
6609: x[j].style.display = 'none';
6610: }
1.160.6.40 raeburn 6611: }
1.160.6.93 raeburn 6612: break;
6613: }
6614: }
6615: if (insttypes > 0) {
6616: toggleDataRow(form,checkbox,target,altprefix);
6617: toggleDataRow(form,checkbox,target,prefix,1);
6618: }
6619: }
6620: }
6621: return;
6622: }
6623:
6624: function toggleDataRow(form,checkbox,target,prefix,docount) {
6625: if (form.elements[checkbox].length != undefined) {
6626: var count = 0;
6627: if (docount) {
6628: for (var i=0; i<form.elements[checkbox].length; i++) {
6629: if (form.elements[checkbox][i].checked) {
6630: count ++;
6631: }
6632: }
6633: }
6634: for (var i=0; i<form.elements[checkbox].length; i++) {
6635: var type = form.elements[checkbox][i].value;
6636: if (document.getElementById(prefix+type)) {
6637: if (form.elements[checkbox][i].checked) {
6638: document.getElementById(prefix+type).style.display = 'table-row';
6639: if (count % 2 == 1) {
6640: document.getElementById(prefix+type).className = target+' LC_odd_row';
6641: } else {
6642: document.getElementById(prefix+type).className = target;
6643: }
6644: count ++;
1.160.6.40 raeburn 6645: } else {
1.160.6.93 raeburn 6646: document.getElementById(prefix+type).style.display = 'none';
6647: }
6648: }
6649: }
6650: }
6651: return;
6652: }
6653:
6654: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
6655: var caller = radio+'_'+status;
6656: if (form.elements[caller].length != undefined) {
6657: for (var i=0; i<form.elements[caller].length; i++) {
6658: if (form.elements[caller][i].checked) {
6659: if (document.getElementById(altprefix+'_inst_'+status)) {
6660: var curr = form.elements[caller][i].value;
6661: if (prefix) {
6662: document.getElementById(prefix+'_'+status).style.display = 'none';
6663: }
6664: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
6665: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
6666: if (curr == 'custom') {
6667: if (prefix) {
6668: document.getElementById(prefix+'_'+status).style.display = 'inline';
6669: }
6670: } else if (curr == 'inst') {
6671: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
6672: } else if (curr == 'noninst') {
6673: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 6674: }
1.160.6.93 raeburn 6675: break;
1.160.6.40 raeburn 6676: }
1.160.6.93 raeburn 6677: }
6678: }
6679: }
6680: }
6681:
6682: // ]]>
6683: </script>
6684:
6685: ENDSCRIPT
6686: }
6687:
6688: sub noninst_users {
6689: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
6690: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
6691: my $class = 'LC_left_item';
6692: if ($css_class) {
6693: $css_class = ' class="'.$css_class.'"';
6694: }
6695: if ($rowid) {
6696: $rowid = ' id="'.$rowid.'"';
6697: }
6698: if ($rowstyle) {
6699: $rowstyle = ' style="'.$rowstyle.'"';
6700: }
6701: my ($output,$description);
6702: if ($type eq 'default') {
6703: $description = &mt('Requests for: [_1]',$typetitle);
6704: } else {
6705: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
6706: }
6707: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
6708: "<td>$description</td>\n".
6709: '<td class="'.$class.'" colspan="2">'.
6710: '<table><tr>';
6711: my %headers = &Apache::lonlocal::texthash(
6712: approve => 'Processing',
6713: email => 'E-mail',
6714: username => 'Username',
6715: );
6716: foreach my $item ('approve','email','username') {
6717: $output .= '<th>'.$headers{$item}.'</th>';
6718: }
6719: $output .= '</tr><tr>';
6720: foreach my $item ('approve','email','username') {
6721: $output .= '<td valign="top">';
6722: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
6723: if ($item eq 'approve') {
6724: %choices = &Apache::lonlocal::texthash (
6725: automatic => 'Automatically approved',
6726: approval => 'Queued for approval',
6727: );
6728: @options = ('automatic','approval');
6729: $hashref = $processing;
6730: $defoption = 'automatic';
6731: $name = 'cancreate_emailprocess_'.$type;
6732: } elsif ($item eq 'email') {
6733: %choices = &Apache::lonlocal::texthash (
6734: any => 'Any e-mail',
6735: inst => 'Institutional only',
6736: noninst => 'Non-institutional only',
6737: custom => 'Custom restrictions',
6738: );
6739: @options = ('any','inst','noninst');
6740: my $showcustom;
6741: if (ref($emailrules) eq 'HASH') {
6742: if (keys(%{$emailrules}) > 0) {
6743: push(@options,'custom');
6744: $showcustom = 'cancreate_emailrule';
6745: if (ref($settings) eq 'HASH') {
6746: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
6747: foreach my $rule (@{$settings->{'email_rule'}}) {
6748: if (exists($emailrules->{$rule})) {
6749: $hascustom ++;
6750: }
6751: }
6752: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
6753: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
6754: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
6755: if (exists($emailrules->{$rule})) {
6756: $hascustom ++;
6757: }
6758: }
6759: }
6760: }
6761: }
6762: }
6763: }
6764: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
6765: "'cancreate_emaildomain','$type'".');"';
6766: $hashref = $emailoptions;
6767: $defoption = 'any';
6768: $name = 'cancreate_emailoptions_'.$type;
6769: } elsif ($item eq 'username') {
6770: %choices = &Apache::lonlocal::texthash (
6771: all => 'Same as e-mail',
6772: first => 'Omit @domain',
6773: free => 'Free to choose',
6774: );
6775: @options = ('all','first','free');
6776: $hashref = $emailverified;
6777: $defoption = 'all';
6778: $name = 'cancreate_usernameoptions_'.$type;
6779: }
6780: foreach my $option (@options) {
6781: my $checked;
6782: if (ref($hashref) eq 'HASH') {
6783: if ($type eq '') {
6784: if (!exists($hashref->{'default'})) {
6785: if ($option eq $defoption) {
6786: $checked = ' checked="checked"';
6787: }
6788: } else {
6789: if ($hashref->{'default'} eq $option) {
6790: $checked = ' checked="checked"';
6791: }
1.160.6.40 raeburn 6792: }
6793: } else {
1.160.6.93 raeburn 6794: if (!exists($hashref->{$type})) {
6795: if ($option eq $defoption) {
6796: $checked = ' checked="checked"';
6797: }
6798: } else {
6799: if ($hashref->{$type} eq $option) {
6800: $checked = ' checked="checked"';
6801: }
1.160.6.40 raeburn 6802: }
6803: }
1.160.6.93 raeburn 6804: } elsif (($item eq 'email') && ($hascustom)) {
6805: if ($option eq 'custom') {
6806: $checked = ' checked="checked"';
6807: }
6808: } elsif ($option eq $defoption) {
6809: $checked = ' checked="checked"';
6810: }
6811: $output .= '<span class="LC_nobreak"><label>'.
6812: '<input type="radio" name="'.$name.'"'.
6813: $checked.' value="'.$option.'"'.$onclick.' />'.
6814: $choices{$option}.'</label></span><br />';
6815: if ($item eq 'email') {
6816: if ($option eq 'custom') {
6817: my $id = 'cancreate_emailrule_'.$type;
6818: my $display = 'none';
6819: if ($checked) {
6820: $display = 'inline';
6821: }
6822: my $numinrow = 2;
6823: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
6824: '<legend>'.&mt('Disallow').'</legend><table>'.
6825: &user_formats_row('email',$settings,$emailrules,
6826: $emailruleorder,$numinrow,'',$type);
6827: '</table></fieldset>';
6828: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
6829: my %text = &Apache::lonlocal::texthash (
6830: inst => 'must end:',
6831: noninst => 'cannot end:',
6832: );
6833: my $value;
6834: if (ref($emaildomain) eq 'HASH') {
6835: if (ref($emaildomain->{$type}) eq 'HASH') {
6836: $value = $emaildomain->{$type}->{$option};
6837: }
6838: }
6839: if ($value eq '') {
6840: $value = '@'.$intdom;
6841: }
6842: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
6843: my $display = 'none';
6844: if ($checked) {
6845: $display = 'inline';
6846: }
6847: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
6848: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
6849: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
6850: '</div>';
6851: }
1.160.6.40 raeburn 6852: }
6853: }
1.160.6.93 raeburn 6854: $output .= '</td>'."\n";
1.160.6.40 raeburn 6855: }
1.160.6.93 raeburn 6856: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 6857: return $output;
6858: }
6859:
1.160.6.5 raeburn 6860: sub captcha_choice {
1.160.6.93 raeburn 6861: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 6862: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
6863: $vertext,$currver);
1.160.6.5 raeburn 6864: my %lt = &captcha_phrases();
6865: $keyentry = 'hidden';
1.160.6.98 raeburn 6866: my $colspan=2;
1.160.6.5 raeburn 6867: if ($context eq 'cancreate') {
1.160.6.34 raeburn 6868: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 6869: } elsif ($context eq 'login') {
6870: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 6871: } elsif ($context eq 'passwords') {
6872: $rowname = &mt('"Forgot Password" CAPTCHA validation');
6873: $colspan=1;
1.160.6.5 raeburn 6874: }
6875: if (ref($settings) eq 'HASH') {
6876: if ($settings->{'captcha'}) {
6877: $checked{$settings->{'captcha'}} = ' checked="checked"';
6878: } else {
6879: $checked{'original'} = ' checked="checked"';
6880: }
6881: if ($settings->{'captcha'} eq 'recaptcha') {
6882: $pubtext = $lt{'pub'};
6883: $privtext = $lt{'priv'};
6884: $keyentry = 'text';
1.160.6.69 raeburn 6885: $vertext = $lt{'ver'};
6886: $currver = $settings->{'recaptchaversion'};
6887: if ($currver ne '2') {
6888: $currver = 1;
6889: }
1.160.6.5 raeburn 6890: }
6891: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
6892: $currpub = $settings->{'recaptchakeys'}{'public'};
6893: $currpriv = $settings->{'recaptchakeys'}{'private'};
6894: }
6895: } else {
6896: $checked{'original'} = ' checked="checked"';
6897: }
1.160.6.93 raeburn 6898: my $css_class;
6899: if ($itemcount%2) {
6900: $css_class = 'LC_odd_row';
6901: }
6902: if ($customcss) {
6903: $css_class .= " $customcss";
6904: }
6905: $css_class =~ s/^\s+//;
6906: if ($css_class) {
6907: $css_class = ' class="'.$css_class.'"';
6908: }
6909: if ($rowstyle) {
6910: $css_class .= ' style="'.$rowstyle.'"';
6911: }
1.160.6.5 raeburn 6912: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 6913: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 6914: '<table><tr><td>'."\n";
6915: foreach my $option ('original','recaptcha','notused') {
6916: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6917: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6918: $lt{$option}.'</label></span>';
6919: unless ($option eq 'notused') {
6920: $output .= (' 'x2)."\n";
6921: }
6922: }
6923: #
6924: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6925: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
6926: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
6927: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
6928: #
6929: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 6930: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 6931: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6932: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6933: $currpub.'" size="40" /></span><br />'."\n".
6934: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6935: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 6936: $currpriv.'" size="40" /></span><br />'.
6937: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6938: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6939: $currver.'" size="3" /></span><br />'.
6940: '</td></tr></table>'."\n".
1.160.6.5 raeburn 6941: '</td></tr>';
6942: return $output;
6943: }
6944:
1.32 raeburn 6945: sub user_formats_row {
1.160.6.93 raeburn 6946: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 6947: my $output;
6948: my %text = (
6949: 'username' => 'new usernames',
6950: 'id' => 'IDs',
6951: );
1.160.6.93 raeburn 6952: unless ($type eq 'email') {
6953: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6954: $output = '<tr '.$css_class.'>'.
6955: '<td><span class="LC_nobreak">'.
6956: &mt("Format rules to check for $text{$type}: ").
6957: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 6958: }
1.27 raeburn 6959: my $rem;
6960: if (ref($ruleorder) eq 'ARRAY') {
6961: for (my $i=0; $i<@{$ruleorder}; $i++) {
6962: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6963: my $rem = $i%($numinrow);
6964: if ($rem == 0) {
6965: if ($i > 0) {
6966: $output .= '</tr>';
6967: }
6968: $output .= '<tr>';
6969: }
6970: my $check = ' ';
1.39 raeburn 6971: if (ref($settings) eq 'HASH') {
6972: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6973: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6974: $check = ' checked="checked" ';
6975: }
1.160.6.93 raeburn 6976: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
6977: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
6978: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
6979: $check = ' checked="checked" ';
6980: }
6981: }
1.27 raeburn 6982: }
6983: }
1.160.6.93 raeburn 6984: my $name = $type.'_rule';
6985: if ($type eq 'email') {
6986: $name .= '_'.$status;
6987: }
1.27 raeburn 6988: $output .= '<td class="LC_left_item">'.
6989: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 6990: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 6991: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6992: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6993: }
6994: }
6995: $rem = @{$ruleorder}%($numinrow);
6996: }
1.160.6.93 raeburn 6997: my $colsleft;
6998: if ($rem) {
6999: $colsleft = $numinrow - $rem;
7000: }
1.27 raeburn 7001: if ($colsleft > 1 ) {
7002: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7003: ' </td>';
7004: } elsif ($colsleft == 1) {
7005: $output .= '<td class="LC_left_item"> </td>';
7006: }
1.160.6.93 raeburn 7007: $output .= '</tr></table>';
7008: unless ($type eq 'email') {
7009: $output .= '</td></tr>';
7010: }
1.27 raeburn 7011: return $output;
7012: }
7013:
1.34 raeburn 7014: sub usercreation_types {
7015: my %lt = &Apache::lonlocal::texthash (
7016: author => 'When adding a co-author',
7017: course => 'When adding a user to a course',
1.100 raeburn 7018: requestcrs => 'When requesting a course',
1.34 raeburn 7019: any => 'Any',
7020: official => 'Institutional only ',
7021: unofficial => 'Non-institutional only',
7022: none => 'None',
7023: );
7024: return %lt;
1.48 raeburn 7025: }
1.34 raeburn 7026:
1.160.6.34 raeburn 7027: sub selfcreation_types {
7028: my %lt = &Apache::lonlocal::texthash (
7029: selfcreate => 'User creates own account',
7030: any => 'Any',
7031: official => 'Institutional only ',
7032: unofficial => 'Non-institutional only',
7033: email => 'E-mail address',
7034: login => 'Institutional Login',
7035: sso => 'SSO',
7036: );
7037: }
7038:
1.28 raeburn 7039: sub authtype_names {
7040: my %lt = &Apache::lonlocal::texthash(
7041: int => 'Internal',
7042: krb4 => 'Kerberos 4',
7043: krb5 => 'Kerberos 5',
7044: loc => 'Local',
7045: );
7046: return %lt;
7047: }
7048:
7049: sub context_names {
7050: my %context_title = &Apache::lonlocal::texthash(
7051: author => 'Creating users when an Author',
7052: course => 'Creating users when in a course',
7053: domain => 'Creating users when a Domain Coordinator',
7054: );
7055: return %context_title;
7056: }
7057:
1.33 raeburn 7058: sub print_usermodification {
7059: my ($position,$dom,$settings,$rowtotal) = @_;
7060: my $numinrow = 4;
7061: my ($context,$datatable,$rowcount);
7062: if ($position eq 'top') {
7063: $rowcount = 0;
7064: $context = 'author';
7065: foreach my $role ('ca','aa') {
7066: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7067: $numinrow,$rowcount);
7068: $$rowtotal ++;
7069: $rowcount ++;
7070: }
1.160.6.37 raeburn 7071: } elsif ($position eq 'bottom') {
1.33 raeburn 7072: $context = 'course';
7073: $rowcount = 0;
7074: foreach my $role ('st','ep','ta','in','cr') {
7075: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7076: $numinrow,$rowcount);
7077: $$rowtotal ++;
7078: $rowcount ++;
7079: }
7080: }
7081: return $datatable;
7082: }
7083:
1.43 raeburn 7084: sub print_defaults {
1.160.6.40 raeburn 7085: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7086: my $rownum = 0;
1.160.6.80 raeburn 7087: my ($datatable,$css_class,$titles);
7088: unless ($position eq 'bottom') {
7089: $titles = &defaults_titles($dom);
7090: }
1.160.6.40 raeburn 7091: if ($position eq 'top') {
7092: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7093: 'datelocale_def','portal_def');
7094: my %defaults;
7095: if (ref($settings) eq 'HASH') {
7096: %defaults = %{$settings};
1.43 raeburn 7097: } else {
1.160.6.40 raeburn 7098: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7099: foreach my $item (@items) {
7100: $defaults{$item} = $domdefaults{$item};
7101: }
1.43 raeburn 7102: }
1.160.6.40 raeburn 7103: foreach my $item (@items) {
7104: if ($rownum%2) {
7105: $css_class = '';
7106: } else {
7107: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 7108: }
1.160.6.40 raeburn 7109: $datatable .= '<tr'.$css_class.'>'.
7110: '<td><span class="LC_nobreak">'.$titles->{$item}.
7111: '</span></td><td class="LC_right_item" colspan="3">';
7112: if ($item eq 'auth_def') {
7113: my @authtypes = ('internal','krb4','krb5','localauth');
7114: my %shortauth = (
7115: internal => 'int',
7116: krb4 => 'krb4',
7117: krb5 => 'krb5',
7118: localauth => 'loc'
7119: );
7120: my %authnames = &authtype_names();
7121: foreach my $auth (@authtypes) {
7122: my $checked = ' ';
7123: if ($defaults{$item} eq $auth) {
7124: $checked = ' checked="checked" ';
7125: }
7126: $datatable .= '<label><input type="radio" name="'.$item.
7127: '" value="'.$auth.'"'.$checked.'/>'.
7128: $authnames{$shortauth{$auth}}.'</label> ';
7129: }
7130: } elsif ($item eq 'timezone_def') {
7131: my $includeempty = 1;
7132: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7133: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 7134: my $includeempty = 1;
7135: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7136: } elsif ($item eq 'lang_def') {
7137: my $includeempty = 1;
7138: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 7139: } else {
1.160.6.98 raeburn 7140: my $size;
7141: if ($item eq 'portal_def') {
7142: $size = ' size="25"';
7143: }
1.160.6.80 raeburn 7144: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98 raeburn 7145: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 7146: }
7147: $datatable .= '</td></tr>';
7148: $rownum ++;
7149: }
1.160.6.40 raeburn 7150: } else {
1.160.6.80 raeburn 7151: my %defaults;
1.160.6.40 raeburn 7152: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 7153: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 7154: my $maxnum = @{$settings->{'inststatusorder'}};
7155: for (my $i=0; $i<$maxnum; $i++) {
7156: $css_class = $rownum%2?' class="LC_odd_row"':'';
7157: my $item = $settings->{'inststatusorder'}->[$i];
7158: my $title = $settings->{'inststatustypes'}->{$item};
7159: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7160: $datatable .= '<tr'.$css_class.'>'.
7161: '<td><span class="LC_nobreak">'.
7162: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7163: for (my $k=0; $k<=$maxnum; $k++) {
7164: my $vpos = $k+1;
7165: my $selstr;
7166: if ($k == $i) {
7167: $selstr = ' selected="selected" ';
7168: }
7169: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7170: }
7171: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7172: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7173: &mt('delete').'</span></td>'.
7174: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
7175: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 7176: '</span></td></tr>';
1.160.6.40 raeburn 7177: }
7178: $css_class = $rownum%2?' class="LC_odd_row"':'';
7179: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7180: $datatable .= '<tr '.$css_class.'>'.
7181: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7182: for (my $k=0; $k<=$maxnum; $k++) {
7183: my $vpos = $k+1;
7184: my $selstr;
7185: if ($k == $maxnum) {
7186: $selstr = ' selected="selected" ';
7187: }
7188: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7189: }
7190: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 7191: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 7192: ' '.&mt('(new)').
7193: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
7194: &mt('Name displayed:').
7195: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7196: '</tr>'."\n";
7197: $rownum ++;
1.141 raeburn 7198: }
1.43 raeburn 7199: }
7200: }
7201: $$rowtotal += $rownum;
7202: return $datatable;
7203: }
7204:
1.160.6.5 raeburn 7205: sub get_languages_hash {
7206: my %langchoices;
7207: foreach my $id (&Apache::loncommon::languageids()) {
7208: my $code = &Apache::loncommon::supportedlanguagecode($id);
7209: if ($code ne '') {
7210: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7211: }
7212: }
7213: return %langchoices;
7214: }
7215:
1.43 raeburn 7216: sub defaults_titles {
1.141 raeburn 7217: my ($dom) = @_;
1.43 raeburn 7218: my %titles = &Apache::lonlocal::texthash (
7219: 'auth_def' => 'Default authentication type',
7220: 'auth_arg_def' => 'Default authentication argument',
7221: 'lang_def' => 'Default language',
1.54 raeburn 7222: 'timezone_def' => 'Default timezone',
1.68 raeburn 7223: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7224: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 7225: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7226: 'intauth_check' => 'Check bcrypt cost if authenticated',
7227: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7228: );
1.141 raeburn 7229: if ($dom) {
7230: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7231: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7232: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7233: $protocol = 'http' if ($protocol ne 'https');
7234: if ($uint_dom) {
7235: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7236: $uint_dom);
7237: }
7238: }
1.43 raeburn 7239: return (\%titles);
7240: }
7241:
1.160.6.97 raeburn 7242: sub print_scantron {
7243: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
7244: if ($position eq 'top') {
7245: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
7246: } else {
7247: return &print_scantronconfig($dom,$settings,\$rowtotal);
7248: }
7249: }
7250:
7251: sub scantron_javascript {
7252: return <<"ENDSCRIPT";
7253:
7254: <script type="text/javascript">
7255: // <![CDATA[
7256:
7257: function toggleScantron(form) {
7258: var csvfieldset = new Array();
7259: if (document.getElementById('scantroncsv_cols')) {
7260: csvfieldset.push(document.getElementById('scantroncsv_cols'));
7261: }
7262: if (document.getElementById('scantroncsv_options')) {
7263: csvfieldset.push(document.getElementById('scantroncsv_options'));
7264: }
7265: if (csvfieldset.length) {
7266: if (document.getElementById('scantronconfcsv')) {
7267: var scantroncsv = document.getElementById('scantronconfcsv');
7268: if (scantroncsv.checked) {
7269: for (var i=0; i<csvfieldset.length; i++) {
7270: csvfieldset[i].style.display = 'block';
7271: }
7272: } else {
7273: for (var i=0; i<csvfieldset.length; i++) {
7274: csvfieldset[i].style.display = 'none';
7275: }
7276: var csvselects = document.getElementsByClassName('scantronconfig_csv');
7277: if (csvselects.length) {
7278: for (var j=0; j<csvselects.length; j++) {
7279: csvselects[j].selectedIndex = 0;
7280: }
7281: }
7282: }
7283: }
7284: }
7285: return;
7286: }
7287: // ]]>
7288: </script>
7289:
7290: ENDSCRIPT
7291:
7292: }
7293:
1.46 raeburn 7294: sub print_scantronformat {
7295: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7296: my $itemcount = 1;
1.60 raeburn 7297: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7298: %confhash);
1.46 raeburn 7299: my $switchserver = &check_switchserver($dom,$confname);
7300: my %lt = &Apache::lonlocal::texthash (
1.95 www 7301: default => 'Default bubblesheet format file error',
7302: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7303: );
7304: my %scantronfiles = (
7305: default => 'default.tab',
7306: custom => 'custom.tab',
7307: );
7308: foreach my $key (keys(%scantronfiles)) {
7309: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7310: .$scantronfiles{$key};
7311: }
7312: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7313: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7314: if (!$switchserver) {
7315: my $servadm = $r->dir_config('lonAdmEMail');
7316: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7317: if ($configuserok eq 'ok') {
7318: if ($author_ok eq 'ok') {
7319: my %legacyfile = (
1.160.6.97 raeburn 7320: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7321: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 7322: );
7323: my %md5chk;
7324: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7325: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7326: chomp($md5chk{$type});
1.46 raeburn 7327: }
7328: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7329: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 7330: ($scantronurls{$type},my $error) =
1.46 raeburn 7331: &legacy_scantronformat($r,$dom,$confname,
7332: $type,$legacyfile{$type},
7333: $scantronurls{$type},
7334: $scantronfiles{$type});
1.60 raeburn 7335: if ($error ne '') {
7336: $error{$type} = $error;
7337: }
7338: }
7339: if (keys(%error) == 0) {
7340: $is_custom = 1;
1.160.6.97 raeburn 7341: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 7342: $scantronurls{'custom'};
1.160.6.97 raeburn 7343: my $putresult =
1.60 raeburn 7344: &Apache::lonnet::put_dom('configuration',
7345: \%confhash,$dom);
7346: if ($putresult ne 'ok') {
1.160.6.97 raeburn 7347: $error{'custom'} =
1.60 raeburn 7348: '<span class="LC_error">'.
7349: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7350: }
1.46 raeburn 7351: }
7352: } else {
1.60 raeburn 7353: ($scantronurls{'default'},my $error) =
1.46 raeburn 7354: &legacy_scantronformat($r,$dom,$confname,
7355: 'default',$legacyfile{'default'},
7356: $scantronurls{'default'},
7357: $scantronfiles{'default'});
1.60 raeburn 7358: if ($error eq '') {
7359: $confhash{'scantron'}{'scantronformat'} = '';
7360: my $putresult =
7361: &Apache::lonnet::put_dom('configuration',
7362: \%confhash,$dom);
7363: if ($putresult ne 'ok') {
7364: $error{'default'} =
7365: '<span class="LC_error">'.
7366: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7367: }
7368: } else {
7369: $error{'default'} = $error;
7370: }
1.46 raeburn 7371: }
7372: }
7373: }
7374: } else {
1.95 www 7375: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7376: }
7377: }
7378: if (ref($settings) eq 'HASH') {
7379: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7380: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7381: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7382: $scantronurl = '';
7383: } else {
7384: $scantronurl = $settings->{'scantronformat'};
7385: }
7386: $is_custom = 1;
7387: } else {
7388: $scantronurl = $scantronurls{'default'};
7389: }
7390: } else {
1.60 raeburn 7391: if ($is_custom) {
7392: $scantronurl = $scantronurls{'custom'};
7393: } else {
7394: $scantronurl = $scantronurls{'default'};
7395: }
1.46 raeburn 7396: }
7397: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7398: $datatable .= '<tr'.$css_class.'>';
7399: if (!$is_custom) {
1.65 raeburn 7400: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7401: '<span class="LC_nobreak">';
1.46 raeburn 7402: if ($scantronurl) {
1.160.6.21 raeburn 7403: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7404: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7405: } else {
7406: $datatable = &mt('File unavailable for display');
7407: }
1.65 raeburn 7408: $datatable .= '</span></td>';
1.60 raeburn 7409: if (keys(%error) == 0) {
7410: $datatable .= '<td valign="bottom">';
7411: if (!$switchserver) {
7412: $datatable .= &mt('Upload:').'<br />';
7413: }
7414: } else {
7415: my $errorstr;
7416: foreach my $key (sort(keys(%error))) {
7417: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7418: }
7419: $datatable .= '<td>'.$errorstr;
7420: }
1.46 raeburn 7421: } else {
7422: if (keys(%error) > 0) {
7423: my $errorstr;
7424: foreach my $key (sort(keys(%error))) {
7425: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7426: }
1.60 raeburn 7427: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7428: } elsif ($scantronurl) {
1.160.6.26 raeburn 7429: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 7430: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7431: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 7432: $link.
7433: '<label><input type="checkbox" name="scantronformat_del"'.
7434: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7435: '<td><span class="LC_nobreak"> '.
7436: &mt('Replace:').'</span><br />';
1.46 raeburn 7437: }
7438: }
7439: if (keys(%error) == 0) {
7440: if ($switchserver) {
7441: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7442: } else {
1.65 raeburn 7443: $datatable .='<span class="LC_nobreak"> '.
7444: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7445: }
7446: }
7447: $datatable .= '</td></tr>';
7448: $$rowtotal ++;
7449: return $datatable;
7450: }
7451:
7452: sub legacy_scantronformat {
7453: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7454: my ($url,$error);
7455: my @statinfo = &Apache::lonnet::stat_file($newurl);
7456: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7457: (my $result,$url) =
7458: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7459: '','',$newfile);
7460: if ($result ne 'ok') {
1.130 raeburn 7461: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7462: }
7463: }
7464: return ($url,$error);
7465: }
1.43 raeburn 7466:
1.160.6.97 raeburn 7467: sub print_scantronconfig {
7468: my ($dom,$settings,$rowtotal) = @_;
7469: my $itemcount = 2;
7470: my $is_checked = ' checked="checked"';
7471: my %optionson = (
7472: hdr => ' checked="checked"',
7473: pad => ' checked="checked"',
7474: rem => ' checked="checked"',
7475: );
7476: my %optionsoff = (
7477: hdr => '',
7478: pad => '',
7479: rem => '',
7480: );
7481: my $currcsvsty = 'none';
7482: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
7483: my @fields = &scantroncsv_fields();
7484: my %titles = &scantronconfig_titles();
7485: if (ref($settings) eq 'HASH') {
7486: if (ref($settings->{config}) eq 'HASH') {
7487: if ($settings->{config}->{dat}) {
7488: $checked{'dat'} = $is_checked;
7489: }
7490: if (ref($settings->{config}->{csv}) eq 'HASH') {
7491: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
7492: %csvfields = %{$settings->{config}->{csv}->{fields}};
7493: if (keys(%csvfields) > 0) {
7494: $checked{'csv'} = $is_checked;
7495: $currcsvsty = 'block';
7496: }
7497: }
7498: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
7499: %csvoptions = %{$settings->{config}->{csv}->{options}};
7500: foreach my $option (keys(%optionson)) {
7501: unless ($csvoptions{$option}) {
7502: $optionsoff{$option} = $optionson{$option};
7503: $optionson{$option} = '';
7504: }
7505: }
7506: }
7507: }
7508: } else {
7509: $checked{'dat'} = $is_checked;
7510: }
7511: } else {
7512: $checked{'dat'} = $is_checked;
7513: }
7514: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
7515: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7516: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
7517: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
7518: foreach my $item ('dat','csv') {
7519: my $id;
7520: if ($item eq 'csv') {
7521: $id = 'id="scantronconfcsv" ';
7522: }
7523: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
7524: $titles{$item}.'</label>'.(' 'x3);
7525: if ($item eq 'csv') {
7526: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
7527: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
7528: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
7529: foreach my $col (@fields) {
7530: my $selnone;
7531: if ($csvfields{$col} eq '') {
7532: $selnone = ' selected="selected"';
7533: }
7534: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
7535: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
7536: '<option value=""'.$selnone.'></option>';
7537: for (my $i=0; $i<20; $i++) {
7538: my $shown = $i+1;
7539: my $sel;
7540: unless ($selnone) {
7541: if (exists($csvfields{$col})) {
7542: if ($csvfields{$col} == $i) {
7543: $sel = ' selected="selected"';
7544: }
7545: }
7546: }
7547: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
7548: }
7549: $datatable .= '</select></td></tr>';
7550: }
7551: $datatable .= '</table></fieldset>'.
7552: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
7553: '<legend>'.&mt('CSV Options').'</legend>';
7554: foreach my $option ('hdr','pad','rem') {
7555: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
7556: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
7557: &mt('Yes').'</label>'.(' 'x2)."\n".
7558: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
7559: }
7560: $datatable .= '</fieldset>';
7561: $itemcount ++;
7562: }
7563: }
7564: $datatable .= '</td></tr>';
7565: $$rowtotal ++;
7566: return $datatable;
7567: }
7568:
7569: sub scantronconfig_titles {
7570: return &Apache::lonlocal::texthash(
7571: dat => 'Standard format (.dat)',
7572: csv => 'Comma separated values (.csv)',
7573: hdr => 'Remove first line in file (contains column titles)',
7574: pad => 'Prepend 0s to PaperID',
7575: rem => 'Remove leading spaces (except Question Response columns)',
7576: CODE => 'CODE',
7577: ID => 'Student ID',
7578: PaperID => 'Paper ID',
7579: FirstName => 'First Name',
7580: LastName => 'Last Name',
7581: FirstQuestion => 'First Question Response',
7582: Section => 'Section',
7583: );
7584: }
7585:
7586: sub scantroncsv_fields {
7587: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
7588: }
7589:
1.49 raeburn 7590: sub print_coursecategories {
1.57 raeburn 7591: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7592: my $datatable;
7593: if ($position eq 'top') {
1.160.6.42 raeburn 7594: my (%checked);
7595: my @catitems = ('unauth','auth');
7596: my @cattypes = ('std','domonly','codesrch','none');
7597: $checked{'unauth'} = 'std';
7598: $checked{'auth'} = 'std';
7599: if (ref($settings) eq 'HASH') {
7600: foreach my $type (@cattypes) {
7601: if ($type eq $settings->{'unauth'}) {
7602: $checked{'unauth'} = $type;
7603: }
7604: if ($type eq $settings->{'auth'}) {
7605: $checked{'auth'} = $type;
7606: }
7607: }
7608: }
7609: my %lt = &Apache::lonlocal::texthash (
7610: unauth => 'Catalog type for unauthenticated users',
7611: auth => 'Catalog type for authenticated users',
7612: none => 'No catalog',
7613: std => 'Standard catalog',
7614: domonly => 'Domain-only catalog',
7615: codesrch => "Code search form",
7616: );
7617: my $itemcount = 0;
7618: foreach my $item (@catitems) {
7619: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7620: $datatable .= '<tr '.$css_class.'>'.
7621: '<td>'.$lt{$item}.'</td>'.
7622: '<td class="LC_right_item"><span class="LC_nobreak">';
7623: foreach my $type (@cattypes) {
7624: my $ischecked;
7625: if ($checked{$item} eq $type) {
7626: $ischecked=' checked="checked"';
7627: }
7628: $datatable .= '<label>'.
7629: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
7630: ' />'.$lt{$type}.'</label> ';
7631: }
1.160.6.87 raeburn 7632: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 7633: $itemcount ++;
7634: }
7635: $$rowtotal += $itemcount;
7636: } elsif ($position eq 'middle') {
1.57 raeburn 7637: my $toggle_cats_crs = ' ';
7638: my $toggle_cats_dom = ' checked="checked" ';
7639: my $can_cat_crs = ' ';
7640: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 7641: my $toggle_catscomm_comm = ' ';
7642: my $toggle_catscomm_dom = ' checked="checked" ';
7643: my $can_catcomm_comm = ' ';
7644: my $can_catcomm_dom = ' checked="checked" ';
7645:
1.57 raeburn 7646: if (ref($settings) eq 'HASH') {
7647: if ($settings->{'togglecats'} eq 'crs') {
7648: $toggle_cats_crs = $toggle_cats_dom;
7649: $toggle_cats_dom = ' ';
7650: }
7651: if ($settings->{'categorize'} eq 'crs') {
7652: $can_cat_crs = $can_cat_dom;
7653: $can_cat_dom = ' ';
7654: }
1.120 raeburn 7655: if ($settings->{'togglecatscomm'} eq 'comm') {
7656: $toggle_catscomm_comm = $toggle_catscomm_dom;
7657: $toggle_catscomm_dom = ' ';
7658: }
7659: if ($settings->{'categorizecomm'} eq 'comm') {
7660: $can_catcomm_comm = $can_catcomm_dom;
7661: $can_catcomm_dom = ' ';
7662: }
1.57 raeburn 7663: }
7664: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 7665: togglecats => 'Show/Hide a course in catalog',
7666: togglecatscomm => 'Show/Hide a community in catalog',
7667: categorize => 'Assign a category to a course',
7668: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7669: );
7670: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 7671: dom => 'Set in Domain',
7672: crs => 'Set in Course',
7673: comm => 'Set in Community',
1.57 raeburn 7674: );
7675: $datatable = '<tr class="LC_odd_row">'.
7676: '<td>'.$title{'togglecats'}.'</td>'.
7677: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7678: '<input type="radio" name="togglecats"'.
7679: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7680: '<label><input type="radio" name="togglecats"'.
7681: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
7682: '</tr><tr>'.
7683: '<td>'.$title{'categorize'}.'</td>'.
7684: '<td class="LC_right_item"><span class="LC_nobreak">'.
7685: '<label><input type="radio" name="categorize"'.
7686: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7687: '<label><input type="radio" name="categorize"'.
7688: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 7689: '</tr><tr class="LC_odd_row">'.
7690: '<td>'.$title{'togglecatscomm'}.'</td>'.
7691: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7692: '<input type="radio" name="togglecatscomm"'.
7693: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7694: '<label><input type="radio" name="togglecatscomm"'.
7695: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
7696: '</tr><tr>'.
7697: '<td>'.$title{'categorizecomm'}.'</td>'.
7698: '<td class="LC_right_item"><span class="LC_nobreak">'.
7699: '<label><input type="radio" name="categorizecomm"'.
7700: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7701: '<label><input type="radio" name="categorizecomm"'.
7702: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 7703: '</tr>';
1.120 raeburn 7704: $$rowtotal += 4;
1.57 raeburn 7705: } else {
7706: my $css_class;
7707: my $itemcount = 1;
7708: my $cathash;
7709: if (ref($settings) eq 'HASH') {
7710: $cathash = $settings->{'cats'};
7711: }
7712: if (ref($cathash) eq 'HASH') {
7713: my (@cats,@trails,%allitems,%idx,@jsarray);
7714: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
7715: \%allitems,\%idx,\@jsarray);
7716: my $maxdepth = scalar(@cats);
7717: my $colattrib = '';
7718: if ($maxdepth > 2) {
7719: $colattrib = ' colspan="2" ';
7720: }
7721: my @path;
7722: if (@cats > 0) {
7723: if (ref($cats[0]) eq 'ARRAY') {
7724: my $numtop = @{$cats[0]};
7725: my $maxnum = $numtop;
1.120 raeburn 7726: my %default_names = (
7727: instcode => &mt('Official courses'),
7728: communities => &mt('Communities'),
7729: );
7730:
7731: if ((!grep(/^instcode$/,@{$cats[0]})) ||
7732: ($cathash->{'instcode::0'} eq '') ||
7733: (!grep(/^communities$/,@{$cats[0]})) ||
7734: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 7735: $maxnum ++;
7736: }
7737: my $lastidx;
7738: for (my $i=0; $i<$numtop; $i++) {
7739: my $parent = $cats[0][$i];
7740: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7741: my $item = &escape($parent).'::0';
7742: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
7743: $lastidx = $idx{$item};
7744: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7745: .'<select name="'.$item.'"'.$chgstr.'>';
7746: for (my $k=0; $k<=$maxnum; $k++) {
7747: my $vpos = $k+1;
7748: my $selstr;
7749: if ($k == $i) {
7750: $selstr = ' selected="selected" ';
7751: }
7752: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7753: }
1.160.6.29 raeburn 7754: $datatable .= '</select></span></td><td>';
1.120 raeburn 7755: if ($parent eq 'instcode' || $parent eq 'communities') {
7756: $datatable .= '<span class="LC_nobreak">'
7757: .$default_names{$parent}.'</span>';
7758: if ($parent eq 'instcode') {
7759: $datatable .= '<br /><span class="LC_nobreak">('
7760: .&mt('with institutional codes')
7761: .')</span></td><td'.$colattrib.'>';
7762: } else {
7763: $datatable .= '<table><tr><td>';
7764: }
7765: $datatable .= '<span class="LC_nobreak">'
7766: .'<label><input type="radio" name="'
7767: .$parent.'" value="1" checked="checked" />'
7768: .&mt('Display').'</label>';
7769: if ($parent eq 'instcode') {
7770: $datatable .= ' ';
7771: } else {
7772: $datatable .= '</span></td></tr><tr><td>'
7773: .'<span class="LC_nobreak">';
7774: }
7775: $datatable .= '<label><input type="radio" name="'
7776: .$parent.'" value="0" />'
7777: .&mt('Do not display').'</label></span>';
7778: if ($parent eq 'communities') {
7779: $datatable .= '</td></tr></table>';
7780: }
7781: $datatable .= '</td>';
1.57 raeburn 7782: } else {
7783: $datatable .= $parent
1.160.6.29 raeburn 7784: .' <span class="LC_nobreak"><label>'
7785: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 7786: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
7787: }
7788: my $depth = 1;
7789: push(@path,$parent);
7790: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
7791: pop(@path);
7792: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
7793: $itemcount ++;
7794: }
1.48 raeburn 7795: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 7796: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
7797: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 7798: for (my $k=0; $k<=$maxnum; $k++) {
7799: my $vpos = $k+1;
7800: my $selstr;
1.57 raeburn 7801: if ($k == $numtop) {
1.48 raeburn 7802: $selstr = ' selected="selected" ';
7803: }
7804: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7805: }
1.59 bisitz 7806: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 7807: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
7808: .'</tr>'."\n";
1.48 raeburn 7809: $itemcount ++;
1.120 raeburn 7810: foreach my $default ('instcode','communities') {
7811: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
7812: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7813: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
7814: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
7815: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
7816: for (my $k=0; $k<=$maxnum; $k++) {
7817: my $vpos = $k+1;
7818: my $selstr;
7819: if ($k == $maxnum) {
7820: $selstr = ' selected="selected" ';
7821: }
7822: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 7823: }
1.120 raeburn 7824: $datatable .= '</select></span></td>'.
7825: '<td><span class="LC_nobreak">'.
7826: $default_names{$default}.'</span>';
7827: if ($default eq 'instcode') {
7828: $datatable .= '<br /><span class="LC_nobreak">('
7829: .&mt('with institutional codes').')</span>';
7830: }
7831: $datatable .= '</td>'
7832: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
7833: .&mt('Display').'</label> '
7834: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
7835: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 7836: }
7837: }
7838: }
1.57 raeburn 7839: } else {
7840: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 7841: }
7842: } else {
1.160.6.87 raeburn 7843: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 7844: .&initialize_categories($itemcount);
1.48 raeburn 7845: }
1.57 raeburn 7846: $$rowtotal += $itemcount;
1.48 raeburn 7847: }
7848: return $datatable;
7849: }
7850:
1.69 raeburn 7851: sub print_serverstatuses {
7852: my ($dom,$settings,$rowtotal) = @_;
7853: my $datatable;
7854: my @pages = &serverstatus_pages();
7855: my (%namedaccess,%machineaccess);
7856: foreach my $type (@pages) {
7857: $namedaccess{$type} = '';
7858: $machineaccess{$type}= '';
7859: }
7860: if (ref($settings) eq 'HASH') {
7861: foreach my $type (@pages) {
7862: if (exists($settings->{$type})) {
7863: if (ref($settings->{$type}) eq 'HASH') {
7864: foreach my $key (keys(%{$settings->{$type}})) {
7865: if ($key eq 'namedusers') {
7866: $namedaccess{$type} = $settings->{$type}->{$key};
7867: } elsif ($key eq 'machines') {
7868: $machineaccess{$type} = $settings->{$type}->{$key};
7869: }
7870: }
7871: }
7872: }
7873: }
7874: }
1.81 raeburn 7875: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7876: my $rownum = 0;
7877: my $css_class;
7878: foreach my $type (@pages) {
7879: $rownum ++;
7880: $css_class = $rownum%2?' class="LC_odd_row"':'';
7881: $datatable .= '<tr'.$css_class.'>'.
7882: '<td><span class="LC_nobreak">'.
7883: $titles->{$type}.'</span></td>'.
7884: '<td class="LC_left_item">'.
7885: '<input type="text" name="'.$type.'_namedusers" '.
7886: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
7887: '<td class="LC_right_item">'.
7888: '<span class="LC_nobreak">'.
7889: '<input type="text" name="'.$type.'_machines" '.
7890: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 7891: '</span></td></tr>'."\n";
1.69 raeburn 7892: }
7893: $$rowtotal += $rownum;
7894: return $datatable;
7895: }
7896:
7897: sub serverstatus_pages {
7898: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 7899: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 7900: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 7901: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 7902: }
7903:
1.160.6.40 raeburn 7904: sub defaults_javascript {
7905: my ($settings) = @_;
1.160.6.98 raeburn 7906: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 7907: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
7908: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
7909: if ($maxnum eq '') {
7910: $maxnum = 0;
7911: }
7912: $maxnum ++;
1.160.6.51 raeburn 7913: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 7914: return <<"ENDSCRIPT";
7915: <script type="text/javascript">
7916: // <![CDATA[
7917: function reorderTypes(form,caller) {
7918: var changedVal;
7919: $jstext
7920: var newpos = 'addinststatus_pos';
7921: var current = new Array;
7922: var maxh = $maxnum;
7923: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7924: var oldVal;
7925: if (caller == newpos) {
7926: changedVal = newitemVal;
7927: } else {
7928: var curritem = 'inststatus_pos_'+caller;
7929: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
7930: current[newitemVal] = newpos;
7931: }
7932: for (var i=0; i<inststatuses.length; i++) {
7933: if (inststatuses[i] != caller) {
7934: var elementName = 'inststatus_pos_'+inststatuses[i];
7935: if (form.elements[elementName]) {
7936: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7937: current[currVal] = elementName;
7938: }
7939: }
7940: }
7941: for (var j=0; j<maxh; j++) {
7942: if (current[j] == undefined) {
7943: oldVal = j;
7944: }
7945: }
7946: if (oldVal < changedVal) {
7947: for (var k=oldVal+1; k<=changedVal ; k++) {
7948: var elementName = current[k];
7949: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7950: }
7951: } else {
7952: for (var k=changedVal; k<oldVal; k++) {
7953: var elementName = current[k];
7954: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7955: }
7956: }
7957: return;
7958: }
7959:
7960: // ]]>
7961: </script>
7962:
7963: ENDSCRIPT
7964: }
7965: }
7966:
1.160.6.98 raeburn 7967: sub passwords_javascript {
1.160.6.99 raeburn 7968: my %intalert = &Apache::lonlocal::texthash (
7969: 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.',
7970: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
7971: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
7972: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
7973: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
7974: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
7975: );
7976: &js_escape(\%intalert);
7977: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 7978: my $intauthjs = <<"ENDSCRIPT";
7979:
7980: function warnIntAuth(field) {
7981: if (field.name == 'intauth_check') {
7982: if (field.value == '2') {
1.160.6.99 raeburn 7983: alert('$intalert{authcheck}');
1.160.6.98 raeburn 7984: }
7985: }
7986: if (field.name == 'intauth_cost') {
7987: field.value.replace(/\s/g,'');
7988: if (field.value != '') {
7989: var regexdigit=/^\\d+\$/;
7990: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 7991: alert('$intalert{authcost}');
7992: }
7993: }
7994: }
7995: return;
7996: }
7997:
7998: function warnIntPass(field) {
7999: field.value.replace(/^\s+/,'');
8000: field.value.replace(/\s+\$/,'');
8001: var regexdigit=/^\\d+\$/;
8002: if (field.name == 'passwords_min') {
8003: if (field.value == '') {
8004: alert('$intalert{passmin}');
8005: field.value = '$defmin';
8006: } else {
8007: if (!regexdigit.test(field.value)) {
8008: alert('$intalert{passmin}');
8009: field.value = '$defmin';
8010: }
8011: var minval = parseInt(field.value,10);
8012: if (minval < $defmin) {
8013: alert('$intalert{passmin}');
8014: field.value = '$defmin';
8015: }
8016: }
8017: } else {
8018: if (field.value == '0') {
8019: field.value = '';
8020: }
8021: if (field.value != '') {
8022: if (field.name == 'passwords_expire') {
8023: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
8024: if (!regexpposnum.test(field.value)) {
8025: alert('$intalert{passexp}');
8026: field.value = '';
8027: } else {
8028: var expval = parseFloat(field.value);
8029: if (expval == 0) {
8030: alert('$intalert{passexp}');
8031: field.value = '';
8032: }
8033: }
8034: } else {
8035: if (!regexdigit.test(field.value)) {
8036: if (field.name == 'passwords_max') {
8037: alert('$intalert{passmax}');
8038: } else {
8039: if (field.name == 'passwords_numsaved') {
8040: alert('$intalert{passnum}');
8041: }
8042: }
1.160.6.102.2 3(raebur 8043:0): field.value = '';
1.160.6.99 raeburn 8044: }
1.160.6.98 raeburn 8045: }
8046: }
8047: }
8048: return;
8049: }
8050:
8051: ENDSCRIPT
8052: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8053: }
8054:
1.49 raeburn 8055: sub coursecategories_javascript {
8056: my ($settings) = @_;
1.57 raeburn 8057: my ($output,$jstext,$cathash);
1.49 raeburn 8058: if (ref($settings) eq 'HASH') {
1.57 raeburn 8059: $cathash = $settings->{'cats'};
8060: }
8061: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8062: my (@cats,@jsarray,%idx);
1.57 raeburn 8063: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8064: if (@jsarray > 0) {
8065: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8066: for (my $i=0; $i<@jsarray; $i++) {
8067: if (ref($jsarray[$i]) eq 'ARRAY') {
8068: my $catstr = join('","',@{$jsarray[$i]});
8069: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8070: }
8071: }
8072: }
8073: } else {
8074: $jstext = ' var categories = Array(1);'."\n".
8075: ' categories[0] = Array("instcode_pos");'."\n";
8076: }
1.160.6.42 raeburn 8077: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8078: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 8079: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8080: &js_escape(\$instcode_reserved);
8081: &js_escape(\$communities_reserved);
8082: &js_escape(\$choose_again);
1.49 raeburn 8083: $output = <<"ENDSCRIPT";
8084: <script type="text/javascript">
1.109 raeburn 8085: // <![CDATA[
1.49 raeburn 8086: function reorderCats(form,parent,item,idx) {
8087: var changedVal;
8088: $jstext
8089: var newpos = 'addcategory_pos';
8090: if (parent == '') {
8091: var has_instcode = 0;
8092: var maxtop = categories[idx].length;
8093: for (var j=0; j<maxtop; j++) {
8094: if (categories[idx][j] == 'instcode::0') {
8095: has_instcode == 1;
8096: }
8097: }
8098: if (has_instcode == 0) {
8099: categories[idx][maxtop] = 'instcode_pos';
8100: }
8101: } else {
8102: newpos += '_'+parent;
8103: }
8104: var maxh = 1 + categories[idx].length;
8105: var current = new Array;
8106: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8107: if (item == newpos) {
8108: changedVal = newitemVal;
8109: } else {
8110: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8111: current[newitemVal] = newpos;
8112: }
8113: for (var i=0; i<categories[idx].length; i++) {
8114: var elementName = categories[idx][i];
8115: if (elementName != item) {
8116: if (form.elements[elementName]) {
8117: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8118: current[currVal] = elementName;
8119: }
8120: }
8121: }
8122: var oldVal;
8123: for (var j=0; j<maxh; j++) {
8124: if (current[j] == undefined) {
8125: oldVal = j;
8126: }
8127: }
8128: if (oldVal < changedVal) {
8129: for (var k=oldVal+1; k<=changedVal ; k++) {
8130: var elementName = current[k];
8131: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8132: }
8133: } else {
8134: for (var k=changedVal; k<oldVal; k++) {
8135: var elementName = current[k];
8136: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8137: }
8138: }
8139: return;
8140: }
1.120 raeburn 8141:
8142: function categoryCheck(form) {
8143: if (form.elements['addcategory_name'].value == 'instcode') {
8144: alert('$instcode_reserved\\n$choose_again');
8145: return false;
8146: }
8147: if (form.elements['addcategory_name'].value == 'communities') {
8148: alert('$communities_reserved\\n$choose_again');
8149: return false;
8150: }
8151: return true;
8152: }
8153:
1.109 raeburn 8154: // ]]>
1.49 raeburn 8155: </script>
8156:
8157: ENDSCRIPT
8158: return $output;
8159: }
8160:
1.48 raeburn 8161: sub initialize_categories {
8162: my ($itemcount) = @_;
1.120 raeburn 8163: my ($datatable,$css_class,$chgstr);
8164: my %default_names = (
8165: instcode => 'Official courses (with institutional codes)',
8166: communities => 'Communities',
8167: );
8168: my $select0 = ' selected="selected"';
8169: my $select1 = '';
8170: foreach my $default ('instcode','communities') {
8171: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 8172: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 8173: if ($default eq 'communities') {
8174: $select1 = $select0;
8175: $select0 = '';
8176: }
8177: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8178: .'<select name="'.$default.'_pos">'
8179: .'<option value="0"'.$select0.'>1</option>'
8180: .'<option value="1"'.$select1.'>2</option>'
8181: .'<option value="2">3</option></select> '
8182: .$default_names{$default}
8183: .'</span></td><td><span class="LC_nobreak">'
8184: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8185: .&mt('Display').'</label> <label>'
8186: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8187: .'</label></span></td></tr>';
1.120 raeburn 8188: $itemcount ++;
8189: }
1.48 raeburn 8190: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8191: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8192: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8193: .'<select name="addcategory_pos"'.$chgstr.'>'
8194: .'<option value="0">1</option>'
8195: .'<option value="1">2</option>'
8196: .'<option value="2" selected="selected">3</option></select> '
1.160.6.102.2 2(raebur 8197:0): .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 8198: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8199: .'</td></tr>';
1.48 raeburn 8200: return $datatable;
8201: }
8202:
8203: sub build_category_rows {
1.49 raeburn 8204: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8205: my ($text,$name,$item,$chgstr);
1.48 raeburn 8206: if (ref($cats) eq 'ARRAY') {
8207: my $maxdepth = scalar(@{$cats});
8208: if (ref($cats->[$depth]) eq 'HASH') {
8209: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8210: my $numchildren = @{$cats->[$depth]{$parent}};
8211: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 8212: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8213: my ($idxnum,$parent_name,$parent_item);
8214: my $higher = $depth - 1;
8215: if ($higher == 0) {
8216: $parent_name = &escape($parent).'::'.$higher;
8217: } else {
8218: if (ref($path) eq 'ARRAY') {
8219: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8220: }
8221: }
8222: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8223: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8224: if ($j < $numchildren) {
1.48 raeburn 8225: $name = $cats->[$depth]{$parent}[$j];
8226: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8227: $idxnum = $idx->{$item};
8228: } else {
8229: $name = $parent_name;
8230: $item = $parent_item;
1.48 raeburn 8231: }
1.49 raeburn 8232: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8233: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8234: for (my $i=0; $i<=$numchildren; $i++) {
8235: my $vpos = $i+1;
8236: my $selstr;
8237: if ($j == $i) {
8238: $selstr = ' selected="selected" ';
8239: }
8240: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8241: }
8242: $text .= '</select> ';
8243: if ($j < $numchildren) {
8244: my $deeper = $depth+1;
8245: $text .= $name.' '
8246: .'<label><input type="checkbox" name="deletecategory" value="'
8247: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8248: if(ref($path) eq 'ARRAY') {
8249: push(@{$path},$name);
1.49 raeburn 8250: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8251: pop(@{$path});
8252: }
8253: } else {
1.160.6.87 raeburn 8254: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 8255: if ($j == $numchildren) {
8256: $text .= $name;
8257: } else {
8258: $text .= $item;
8259: }
8260: $text .= '" value="" />';
8261: }
8262: $text .= '</td></tr>';
8263: }
8264: $text .= '</table></td>';
8265: } else {
8266: my $higher = $depth-1;
8267: if ($higher == 0) {
8268: $name = &escape($parent).'::'.$higher;
8269: } else {
8270: if (ref($path) eq 'ARRAY') {
8271: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8272: }
8273: }
8274: my $colspan;
8275: if ($parent ne 'instcode') {
8276: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 8277: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 8278: }
8279: }
8280: }
8281: }
8282: return $text;
8283: }
8284:
1.33 raeburn 8285: sub modifiable_userdata_row {
1.160.6.93 raeburn 8286: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8287: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 8288: my ($role,$rolename,$statustype);
8289: $role = $item;
1.160.6.34 raeburn 8290: if ($context eq 'cancreate') {
1.160.6.93 raeburn 8291: if ($item =~ /^(emailusername)_(.+)$/) {
8292: $role = $1;
8293: $statustype = $2;
1.160.6.35 raeburn 8294: if (ref($usertypes) eq 'HASH') {
8295: if ($usertypes->{$statustype}) {
8296: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8297: } else {
8298: $rolename = &mt('Data provided by user');
8299: }
8300: }
1.160.6.34 raeburn 8301: }
8302: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8303: if (ref($usertypes) eq 'HASH') {
8304: $rolename = $usertypes->{$role};
8305: } else {
8306: $rolename = $role;
8307: }
1.33 raeburn 8308: } else {
1.63 raeburn 8309: if ($role eq 'cr') {
8310: $rolename = &mt('Custom role');
8311: } else {
8312: $rolename = &Apache::lonnet::plaintext($role);
8313: }
1.33 raeburn 8314: }
1.160.6.34 raeburn 8315: my (@fields,%fieldtitles);
8316: if (ref($fieldsref) eq 'ARRAY') {
8317: @fields = @{$fieldsref};
8318: } else {
8319: @fields = ('lastname','firstname','middlename','generation',
8320: 'permanentemail','id');
8321: }
8322: if ((ref($titlesref) eq 'HASH')) {
8323: %fieldtitles = %{$titlesref};
8324: } else {
8325: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8326: }
1.33 raeburn 8327: my $output;
1.160.6.93 raeburn 8328: my $css_class;
8329: if ($rowcount%2) {
8330: $css_class = 'LC_odd_row';
8331: }
8332: if ($customcss) {
8333: $css_class .= " $customcss";
8334: }
8335: $css_class =~ s/^\s+//;
8336: if ($css_class) {
8337: $css_class = ' class="'.$css_class.'"';
8338: }
8339: if ($rowstyle) {
8340: $css_class .= ' style="'.$rowstyle.'"';
8341: }
8342: if ($rowid) {
8343: $rowid = ' id="'.$rowid.'"';
8344: }
8345:
8346: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8347: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8348: '<td class="LC_left_item" colspan="2"><table>';
8349: my $rem;
8350: my %checks;
8351: if (ref($settings) eq 'HASH') {
8352: if (ref($settings->{$context}) eq 'HASH') {
8353: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 8354: my $hashref = $settings->{$context}->{$role};
8355: if ($role eq 'emailusername') {
8356: if ($statustype) {
8357: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8358: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 8359: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 8360: foreach my $field (@fields) {
8361: if ($hashref->{$field}) {
8362: $checks{$field} = $hashref->{$field};
8363: }
8364: }
8365: }
8366: }
8367: }
8368: } else {
8369: if (ref($hashref) eq 'HASH') {
8370: foreach my $field (@fields) {
8371: if ($hashref->{$field}) {
8372: $checks{$field} = ' checked="checked" ';
8373: }
8374: }
1.33 raeburn 8375: }
8376: }
8377: }
8378: }
8379: }
1.160.6.93 raeburn 8380:
8381: my $total = scalar(@fields);
8382: for (my $i=0; $i<$total; $i++) {
8383: $rem = $i%($numinrow);
1.33 raeburn 8384: if ($rem == 0) {
8385: if ($i > 0) {
8386: $output .= '</tr>';
8387: }
8388: $output .= '<tr>';
8389: }
8390: my $check = ' ';
1.160.6.35 raeburn 8391: unless ($role eq 'emailusername') {
8392: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 8393: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 8394: } else {
8395: if ($role eq 'st') {
8396: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 8397: $check = ' checked="checked" ';
1.160.6.35 raeburn 8398: }
1.33 raeburn 8399: }
8400: }
8401: }
8402: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 8403: '<span class="LC_nobreak">';
8404: if ($role eq 'emailusername') {
8405: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8406: $checks{$fields[$i]} = 'omit';
8407: }
8408: foreach my $option ('required','optional','omit') {
8409: my $checked='';
8410: if ($checks{$fields[$i]} eq $option) {
8411: $checked='checked="checked" ';
8412: }
8413: $output .= '<label>'.
8414: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
8415: &mt($option).'</label>'.(' ' x2);
8416: }
8417: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8418: } else {
8419: $output .= '<label>'.
8420: '<input type="checkbox" name="canmodify_'.$role.'" '.
8421: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8422: '</label>';
8423: }
8424: $output .= '</span></td>';
1.33 raeburn 8425: }
1.160.6.93 raeburn 8426: $rem = $total%$numinrow;
8427: my $colsleft;
8428: if ($rem) {
8429: $colsleft = $numinrow - $rem;
8430: }
8431: if ($colsleft > 1) {
1.33 raeburn 8432: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8433: ' </td>';
8434: } elsif ($colsleft == 1) {
8435: $output .= '<td class="LC_left_item"> </td>';
8436: }
8437: $output .= '</tr></table></td></tr>';
8438: return $output;
8439: }
1.28 raeburn 8440:
1.93 raeburn 8441: sub insttypes_row {
1.160.6.93 raeburn 8442: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8443: $customcss,$rowstyle) = @_;
1.93 raeburn 8444: my %lt = &Apache::lonlocal::texthash (
8445: cansearch => 'Users allowed to search',
8446: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8447: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 8448: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 8449: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8450: );
8451: my $showdom;
8452: if ($context eq 'cansearch') {
8453: $showdom = ' ('.$dom.')';
8454: }
1.160.6.5 raeburn 8455: my $class = 'LC_left_item';
8456: if ($context eq 'statustocreate') {
8457: $class = 'LC_right_item';
8458: }
1.160.6.93 raeburn 8459: my $css_class;
8460: if ($$rowtotal%2) {
8461: $css_class = 'LC_odd_row';
8462: }
8463: if ($customcss) {
8464: $css_class .= ' '.$customcss;
8465: }
8466: $css_class =~ s/^\s+//;
8467: if ($css_class) {
8468: $css_class = ' class="'.$css_class.'"';
8469: }
8470: if ($rowstyle) {
8471: $css_class .= ' style="'.$rowstyle.'"';
8472: }
8473: if ($onclick) {
8474: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 8475: }
8476: my $output = '<tr'.$css_class.'>'.
8477: '<td>'.$lt{$context}.$showdom.
8478: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8479: my $rem;
8480: if (ref($types) eq 'ARRAY') {
8481: for (my $i=0; $i<@{$types}; $i++) {
8482: if (defined($usertypes->{$types->[$i]})) {
8483: my $rem = $i%($numinrow);
8484: if ($rem == 0) {
8485: if ($i > 0) {
8486: $output .= '</tr>';
8487: }
8488: $output .= '<tr>';
1.23 raeburn 8489: }
1.26 raeburn 8490: my $check = ' ';
1.99 raeburn 8491: if (ref($settings) eq 'HASH') {
8492: if (ref($settings->{$context}) eq 'ARRAY') {
8493: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8494: $check = ' checked="checked" ';
8495: }
1.160.6.101 raeburn 8496: } elsif (ref($settings->{$context}) eq 'HASH') {
8497: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8498: $check = ' checked="checked" ';
8499: }
1.99 raeburn 8500: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8501: $check = ' checked="checked" ';
8502: }
1.23 raeburn 8503: }
1.26 raeburn 8504: $output .= '<td class="LC_left_item">'.
8505: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8506: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 8507: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 8508: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8509: }
8510: }
1.26 raeburn 8511: $rem = @{$types}%($numinrow);
1.23 raeburn 8512: }
8513: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 8514: if ($context eq 'overrides') {
8515: if ($colsleft > 1) {
8516: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8517: } else {
8518: $output .= '<td class="LC_left_item">';
8519: }
8520: $output .= ' ';
1.23 raeburn 8521: } else {
1.160.6.101 raeburn 8522: if ($rem == 0) {
8523: $output .= '<tr>';
8524: }
8525: if ($colsleft > 1) {
8526: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8527: } else {
8528: $output .= '<td class="LC_left_item">';
8529: }
8530: my $defcheck = ' ';
8531: if (ref($settings) eq 'HASH') {
8532: if (ref($settings->{$context}) eq 'ARRAY') {
8533: if (grep(/^default$/,@{$settings->{$context}})) {
8534: $defcheck = ' checked="checked" ';
8535: }
8536: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8537: $defcheck = ' checked="checked" ';
8538: }
1.26 raeburn 8539: }
1.160.6.101 raeburn 8540: $output .= '<span class="LC_nobreak"><label>'.
8541: '<input type="checkbox" name="'.$context.'" '.
8542: 'value="default"'.$defcheck.$onclick.' />'.
8543: $othertitle.'</label></span>';
1.23 raeburn 8544: }
1.160.6.101 raeburn 8545: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8546: return $output;
1.23 raeburn 8547: }
8548:
8549: sub sorted_searchtitles {
8550: my %searchtitles = &Apache::lonlocal::texthash(
8551: 'uname' => 'username',
8552: 'lastname' => 'last name',
8553: 'lastfirst' => 'last name, first name',
8554: );
8555: my @titleorder = ('uname','lastname','lastfirst');
8556: return (\%searchtitles,\@titleorder);
8557: }
8558:
1.25 raeburn 8559: sub sorted_searchtypes {
8560: my %srchtypes_desc = (
8561: exact => 'is exact match',
8562: contains => 'contains ..',
8563: begins => 'begins with ..',
8564: );
8565: my @srchtypeorder = ('exact','begins','contains');
8566: return (\%srchtypes_desc,\@srchtypeorder);
8567: }
8568:
1.3 raeburn 8569: sub usertype_update_row {
8570: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8571: my $datatable;
8572: my $numinrow = 4;
8573: foreach my $type (@{$types}) {
8574: if (defined($usertypes->{$type})) {
8575: $$rownums ++;
8576: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8577: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8578: '</td><td class="LC_left_item"><table>';
8579: for (my $i=0; $i<@{$fields}; $i++) {
8580: my $rem = $i%($numinrow);
8581: if ($rem == 0) {
8582: if ($i > 0) {
8583: $datatable .= '</tr>';
8584: }
8585: $datatable .= '<tr>';
8586: }
8587: my $check = ' ';
1.39 raeburn 8588: if (ref($settings) eq 'HASH') {
8589: if (ref($settings->{'fields'}) eq 'HASH') {
8590: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8591: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8592: $check = ' checked="checked" ';
8593: }
1.3 raeburn 8594: }
8595: }
8596: }
8597:
8598: if ($i == @{$fields}-1) {
8599: my $colsleft = $numinrow - $rem;
8600: if ($colsleft > 1) {
8601: $datatable .= '<td colspan="'.$colsleft.'">';
8602: } else {
8603: $datatable .= '<td>';
8604: }
8605: } else {
8606: $datatable .= '<td>';
8607: }
1.8 raeburn 8608: $datatable .= '<span class="LC_nobreak"><label>'.
8609: '<input type="checkbox" name="updateable_'.$type.
8610: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8611: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8612: }
8613: $datatable .= '</tr></table></td></tr>';
8614: }
8615: }
8616: return $datatable;
1.1 raeburn 8617: }
8618:
8619: sub modify_login {
1.160.6.24 raeburn 8620: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 8621: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8622: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8623: %title = ( coursecatalog => 'Display course catalog',
8624: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 8625: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 8626: newuser => 'Link for visitors to create a user account',
8627: loginheader => 'Log-in box header');
8628: @offon = ('off','on');
1.112 raeburn 8629: if (ref($domconfig{login}) eq 'HASH') {
8630: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8631: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8632: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8633: }
8634: }
8635: }
1.9 raeburn 8636: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8637: \%domconfig,\%loginhash);
1.160.6.14 raeburn 8638: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8639: foreach my $item (@toggles) {
8640: $loginhash{login}{$item} = $env{'form.'.$item};
8641: }
1.41 raeburn 8642: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 8643: if (ref($colchanges{'login'}) eq 'HASH') {
8644: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8645: \%loginhash);
8646: }
1.110 raeburn 8647:
1.149 raeburn 8648: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 8649: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 8650: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 8651: if (keys(%servers) > 1) {
8652: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 8653: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8654: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8655: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8656: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8657: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8658: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8659: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8660: $changes{'loginvia'}{$lonhost} = 1;
8661: } else {
8662: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8663: $changes{'loginvia'}{$lonhost} = 1;
8664: }
8665: } else {
8666: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8667: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8668: $changes{'loginvia'}{$lonhost} = 1;
8669: }
8670: }
8671: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8672: foreach my $item (@loginvia_attribs) {
8673: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
8674: }
8675: } else {
8676: foreach my $item (@loginvia_attribs) {
8677: my $new = $env{'form.'.$lonhost.'_'.$item};
8678: if (($item eq 'serverpath') && ($new eq 'custom')) {
8679: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
8680: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8681: $new = '/';
8682: }
8683: }
8684: if (($item eq 'custompath') &&
8685: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8686: $new = '';
8687: }
8688: if ($new ne $curr_loginvia{$lonhost}{$item}) {
8689: $changes{'loginvia'}{$lonhost} = 1;
8690: }
8691: if ($item eq 'exempt') {
1.160.6.56 raeburn 8692: $new = &check_exempt_addresses($new);
1.128 raeburn 8693: }
8694: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8695: }
8696: }
1.112 raeburn 8697: } else {
1.128 raeburn 8698: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8699: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 8700: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 8701: foreach my $item (@loginvia_attribs) {
8702: my $new = $env{'form.'.$lonhost.'_'.$item};
8703: if (($item eq 'serverpath') && ($new eq 'custom')) {
8704: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8705: $new = '/';
8706: }
8707: }
8708: if (($item eq 'custompath') &&
8709: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8710: $new = '';
8711: }
8712: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8713: }
1.110 raeburn 8714: }
8715: }
8716: }
8717: }
1.119 raeburn 8718:
1.160.6.5 raeburn 8719: my $servadm = $r->dir_config('lonAdmEMail');
8720: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
8721: if (ref($domconfig{'login'}) eq 'HASH') {
8722: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
8723: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
8724: if ($lang eq 'nolang') {
8725: push(@currlangs,$lang);
8726: } elsif (defined($langchoices{$lang})) {
8727: push(@currlangs,$lang);
8728: } else {
8729: next;
8730: }
8731: }
8732: }
8733: }
8734: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
8735: if (@currlangs > 0) {
8736: foreach my $lang (@currlangs) {
8737: if (grep(/^\Q$lang\E$/,@delurls)) {
8738: $changes{'helpurl'}{$lang} = 1;
8739: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
8740: $changes{'helpurl'}{$lang} = 1;
8741: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
8742: push(@newlangs,$lang);
8743: } else {
8744: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8745: }
8746: }
8747: }
8748: unless (grep(/^nolang$/,@currlangs)) {
8749: if ($env{'form.loginhelpurl_nolang.filename'}) {
8750: $changes{'helpurl'}{'nolang'} = 1;
8751: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
8752: push(@newlangs,'nolang');
8753: }
8754: }
8755: if ($env{'form.loginhelpurl_add_lang'}) {
8756: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
8757: ($env{'form.loginhelpurl_add_file.filename'})) {
8758: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
8759: $addedfile = $env{'form.loginhelpurl_add_lang'};
8760: }
8761: }
8762: if ((@newlangs > 0) || ($addedfile)) {
8763: my $error;
8764: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8765: if ($configuserok eq 'ok') {
8766: if ($switchserver) {
8767: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
8768: } elsif ($author_ok eq 'ok') {
8769: my @allnew = @newlangs;
8770: if ($addedfile ne '') {
8771: push(@allnew,$addedfile);
8772: }
8773: foreach my $lang (@allnew) {
8774: my $formelem = 'loginhelpurl_'.$lang;
8775: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
8776: $formelem = 'loginhelpurl_add_file';
8777: }
8778: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8779: "help/$lang",'','',$newfile{$lang});
8780: if ($result eq 'ok') {
8781: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
8782: $changes{'helpurl'}{$lang} = 1;
8783: } else {
8784: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
8785: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8786: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
8787: (!grep(/^\Q$lang\E$/,@delurls))) {
8788: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8789: }
8790: }
8791: }
8792: } else {
8793: $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);
8794: }
8795: } else {
8796: $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);
8797: }
8798: if ($error) {
8799: &Apache::lonnet::logthis($error);
8800: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8801: }
8802: }
1.160.6.56 raeburn 8803:
8804: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
8805: if (ref($domconfig{'login'}) eq 'HASH') {
8806: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
8807: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
8808: if ($domservers{$lonhost}) {
8809: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8810: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 8811: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 8812: }
8813: }
8814: }
8815: }
8816: }
8817: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
8818: foreach my $lonhost (sort(keys(%domservers))) {
8819: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8820: $changes{'headtag'}{$lonhost} = 1;
8821: } else {
8822: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
8823: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
8824: }
8825: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
8826: push(@newhosts,$lonhost);
8827: } elsif ($currheadtagurls{$lonhost}) {
8828: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
8829: if ($currexempt{$lonhost}) {
8830: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
8831: $changes{'headtag'}{$lonhost} = 1;
8832: }
8833: } elsif ($possexempt{$lonhost}) {
8834: $changes{'headtag'}{$lonhost} = 1;
8835: }
8836: if ($possexempt{$lonhost}) {
8837: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8838: }
8839: }
8840: }
8841: }
8842: if (@newhosts) {
8843: my $error;
8844: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8845: if ($configuserok eq 'ok') {
8846: if ($switchserver) {
8847: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
8848: } elsif ($author_ok eq 'ok') {
8849: foreach my $lonhost (@newhosts) {
8850: my $formelem = 'loginheadtag_'.$lonhost;
8851: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8852: "login/headtag/$lonhost",'','',
8853: $env{'form.loginheadtag_'.$lonhost.'.filename'});
8854: if ($result eq 'ok') {
8855: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
8856: $changes{'headtag'}{$lonhost} = 1;
8857: if ($possexempt{$lonhost}) {
8858: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8859: }
8860: } else {
8861: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
8862: $newheadtagurls{$lonhost},$result);
8863: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8864: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
8865: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
8866: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
8867: }
8868: }
8869: }
8870: } else {
8871: $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);
8872: }
8873: } else {
8874: $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);
8875: }
8876: if ($error) {
8877: &Apache::lonnet::logthis($error);
8878: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8879: }
8880: }
1.160.6.5 raeburn 8881: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
8882:
8883: my $defaulthelpfile = '/adm/loginproblems.html';
8884: my $defaulttext = &mt('Default in use');
8885:
1.1 raeburn 8886: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
8887: $dom);
8888: if ($putresult eq 'ok') {
1.160.6.14 raeburn 8889: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8890: my %defaultchecked = (
8891: 'coursecatalog' => 'on',
1.160.6.14 raeburn 8892: 'helpdesk' => 'on',
1.42 raeburn 8893: 'adminmail' => 'off',
1.43 raeburn 8894: 'newuser' => 'off',
1.42 raeburn 8895: );
1.55 raeburn 8896: if (ref($domconfig{'login'}) eq 'HASH') {
8897: foreach my $item (@toggles) {
8898: if ($defaultchecked{$item} eq 'on') {
8899: if (($domconfig{'login'}{$item} eq '0') &&
8900: ($env{'form.'.$item} eq '1')) {
8901: $changes{$item} = 1;
8902: } elsif (($domconfig{'login'}{$item} eq '' ||
8903: $domconfig{'login'}{$item} eq '1') &&
8904: ($env{'form.'.$item} eq '0')) {
8905: $changes{$item} = 1;
8906: }
8907: } elsif ($defaultchecked{$item} eq 'off') {
8908: if (($domconfig{'login'}{$item} eq '1') &&
8909: ($env{'form.'.$item} eq '0')) {
8910: $changes{$item} = 1;
8911: } elsif (($domconfig{'login'}{$item} eq '' ||
8912: $domconfig{'login'}{$item} eq '0') &&
8913: ($env{'form.'.$item} eq '1')) {
8914: $changes{$item} = 1;
8915: }
1.42 raeburn 8916: }
8917: }
1.41 raeburn 8918: }
1.6 raeburn 8919: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 8920: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8921: if (ref($lastactref) eq 'HASH') {
8922: $lastactref->{'domainconfig'} = 1;
8923: }
1.1 raeburn 8924: $resulttext = &mt('Changes made:').'<ul>';
8925: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 8926: if ($item eq 'loginvia') {
1.112 raeburn 8927: if (ref($changes{$item}) eq 'HASH') {
8928: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
8929: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 8930: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
8931: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
8932: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
8933: $protocol = 'http' if ($protocol ne 'https');
8934: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
8935:
8936: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
8937: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
8938: } else {
8939: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
8940: }
8941: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
8942: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
8943: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
8944: }
8945: $resulttext .= '</li>';
8946: } else {
8947: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
8948: }
1.112 raeburn 8949: } else {
1.128 raeburn 8950: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 8951: }
8952: }
1.128 raeburn 8953: $resulttext .= '</ul></li>';
1.112 raeburn 8954: }
1.160.6.5 raeburn 8955: } elsif ($item eq 'helpurl') {
8956: if (ref($changes{$item}) eq 'HASH') {
8957: foreach my $lang (sort(keys(%{$changes{$item}}))) {
8958: if (grep(/^\Q$lang\E$/,@delurls)) {
8959: my ($chg,$link);
8960: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
8961: if ($lang eq 'nolang') {
8962: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
8963: } else {
8964: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
8965: }
8966: $resulttext .= '<li>'.$chg.'</li>';
8967: } else {
8968: my $chg;
8969: if ($lang eq 'nolang') {
8970: $chg = &mt('custom log-in help file for no preferred language');
8971: } else {
8972: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
8973: }
8974: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
8975: $loginhash{'login'}{'helpurl'}{$lang}.
8976: '?inhibitmenu=yes',$chg,600,500).
8977: '</li>';
8978: }
8979: }
8980: }
1.160.6.56 raeburn 8981: } elsif ($item eq 'headtag') {
8982: if (ref($changes{$item}) eq 'HASH') {
8983: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8984: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8985: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
8986: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8987: $resulttext .= '<li><a href="'.
8988: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
8989: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
8990: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
8991: if ($possexempt{$lonhost}) {
8992: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
8993: } else {
8994: $resulttext .= &mt('included for any client IP');
8995: }
8996: $resulttext .= '</li>';
8997: }
8998: }
8999: }
1.160.6.5 raeburn 9000: } elsif ($item eq 'captcha') {
9001: if (ref($loginhash{'login'}) eq 'HASH') {
9002: my $chgtxt;
9003: if ($loginhash{'login'}{$item} eq 'notused') {
9004: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9005: } else {
9006: my %captchas = &captcha_phrases();
9007: if ($captchas{$loginhash{'login'}{$item}}) {
9008: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9009: } else {
9010: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9011: }
9012: }
9013: $resulttext .= '<li>'.$chgtxt.'</li>';
9014: }
9015: } elsif ($item eq 'recaptchakeys') {
9016: if (ref($loginhash{'login'}) eq 'HASH') {
9017: my ($privkey,$pubkey);
9018: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9019: $pubkey = $loginhash{'login'}{$item}{'public'};
9020: $privkey = $loginhash{'login'}{$item}{'private'};
9021: }
9022: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9023: if (!$pubkey) {
9024: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9025: } else {
9026: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9027: }
9028: if (!$privkey) {
9029: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9030: } else {
1.160.6.53 raeburn 9031: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 9032: }
9033: $chgtxt .= '</ul>';
9034: $resulttext .= '<li>'.$chgtxt.'</li>';
9035: }
1.160.6.69 raeburn 9036: } elsif ($item eq 'recaptchaversion') {
9037: if (ref($loginhash{'login'}) eq 'HASH') {
9038: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
9039: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
9040: '</li>';
9041: }
9042: }
1.41 raeburn 9043: } else {
9044: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9045: }
1.1 raeburn 9046: }
1.6 raeburn 9047: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9048: } else {
9049: $resulttext = &mt('No changes made to log-in page settings');
9050: }
9051: } else {
1.11 albertel 9052: $resulttext = '<span class="LC_error">'.
9053: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9054: }
1.6 raeburn 9055: if ($errors) {
1.9 raeburn 9056: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9057: $errors.'</ul>';
9058: }
9059: return $resulttext;
9060: }
9061:
1.160.6.56 raeburn 9062: sub check_exempt_addresses {
9063: my ($iplist) = @_;
9064: $iplist =~ s/^\s+//;
9065: $iplist =~ s/\s+$//;
9066: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9067: my (@okips,$new);
9068: foreach my $ip (@poss_ips) {
9069: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9070: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9071: push(@okips,$ip);
9072: }
9073: }
9074: }
9075: if (@okips > 0) {
9076: $new = join(',',@okips);
9077: } else {
9078: $new = '';
9079: }
9080: return $new;
9081: }
9082:
1.6 raeburn 9083: sub color_font_choices {
9084: my %choices =
9085: &Apache::lonlocal::texthash (
9086: img => "Header",
9087: bgs => "Background colors",
9088: links => "Link colors",
1.55 raeburn 9089: images => "Images",
1.6 raeburn 9090: font => "Font color",
1.160.6.22 raeburn 9091: fontmenu => "Font menu",
1.76 raeburn 9092: pgbg => "Page",
1.6 raeburn 9093: tabbg => "Header",
9094: sidebg => "Border",
9095: link => "Link",
9096: alink => "Active link",
9097: vlink => "Visited link",
9098: );
9099: return %choices;
9100: }
9101:
9102: sub modify_rolecolors {
1.160.6.24 raeburn 9103: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9104: my ($resulttext,%rolehash);
9105: $rolehash{'rolecolors'} = {};
1.55 raeburn 9106: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9107: if ($domconfig{'rolecolors'} eq '') {
9108: $domconfig{'rolecolors'} = {};
9109: }
9110: }
1.9 raeburn 9111: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9112: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9113: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9114: $dom);
9115: if ($putresult eq 'ok') {
9116: if (keys(%changes) > 0) {
1.41 raeburn 9117: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9118: if (ref($lastactref) eq 'HASH') {
9119: $lastactref->{'domainconfig'} = 1;
9120: }
1.6 raeburn 9121: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9122: $rolehash{'rolecolors'});
9123: } else {
9124: $resulttext = &mt('No changes made to default color schemes');
9125: }
9126: } else {
1.11 albertel 9127: $resulttext = '<span class="LC_error">'.
9128: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9129: }
9130: if ($errors) {
9131: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9132: $errors.'</ul>';
9133: }
9134: return $resulttext;
9135: }
9136:
9137: sub modify_colors {
1.9 raeburn 9138: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9139: my (%changes,%choices);
1.51 raeburn 9140: my @bgs;
1.6 raeburn 9141: my @links = ('link','alink','vlink');
1.41 raeburn 9142: my @logintext;
1.6 raeburn 9143: my @images;
9144: my $servadm = $r->dir_config('lonAdmEMail');
9145: my $errors;
1.160.6.22 raeburn 9146: my %defaults;
1.6 raeburn 9147: foreach my $role (@{$roles}) {
9148: if ($role eq 'login') {
1.12 raeburn 9149: %choices = &login_choices();
1.41 raeburn 9150: @logintext = ('textcol','bgcol');
1.12 raeburn 9151: } else {
9152: %choices = &color_font_choices();
9153: }
9154: if ($role eq 'login') {
1.41 raeburn 9155: @images = ('img','logo','domlogo','login');
1.51 raeburn 9156: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9157: } else {
9158: @images = ('img');
1.160.6.22 raeburn 9159: @bgs = ('pgbg','tabbg','sidebg');
9160: }
9161: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9162: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9163: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9164: }
9165: if ($role eq 'login') {
9166: foreach my $item (@logintext) {
1.160.6.39 raeburn 9167: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9168: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9169: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9170: }
9171: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 9172: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9173: }
9174: }
9175: } else {
1.160.6.39 raeburn 9176: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9177: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9178: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9179: }
9180: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 9181: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9182: }
1.6 raeburn 9183: }
1.160.6.22 raeburn 9184: foreach my $item (@bgs) {
1.160.6.39 raeburn 9185: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9186: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9187: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9188: }
9189: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 9190: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9191: }
9192: }
9193: foreach my $item (@links) {
1.160.6.39 raeburn 9194: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9195: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9196: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9197: }
9198: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 9199: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9200: }
1.6 raeburn 9201: }
1.46 raeburn 9202: my ($configuserok,$author_ok,$switchserver) =
9203: &config_check($dom,$confname,$servadm);
1.9 raeburn 9204: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 9205: if (ref($domconfig->{$role}) ne 'HASH') {
9206: $domconfig->{$role} = {};
9207: }
1.8 raeburn 9208: foreach my $img (@images) {
1.70 raeburn 9209: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9210: if (defined($env{'form.login_showlogo_'.$img})) {
9211: $confhash->{$role}{'showlogo'}{$img} = 1;
9212: } else {
9213: $confhash->{$role}{'showlogo'}{$img} = 0;
9214: }
9215: }
1.18 albertel 9216: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9217: && !defined($domconfig->{$role}{$img})
9218: && !$env{'form.'.$role.'_del_'.$img}
9219: && $env{'form.'.$role.'_import_'.$img}) {
9220: # import the old configured image from the .tab setting
9221: # if they haven't provided a new one
9222: $domconfig->{$role}{$img} =
9223: $env{'form.'.$role.'_import_'.$img};
9224: }
1.6 raeburn 9225: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9226: my $error;
1.6 raeburn 9227: if ($configuserok eq 'ok') {
1.9 raeburn 9228: if ($switchserver) {
1.12 raeburn 9229: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9230: } else {
9231: if ($author_ok eq 'ok') {
9232: my ($result,$logourl) =
9233: &publishlogo($r,'upload',$role.'_'.$img,
9234: $dom,$confname,$img,$width,$height);
9235: if ($result eq 'ok') {
9236: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9237: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9238: } else {
1.12 raeburn 9239: $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 9240: }
9241: } else {
1.46 raeburn 9242: $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 9243: }
9244: }
9245: } else {
1.46 raeburn 9246: $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 9247: }
9248: if ($error) {
1.8 raeburn 9249: &Apache::lonnet::logthis($error);
1.11 albertel 9250: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9251: }
9252: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9253: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9254: my $error;
9255: if ($configuserok eq 'ok') {
9256: # is confname an author?
9257: if ($switchserver eq '') {
9258: if ($author_ok eq 'ok') {
9259: my ($result,$logourl) =
9260: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9261: $dom,$confname,$img,$width,$height);
9262: if ($result eq 'ok') {
9263: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9264: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9265: }
9266: }
9267: }
9268: }
1.6 raeburn 9269: }
9270: }
9271: }
9272: if (ref($domconfig) eq 'HASH') {
9273: if (ref($domconfig->{$role}) eq 'HASH') {
9274: foreach my $img (@images) {
9275: if ($domconfig->{$role}{$img} ne '') {
9276: if ($env{'form.'.$role.'_del_'.$img}) {
9277: $confhash->{$role}{$img} = '';
1.12 raeburn 9278: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9279: } else {
1.9 raeburn 9280: if ($confhash->{$role}{$img} eq '') {
9281: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
9282: }
1.6 raeburn 9283: }
9284: } else {
9285: if ($env{'form.'.$role.'_del_'.$img}) {
9286: $confhash->{$role}{$img} = '';
1.12 raeburn 9287: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9288: }
9289: }
1.70 raeburn 9290: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
9291: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
9292: if ($confhash->{$role}{'showlogo'}{$img} ne
9293: $domconfig->{$role}{'showlogo'}{$img}) {
9294: $changes{$role}{'showlogo'}{$img} = 1;
9295: }
9296: } else {
9297: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9298: $changes{$role}{'showlogo'}{$img} = 1;
9299: }
9300: }
9301: }
9302: }
1.6 raeburn 9303: if ($domconfig->{$role}{'font'} ne '') {
9304: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
9305: $changes{$role}{'font'} = 1;
9306: }
9307: } else {
9308: if ($confhash->{$role}{'font'}) {
9309: $changes{$role}{'font'} = 1;
9310: }
9311: }
1.107 raeburn 9312: if ($role ne 'login') {
9313: if ($domconfig->{$role}{'fontmenu'} ne '') {
9314: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
9315: $changes{$role}{'fontmenu'} = 1;
9316: }
9317: } else {
9318: if ($confhash->{$role}{'fontmenu'}) {
9319: $changes{$role}{'fontmenu'} = 1;
9320: }
1.97 tempelho 9321: }
9322: }
1.6 raeburn 9323: foreach my $item (@bgs) {
9324: if ($domconfig->{$role}{$item} ne '') {
9325: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9326: $changes{$role}{'bgs'}{$item} = 1;
9327: }
9328: } else {
9329: if ($confhash->{$role}{$item}) {
9330: $changes{$role}{'bgs'}{$item} = 1;
9331: }
9332: }
9333: }
9334: foreach my $item (@links) {
9335: if ($domconfig->{$role}{$item} ne '') {
9336: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9337: $changes{$role}{'links'}{$item} = 1;
9338: }
9339: } else {
9340: if ($confhash->{$role}{$item}) {
9341: $changes{$role}{'links'}{$item} = 1;
9342: }
9343: }
9344: }
1.41 raeburn 9345: foreach my $item (@logintext) {
9346: if ($domconfig->{$role}{$item} ne '') {
9347: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9348: $changes{$role}{'logintext'}{$item} = 1;
9349: }
9350: } else {
9351: if ($confhash->{$role}{$item}) {
9352: $changes{$role}{'logintext'}{$item} = 1;
9353: }
9354: }
9355: }
1.6 raeburn 9356: } else {
9357: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9358: \@logintext,$confhash,\%changes);
1.6 raeburn 9359: }
9360: } else {
9361: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9362: \@logintext,$confhash,\%changes);
1.6 raeburn 9363: }
9364: }
9365: return ($errors,%changes);
9366: }
9367:
1.46 raeburn 9368: sub config_check {
9369: my ($dom,$confname,$servadm) = @_;
9370: my ($configuserok,$author_ok,$switchserver,%currroles);
9371: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
9372: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
9373: $confname,$servadm);
9374: if ($configuserok eq 'ok') {
9375: $switchserver = &check_switchserver($dom,$confname);
9376: if ($switchserver eq '') {
9377: $author_ok = &check_authorstatus($dom,$confname,%currroles);
9378: }
9379: }
9380: return ($configuserok,$author_ok,$switchserver);
9381: }
9382:
1.6 raeburn 9383: sub default_change_checker {
1.41 raeburn 9384: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 9385: foreach my $item (@{$links}) {
9386: if ($confhash->{$role}{$item}) {
9387: $changes->{$role}{'links'}{$item} = 1;
9388: }
9389: }
9390: foreach my $item (@{$bgs}) {
9391: if ($confhash->{$role}{$item}) {
9392: $changes->{$role}{'bgs'}{$item} = 1;
9393: }
9394: }
1.41 raeburn 9395: foreach my $item (@{$logintext}) {
9396: if ($confhash->{$role}{$item}) {
9397: $changes->{$role}{'logintext'}{$item} = 1;
9398: }
9399: }
1.6 raeburn 9400: foreach my $img (@{$images}) {
9401: if ($env{'form.'.$role.'_del_'.$img}) {
9402: $confhash->{$role}{$img} = '';
1.12 raeburn 9403: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 9404: }
1.70 raeburn 9405: if ($role eq 'login') {
9406: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9407: $changes->{$role}{'showlogo'}{$img} = 1;
9408: }
9409: }
1.6 raeburn 9410: }
9411: if ($confhash->{$role}{'font'}) {
9412: $changes->{$role}{'font'} = 1;
9413: }
1.48 raeburn 9414: }
1.6 raeburn 9415:
9416: sub display_colorchgs {
9417: my ($dom,$changes,$roles,$confhash) = @_;
9418: my (%choices,$resulttext);
9419: if (!grep(/^login$/,@{$roles})) {
9420: $resulttext = &mt('Changes made:').'<br />';
9421: }
9422: foreach my $role (@{$roles}) {
9423: if ($role eq 'login') {
9424: %choices = &login_choices();
9425: } else {
9426: %choices = &color_font_choices();
9427: }
9428: if (ref($changes->{$role}) eq 'HASH') {
9429: if ($role ne 'login') {
9430: $resulttext .= '<h4>'.&mt($role).'</h4>';
9431: }
9432: foreach my $key (sort(keys(%{$changes->{$role}}))) {
9433: if ($role ne 'login') {
9434: $resulttext .= '<ul>';
9435: }
9436: if (ref($changes->{$role}{$key}) eq 'HASH') {
9437: if ($role ne 'login') {
9438: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9439: }
9440: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 9441: if (($role eq 'login') && ($key eq 'showlogo')) {
9442: if ($confhash->{$role}{$key}{$item}) {
9443: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9444: } else {
9445: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9446: }
9447: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 9448: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9449: } else {
1.12 raeburn 9450: my $newitem = $confhash->{$role}{$item};
9451: if ($key eq 'images') {
9452: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
9453: }
9454: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 9455: }
9456: }
9457: if ($role ne 'login') {
9458: $resulttext .= '</ul></li>';
9459: }
9460: } else {
9461: if ($confhash->{$role}{$key} eq '') {
9462: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9463: } else {
9464: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9465: }
9466: }
9467: if ($role ne 'login') {
9468: $resulttext .= '</ul>';
9469: }
9470: }
9471: }
9472: }
1.3 raeburn 9473: return $resulttext;
1.1 raeburn 9474: }
9475:
1.9 raeburn 9476: sub thumb_dimensions {
9477: return ('200','50');
9478: }
9479:
1.16 raeburn 9480: sub check_dimensions {
9481: my ($inputfile) = @_;
9482: my ($fullwidth,$fullheight);
9483: if ($inputfile =~ m|^[/\w.\-]+$|) {
9484: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9485: my $imageinfo = <PIPE>;
9486: if (!close(PIPE)) {
9487: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9488: }
9489: chomp($imageinfo);
9490: my ($fullsize) =
1.21 raeburn 9491: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 9492: if ($fullsize) {
9493: ($fullwidth,$fullheight) = split(/x/,$fullsize);
9494: }
9495: }
9496: }
9497: return ($fullwidth,$fullheight);
9498: }
9499:
1.9 raeburn 9500: sub check_configuser {
9501: my ($uhome,$dom,$confname,$servadm) = @_;
9502: my ($configuserok,%currroles);
9503: if ($uhome eq 'no_host') {
9504: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 9505: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 9506: $configuserok =
9507: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
9508: $configpass,'','','','','',undef,$servadm);
9509: } else {
9510: $configuserok = 'ok';
9511: %currroles =
9512: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9513: }
9514: return ($configuserok,%currroles);
9515: }
9516:
9517: sub check_authorstatus {
9518: my ($dom,$confname,%currroles) = @_;
9519: my $author_ok;
1.40 raeburn 9520: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 9521: my $start = time;
9522: my $end = 0;
9523: $author_ok =
9524: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 9525: 'au',$end,$start,'','','domconfig');
1.9 raeburn 9526: } else {
9527: $author_ok = 'ok';
9528: }
9529: return $author_ok;
9530: }
9531:
9532: sub publishlogo {
1.46 raeburn 9533: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 9534: my ($output,$fname,$logourl);
9535: if ($action eq 'upload') {
9536: $fname=$env{'form.'.$formname.'.filename'};
9537: chop($env{'form.'.$formname});
9538: } else {
9539: ($fname) = ($formname =~ /([^\/]+)$/);
9540: }
1.46 raeburn 9541: if ($savefileas ne '') {
9542: $fname = $savefileas;
9543: }
1.9 raeburn 9544: $fname=&Apache::lonnet::clean_filename($fname);
9545: # See if there is anything left
9546: unless ($fname) { return ('error: no uploaded file'); }
9547: $fname="$subdir/$fname";
1.160.6.5 raeburn 9548: my $docroot=$r->dir_config('lonDocRoot');
9549: my $filepath="$docroot/priv";
9550: my $relpath = "$dom/$confname";
1.9 raeburn 9551: my ($fnamepath,$file,$fetchthumb);
9552: $file=$fname;
9553: if ($fname=~m|/|) {
9554: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9555: }
1.160.6.26 raeburn 9556: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9557: my $count;
1.160.6.5 raeburn 9558: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9559: $filepath.="/$parts[$count]";
9560: if ((-e $filepath)!=1) {
9561: mkdir($filepath,02770);
9562: }
9563: }
9564: # Check for bad extension and disallow upload
9565: if ($file=~/\.(\w+)$/ &&
9566: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9567: $output =
1.160.6.25 raeburn 9568: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9569: } elsif ($file=~/\.(\w+)$/ &&
9570: !defined(&Apache::loncommon::fileembstyle($1))) {
9571: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9572: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 9573: $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 9574: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 9575: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9576: } else {
9577: my $source = $filepath.'/'.$file;
9578: my $logfile;
1.160.6.88 raeburn 9579: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 9580: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9581: }
9582: print $logfile
9583: "\n================= Publish ".localtime()." ================\n".
9584: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9585: # Save the file
1.160.6.88 raeburn 9586: if (!open(FH,">",$source)) {
1.9 raeburn 9587: &Apache::lonnet::logthis('Failed to create '.$source);
9588: return (&mt('Failed to create file'));
9589: }
9590: if ($action eq 'upload') {
9591: if (!print FH ($env{'form.'.$formname})) {
9592: &Apache::lonnet::logthis('Failed to write to '.$source);
9593: return (&mt('Failed to write file'));
9594: }
9595: } else {
9596: my $original = &Apache::lonnet::filelocation('',$formname);
9597: if(!copy($original,$source)) {
9598: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9599: return (&mt('Failed to write file'));
9600: }
9601: }
9602: close(FH);
9603: chmod(0660, $source); # Permissions to rw-rw---.
9604:
9605: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9606: my $copyfile=$targetdir.'/'.$file;
9607:
9608: my @parts=split(/\//,$targetdir);
9609: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9610: for (my $count=5;$count<=$#parts;$count++) {
9611: $path.="/$parts[$count]";
9612: if (!-e $path) {
9613: print $logfile "\nCreating directory ".$path;
9614: mkdir($path,02770);
9615: }
9616: }
9617: my $versionresult;
9618: if (-e $copyfile) {
9619: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9620: } else {
9621: $versionresult = 'ok';
9622: }
9623: if ($versionresult eq 'ok') {
9624: if (copy($source,$copyfile)) {
9625: print $logfile "\nCopied original source to ".$copyfile."\n";
9626: $output = 'ok';
9627: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9628: push(@{$modified_urls},[$copyfile,$source]);
9629: my $metaoutput =
9630: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9631: unless ($registered_cleanup) {
9632: my $handlers = $r->get_handlers('PerlCleanupHandler');
9633: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9634: $registered_cleanup=1;
9635: }
1.9 raeburn 9636: } else {
9637: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9638: $output = &mt('Failed to copy file to RES space').", $!";
9639: }
9640: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9641: my $inputfile = $filepath.'/'.$file;
9642: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 9643: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9644: if ($fullwidth ne '' && $fullheight ne '') {
9645: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9646: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 9647: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
9648: system({$args[0]} @args);
1.16 raeburn 9649: chmod(0660, $filepath.'/tn-'.$file);
9650: if (-e $outfile) {
9651: my $copyfile=$targetdir.'/tn-'.$file;
9652: if (copy($outfile,$copyfile)) {
9653: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 9654: my $thumb_metaoutput =
9655: &write_metadata($dom,$confname,$formname,
9656: $targetdir,'tn-'.$file,$logfile);
9657: push(@{$modified_urls},[$copyfile,$outfile]);
9658: unless ($registered_cleanup) {
9659: my $handlers = $r->get_handlers('PerlCleanupHandler');
9660: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9661: $registered_cleanup=1;
9662: }
1.16 raeburn 9663: } else {
9664: print $logfile "\nUnable to write ".$copyfile.
9665: ':'.$!."\n";
9666: }
9667: }
1.9 raeburn 9668: }
9669: }
9670: }
9671: } else {
9672: $output = $versionresult;
9673: }
9674: }
9675: return ($output,$logourl);
9676: }
9677:
9678: sub logo_versioning {
9679: my ($targetdir,$file,$logfile) = @_;
9680: my $target = $targetdir.'/'.$file;
9681: my ($maxversion,$fn,$extn,$output);
9682: $maxversion = 0;
9683: if ($file =~ /^(.+)\.(\w+)$/) {
9684: $fn=$1;
9685: $extn=$2;
9686: }
9687: opendir(DIR,$targetdir);
9688: while (my $filename=readdir(DIR)) {
9689: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
9690: $maxversion=($1>$maxversion)?$1:$maxversion;
9691: }
9692: }
9693: $maxversion++;
9694: print $logfile "\nCreating old version ".$maxversion."\n";
9695: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
9696: if (copy($target,$copyfile)) {
9697: print $logfile "Copied old target to ".$copyfile."\n";
9698: $copyfile=$copyfile.'.meta';
9699: if (copy($target.'.meta',$copyfile)) {
9700: print $logfile "Copied old target metadata to ".$copyfile."\n";
9701: $output = 'ok';
9702: } else {
9703: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
9704: $output = &mt('Failed to copy old meta').", $!, ";
9705: }
9706: } else {
9707: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
9708: $output = &mt('Failed to copy old target').", $!, ";
9709: }
9710: return $output;
9711: }
9712:
9713: sub write_metadata {
9714: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
9715: my (%metadatafields,%metadatakeys,$output);
9716: $metadatafields{'title'}=$formname;
9717: $metadatafields{'creationdate'}=time;
9718: $metadatafields{'lastrevisiondate'}=time;
9719: $metadatafields{'copyright'}='public';
9720: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
9721: $env{'user.domain'};
9722: $metadatafields{'authorspace'}=$confname.':'.$dom;
9723: $metadatafields{'domain'}=$dom;
9724: {
9725: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
9726: my $mfh;
1.160.6.88 raeburn 9727: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 9728: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 9729: unless ($_=~/\./) {
9730: my $unikey=$_;
9731: $unikey=~/^([A-Za-z]+)/;
9732: my $tag=$1;
9733: $tag=~tr/A-Z/a-z/;
9734: print $mfh "\n\<$tag";
9735: foreach (split(/\,/,$metadatakeys{$unikey})) {
9736: my $value=$metadatafields{$unikey.'.'.$_};
9737: $value=~s/\"/\'\'/g;
9738: print $mfh ' '.$_.'="'.$value.'"';
9739: }
9740: print $mfh '>'.
9741: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
9742: .'</'.$tag.'>';
9743: }
9744: }
9745: $output = 'ok';
9746: print $logfile "\nWrote metadata";
9747: close($mfh);
9748: } else {
9749: print $logfile "\nFailed to open metadata file";
1.9 raeburn 9750: $output = &mt('Could not write metadata');
9751: }
9752: }
1.155 raeburn 9753: return $output;
9754: }
9755:
9756: sub notifysubscribed {
9757: foreach my $targetsource (@{$modified_urls}){
9758: next unless (ref($targetsource) eq 'ARRAY');
9759: my ($target,$source)=@{$targetsource};
9760: if ($source ne '') {
1.160.6.88 raeburn 9761: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 9762: print $logfh "\nCleanup phase: Notifications\n";
9763: my @subscribed=&subscribed_hosts($target);
9764: foreach my $subhost (@subscribed) {
9765: print $logfh "\nNotifying host ".$subhost.':';
9766: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
9767: print $logfh $reply;
9768: }
9769: my @subscribedmeta=&subscribed_hosts("$target.meta");
9770: foreach my $subhost (@subscribedmeta) {
9771: print $logfh "\nNotifying host for metadata only ".$subhost.':';
9772: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
9773: $subhost);
9774: print $logfh $reply;
9775: }
9776: print $logfh "\n============ Done ============\n";
1.160 raeburn 9777: close($logfh);
1.155 raeburn 9778: }
9779: }
9780: }
9781: return OK;
9782: }
9783:
9784: sub subscribed_hosts {
9785: my ($target) = @_;
9786: my @subscribed;
1.160.6.88 raeburn 9787: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 9788: while (my $subline=<$fh>) {
9789: if ($subline =~ /^($match_lonid):/) {
9790: my $host = $1;
9791: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
9792: unless (grep(/^\Q$host\E$/,@subscribed)) {
9793: push(@subscribed,$host);
9794: }
9795: }
9796: }
9797: }
9798: }
9799: return @subscribed;
1.9 raeburn 9800: }
9801:
9802: sub check_switchserver {
9803: my ($dom,$confname) = @_;
9804: my ($allowed,$switchserver);
9805: my $home = &Apache::lonnet::homeserver($confname,$dom);
9806: if ($home eq 'no_host') {
9807: $home = &Apache::lonnet::domain($dom,'primary');
9808: }
9809: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 9810: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
9811: if (!$allowed) {
1.160.6.11 raeburn 9812: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 9813: }
9814: return $switchserver;
9815: }
9816:
1.1 raeburn 9817: sub modify_quotas {
1.160.6.30 raeburn 9818: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 9819: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 9820: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 9821: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
9822: $validationfieldsref);
1.86 raeburn 9823: if ($action eq 'quotas') {
9824: $context = 'tools';
1.160.6.26 raeburn 9825: } else {
1.86 raeburn 9826: $context = $action;
9827: }
9828: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 9829: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 9830: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 9831: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
9832: %titles = &courserequest_titles();
9833: $toolregexp = join('|',@usertools);
9834: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 9835: $confname = $dom.'-domainconfig';
9836: my $servadm = $r->dir_config('lonAdmEMail');
9837: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 9838: ($validationitemsref,$validationnamesref,$validationfieldsref) =
9839: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 9840: } elsif ($context eq 'requestauthor') {
9841: @usertools = ('author');
9842: %titles = &authorrequest_titles();
1.86 raeburn 9843: } else {
1.160.6.4 raeburn 9844: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 9845: %titles = &tool_titles();
1.86 raeburn 9846: }
1.160.6.27 raeburn 9847: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 9848: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9849: foreach my $key (keys(%env)) {
1.101 raeburn 9850: if ($context eq 'requestcourses') {
9851: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
9852: my $item = $1;
9853: my $type = $2;
9854: if ($type =~ /^limit_(.+)/) {
9855: $limithash{$item}{$1} = $env{$key};
9856: } else {
9857: $confhash{$item}{$type} = $env{$key};
9858: }
9859: }
1.160.6.5 raeburn 9860: } elsif ($context eq 'requestauthor') {
9861: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
9862: $confhash{$1} = $env{$key};
9863: }
1.101 raeburn 9864: } else {
1.86 raeburn 9865: if ($key =~ /^form\.quota_(.+)$/) {
9866: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 9867: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
9868: $confhash{'authorquota'}{$1} = $env{$key};
9869: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 9870: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
9871: }
1.72 raeburn 9872: }
9873: }
1.160.6.5 raeburn 9874: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 9875: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 9876: @approvalnotify = sort(@approvalnotify);
9877: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 9878: my @crstypes = ('official','unofficial','community','textbook');
9879: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
9880: foreach my $type (@hasuniquecode) {
9881: if (grep(/^\Q$type\E$/,@crstypes)) {
9882: $confhash{'uniquecode'}{$type} = 1;
9883: }
9884: }
1.160.6.46 raeburn 9885: my (%newbook,%allpos);
1.160.6.30 raeburn 9886: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9887: foreach my $type ('textbooks','templates') {
9888: @{$allpos{$type}} = ();
9889: my $invalid;
9890: if ($type eq 'textbooks') {
9891: $invalid = &mt('Invalid LON-CAPA course for textbook');
9892: } else {
9893: $invalid = &mt('Invalid LON-CAPA course for template');
9894: }
9895: if ($env{'form.'.$type.'_addbook'}) {
9896: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
9897: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
9898: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
9899: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
9900: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9901: } else {
9902: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9903: my $position = $env{'form.'.$type.'_addbook_pos'};
9904: $position =~ s/\D+//g;
9905: if ($position ne '') {
9906: $allpos{$type}[$position] = $newbook{$type};
9907: }
1.160.6.30 raeburn 9908: }
1.160.6.46 raeburn 9909: } else {
9910: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 9911: }
9912: }
1.160.6.46 raeburn 9913: }
1.160.6.30 raeburn 9914: }
1.102 raeburn 9915: if (ref($domconfig{$action}) eq 'HASH') {
9916: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
9917: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
9918: $changes{'notify'}{'approval'} = 1;
9919: }
9920: } else {
1.144 raeburn 9921: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9922: $changes{'notify'}{'approval'} = 1;
9923: }
9924: }
1.160.6.30 raeburn 9925: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
9926: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9927: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
9928: unless ($confhash{'uniquecode'}{$crstype}) {
9929: $changes{'uniquecode'} = 1;
9930: }
9931: }
9932: unless ($changes{'uniquecode'}) {
9933: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
9934: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
9935: $changes{'uniquecode'} = 1;
9936: }
9937: }
9938: }
9939: } else {
9940: $changes{'uniquecode'} = 1;
9941: }
9942: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
9943: $changes{'uniquecode'} = 1;
9944: }
9945: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9946: foreach my $type ('textbooks','templates') {
9947: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9948: my %deletions;
9949: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
9950: if (@todelete) {
9951: map { $deletions{$_} = 1; } @todelete;
9952: }
9953: my %imgdeletions;
9954: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
9955: if (@todeleteimages) {
9956: map { $imgdeletions{$_} = 1; } @todeleteimages;
9957: }
9958: my $maxnum = $env{'form.'.$type.'_maxnum'};
9959: for (my $i=0; $i<=$maxnum; $i++) {
9960: my $itemid = $env{'form.'.$type.'_id_'.$i};
9961: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
9962: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
9963: if ($deletions{$key}) {
9964: if ($domconfig{$action}{$type}{$key}{'image'}) {
9965: #FIXME need to obsolete item in RES space
9966: }
9967: next;
9968: } else {
9969: my $newpos = $env{'form.'.$itemid};
9970: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 9971: foreach my $item ('subject','title','publisher','author') {
9972: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9973: ($type eq 'templates'));
1.160.6.46 raeburn 9974: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
9975: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
9976: $changes{$type}{$key} = 1;
9977: }
9978: }
9979: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 9980: }
1.160.6.46 raeburn 9981: if ($imgdeletions{$key}) {
9982: $changes{$type}{$key} = 1;
9983: #FIXME need to obsolete item in RES space
9984: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
9985: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 9986: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9987: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9988: } else {
9989: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
9990: $cdom,$cnum,$type,$configuserok,
9991: $switchserver,$author_ok);
9992: if ($imgurl) {
9993: $confhash{$type}{$key}{'image'} = $imgurl;
9994: $changes{$type}{$key} = 1;
9995: }
9996: if ($error) {
9997: &Apache::lonnet::logthis($error);
9998: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9999: }
1.160.6.46 raeburn 10000: }
10001: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10002: $confhash{$type}{$key}{'image'} =
10003: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 10004: }
10005: }
10006: }
10007: }
10008: }
10009: }
1.102 raeburn 10010: } else {
1.144 raeburn 10011: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10012: $changes{'notify'}{'approval'} = 1;
10013: }
1.160.6.30 raeburn 10014: if (ref($confhash{'uniquecode'} eq 'HASH')) {
10015: $changes{'uniquecode'} = 1;
10016: }
10017: }
10018: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10019: foreach my $type ('textbooks','templates') {
10020: if ($newbook{$type}) {
10021: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 10022: foreach my $item ('subject','title','publisher','author') {
10023: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10024: ($type eq 'template'));
1.160.6.46 raeburn 10025: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10026: if ($env{'form.'.$type.'_addbook_'.$item}) {
10027: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10028: }
10029: }
10030: if ($type eq 'textbooks') {
10031: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10032: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 10033: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10034: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10035: } else {
10036: my ($imageurl,$error) =
10037: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10038: $configuserok,$switchserver,$author_ok);
10039: if ($imageurl) {
10040: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10041: }
10042: if ($error) {
10043: &Apache::lonnet::logthis($error);
10044: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10045: }
1.160.6.46 raeburn 10046: }
10047: }
1.160.6.30 raeburn 10048: }
10049: }
1.160.6.46 raeburn 10050: if (@{$allpos{$type}} > 0) {
10051: my $idx = 0;
10052: foreach my $item (@{$allpos{$type}}) {
10053: if ($item ne '') {
10054: $confhash{$type}{$item}{'order'} = $idx;
10055: if (ref($domconfig{$action}) eq 'HASH') {
10056: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10057: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10058: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10059: $changes{$type}{$item} = 1;
10060: }
1.160.6.30 raeburn 10061: }
10062: }
10063: }
1.160.6.46 raeburn 10064: $idx ++;
1.160.6.30 raeburn 10065: }
10066: }
10067: }
10068: }
1.160.6.39 raeburn 10069: if (ref($validationitemsref) eq 'ARRAY') {
10070: foreach my $item (@{$validationitemsref}) {
10071: if ($item eq 'fields') {
10072: my @changed;
10073: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10074: if (@{$confhash{'validation'}{$item}} > 0) {
10075: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10076: }
1.160.6.65 raeburn 10077: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10078: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10079: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10080: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10081: $domconfig{'requestcourses'}{'validation'}{$item});
10082: } else {
10083: @changed = @{$confhash{'validation'}{$item}};
10084: }
1.160.6.39 raeburn 10085: } else {
10086: @changed = @{$confhash{'validation'}{$item}};
10087: }
10088: } else {
10089: @changed = @{$confhash{'validation'}{$item}};
10090: }
10091: if (@changed) {
10092: if ($confhash{'validation'}{$item}) {
10093: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10094: } else {
10095: $changes{'validation'}{$item} = &mt('None');
10096: }
10097: }
10098: } else {
10099: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10100: if ($item eq 'markup') {
10101: if ($env{'form.requestcourses_validation_'.$item}) {
10102: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10103: }
10104: }
1.160.6.65 raeburn 10105: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10106: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10107: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10108: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10109: }
10110: } else {
10111: if ($confhash{'validation'}{$item} ne '') {
10112: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10113: }
1.160.6.39 raeburn 10114: }
10115: } else {
10116: if ($confhash{'validation'}{$item} ne '') {
10117: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10118: }
10119: }
10120: }
10121: }
10122: }
10123: if ($env{'form.validationdc'}) {
10124: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 10125: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 10126: if (exists($domcoords{$newval})) {
10127: $confhash{'validation'}{'dc'} = $newval;
10128: }
10129: }
10130: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 10131: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10132: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10133: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10134: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10135: if ($confhash{'validation'}{'dc'} eq '') {
10136: $changes{'validation'}{'dc'} = &mt('None');
10137: } else {
10138: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10139: }
1.160.6.39 raeburn 10140: }
1.160.6.65 raeburn 10141: } elsif ($confhash{'validation'}{'dc'} ne '') {
10142: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 10143: }
10144: } elsif ($confhash{'validation'}{'dc'} ne '') {
10145: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10146: }
10147: } elsif ($confhash{'validation'}{'dc'} ne '') {
10148: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10149: }
1.160.6.65 raeburn 10150: } else {
10151: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10152: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10153: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10154: $changes{'validation'}{'dc'} = &mt('None');
10155: }
10156: }
1.160.6.39 raeburn 10157: }
10158: }
1.102 raeburn 10159: }
10160: } else {
1.86 raeburn 10161: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 10162: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10163: }
1.72 raeburn 10164: foreach my $item (@usertools) {
10165: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10166: my $unset;
1.101 raeburn 10167: if ($context eq 'requestcourses') {
1.104 raeburn 10168: $unset = '0';
10169: if ($type eq '_LC_adv') {
10170: $unset = '';
10171: }
1.101 raeburn 10172: if ($confhash{$item}{$type} eq 'autolimit') {
10173: $confhash{$item}{$type} .= '=';
10174: unless ($limithash{$item}{$type} =~ /\D/) {
10175: $confhash{$item}{$type} .= $limithash{$item}{$type};
10176: }
10177: }
1.160.6.5 raeburn 10178: } elsif ($context eq 'requestauthor') {
10179: $unset = '0';
10180: if ($type eq '_LC_adv') {
10181: $unset = '';
10182: }
1.72 raeburn 10183: } else {
1.101 raeburn 10184: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10185: $confhash{$item}{$type} = 1;
10186: } else {
10187: $confhash{$item}{$type} = 0;
10188: }
1.72 raeburn 10189: }
1.86 raeburn 10190: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 10191: if ($action eq 'requestauthor') {
10192: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10193: $changes{$type} = 1;
10194: }
10195: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10196: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10197: $changes{$item}{$type} = 1;
10198: }
10199: } else {
10200: if ($context eq 'requestcourses') {
1.104 raeburn 10201: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 10202: $changes{$item}{$type} = 1;
10203: }
10204: } else {
10205: if (!$confhash{$item}{$type}) {
10206: $changes{$item}{$type} = 1;
10207: }
10208: }
10209: }
10210: } else {
10211: if ($context eq 'requestcourses') {
1.104 raeburn 10212: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10213: $changes{$item}{$type} = 1;
10214: }
1.160.6.5 raeburn 10215: } elsif ($context eq 'requestauthor') {
10216: if ($confhash{$type} ne $unset) {
10217: $changes{$type} = 1;
10218: }
1.72 raeburn 10219: } else {
10220: if (!$confhash{$item}{$type}) {
10221: $changes{$item}{$type} = 1;
10222: }
10223: }
10224: }
1.1 raeburn 10225: }
10226: }
1.160.6.5 raeburn 10227: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10228: if (ref($domconfig{'quotas'}) eq 'HASH') {
10229: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10230: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10231: if (exists($confhash{'defaultquota'}{$key})) {
10232: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10233: $changes{'defaultquota'}{$key} = 1;
10234: }
10235: } else {
10236: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10237: }
10238: }
1.86 raeburn 10239: } else {
10240: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10241: if (exists($confhash{'defaultquota'}{$key})) {
10242: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10243: $changes{'defaultquota'}{$key} = 1;
10244: }
10245: } else {
10246: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10247: }
1.1 raeburn 10248: }
10249: }
1.160.6.20 raeburn 10250: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10251: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10252: if (exists($confhash{'authorquota'}{$key})) {
10253: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10254: $changes{'authorquota'}{$key} = 1;
10255: }
10256: } else {
10257: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10258: }
10259: }
10260: }
1.1 raeburn 10261: }
1.86 raeburn 10262: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10263: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10264: if (ref($domconfig{'quotas'}) eq 'HASH') {
10265: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10266: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
10267: $changes{'defaultquota'}{$key} = 1;
10268: }
10269: } else {
10270: if (!exists($domconfig{'quotas'}{$key})) {
10271: $changes{'defaultquota'}{$key} = 1;
10272: }
1.72 raeburn 10273: }
10274: } else {
1.86 raeburn 10275: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 10276: }
1.1 raeburn 10277: }
10278: }
1.160.6.20 raeburn 10279: if (ref($confhash{'authorquota'}) eq 'HASH') {
10280: foreach my $key (keys(%{$confhash{'authorquota'}})) {
10281: if (ref($domconfig{'quotas'}) eq 'HASH') {
10282: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10283: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
10284: $changes{'authorquota'}{$key} = 1;
10285: }
10286: } else {
10287: $changes{'authorquota'}{$key} = 1;
10288: }
10289: } else {
10290: $changes{'authorquota'}{$key} = 1;
10291: }
10292: }
10293: }
1.1 raeburn 10294: }
1.72 raeburn 10295:
1.160.6.5 raeburn 10296: if ($context eq 'requestauthor') {
10297: $domdefaults{'requestauthor'} = \%confhash;
10298: } else {
10299: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 10300: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 10301: $domdefaults{$key} = $confhash{$key};
10302: }
1.160.6.5 raeburn 10303: }
1.72 raeburn 10304: }
1.160.6.5 raeburn 10305:
1.1 raeburn 10306: my %quotahash = (
1.86 raeburn 10307: $action => { %confhash }
1.1 raeburn 10308: );
10309: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
10310: $dom);
10311: if ($putresult eq 'ok') {
10312: if (keys(%changes) > 0) {
1.72 raeburn 10313: my $cachetime = 24*60*60;
10314: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10315: if (ref($lastactref) eq 'HASH') {
10316: $lastactref->{'domdefaults'} = 1;
10317: }
1.1 raeburn 10318: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 10319: unless (($context eq 'requestcourses') ||
10320: ($context eq 'requestauthor')) {
1.86 raeburn 10321: if (ref($changes{'defaultquota'}) eq 'HASH') {
10322: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
10323: foreach my $type (@{$types},'default') {
10324: if (defined($changes{'defaultquota'}{$type})) {
10325: my $typetitle = $usertypes->{$type};
10326: if ($type eq 'default') {
10327: $typetitle = $othertitle;
10328: }
1.160.6.28 raeburn 10329: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 10330: }
10331: }
1.86 raeburn 10332: $resulttext .= '</ul></li>';
1.72 raeburn 10333: }
1.160.6.20 raeburn 10334: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 10335: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 10336: foreach my $type (@{$types},'default') {
10337: if (defined($changes{'authorquota'}{$type})) {
10338: my $typetitle = $usertypes->{$type};
10339: if ($type eq 'default') {
10340: $typetitle = $othertitle;
10341: }
1.160.6.28 raeburn 10342: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 10343: }
10344: }
10345: $resulttext .= '</ul></li>';
10346: }
1.72 raeburn 10347: }
1.80 raeburn 10348: my %newenv;
1.72 raeburn 10349: foreach my $item (@usertools) {
1.160.6.5 raeburn 10350: my (%haschgs,%inconf);
10351: if ($context eq 'requestauthor') {
10352: %haschgs = %changes;
10353: %inconf = %confhash;
10354: } else {
10355: if (ref($changes{$item}) eq 'HASH') {
10356: %haschgs = %{$changes{$item}};
10357: }
10358: if (ref($confhash{$item}) eq 'HASH') {
10359: %inconf = %{$confhash{$item}};
10360: }
10361: }
10362: if (keys(%haschgs) > 0) {
1.80 raeburn 10363: my $newacc =
10364: &Apache::lonnet::usertools_access($env{'user.name'},
10365: $env{'user.domain'},
1.86 raeburn 10366: $item,'reload',$context);
1.160.6.5 raeburn 10367: if (($context eq 'requestcourses') ||
10368: ($context eq 'requestauthor')) {
1.108 raeburn 10369: if ($env{'environment.canrequest.'.$item} ne $newacc) {
10370: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 10371: }
10372: } else {
10373: if ($env{'environment.availabletools.'.$item} ne $newacc) {
10374: $newenv{'environment.availabletools.'.$item} = $newacc;
10375: }
1.80 raeburn 10376: }
1.160.6.5 raeburn 10377: unless ($context eq 'requestauthor') {
10378: $resulttext .= '<li>'.$titles{$item}.'<ul>';
10379: }
1.72 raeburn 10380: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 10381: if ($haschgs{$type}) {
1.72 raeburn 10382: my $typetitle = $usertypes->{$type};
10383: if ($type eq 'default') {
10384: $typetitle = $othertitle;
10385: } elsif ($type eq '_LC_adv') {
10386: $typetitle = 'LON-CAPA Advanced Users';
10387: }
1.160.6.5 raeburn 10388: if ($inconf{$type}) {
1.101 raeburn 10389: if ($context eq 'requestcourses') {
10390: my $cond;
1.160.6.5 raeburn 10391: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 10392: if ($1 eq '') {
10393: $cond = &mt('(Automatic processing of any request).');
10394: } else {
10395: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
10396: }
10397: } else {
1.160.6.5 raeburn 10398: $cond = $conditions{$inconf{$type}};
1.101 raeburn 10399: }
10400: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 10401: } elsif ($context eq 'requestauthor') {
10402: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
10403: $titles{$inconf{$type}},$typetitle);
10404:
1.101 raeburn 10405: } else {
10406: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
10407: }
1.72 raeburn 10408: } else {
1.104 raeburn 10409: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 10410: if ($inconf{$type} eq '0') {
1.104 raeburn 10411: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10412: } else {
10413: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
10414: }
10415: } else {
10416: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10417: }
1.72 raeburn 10418: }
10419: }
1.26 raeburn 10420: }
1.160.6.5 raeburn 10421: unless ($context eq 'requestauthor') {
10422: $resulttext .= '</ul></li>';
10423: }
1.26 raeburn 10424: }
1.1 raeburn 10425: }
1.160.6.5 raeburn 10426: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 10427: if (ref($changes{'notify'}) eq 'HASH') {
10428: if ($changes{'notify'}{'approval'}) {
10429: if (ref($confhash{'notify'}) eq 'HASH') {
10430: if ($confhash{'notify'}{'approval'}) {
10431: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
10432: } else {
1.160.6.5 raeburn 10433: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 10434: }
10435: }
10436: }
10437: }
10438: }
1.160.6.30 raeburn 10439: if ($action eq 'requestcourses') {
10440: my @offon = ('off','on');
10441: if ($changes{'uniquecode'}) {
10442: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10443: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10444: $resulttext .= '<li>'.
10445: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10446: '</li>';
10447: } else {
10448: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10449: '</li>';
10450: }
10451: }
1.160.6.46 raeburn 10452: foreach my $type ('textbooks','templates') {
10453: if (ref($changes{$type}) eq 'HASH') {
10454: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10455: foreach my $key (sort(keys(%{$changes{$type}}))) {
10456: my %coursehash = &Apache::lonnet::coursedescription($key);
10457: my $coursetitle = $coursehash{'description'};
10458: my $position = $confhash{$type}{$key}{'order'} + 1;
10459: $resulttext .= '<li>';
1.160.6.47 raeburn 10460: foreach my $item ('subject','title','publisher','author') {
10461: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10462: ($type eq 'templates'));
1.160.6.46 raeburn 10463: my $name = $item.':';
10464: $name =~ s/^(\w)/\U$1/;
10465: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10466: }
10467: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10468: if ($type eq 'textbooks') {
10469: if ($confhash{$type}{$key}{'image'}) {
10470: $resulttext .= ' '.&mt('Image: [_1]',
10471: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10472: ' alt="Textbook cover" />').'<br />';
10473: }
10474: }
10475: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 10476: }
1.160.6.46 raeburn 10477: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 10478: }
10479: }
1.160.6.39 raeburn 10480: if (ref($changes{'validation'}) eq 'HASH') {
10481: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10482: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10483: foreach my $item (@{$validationitemsref}) {
10484: if (exists($changes{'validation'}{$item})) {
10485: if ($item eq 'markup') {
10486: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10487: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10488: } else {
10489: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10490: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10491: }
10492: }
10493: }
10494: if (exists($changes{'validation'}{'dc'})) {
10495: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
10496: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
10497: }
10498: }
10499: }
1.160.6.30 raeburn 10500: }
1.1 raeburn 10501: $resulttext .= '</ul>';
1.80 raeburn 10502: if (keys(%newenv)) {
10503: &Apache::lonnet::appenv(\%newenv);
10504: }
1.1 raeburn 10505: } else {
1.86 raeburn 10506: if ($context eq 'requestcourses') {
10507: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 10508: } elsif ($context eq 'requestauthor') {
10509: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 10510: } else {
1.90 weissno 10511: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 10512: }
1.1 raeburn 10513: }
10514: } else {
1.11 albertel 10515: $resulttext = '<span class="LC_error">'.
10516: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10517: }
1.160.6.30 raeburn 10518: if ($errors) {
10519: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10520: '<ul>'.$errors.'</ul></p>';
10521: }
1.3 raeburn 10522: return $resulttext;
1.1 raeburn 10523: }
10524:
1.160.6.30 raeburn 10525: sub process_textbook_image {
1.160.6.46 raeburn 10526: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 10527: my $filename = $env{'form.'.$caller.'.filename'};
10528: my ($error,$url);
10529: my ($width,$height) = (50,50);
10530: if ($configuserok eq 'ok') {
10531: if ($switchserver) {
10532: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10533: $switchserver);
10534: } elsif ($author_ok eq 'ok') {
10535: my ($result,$imageurl) =
10536: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 10537: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 10538: if ($result eq 'ok') {
10539: $url = $imageurl;
10540: } else {
10541: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10542: }
10543: } else {
10544: $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);
10545: }
10546: } else {
10547: $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);
10548: }
10549: return ($url,$error);
10550: }
10551:
1.160.6.102.2 1(raebur 10552:0): sub modify_ltitools {
10553:0): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10554:0): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10555:0): my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
10556:0): my $confname = $dom.'-domainconfig';
10557:0): my $servadm = $r->dir_config('lonAdmEMail');
10558:0): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10559:0): my (%posslti,%possfield);
10560:0): my @courseroles = ('cc','in','ta','ep','st');
10561:0): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10562:0): map { $posslti{$_} = 1; } @ltiroles;
10563:0): my @allfields = ('fullname','firstname','lastname','email','user','roles');
10564:0): map { $possfield{$_} = 1; } @allfields;
10565:0): my %lt = <itools_names();
10566:0): if ($env{'form.ltitools_add'}) {
10567:0): my $title = $env{'form.ltitools_add_title'};
10568:0): $title =~ s/(`)/'/g;
10569:0): ($newid,my $error) = &get_ltitools_id($dom,$title);
10570:0): if ($newid) {
10571:0): my $position = $env{'form.ltitools_add_pos'};
10572:0): $position =~ s/\D+//g;
10573:0): if ($position ne '') {
10574:0): $allpos[$position] = $newid;
10575:0): }
10576:0): $changes{$newid} = 1;
5(raebur 10577:0): foreach my $item ('title','url','key','secret','lifetime') {
1(raebur 10578:0): $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
5(raebur 10579:0): if ($item eq 'lifetime') {
10580:0): $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
10581:0): }
1(raebur 10582:0): if ($env{'form.ltitools_add_'.$item}) {
10583:0): if (($item eq 'key') || ($item eq 'secret')) {
10584:0): $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10585:0): } else {
10586:0): $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10587:0): }
10588:0): }
10589:0): }
10590:0): if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10591:0): $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10592:0): }
10593:0): if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10594:0): $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10595:0): }
5(raebur 10596:0): if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
10597:0): $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
10598:0): } else {
10599:0): $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
10600:0): }
1(raebur 10601:0): foreach my $item ('width','height','linktext','explanation') {
10602:0): $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10603:0): $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
10604:0): if (($item eq 'width') || ($item eq 'height')) {
10605:0): if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10606:0): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10607:0): }
10608:0): } else {
10609:0): if ($env{'form.ltitools_add_'.$item} ne '') {
10610:0): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10611:0): }
10612:0): }
10613:0): }
10614:0): if ($env{'form.ltitools_add_target'} eq 'window') {
10615:0): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
10616:0): } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10617:0): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
10618:0): } else {
10619:0): $confhash{$newid}{'display'}{'target'} = 'iframe';
10620:0): }
10621:0): if ($env{'form.ltitools_add_image.filename'} ne '') {
10622:0): my ($imageurl,$error) =
10623:0): &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
10624:0): $configuserok,$switchserver,$author_ok);
10625:0): if ($imageurl) {
10626:0): $confhash{$newid}{'image'} = $imageurl;
10627:0): }
10628:0): if ($error) {
10629:0): &Apache::lonnet::logthis($error);
10630:0): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10631:0): }
10632:0): }
10633:0): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
10634:0): foreach my $field (@fields) {
10635:0): if ($possfield{$field}) {
10636:0): if ($field eq 'roles') {
10637:0): foreach my $role (@courseroles) {
10638:0): my $choice = $env{'form.ltitools_add_roles_'.$role};
10639:0): if (($choice ne '') && ($posslti{$choice})) {
10640:0): $confhash{$newid}{'roles'}{$role} = $choice;
10641:0): if ($role eq 'cc') {
10642:0): $confhash{$newid}{'roles'}{'co'} = $choice;
10643:0): }
10644:0): }
10645:0): }
10646:0): } else {
10647:0): $confhash{$newid}{'fields'}{$field} = 1;
10648:0): }
10649:0): }
10650:0): }
5(raebur 10651:0): if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
10652:0): if ($confhash{$newid}{'fields'}{'user'}) {
10653:0): if ($env{'form.ltitools_userincdom_add'}) {
10654:0): $confhash{$newid}{'incdom'} = 1;
10655:0): }
10656:0): }
10657:0): }
1(raebur 10658:0): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
10659:0): foreach my $item (@courseconfig) {
10660:0): $confhash{$newid}{'crsconf'}{$item} = 1;
10661:0): }
10662:0): if ($env{'form.ltitools_add_custom'}) {
10663:0): my $name = $env{'form.ltitools_add_custom_name'};
10664:0): my $value = $env{'form.ltitools_add_custom_value'};
10665:0): $value =~ s/(`)/'/g;
10666:0): $name =~ s/(`)/'/g;
10667:0): $confhash{$newid}{'custom'}{$name} = $value;
10668:0): }
10669:0): } else {
10670:0): my $error = &mt('Failed to acquire unique ID for new external tool');
10671:0): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10672:0): }
10673:0): }
10674:0): if (ref($domconfig{$action}) eq 'HASH') {
10675:0): my %deletions;
10676:0): my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
10677:0): if (@todelete) {
10678:0): map { $deletions{$_} = 1; } @todelete;
10679:0): }
10680:0): my %customadds;
10681:0): my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
10682:0): if (@newcustom) {
10683:0): map { $customadds{$_} = 1; } @newcustom;
10684:0): }
10685:0): my %imgdeletions;
10686:0): my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
10687:0): if (@todeleteimages) {
10688:0): map { $imgdeletions{$_} = 1; } @todeleteimages;
10689:0): }
10690:0): my $maxnum = $env{'form.ltitools_maxnum'};
10691:0): for (my $i=0; $i<=$maxnum; $i++) {
10692:0): my $itemid = $env{'form.ltitools_id_'.$i};
10693:0): $itemid =~ s/\D+//g;
10694:0): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10695:0): if ($deletions{$itemid}) {
10696:0): if ($domconfig{$action}{$itemid}{'image'}) {
10697:0): #FIXME need to obsolete item in RES space
10698:0): }
10699:0): $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
10700:0): next;
10701:0): } else {
10702:0): my $newpos = $env{'form.ltitools_'.$itemid};
10703:0): $newpos =~ s/\D+//g;
5(raebur 10704:0): foreach my $item ('title','url','lifetime') {
1(raebur 10705:0): $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10706:0): if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
10707:0): $changes{$itemid} = 1;
10708:0): }
10709:0): }
10710:0): foreach my $item ('key','secret') {
10711:0): $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10712:0): if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
10713:0): $changes{$itemid} = 1;
10714:0): }
10715:0): }
10716:0): if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
10717:0): $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
10718:0): }
10719:0): if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
10720:0): $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
10721:0): }
5(raebur 10722:0): if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
10723:0): $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
10724:0): } else {
10725:0): $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
10726:0): }
10727:0): if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
10728:0): if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
10729:0): $changes{$itemid} = 1;
10730:0): }
10731:0): } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
10732:0): $changes{$itemid} = 1;
10733:0): }
1(raebur 10734:0): foreach my $size ('width','height') {
10735:0): $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
10736:0): $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
10737:0): if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
10738:0): $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
10739:0): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10740:0): if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
10741:0): $changes{$itemid} = 1;
10742:0): }
10743:0): } else {
10744:0): $changes{$itemid} = 1;
10745:0): }
10746:0): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10747:0): if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
10748:0): $changes{$itemid} = 1;
10749:0): }
10750:0): }
10751:0): }
10752:0): foreach my $item ('linktext','explanation') {
10753:0): $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
10754:0): $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
10755:0): if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
10756:0): $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10757:0): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10758:0): if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
10759:0): $changes{$itemid} = 1;
10760:0): }
10761:0): } else {
10762:0): $changes{$itemid} = 1;
10763:0): }
10764:0): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10765:0): if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
10766:0): $changes{$itemid} = 1;
10767:0): }
10768:0): }
10769:0): }
10770:0): if ($env{'form.ltitools_target_'.$i} eq 'window') {
10771:0): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
10772:0): } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
10773:0): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
10774:0): } else {
10775:0): $confhash{$itemid}{'display'}{'target'} = 'iframe';
10776:0): }
10777:0): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10778:0): if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
10779:0): $changes{$itemid} = 1;
10780:0): }
10781:0): } else {
10782:0): $changes{$itemid} = 1;
10783:0): }
10784:0): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
5(raebur 10785:0): foreach my $item ('label','title','target','linktext','explanation','append') {
1(raebur 10786:0): if (grep(/^\Q$item\E$/,@courseconfig)) {
10787:0): $confhash{$itemid}{'crsconf'}{$item} = 1;
10788:0): if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
10789:0): if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
10790:0): $changes{$itemid} = 1;
10791:0): }
10792:0): } else {
10793:0): $changes{$itemid} = 1;
10794:0): }
10795:0): }
10796:0): }
10797:0): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
10798:0): foreach my $field (@fields) {
10799:0): if ($possfield{$field}) {
10800:0): if ($field eq 'roles') {
10801:0): foreach my $role (@courseroles) {
10802:0): my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
10803:0): if (($choice ne '') && ($posslti{$choice})) {
10804:0): $confhash{$itemid}{'roles'}{$role} = $choice;
10805:0): if ($role eq 'cc') {
10806:0): $confhash{$itemid}{'roles'}{'co'} = $choice;
10807:0): }
10808:0): }
10809:0): if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
10810:0): if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
10811:0): $changes{$itemid} = 1;
10812:0): }
10813:0): } elsif ($confhash{$itemid}{'roles'}{$role}) {
10814:0): $changes{$itemid} = 1;
10815:0): }
10816:0): }
10817:0): } else {
10818:0): $confhash{$itemid}{'fields'}{$field} = 1;
10819:0): if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
10820:0): if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
10821:0): $changes{$itemid} = 1;
10822:0): }
10823:0): } else {
10824:0): $changes{$itemid} = 1;
10825:0): }
10826:0): }
10827:0): }
10828:0): }
5(raebur 10829:0): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
10830:0): if ($confhash{$itemid}{'fields'}{'user'}) {
10831:0): if ($env{'form.ltitools_userincdom_'.$i}) {
10832:0): $confhash{$itemid}{'incdom'} = 1;
10833:0): }
10834:0): if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
10835:0): $changes{$itemid} = 1;
10836:0): }
10837:0): }
10838:0): }
1(raebur 10839:0): $allpos[$newpos] = $itemid;
10840:0): }
10841:0): if ($imgdeletions{$itemid}) {
10842:0): $changes{$itemid} = 1;
10843:0): #FIXME need to obsolete item in RES space
10844:0): } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
10845:0): my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
10846:0): $itemid,$configuserok,$switchserver,
10847:0): $author_ok);
10848:0): if ($imgurl) {
10849:0): $confhash{$itemid}{'image'} = $imgurl;
10850:0): $changes{$itemid} = 1;
10851:0): }
10852:0): if ($error) {
10853:0): &Apache::lonnet::logthis($error);
10854:0): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10855:0): }
10856:0): } elsif ($domconfig{$action}{$itemid}{'image'}) {
10857:0): $confhash{$itemid}{'image'} =
10858:0): $domconfig{$action}{$itemid}{'image'};
10859:0): }
10860:0): if ($customadds{$i}) {
10861:0): my $name = $env{'form.ltitools_custom_name_'.$i};
10862:0): $name =~ s/(`)/'/g;
10863:0): $name =~ s/^\s+//;
10864:0): $name =~ s/\s+$//;
10865:0): my $value = $env{'form.ltitools_custom_value_'.$i};
10866:0): $value =~ s/(`)/'/g;
10867:0): $value =~ s/^\s+//;
10868:0): $value =~ s/\s+$//;
10869:0): if ($name ne '') {
10870:0): $confhash{$itemid}{'custom'}{$name} = $value;
10871:0): $changes{$itemid} = 1;
10872:0): }
10873:0): }
10874:0): my %customdels;
10875:0): my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
10876:0): if (@customdeletions) {
10877:0): $changes{$itemid} = 1;
10878:0): }
10879:0): map { $customdels{$_} = 1; } @customdeletions;
10880:0): if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
10881:0): foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
10882:0): unless ($customdels{$key}) {
10883:0): if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
10884:0): $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
10885:0): }
10886:0): if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
10887:0): $changes{$itemid} = 1;
10888:0): }
10889:0): }
10890:0): }
10891:0): }
10892:0): unless ($changes{$itemid}) {
10893:0): foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
10894:0): if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
10895:0): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
10896:0): foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
10897:0): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
10898:0): $changes{$itemid} = 1;
10899:0): last;
10900:0): }
10901:0): }
10902:0): } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
10903:0): $changes{$itemid} = 1;
10904:0): }
10905:0): }
10906:0): last if ($changes{$itemid});
10907:0): }
10908:0): }
10909:0): }
10910:0): }
10911:0): }
10912:0): if (@allpos > 0) {
10913:0): my $idx = 0;
10914:0): foreach my $itemid (@allpos) {
10915:0): if ($itemid ne '') {
10916:0): $confhash{$itemid}{'order'} = $idx;
10917:0): if (ref($domconfig{$action}) eq 'HASH') {
10918:0): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10919:0): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
10920:0): $changes{$itemid} = 1;
10921:0): }
10922:0): }
10923:0): }
10924:0): $idx ++;
10925:0): }
10926:0): }
10927:0): }
10928:0): my %ltitoolshash = (
10929:0): $action => { %confhash }
10930:0): );
10931:0): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
10932:0): $dom);
10933:0): if ($putresult eq 'ok') {
10934:0): my %ltienchash = (
10935:0): $action => { %encconfig }
10936:0): );
10937:0): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
10938:0): if (keys(%changes) > 0) {
10939:0): my $cachetime = 24*60*60;
10940:0): my %ltiall = %confhash;
10941:0): foreach my $id (keys(%ltiall)) {
10942:0): if (ref($encconfig{$id}) eq 'HASH') {
10943:0): foreach my $item ('key','secret') {
10944:0): $ltiall{$id}{$item} = $encconfig{$id}{$item};
10945:0): }
10946:0): }
10947:0): }
10948:0): &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
10949:0): if (ref($lastactref) eq 'HASH') {
10950:0): $lastactref->{'ltitools'} = 1;
10951:0): }
10952:0): $resulttext = &mt('Changes made:').'<ul>';
10953:0): my %bynum;
10954:0): foreach my $itemid (sort(keys(%changes))) {
10955:0): my $position = $confhash{$itemid}{'order'};
10956:0): $bynum{$position} = $itemid;
10957:0): }
10958:0): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
10959:0): my $itemid = $bynum{$pos};
10960:0): if (ref($confhash{$itemid}) ne 'HASH') {
10961:0): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
10962:0): } else {
10963:0): $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
10964:0): if ($confhash{$itemid}{'image'}) {
10965:0): $resulttext .= ' '.
10966:0): '<img src="'.$confhash{$itemid}{'image'}.'"'.
10967:0): ' alt="'.&mt('Tool Provider icon').'" />';
10968:0): }
10969:0): $resulttext .= '</li><ul>';
10970:0): my $position = $pos + 1;
10971:0): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
5(raebur 10972:0): foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1(raebur 10973:0): if ($confhash{$itemid}{$item} ne '') {
10974:0): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
10975:0): }
10976:0): }
10977:0): if ($encconfig{$itemid}{'key'} ne '') {
10978:0): $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
10979:0): }
10980:0): if ($encconfig{$itemid}{'secret'} ne '') {
10981:0): $resulttext .= '<li>'.$lt{'secret'}.': ';
10982:0): my $num = length($encconfig{$itemid}{'secret'});
10983:0): $resulttext .= ('*'x$num).'</li>';
10984:0): }
10985:0): $resulttext .= '<li>'.&mt('Configurable in course:');
5(raebur 10986:0): my @possconfig = ('label','title','target','linktext','explanation','append');
1(raebur 10987:0): my $numconfig = 0;
10988:0): if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
10989:0): foreach my $item (@possconfig) {
10990:0): if ($confhash{$itemid}{'crsconf'}{$item}) {
10991:0): $numconfig ++;
10992:0): $resulttext .= ' "'.$lt{'crs'.$item}.'"';
10993:0): }
10994:0): }
10995:0): }
10996:0): if (!$numconfig) {
10997:0): $resulttext .= &mt('None');
10998:0): }
10999:0): $resulttext .= '</li>';
11000:0): if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11001:0): my $displaylist;
11002:0): if ($confhash{$itemid}{'display'}{'target'}) {
11003:0): $displaylist = &mt('Display target').': '.
11004:0): $confhash{$itemid}{'display'}{'target'}.',';
11005:0): }
11006:0): foreach my $size ('width','height') {
11007:0): if ($confhash{$itemid}{'display'}{$size}) {
11008:0): $displaylist .= (' 'x2).$lt{$size}.': '.
11009:0): $confhash{$itemid}{'display'}{$size}.',';
11010:0): }
11011:0): }
11012:0): if ($displaylist) {
11013:0): $displaylist =~ s/,$//;
11014:0): $resulttext .= '<li>'.$displaylist.'</li>';
11015:0): }
11016:0): foreach my $item ('linktext','explanation') {
11017:0): if ($confhash{$itemid}{'display'}{$item}) {
11018:0): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11019:0): }
11020:0): }
11021:0): }
11022:0): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11023:0): my $fieldlist;
11024:0): foreach my $field (@allfields) {
11025:0): if ($confhash{$itemid}{'fields'}{$field}) {
11026:0): $fieldlist .= (' 'x2).$lt{$field}.',';
11027:0): }
11028:0): }
11029:0): if ($fieldlist) {
11030:0): $fieldlist =~ s/,$//;
5(raebur 11031:0): if ($confhash{$itemid}{'fields'}{'user'}) {
11032:0): if ($confhash{$itemid}{'incdom'}) {
11033:0): $fieldlist .= ' ('.&mt('username:domain').')';
11034:0): } else {
11035:0): $fieldlist .= ' ('.&mt('username').')';
11036:0): }
11037:0): }
1(raebur 11038:0): $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11039:0): }
11040:0): }
11041:0): if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11042:0): my $rolemaps;
11043:0): foreach my $role (@courseroles) {
11044:0): if ($confhash{$itemid}{'roles'}{$role}) {
11045:0): $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11046:0): $confhash{$itemid}{'roles'}{$role}.',';
11047:0): }
11048:0): }
11049:0): if ($rolemaps) {
11050:0): $rolemaps =~ s/,$//;
11051:0): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11052:0): }
11053:0): }
11054:0): if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11055:0): my $customlist;
11056:0): if (keys(%{$confhash{$itemid}{'custom'}})) {
11057:0): foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11058:0): $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11059:0): }
11060:0): }
11061:0): if ($customlist) {
5(raebur 11062:0): $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1(raebur 11063:0): }
11064:0): }
11065:0): $resulttext .= '</ul></li>';
11066:0): }
11067:0): }
11068:0): $resulttext .= '</ul>';
11069:0): } else {
11070:0): $resulttext = &mt('No changes made.');
11071:0): }
11072:0): } else {
11073:0): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11074:0): }
11075:0): if ($errors) {
11076:0): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11077:0): $errors.'</ul>';
11078:0): }
11079:0): return $resulttext;
11080:0): }
11081:0):
11082:0): sub process_ltitools_image {
11083:0): my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11084:0): my $filename = $env{'form.'.$caller.'.filename'};
11085:0): my ($error,$url);
11086:0): my ($width,$height) = (21,21);
11087:0): if ($configuserok eq 'ok') {
11088:0): if ($switchserver) {
11089:0): $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11090:0): $switchserver);
11091:0): } elsif ($author_ok eq 'ok') {
11092:0): my ($result,$imageurl,$madethumb) =
11093:0): &publishlogo($r,'upload',$caller,$dom,$confname,
11094:0): "ltitools/$itemid/icon",$width,$height);
11095:0): if ($result eq 'ok') {
11096:0): if ($madethumb) {
11097:0): my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11098:0): my $imagethumb = "$path/tn-".$imagefile;
11099:0): $url = $imagethumb;
11100:0): } else {
11101:0): $url = $imageurl;
11102:0): }
11103:0): } else {
11104:0): $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11105:0): }
11106:0): } else {
11107: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);
11108:0): }
11109:0): } else {
11110: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);
11111:0): }
11112:0): return ($url,$error);
11113:0): }
11114:0):
11115:0): sub get_ltitools_id {
11116:0): my ($cdom,$title) = @_;
11117:0): # get lock on ltitools db
11118:0): my $lockhash = {
11119:0): lock => $env{'user.name'}.
11120:0): ':'.$env{'user.domain'},
11121:0): };
11122:0): my $tries = 0;
11123:0): my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11124:0): my ($id,$error);
11125:0):
11126:0): while (($gotlock ne 'ok') && ($tries<10)) {
11127:0): $tries ++;
11128:0): sleep (0.1);
11129:0): $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11130:0): }
11131:0): if ($gotlock eq 'ok') {
11132:0): my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11133:0): if ($currids{'lock'}) {
11134:0): delete($currids{'lock'});
11135:0): if (keys(%currids)) {
11136:0): my @curr = sort { $a <=> $b } keys(%currids);
11137:0): if ($curr[-1] =~ /^\d+$/) {
11138:0): $id = 1 + $curr[-1];
11139:0): }
11140:0): } else {
11141:0): $id = 1;
11142:0): }
11143:0): if ($id) {
11144:0): unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11145:0): $error = 'nostore';
11146:0): }
11147:0): } else {
11148:0): $error = 'nonumber';
11149:0): }
11150:0): }
11151:0): my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11152:0): } else {
11153:0): $error = 'nolock';
11154:0): }
11155:0): return ($id,$error);
11156:0): }
11157:0):
1.3 raeburn 11158: sub modify_autoenroll {
1.160.6.24 raeburn 11159: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 11160: my ($resulttext,%changes);
11161: my %currautoenroll;
11162: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
11163: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
11164: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
11165: }
11166: }
11167: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
11168: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 11169: sender => 'Sender for notification messages',
1.160.6.68 raeburn 11170: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
11171: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 11172: my @offon = ('off','on');
1.17 raeburn 11173: my $sender_uname = $env{'form.sender_uname'};
11174: my $sender_domain = $env{'form.sender_domain'};
11175: if ($sender_domain eq '') {
11176: $sender_uname = '';
11177: } elsif ($sender_uname eq '') {
11178: $sender_domain = '';
11179: }
1.129 raeburn 11180: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 11181: my $failsafe = $env{'form.autoenroll_failsafe'};
11182: $failsafe =~ s{^\s+|\s+$}{}g;
11183: if ($failsafe =~ /\D/) {
11184: undef($failsafe);
11185: }
1.1 raeburn 11186: my %autoenrollhash = (
1.129 raeburn 11187: autoenroll => { 'run' => $env{'form.autoenroll_run'},
11188: 'sender_uname' => $sender_uname,
11189: 'sender_domain' => $sender_domain,
11190: 'co-owners' => $coowners,
1.160.6.68 raeburn 11191: 'autofailsafe' => $failsafe,
1.1 raeburn 11192: }
11193: );
1.4 raeburn 11194: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
11195: $dom);
1.1 raeburn 11196: if ($putresult eq 'ok') {
11197: if (exists($currautoenroll{'run'})) {
11198: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
11199: $changes{'run'} = 1;
11200: }
11201: } elsif ($autorun) {
11202: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 11203: $changes{'run'} = 1;
1.1 raeburn 11204: }
11205: }
1.17 raeburn 11206: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 11207: $changes{'sender'} = 1;
11208: }
1.17 raeburn 11209: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 11210: $changes{'sender'} = 1;
11211: }
1.129 raeburn 11212: if ($currautoenroll{'co-owners'} ne '') {
11213: if ($currautoenroll{'co-owners'} ne $coowners) {
11214: $changes{'coowners'} = 1;
11215: }
11216: } elsif ($coowners) {
11217: $changes{'coowners'} = 1;
1.160.6.68 raeburn 11218: }
11219: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
11220: $changes{'autofailsafe'} = 1;
11221: }
1.1 raeburn 11222: if (keys(%changes) > 0) {
11223: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 11224: if ($changes{'run'}) {
1.1 raeburn 11225: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
11226: }
11227: if ($changes{'sender'}) {
1.17 raeburn 11228: if ($sender_uname eq '' || $sender_domain eq '') {
11229: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
11230: } else {
11231: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
11232: }
1.1 raeburn 11233: }
1.129 raeburn 11234: if ($changes{'coowners'}) {
11235: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
11236: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 11237: if (ref($lastactref) eq 'HASH') {
11238: $lastactref->{'domainconfig'} = 1;
11239: }
1.129 raeburn 11240: }
1.160.6.68 raeburn 11241: if ($changes{'autofailsafe'}) {
11242: if ($failsafe ne '') {
1.160.6.82 raeburn 11243: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 11244: } else {
1.160.6.82 raeburn 11245: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 11246: }
11247: &Apache::lonnet::get_domain_defaults($dom,1);
11248: if (ref($lastactref) eq 'HASH') {
11249: $lastactref->{'domdefaults'} = 1;
11250: }
11251: }
1.1 raeburn 11252: $resulttext .= '</ul>';
11253: } else {
11254: $resulttext = &mt('No changes made to auto-enrollment settings');
11255: }
11256: } else {
1.11 albertel 11257: $resulttext = '<span class="LC_error">'.
11258: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11259: }
1.3 raeburn 11260: return $resulttext;
1.1 raeburn 11261: }
11262:
11263: sub modify_autoupdate {
1.3 raeburn 11264: my ($dom,%domconfig) = @_;
1.1 raeburn 11265: my ($resulttext,%currautoupdate,%fields,%changes);
11266: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
11267: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
11268: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
11269: }
11270: }
11271: my @offon = ('off','on');
11272: my %title = &Apache::lonlocal::texthash (
11273: run => 'Auto-update:',
11274: classlists => 'Updates to user information in classlists?'
11275: );
1.44 raeburn 11276: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11277: my %fieldtitles = &Apache::lonlocal::texthash (
11278: id => 'Student/Employee ID',
1.20 raeburn 11279: permanentemail => 'E-mail address',
1.1 raeburn 11280: lastname => 'Last Name',
11281: firstname => 'First Name',
11282: middlename => 'Middle Name',
1.132 raeburn 11283: generation => 'Generation',
1.1 raeburn 11284: );
1.142 raeburn 11285: $othertitle = &mt('All users');
1.1 raeburn 11286: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 11287: $othertitle = &mt('Other users');
1.1 raeburn 11288: }
11289: foreach my $key (keys(%env)) {
11290: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 11291: my ($usertype,$item) = ($1,$2);
11292: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
11293: if ($usertype eq 'default') {
11294: push(@{$fields{$1}},$2);
11295: } elsif (ref($types) eq 'ARRAY') {
11296: if (grep(/^\Q$usertype\E$/,@{$types})) {
11297: push(@{$fields{$1}},$2);
11298: }
11299: }
11300: }
1.1 raeburn 11301: }
11302: }
1.131 raeburn 11303: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
11304: @lockablenames = sort(@lockablenames);
11305: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
11306: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11307: if (@changed) {
11308: $changes{'lockablenames'} = 1;
11309: }
11310: } else {
11311: if (@lockablenames) {
11312: $changes{'lockablenames'} = 1;
11313: }
11314: }
1.1 raeburn 11315: my %updatehash = (
11316: autoupdate => { run => $env{'form.autoupdate_run'},
11317: classlists => $env{'form.classlists'},
11318: fields => {%fields},
1.131 raeburn 11319: lockablenames => \@lockablenames,
1.1 raeburn 11320: }
11321: );
11322: foreach my $key (keys(%currautoupdate)) {
11323: if (($key eq 'run') || ($key eq 'classlists')) {
11324: if (exists($updatehash{autoupdate}{$key})) {
11325: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
11326: $changes{$key} = 1;
11327: }
11328: }
11329: } elsif ($key eq 'fields') {
11330: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 11331: foreach my $item (@{$types},'default') {
1.1 raeburn 11332: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
11333: my $change = 0;
11334: foreach my $type (@{$currautoupdate{$key}{$item}}) {
11335: if (!exists($fields{$item})) {
11336: $change = 1;
1.132 raeburn 11337: last;
1.1 raeburn 11338: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 11339: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 11340: $change = 1;
1.132 raeburn 11341: last;
1.1 raeburn 11342: }
11343: }
11344: }
11345: if ($change) {
11346: push(@{$changes{$key}},$item);
11347: }
1.26 raeburn 11348: }
1.1 raeburn 11349: }
11350: }
1.131 raeburn 11351: } elsif ($key eq 'lockablenames') {
11352: if (ref($currautoupdate{$key}) eq 'ARRAY') {
11353: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11354: if (@changed) {
11355: $changes{'lockablenames'} = 1;
11356: }
11357: } else {
11358: if (@lockablenames) {
11359: $changes{'lockablenames'} = 1;
11360: }
11361: }
11362: }
11363: }
11364: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
11365: if (@lockablenames) {
11366: $changes{'lockablenames'} = 1;
1.1 raeburn 11367: }
11368: }
1.26 raeburn 11369: foreach my $item (@{$types},'default') {
11370: if (defined($fields{$item})) {
11371: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 11372: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
11373: my $change = 0;
11374: if (ref($fields{$item}) eq 'ARRAY') {
11375: foreach my $type (@{$fields{$item}}) {
11376: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
11377: $change = 1;
11378: last;
11379: }
11380: }
11381: }
11382: if ($change) {
11383: push(@{$changes{'fields'}},$item);
11384: }
11385: } else {
1.26 raeburn 11386: push(@{$changes{'fields'}},$item);
11387: }
11388: } else {
11389: push(@{$changes{'fields'}},$item);
1.1 raeburn 11390: }
11391: }
11392: }
11393: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
11394: $dom);
11395: if ($putresult eq 'ok') {
11396: if (keys(%changes) > 0) {
11397: $resulttext = &mt('Changes made:').'<ul>';
11398: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 11399: if ($key eq 'lockablenames') {
11400: $resulttext .= '<li>';
11401: if (@lockablenames) {
11402: $usertypes->{'default'} = $othertitle;
11403: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
11404: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
11405: } else {
11406: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
11407: }
11408: $resulttext .= '</li>';
11409: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 11410: foreach my $item (@{$changes{$key}}) {
11411: my @newvalues;
11412: foreach my $type (@{$fields{$item}}) {
11413: push(@newvalues,$fieldtitles{$type});
11414: }
1.3 raeburn 11415: my $newvaluestr;
11416: if (@newvalues > 0) {
11417: $newvaluestr = join(', ',@newvalues);
11418: } else {
11419: $newvaluestr = &mt('none');
1.6 raeburn 11420: }
1.1 raeburn 11421: if ($item eq 'default') {
1.26 raeburn 11422: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 11423: } else {
1.26 raeburn 11424: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 11425: }
11426: }
11427: } else {
11428: my $newvalue;
11429: if ($key eq 'run') {
11430: $newvalue = $offon[$env{'form.autoupdate_run'}];
11431: } else {
11432: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 11433: }
1.1 raeburn 11434: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
11435: }
11436: }
11437: $resulttext .= '</ul>';
11438: } else {
1.3 raeburn 11439: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 11440: }
11441: } else {
1.11 albertel 11442: $resulttext = '<span class="LC_error">'.
11443: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11444: }
1.3 raeburn 11445: return $resulttext;
1.1 raeburn 11446: }
11447:
1.125 raeburn 11448: sub modify_autocreate {
11449: my ($dom,%domconfig) = @_;
11450: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
11451: if (ref($domconfig{'autocreate'}) eq 'HASH') {
11452: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
11453: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
11454: }
11455: }
11456: my %title= ( xml => 'Auto-creation of courses in XML course description files',
11457: req => 'Auto-creation of validated requests for official courses',
11458: xmldc => 'Identity of course creator of courses from XML files',
11459: );
11460: my @types = ('xml','req');
11461: foreach my $item (@types) {
11462: $newvals{$item} = $env{'form.autocreate_'.$item};
11463: $newvals{$item} =~ s/\D//g;
11464: $newvals{$item} = 0 if ($newvals{$item} eq '');
11465: }
11466: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 11467: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 11468: unless (exists($domcoords{$newvals{'xmldc'}})) {
11469: $newvals{'xmldc'} = '';
11470: }
11471: %autocreatehash = (
11472: autocreate => { xml => $newvals{'xml'},
11473: req => $newvals{'req'},
11474: }
11475: );
11476: if ($newvals{'xmldc'} ne '') {
11477: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
11478: }
11479: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
11480: $dom);
11481: if ($putresult eq 'ok') {
11482: my @items = @types;
11483: if ($newvals{'xml'}) {
11484: push(@items,'xmldc');
11485: }
11486: foreach my $item (@items) {
11487: if (exists($currautocreate{$item})) {
11488: if ($currautocreate{$item} ne $newvals{$item}) {
11489: $changes{$item} = 1;
11490: }
11491: } elsif ($newvals{$item}) {
11492: $changes{$item} = 1;
11493: }
11494: }
11495: if (keys(%changes) > 0) {
11496: my @offon = ('off','on');
11497: $resulttext = &mt('Changes made:').'<ul>';
11498: foreach my $item (@types) {
11499: if ($changes{$item}) {
11500: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 11501: $resulttext .= '<li>'.
11502: &mt("$title{$item} set to [_1]$newtxt [_2]",
11503: '<b>','</b>').
11504: '</li>';
1.125 raeburn 11505: }
11506: }
11507: if ($changes{'xmldc'}) {
11508: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
11509: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 11510: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 11511: }
11512: $resulttext .= '</ul>';
11513: } else {
11514: $resulttext = &mt('No changes made to auto-creation settings');
11515: }
11516: } else {
11517: $resulttext = '<span class="LC_error">'.
11518: &mt('An error occurred: [_1]',$putresult).'</span>';
11519: }
11520: return $resulttext;
11521: }
11522:
1.23 raeburn 11523: sub modify_directorysrch {
1.160.6.81 raeburn 11524: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 11525: my ($resulttext,%changes);
11526: my %currdirsrch;
11527: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
11528: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
11529: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
11530: }
11531: }
1.160.6.72 raeburn 11532: my %title = ( available => 'Institutional directory search available',
11533: localonly => 'Other domains can search institution',
11534: lcavailable => 'LON-CAPA directory search available',
11535: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 11536: searchby => 'Search types',
11537: searchtypes => 'Search latitude');
11538: my @offon = ('off','on');
1.24 raeburn 11539: my @otherdoms = ('Yes','No');
1.23 raeburn 11540:
1.25 raeburn 11541: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 11542: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
11543: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
11544:
1.44 raeburn 11545: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 11546: if (keys(%{$usertypes}) == 0) {
11547: @cansearch = ('default');
11548: } else {
11549: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
11550: foreach my $type (@{$currdirsrch{'cansearch'}}) {
11551: if (!grep(/^\Q$type\E$/,@cansearch)) {
11552: push(@{$changes{'cansearch'}},$type);
11553: }
1.23 raeburn 11554: }
1.26 raeburn 11555: foreach my $type (@cansearch) {
11556: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
11557: push(@{$changes{'cansearch'}},$type);
11558: }
1.23 raeburn 11559: }
1.26 raeburn 11560: } else {
11561: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 11562: }
11563: }
11564:
11565: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
11566: foreach my $by (@{$currdirsrch{'searchby'}}) {
11567: if (!grep(/^\Q$by\E$/,@searchby)) {
11568: push(@{$changes{'searchby'}},$by);
11569: }
11570: }
11571: foreach my $by (@searchby) {
11572: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
11573: push(@{$changes{'searchby'}},$by);
11574: }
11575: }
11576: } else {
11577: push(@{$changes{'searchby'}},@searchby);
11578: }
1.25 raeburn 11579:
11580: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
11581: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
11582: if (!grep(/^\Q$type\E$/,@searchtypes)) {
11583: push(@{$changes{'searchtypes'}},$type);
11584: }
11585: }
11586: foreach my $type (@searchtypes) {
11587: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
11588: push(@{$changes{'searchtypes'}},$type);
11589: }
11590: }
11591: } else {
11592: if (exists($currdirsrch{'searchtypes'})) {
11593: foreach my $type (@searchtypes) {
11594: if ($type ne $currdirsrch{'searchtypes'}) {
11595: push(@{$changes{'searchtypes'}},$type);
11596: }
11597: }
11598: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
11599: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
11600: }
11601: } else {
11602: push(@{$changes{'searchtypes'}},@searchtypes);
11603: }
11604: }
11605:
1.23 raeburn 11606: my %dirsrch_hash = (
11607: directorysrch => { available => $env{'form.dirsrch_available'},
11608: cansearch => \@cansearch,
1.160.6.72 raeburn 11609: localonly => $env{'form.dirsrch_instlocalonly'},
11610: lclocalonly => $env{'form.dirsrch_domlocalonly'},
11611: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 11612: searchby => \@searchby,
1.25 raeburn 11613: searchtypes => \@searchtypes,
1.23 raeburn 11614: }
11615: );
11616: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
11617: $dom);
11618: if ($putresult eq 'ok') {
11619: if (exists($currdirsrch{'available'})) {
11620: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
11621: $changes{'available'} = 1;
11622: }
11623: } else {
11624: if ($env{'form.dirsrch_available'} eq '1') {
11625: $changes{'available'} = 1;
11626: }
11627: }
1.160.6.72 raeburn 11628: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 11629: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
11630: $changes{'lcavailable'} = 1;
11631: }
1.24 raeburn 11632: } else {
1.160.6.72 raeburn 11633: if ($env{'form.dirsrch_lcavailable'} eq '1') {
11634: $changes{'lcavailable'} = 1;
11635: }
11636: }
11637: if (exists($currdirsrch{'localonly'})) {
11638: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 11639: $changes{'localonly'} = 1;
11640: }
1.160.6.72 raeburn 11641: } else {
11642: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
11643: $changes{'localonly'} = 1;
11644: }
11645: }
11646: if (exists($currdirsrch{'lclocalonly'})) {
11647: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
11648: $changes{'lclocalonly'} = 1;
11649: }
11650: } else {
11651: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
11652: $changes{'lclocalonly'} = 1;
11653: }
1.24 raeburn 11654: }
1.23 raeburn 11655: if (keys(%changes) > 0) {
11656: $resulttext = &mt('Changes made:').'<ul>';
11657: if ($changes{'available'}) {
11658: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
11659: }
1.160.6.72 raeburn 11660: if ($changes{'lcavailable'}) {
11661: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
11662: }
1.24 raeburn 11663: if ($changes{'localonly'}) {
1.160.6.72 raeburn 11664: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
11665: }
11666: if ($changes{'lclocalonly'}) {
11667: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 11668: }
1.23 raeburn 11669: if (ref($changes{'cansearch'}) eq 'ARRAY') {
11670: my $chgtext;
1.26 raeburn 11671: if (ref($usertypes) eq 'HASH') {
11672: if (keys(%{$usertypes}) > 0) {
11673: foreach my $type (@{$types}) {
11674: if (grep(/^\Q$type\E$/,@cansearch)) {
11675: $chgtext .= $usertypes->{$type}.'; ';
11676: }
11677: }
11678: if (grep(/^default$/,@cansearch)) {
11679: $chgtext .= $othertitle;
11680: } else {
11681: $chgtext =~ s/\; $//;
11682: }
1.160.6.13 raeburn 11683: $resulttext .=
11684: '<li>'.
11685: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
11686: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
11687: '</li>';
1.23 raeburn 11688: }
11689: }
11690: }
11691: if (ref($changes{'searchby'}) eq 'ARRAY') {
11692: my ($searchtitles,$titleorder) = &sorted_searchtitles();
11693: my $chgtext;
11694: foreach my $type (@{$titleorder}) {
11695: if (grep(/^\Q$type\E$/,@searchby)) {
11696: if (defined($searchtitles->{$type})) {
11697: $chgtext .= $searchtitles->{$type}.'; ';
11698: }
11699: }
11700: }
11701: $chgtext =~ s/\; $//;
11702: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
11703: }
1.25 raeburn 11704: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
11705: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
11706: my $chgtext;
11707: foreach my $type (@{$srchtypeorder}) {
11708: if (grep(/^\Q$type\E$/,@searchtypes)) {
11709: if (defined($srchtypes_desc->{$type})) {
11710: $chgtext .= $srchtypes_desc->{$type}.'; ';
11711: }
11712: }
11713: }
11714: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 11715: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 11716: }
11717: $resulttext .= '</ul>';
1.160.6.81 raeburn 11718: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
11719: if (ref($lastactref) eq 'HASH') {
11720: $lastactref->{'directorysrch'} = 1;
11721: }
1.23 raeburn 11722: } else {
1.160.6.72 raeburn 11723: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 11724: }
11725: } else {
11726: $resulttext = '<span class="LC_error">'.
1.27 raeburn 11727: &mt('An error occurred: [_1]',$putresult).'</span>';
11728: }
11729: return $resulttext;
11730: }
11731:
1.28 raeburn 11732: sub modify_contacts {
1.160.6.24 raeburn 11733: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 11734: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
11735: if (ref($domconfig{'contacts'}) eq 'HASH') {
11736: foreach my $key (keys(%{$domconfig{'contacts'}})) {
11737: $currsetting{$key} = $domconfig{'contacts'}{$key};
11738: }
11739: }
1.160.6.78 raeburn 11740: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 11741: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 11742: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 11743: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.102.2 7(raebur 11744:1): my @toggles = ('reporterrors','reportupdates','reportstatus');
11745:1): my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 11746: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 11747: foreach my $type (@mailings) {
11748: @{$newsetting{$type}} =
11749: &Apache::loncommon::get_env_multiple('form.'.$type);
11750: foreach my $item (@contacts) {
11751: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
11752: $contacts_hash{contacts}{$type}{$item} = 1;
11753: } else {
11754: $contacts_hash{contacts}{$type}{$item} = 0;
11755: }
1.160.6.78 raeburn 11756: }
1.28 raeburn 11757: $others{$type} = $env{'form.'.$type.'_others'};
11758: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 11759: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11760: $bcc{$type} = $env{'form.'.$type.'_bcc'};
11761: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 11762: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
11763: $includestr{$type} = $env{'form.'.$type.'_includestr'};
11764: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
11765: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
11766: }
1.134 raeburn 11767: }
1.28 raeburn 11768: }
11769: foreach my $item (@contacts) {
11770: $to{$item} = $env{'form.'.$item};
11771: $contacts_hash{'contacts'}{$item} = $to{$item};
11772: }
1.160.6.23 raeburn 11773: foreach my $item (@toggles) {
11774: if ($env{'form.'.$item} =~ /^(0|1)$/) {
11775: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
11776: }
11777: }
1.160.6.102.2 7(raebur 11778:1): my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
11779:1): foreach my $item (@lonstatus) {
11780:1): if ($item eq 'excluded') {
11781:1): my (%serverhomes,@excluded);
11782:1): map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
11783:1): my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
11784:1): if (@possexcluded) {
11785:1): foreach my $id (sort(@possexcluded)) {
11786:1): if ($serverhomes{$id}) {
11787:1): push(@excluded,$id);
11788:1): }
11789:1): }
11790:1): }
11791:1): if (@excluded) {
11792:1): $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
11793:1): }
11794:1): } elsif ($item eq 'weights') {
11795:1): foreach my $type ('E','W','N','U') {
11796:1): $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
11797:1): if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
11798:1): unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
11799:1): $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
11800:1): $env{'form.error'.$item.'_'.$type};
11801:1): }
11802:1): }
11803:1): }
11804:1): } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
11805:1): $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
11806:1): if ($env{'form.error'.$item} =~ /^\d+$/) {
11807:1): unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
11808:1): $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
11809:1): }
11810:1): }
11811:1): }
11812:1): }
1.160.6.78 raeburn 11813: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
11814: foreach my $field (@{$fields}) {
11815: if (ref($possoptions->{$field}) eq 'ARRAY') {
11816: my $value = $env{'form.helpform_'.$field};
11817: $value =~ s/^\s+|\s+$//g;
11818: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 11819: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 11820: if ($field eq 'screenshot') {
11821: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
11822: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 11823: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 11824: }
11825: }
11826: }
11827: }
11828: }
11829: }
1.160.6.101 raeburn 11830: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11831: my (@statuses,%usertypeshash,@overrides);
11832: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
11833: @statuses = @{$types};
11834: if (ref($usertypes) eq 'HASH') {
11835: %usertypeshash = %{$usertypes};
11836: }
11837: }
11838: if (@statuses) {
11839: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
11840: foreach my $type (@possoverrides) {
11841: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
11842: push(@overrides,$type);
11843: }
11844: }
11845: if (@overrides) {
11846: foreach my $type (@overrides) {
11847: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
11848: foreach my $item (@contacts) {
11849: if (grep(/^\Q$item\E$/,@standard)) {
11850: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
11851: $newsetting{'override_'.$type}{$item} = 1;
11852: } else {
11853: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
11854: $newsetting{'override_'.$type}{$item} = 0;
11855: }
11856: }
11857: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
11858: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
11859: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
11860: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
11861: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
11862: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
11863: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
11864: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
11865: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
11866: }
11867: }
11868: }
11869: }
1.28 raeburn 11870: if (keys(%currsetting) > 0) {
11871: foreach my $item (@contacts) {
11872: if ($to{$item} ne $currsetting{$item}) {
11873: $changes{$item} = 1;
11874: }
11875: }
11876: foreach my $type (@mailings) {
11877: foreach my $item (@contacts) {
11878: if (ref($currsetting{$type}) eq 'HASH') {
11879: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
11880: push(@{$changes{$type}},$item);
11881: }
11882: } else {
11883: push(@{$changes{$type}},@{$newsetting{$type}});
11884: }
11885: }
11886: if ($others{$type} ne $currsetting{$type}{'others'}) {
11887: push(@{$changes{$type}},'others');
11888: }
1.160.6.78 raeburn 11889: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11890: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
11891: push(@{$changes{$type}},'bcc');
11892: }
1.160.6.78 raeburn 11893: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
11894: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
11895: push(@{$changes{$type}},'include');
11896: }
11897: }
11898: }
11899: if (ref($fields) eq 'ARRAY') {
11900: if (ref($currsetting{'helpform'}) eq 'HASH') {
11901: foreach my $field (@{$fields}) {
11902: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
11903: push(@{$changes{'helpform'}},$field);
11904: }
11905: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11906: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
11907: push(@{$changes{'helpform'}},'maxsize');
11908: }
11909: }
11910: }
11911: } else {
11912: foreach my $field (@{$fields}) {
11913: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
11914: push(@{$changes{'helpform'}},$field);
11915: }
11916: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11917: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
11918: push(@{$changes{'helpform'}},'maxsize');
11919: }
11920: }
11921: }
1.134 raeburn 11922: }
1.28 raeburn 11923: }
1.160.6.101 raeburn 11924: if (@statuses) {
11925: if (ref($currsetting{'overrides'}) eq 'HASH') {
11926: foreach my $key (keys(%{$currsetting{'overrides'}})) {
11927: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
11928: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
11929: foreach my $item (@contacts,'bcc','others','include') {
11930: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
11931: push(@{$changes{'overrides'}},$key);
11932: last;
11933: }
11934: }
11935: } else {
11936: push(@{$changes{'overrides'}},$key);
11937: }
11938: }
11939: }
11940: foreach my $key (@overrides) {
11941: unless (exists($currsetting{'overrides'}{$key})) {
11942: push(@{$changes{'overrides'}},$key);
11943: }
11944: }
11945: } else {
11946: foreach my $key (@overrides) {
11947: push(@{$changes{'overrides'}},$key);
11948: }
11949: }
11950: }
1.160.6.102.2 7(raebur 11951:1): if (ref($currsetting{'lonstatus'}) eq 'HASH') {
11952:1): foreach my $key ('excluded','weights','threshold','sysmail') {
11953:1): if ($key eq 'excluded') {
11954:1): if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
11955:1): (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
11956:1): if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
11957:1): (@{$currsetting{'lonstatus'}{$key}})) {
11958:1): my @diffs =
11959:1): &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
11960:1): $currsetting{'lonstatus'}{$key});
11961:1): if (@diffs) {
11962:1): push(@{$changes{'lonstatus'}},$key);
11963:1): }
11964:1): } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
11965:1): push(@{$changes{'lonstatus'}},$key);
11966:1): }
11967:1): } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
11968:1): (@{$currsetting{'lonstatus'}{$key}})) {
11969:1): push(@{$changes{'lonstatus'}},$key);
11970:1): }
11971:1): } elsif ($key eq 'weights') {
11972:1): if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
11973:1): (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
11974:1): if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
11975:1): foreach my $type ('E','W','N','U') {
11976:1): unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
11977:1): $currsetting{'lonstatus'}{$key}{$type}) {
11978:1): push(@{$changes{'lonstatus'}},$key);
11979:1): last;
11980:1): }
11981:1): }
11982:1): } else {
11983:1): foreach my $type ('E','W','N','U') {
11984:1): if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
11985:1): push(@{$changes{'lonstatus'}},$key);
11986:1): last;
11987:1): }
11988:1): }
11989:1): }
11990:1): } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
11991:1): foreach my $type ('E','W','N','U') {
11992:1): if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
11993:1): push(@{$changes{'lonstatus'}},$key);
11994:1): last;
11995:1): }
11996:1): }
11997:1): }
11998:1): } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
11999:1): if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12000:1): if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12001:1): if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
12002:1): push(@{$changes{'lonstatus'}},$key);
12003:1): }
12004:1): } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
12005:1): push(@{$changes{'lonstatus'}},$key);
12006:1): }
12007:1): } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12008:1): push(@{$changes{'lonstatus'}},$key);
12009:1): }
12010:1): }
12011:1): }
12012:1): } else {
12013:1): if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12014:1): foreach my $key ('excluded','weights','threshold','sysmail') {
12015:1): if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12016:1): push(@{$changes{'lonstatus'}},$key);
12017:1): }
12018:1): }
12019:1): }
12020:1): }
1.28 raeburn 12021: } else {
12022: my %default;
12023: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12024: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12025: $default{'errormail'} = 'adminemail';
12026: $default{'packagesmail'} = 'adminemail';
12027: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 12028: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12029: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12030: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 12031: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 12032: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 12033: foreach my $item (@contacts) {
12034: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 12035: $changes{$item} = 1;
1.160.6.23 raeburn 12036: }
1.28 raeburn 12037: }
12038: foreach my $type (@mailings) {
12039: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12040: push(@{$changes{$type}},@{$newsetting{$type}});
12041: }
12042: if ($others{$type} ne '') {
12043: push(@{$changes{$type}},'others');
1.134 raeburn 12044: }
1.160.6.78 raeburn 12045: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12046: if ($bcc{$type} ne '') {
12047: push(@{$changes{$type}},'bcc');
12048: }
1.160.6.78 raeburn 12049: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12050: push(@{$changes{$type}},'include');
12051: }
12052: }
12053: }
12054: if (ref($fields) eq 'ARRAY') {
12055: foreach my $field (@{$fields}) {
12056: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12057: push(@{$changes{'helpform'}},$field);
12058: }
12059: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12060: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12061: push(@{$changes{'helpform'}},'maxsize');
12062: }
12063: }
1.134 raeburn 12064: }
1.28 raeburn 12065: }
1.160.6.102.2 7(raebur 12066:1): if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12067:1): foreach my $key ('excluded','weights','threshold','sysmail') {
12068:1): if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12069:1): push(@{$changes{'lonstatus'}},$key);
12070:1): }
12071:1): }
12072:1): }
1.28 raeburn 12073: }
1.160.6.23 raeburn 12074: foreach my $item (@toggles) {
12075: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12076: $changes{$item} = 1;
12077: } elsif ((!$env{'form.'.$item}) &&
12078: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12079: $changes{$item} = 1;
12080: }
12081: }
1.28 raeburn 12082: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12083: $dom);
12084: if ($putresult eq 'ok') {
12085: if (keys(%changes) > 0) {
1.160.6.24 raeburn 12086: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12087: if (ref($lastactref) eq 'HASH') {
12088: $lastactref->{'domainconfig'} = 1;
12089: }
1.28 raeburn 12090: my ($titles,$short_titles) = &contact_titles();
12091: $resulttext = &mt('Changes made:').'<ul>';
12092: foreach my $item (@contacts) {
12093: if ($changes{$item}) {
12094: $resulttext .= '<li>'.$titles->{$item}.
12095: &mt(' set to: ').
12096: '<span class="LC_cusr_emph">'.
12097: $to{$item}.'</span></li>';
12098: }
12099: }
12100: foreach my $type (@mailings) {
12101: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 12102: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
12103: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
12104: } else {
12105: $resulttext .= '<li>'.$titles->{$type}.': ';
12106: }
1.28 raeburn 12107: my @text;
12108: foreach my $item (@{$newsetting{$type}}) {
12109: push(@text,$short_titles->{$item});
12110: }
12111: if ($others{$type} ne '') {
12112: push(@text,$others{$type});
12113: }
1.160.6.78 raeburn 12114: if (@text) {
12115: $resulttext .= '<span class="LC_cusr_emph">'.
12116: join(', ',@text).'</span>';
12117: }
12118: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12119: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 12120: my $bcctext;
12121: if (@text) {
12122: $bcctext = ' '.&mt('with Bcc to');
12123: } else {
12124: $bcctext = '(Bcc)';
12125: }
12126: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12127: } elsif (!@text) {
12128: $resulttext .= &mt('No one');
1.134 raeburn 12129: }
1.160.6.78 raeburn 12130: if ($includestr{$type} ne '') {
12131: if ($includeloc{$type} eq 'b') {
12132: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12133: } elsif ($includeloc{$type} eq 's') {
12134: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12135: }
12136: }
12137: } elsif (!@text) {
12138: $resulttext .= &mt('No recipients');
1.134 raeburn 12139: }
12140: $resulttext .= '</li>';
1.28 raeburn 12141: }
12142: }
1.160.6.101 raeburn 12143: if (ref($changes{'overrides'}) eq 'ARRAY') {
12144: my @deletions;
12145: foreach my $type (@{$changes{'overrides'}}) {
12146: if ($usertypeshash{$type}) {
12147: if (grep(/^\Q$type\E/,@overrides)) {
12148: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12149: $usertypeshash{$type}).'<ul><li>';
12150: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12151: my @text;
12152: foreach my $item (@contacts) {
12153: if ($newsetting{'override_'.$type}{$item}) {
12154: push(@text,$short_titles->{$item});
12155: }
12156: }
12157: if ($newsetting{'override_'.$type}{'others'} ne '') {
12158: push(@text,$newsetting{'override_'.$type}{'others'});
12159: }
12160:
12161: if (@text) {
12162: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12163: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12164: }
12165: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12166: my $bcctext;
12167: if (@text) {
12168: $bcctext = ' '.&mt('with Bcc to');
12169: } else {
12170: $bcctext = '(Bcc)';
12171: }
12172: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12173: } elsif (!@text) {
12174: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12175: }
12176: $resulttext .= '</li>';
12177: if ($newsetting{'override_'.$type}{'include'} ne '') {
12178: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12179: if ($loc eq 'b') {
12180: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12181: } elsif ($loc eq 's') {
12182: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12183: }
12184: }
12185: }
12186: $resulttext .= '</li></ul></li>';
12187: } else {
12188: push(@deletions,$usertypeshash{$type});
12189: }
12190: }
12191: }
12192: if (@deletions) {
12193: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12194: join(', ',@deletions)).'</li>';
12195: }
12196: }
1.160.6.23 raeburn 12197: my @offon = ('off','on');
1.160.6.102.2 7(raebur 12198:1): my $corelink = &core_link_msu();
1.160.6.23 raeburn 12199: if ($changes{'reporterrors'}) {
12200: $resulttext .= '<li>'.
12201: &mt('E-mail error reports to [_1] set to "'.
12202: $offon[$env{'form.reporterrors'}].'".',
1.160.6.102.2 7(raebur 12203:1): $corelink).
1.160.6.23 raeburn 12204: '</li>';
12205: }
12206: if ($changes{'reportupdates'}) {
12207: $resulttext .= '<li>'.
12208: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12209: $offon[$env{'form.reportupdates'}].'".',
1.160.6.102.2 7(raebur 12210:1): $corelink).
1.160.6.23 raeburn 12211: '</li>';
12212: }
1.160.6.102.2 7(raebur 12213:1): if ($changes{'reportstatus'}) {
12214:1): $resulttext .= '<li>'.
12215:1): &mt('E-mail status if errors above threshold to [_1] set to "'.
12216:1): $offon[$env{'form.reportstatus'}].'".',
12217:1): $corelink).
12218:1): '</li>';
12219:1): }
12220:1): if (ref($changes{'lonstatus'}) eq 'ARRAY') {
12221:1): $resulttext .= '<li>'.
12222:1): &mt('Nightly status check e-mail settings').':<ul>';
12223:1): my (%defval,%use_def,%shown);
12224:1): $defval{'threshold'} = $lonstatus_defs->{'threshold'};
12225:1): $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
12226:1): $defval{'weights'} =
12227:1): join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
12228:1): $defval{'excluded'} = &mt('None');
12229:1): if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
12230:1): foreach my $item ('threshold','sysmail','weights','excluded') {
12231:1): if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
12232:1): if (($item eq 'threshold') || ($item eq 'sysmail')) {
12233:1): $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
12234:1): } elsif ($item eq 'weights') {
12235:1): if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
12236:1): foreach my $type ('E','W','N','U') {
12237:1): $shown{$item} .= $lonstatus_names->{$type}.'=';
12238:1): if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
12239:1): $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
12240:1): } else {
12241:1): $shown{$item} .= $lonstatus_defs->{$type};
12242:1): }
12243:1): $shown{$item} .= ', ';
12244:1): }
12245:1): $shown{$item} =~ s/, $//;
12246:1): } else {
12247:1): $shown{$item} = $defval{$item};
12248:1): }
12249:1): } elsif ($item eq 'excluded') {
12250:1): if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
12251:1): $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
12252:1): } else {
12253:1): $shown{$item} = $defval{$item};
12254:1): }
12255:1): }
12256:1): } else {
12257:1): $shown{$item} = $defval{$item};
12258:1): }
12259:1): }
12260:1): } else {
12261:1): foreach my $item ('threshold','weights','excluded','sysmail') {
12262:1): $shown{$item} = $defval{$item};
12263:1): }
12264:1): }
12265:1): foreach my $item ('threshold','weights','excluded','sysmail') {
12266:1): $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
12267:1): $shown{$item}).'</li>';
12268:1): }
12269:1): $resulttext .= '</ul></li>';
12270:1): }
1.160.6.78 raeburn 12271: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12272: my (@optional,@required,@unused,$maxsizechg);
12273: foreach my $field (@{$changes{'helpform'}}) {
12274: if ($field eq 'maxsize') {
12275: $maxsizechg = 1;
12276: next;
12277: }
12278: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
12279: push(@optional,$field);
12280: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12281: push(@unused,$field);
12282: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
12283: push(@required,$field);
12284: }
12285: }
12286: if (@optional) {
12287: $resulttext .= '<li>'.
12288: &mt('Help form fields changed to "Optional": [_1].',
12289: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12290: '</li>';
12291: }
12292: if (@required) {
12293: $resulttext .= '<li>'.
12294: &mt('Help form fields changed to "Required": [_1].',
12295: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12296: '</li>';
12297: }
12298: if (@unused) {
12299: $resulttext .= '<li>'.
12300: &mt('Help form fields changed to "Not shown": [_1].',
12301: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12302: '</li>';
12303: }
12304: if ($maxsizechg) {
12305: $resulttext .= '<li>'.
12306: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12307: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12308: '</li>';
12309: }
12310: }
1.28 raeburn 12311: $resulttext .= '</ul>';
12312: } else {
1.160.6.78 raeburn 12313: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 12314: }
12315: } else {
12316: $resulttext = '<span class="LC_error">'.
12317: &mt('An error occurred: [_1].',$putresult).'</span>';
12318: }
12319: return $resulttext;
12320: }
12321:
1.160.6.98 raeburn 12322: sub modify_passwords {
12323: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
12324: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
12325: $updatedefaults,$updateconf);
12326: my $customfn = 'resetpw.html';
12327: if (ref($domconfig{'passwords'}) eq 'HASH') {
12328: %current = %{$domconfig{'passwords'}};
12329: }
12330: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12331: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12332: if (ref($types) eq 'ARRAY') {
12333: @oktypes = @{$types};
12334: }
12335: push(@oktypes,'default');
12336:
12337: my %titles = &Apache::lonlocal::texthash (
12338: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
12339: intauth_check => 'Check bcrypt cost if authenticated',
12340: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
12341: permanent => 'Permanent e-mail address',
12342: critical => 'Critical notification address',
12343: notify => 'Notification address',
12344: min => 'Minimum password length',
12345: max => 'Maximum password length',
12346: chars => 'Required characters',
12347: numsaved => 'Number of previous passwords to save',
12348: reset => 'Resetting Forgotten Password',
12349: intauth => 'Encryption of Stored Passwords (Internal Auth)',
12350: rules => 'Rules for LON-CAPA Passwords',
12351: crsownerchg => 'Course Owner Changing Student Passwords',
12352: username => 'Username',
12353: email => 'E-mail address',
12354: );
12355:
12356: #
12357: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
12358: #
12359: my (%curr_defaults,%save_defaults);
12360: if (ref($domconfig{'defaults'}) eq 'HASH') {
12361: foreach my $key (keys(%{$domconfig{'defaults'}})) {
12362: if ($key =~ /^intauth_(cost|check|switch)$/) {
12363: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
12364: } else {
12365: $save_defaults{$key} = $domconfig{'defaults'}{$key};
12366: }
12367: }
12368: }
12369: my %staticdefaults = (
12370: 'resetlink' => 2,
12371: 'resetcase' => \@oktypes,
12372: 'resetprelink' => 'both',
12373: 'resetemail' => ['critical','notify','permanent'],
12374: 'intauth_cost' => 10,
12375: 'intauth_check' => 0,
12376: 'intauth_switch' => 0,
12377: );
1.160.6.99 raeburn 12378: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 12379: foreach my $type (@oktypes) {
12380: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
12381: }
12382: my $linklife = $env{'form.passwords_link'};
12383: $linklife =~ s/^\s+|\s+$//g;
12384: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
12385: $newvalues{'resetlink'} = $linklife;
12386: if ($current{'resetlink'}) {
12387: if ($current{'resetlink'} ne $linklife) {
12388: $changes{'reset'} = 1;
12389: }
1.160.6.102 raeburn 12390: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12391: if ($staticdefaults{'resetlink'} ne $linklife) {
12392: $changes{'reset'} = 1;
12393: }
12394: }
12395: } elsif ($current{'resetlink'}) {
12396: $changes{'reset'} = 1;
12397: }
12398: my @casesens;
12399: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
12400: foreach my $case (sort(@posscase)) {
12401: if (grep(/^\Q$case\E$/,@oktypes)) {
12402: push(@casesens,$case);
12403: }
12404: }
12405: $newvalues{'resetcase'} = \@casesens;
12406: if (ref($current{'resetcase'}) eq 'ARRAY') {
12407: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
12408: if (@diffs > 0) {
12409: $changes{'reset'} = 1;
12410: }
1.160.6.102 raeburn 12411: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12412: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
12413: if (@diffs > 0) {
12414: $changes{'reset'} = 1;
12415: }
12416: }
12417: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
12418: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
12419: if (exists($current{'resetprelink'})) {
12420: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
12421: $changes{'reset'} = 1;
12422: }
1.160.6.102 raeburn 12423: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12424: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
12425: $changes{'reset'} = 1;
12426: }
12427: }
12428: } elsif ($current{'resetprelink'}) {
12429: $changes{'reset'} = 1;
12430: }
12431: foreach my $type (@oktypes) {
12432: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
12433: my @postlink;
12434: foreach my $item (sort(@possplink)) {
12435: if ($item =~ /^(email|username)$/) {
12436: push(@postlink,$item);
12437: }
12438: }
12439: $newvalues{'resetpostlink'}{$type} = \@postlink;
12440: unless ($changes{'reset'}) {
12441: if (ref($current{'resetpostlink'}) eq 'HASH') {
12442: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
12443: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
12444: if (@diffs > 0) {
12445: $changes{'reset'} = 1;
12446: }
12447: } else {
12448: $changes{'reset'} = 1;
12449: }
1.160.6.102 raeburn 12450: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12451: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
12452: if (@diffs > 0) {
12453: $changes{'reset'} = 1;
12454: }
12455: }
12456: }
12457: }
12458: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
12459: my @resetemail;
12460: foreach my $item (sort(@possemailsrc)) {
12461: if ($item =~ /^(permanent|critical|notify)$/) {
12462: push(@resetemail,$item);
12463: }
12464: }
12465: $newvalues{'resetemail'} = \@resetemail;
12466: unless ($changes{'reset'}) {
12467: if (ref($current{'resetemail'}) eq 'ARRAY') {
12468: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
12469: if (@diffs > 0) {
12470: $changes{'reset'} = 1;
12471: }
1.160.6.102 raeburn 12472: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12473: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
12474: if (@diffs > 0) {
12475: $changes{'reset'} = 1;
12476: }
12477: }
12478: }
12479: if ($env{'form.passwords_stdtext'} == 0) {
12480: $newvalues{'resetremove'} = 1;
12481: unless ($current{'resetremove'}) {
12482: $changes{'reset'} = 1;
12483: }
12484: } elsif ($current{'resetremove'}) {
12485: $changes{'reset'} = 1;
12486: }
12487: if ($env{'form.passwords_customfile.filename'} ne '') {
12488: my $servadm = $r->dir_config('lonAdmEMail');
12489: my $servadm = $r->dir_config('lonAdmEMail');
12490: my ($configuserok,$author_ok,$switchserver) =
12491: &config_check($dom,$confname,$servadm);
12492: my $error;
12493: if ($configuserok eq 'ok') {
12494: if ($switchserver) {
12495: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
12496: } else {
12497: if ($author_ok eq 'ok') {
12498: my ($result,$customurl) =
12499: &publishlogo($r,'upload','passwords_customfile',$dom,
12500: $confname,'customtext/resetpw','','',$customfn);
12501: if ($result eq 'ok') {
12502: $newvalues{'resetcustom'} = $customurl;
12503: $changes{'reset'} = 1;
12504: } else {
12505: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
12506: }
12507: } else {
12508: $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);
12509: }
12510: }
12511: } else {
12512: $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);
12513: }
12514: if ($error) {
12515: &Apache::lonnet::logthis($error);
12516: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12517: }
12518: } elsif ($current{'resetcustom'}) {
12519: if ($env{'form.passwords_custom_del'}) {
12520: $changes{'reset'} = 1;
12521: } else {
12522: $newvalues{'resetcustom'} = $current{'resetcustom'};
12523: }
12524: }
12525: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
12526: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
12527: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
12528: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
12529: $changes{'intauth'} = 1;
12530: }
12531: } else {
12532: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
12533: }
12534: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
12535: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
12536: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
12537: $changes{'intauth'} = 1;
12538: }
12539: } else {
12540: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12541: }
12542: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
12543: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
12544: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
12545: $changes{'intauth'} = 1;
12546: }
12547: } else {
12548: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12549: }
12550: foreach my $item ('cost','check','switch') {
12551: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
12552: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
12553: $updatedefaults = 1;
12554: }
12555: }
12556: foreach my $rule ('min','max','numsaved') {
12557: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.160.6.99 raeburn 12558: my $ruleok;
12559: if ($rule eq 'min') {
12560: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
12561: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
12562: $ruleok = 1;
12563: }
12564: }
12565: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
12566: ($env{'form.passwords_'.$rule} ne '0')) {
12567: $ruleok = 1;
12568: }
12569: if ($ruleok) {
1.160.6.98 raeburn 12570: $newvalues{$rule} = $env{'form.passwords_'.$rule};
12571: if (exists($current{$rule})) {
12572: if ($newvalues{$rule} ne $current{$rule}) {
12573: $changes{'rules'} = 1;
12574: }
12575: } elsif ($rule eq 'min') {
12576: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
12577: $changes{'rules'} = 1;
12578: }
1.160.6.102.2 3(raebur 12579:0): } else {
12580:0): $changes{'rules'} = 1;
1.160.6.98 raeburn 12581: }
12582: } elsif (exists($current{$rule})) {
12583: $changes{'rules'} = 1;
12584: }
12585: }
12586: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
12587: my @chars;
12588: foreach my $item (sort(@posschars)) {
12589: if ($item =~ /^(uc|lc|num|spec)$/) {
12590: push(@chars,$item);
12591: }
12592: }
12593: $newvalues{'chars'} = \@chars;
12594: unless ($changes{'rules'}) {
12595: if (ref($current{'chars'}) eq 'ARRAY') {
12596: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
12597: if (@diffs > 0) {
12598: $changes{'rules'} = 1;
12599: }
12600: } else {
12601: if (@chars > 0) {
12602: $changes{'rules'} = 1;
12603: }
12604: }
12605: }
12606: my %crsownerchg = (
12607: by => [],
12608: for => [],
12609: );
12610: foreach my $item ('by','for') {
12611: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
12612: foreach my $type (sort(@posstypes)) {
12613: if (grep(/^\Q$type\E$/,@oktypes)) {
12614: push(@{$crsownerchg{$item}},$type);
12615: }
12616: }
12617: }
12618: $newvalues{'crsownerchg'} = \%crsownerchg;
12619: if (ref($current{'crsownerchg'}) eq 'HASH') {
12620: foreach my $item ('by','for') {
12621: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
12622: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
12623: if (@diffs > 0) {
12624: $changes{'crsownerchg'} = 1;
12625: last;
12626: }
12627: }
12628: }
1.160.6.102 raeburn 12629: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 12630: foreach my $item ('by','for') {
12631: if (@{$crsownerchg{$item}} > 0) {
12632: $changes{'crsownerchg'} = 1;
12633: last;
12634: }
12635: }
12636: }
12637:
12638: my %confighash = (
12639: defaults => \%save_defaults,
12640: passwords => \%newvalues,
12641: );
12642: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
12643:
12644: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
12645: if ($putresult eq 'ok') {
12646: if (keys(%changes) > 0) {
12647: $resulttext = &mt('Changes made: ').'<ul>';
12648: foreach my $key ('reset','intauth','rules','crsownerchg') {
12649: if ($changes{$key}) {
12650: unless ($key eq 'intauth') {
12651: $updateconf = 1;
12652: }
12653: $resulttext .= '<li>'.$titles{$key}.':<ul>';
12654: if ($key eq 'reset') {
12655: if ($confighash{'passwords'}{'captcha'} eq 'original') {
12656: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
12657: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
12658: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.102.2 3(raebur 12659:0): &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
12660:0): if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
12661:0): $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
12662:0): &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
12663:0): }
1.160.6.98 raeburn 12664: } else {
12665: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
12666: }
12667: if ($confighash{'passwords'}{'resetlink'}) {
12668: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
12669: } else {
12670: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
12671: &mt('Will default to 2 hours').'</li>';
12672: }
12673: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
12674: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
12675: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
12676: } else {
12677: my $casesens;
12678: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
12679: if ($type eq 'default') {
12680: $casesens .= $othertitle.', ';
12681: } elsif ($usertypes->{$type} ne '') {
12682: $casesens .= $usertypes->{$type}.', ';
12683: }
12684: }
12685: $casesens =~ s/\Q, \E$//;
12686: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
12687: }
12688: } else {
12689: $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>';
12690: }
12691: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
12692: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
12693: } else {
12694: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
12695: }
12696: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
12697: my $output;
12698: if (ref($types) eq 'ARRAY') {
12699: foreach my $type (@{$types}) {
12700: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
12701: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
12702: $output .= $usertypes->{$type}.' -- '.&mt('none');
12703: } else {
12704: $output .= $usertypes->{$type}.' -- '.
12705: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
12706: }
12707: }
12708: }
12709: }
12710: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
12711: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
12712: $output .= $othertitle.' -- '.&mt('none');
12713: } else {
12714: $output .= $othertitle.' -- '.
12715: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
12716: }
12717: }
12718: if ($output) {
12719: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
12720: } else {
12721: $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>';
12722: }
12723: } else {
12724: $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>';
12725: }
12726: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
12727: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
12728: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
12729: } else {
12730: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
12731: }
12732: } else {
12733: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
12734: }
12735: if ($confighash{'passwords'}{'resetremove'}) {
12736: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
12737: } else {
12738: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
12739: }
12740: if ($confighash{'passwords'}{'resetcustom'}) {
12741: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.102.2 3(raebur 12742:0): &mt('custom text'),600,500,undef,undef,
12743:0): undef,undef,'background-color:#ffffff');
12744:0): $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 12745: } else {
12746: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
12747: }
12748: } elsif ($key eq 'intauth') {
12749: foreach my $item ('cost','switch','check') {
12750: my $value = $save_defaults{$key.'_'.$item};
12751: if ($item eq 'switch') {
12752: my %optiondesc = &Apache::lonlocal::texthash (
12753: 0 => 'No',
12754: 1 => 'Yes',
12755: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12756: );
12757: if ($value =~ /^(0|1|2)$/) {
12758: $value = $optiondesc{$value};
12759: } else {
12760: $value = &mt('none -- defaults to No');
12761: }
12762: } elsif ($item eq 'check') {
12763: my %optiondesc = &Apache::lonlocal::texthash (
12764: 0 => 'No',
12765: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12766: 2 => 'Yes, disallow login if stored cost is less than domain default',
12767: );
12768: if ($value =~ /^(0|1|2)$/) {
12769: $value = $optiondesc{$value};
12770: } else {
12771: $value = &mt('none -- defaults to No');
12772: }
12773: }
12774: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
12775: }
12776: } elsif ($key eq 'rules') {
12777: foreach my $rule ('min','max','numsaved') {
12778: if ($confighash{'passwords'}{$rule} eq '') {
12779: if ($rule eq 'min') {
12780: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 12781: ' '.&mt('Default of [_1] will be used',
12782: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 12783: } else {
12784: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
12785: }
12786: } else {
12787: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
12788: }
12789: }
1.160.6.102.2 3(raebur 12790:0): if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
12791:0): if (@{$confighash{'passwords'}{'chars'}} > 0) {
12792:0): my %rulenames = &Apache::lonlocal::texthash(
12793:0): uc => 'At least one upper case letter',
12794:0): lc => 'At least one lower case letter',
12795:0): num => 'At least one number',
12796:0): spec => 'At least one non-alphanumeric',
12797:0): );
12798:0): my $needed = '<ul><li>'.
12799:0): join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
12800:0): '</li></ul>';
12801:0): $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
12802:0): } else {
12803:0): $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
12804:0): }
12805:0): } else {
12806:0): $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
12807:0): }
1.160.6.98 raeburn 12808: } elsif ($key eq 'crsownerchg') {
12809: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
12810: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
12811: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
12812: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
12813: } else {
12814: my %crsownerstr;
12815: foreach my $item ('by','for') {
12816: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
12817: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
12818: if ($type eq 'default') {
12819: $crsownerstr{$item} .= $othertitle.', ';
12820: } elsif ($usertypes->{$type} ne '') {
12821: $crsownerstr{$item} .= $usertypes->{$type}.', ';
12822: }
12823: }
12824: $crsownerstr{$item} =~ s/\Q, \E$//;
12825: }
12826: }
12827: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
12828: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
12829: }
12830: } else {
12831: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
12832: }
12833: }
12834: $resulttext .= '</ul></li>';
12835: }
12836: }
12837: $resulttext .= '</ul>';
12838: } else {
12839: $resulttext = &mt('No changes made to password settings');
12840: }
12841: my $cachetime = 24*60*60;
12842: if ($updatedefaults) {
12843: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12844: if (ref($lastactref) eq 'HASH') {
12845: $lastactref->{'domdefaults'} = 1;
12846: }
12847: }
12848: if ($updateconf) {
12849: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
12850: if (ref($lastactref) eq 'HASH') {
12851: $lastactref->{'passwdconf'} = 1;
12852: }
12853: }
12854: } else {
12855: $resulttext = '<span class="LC_error">'.
12856: &mt('An error occurred: [_1]',$putresult).'</span>';
12857: }
12858: if ($errors) {
12859: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
12860: $errors.'</ul></p>';
12861: }
12862: return $resulttext;
12863: }
12864:
1.28 raeburn 12865: sub modify_usercreation {
1.27 raeburn 12866: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 12867: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 12868: my $warningmsg;
1.27 raeburn 12869: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12870: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 12871: if ($key eq 'cancreate') {
12872: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
12873: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 12874: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 12875: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 12876: } else {
12877: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 12878: }
1.50 raeburn 12879: }
1.43 raeburn 12880: }
1.160.6.34 raeburn 12881: } elsif ($key eq 'email_rule') {
12882: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
12883: } else {
12884: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 12885: }
12886: }
1.34 raeburn 12887: }
1.160.6.34 raeburn 12888: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
12889: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
12890: my @contexts = ('author','course','requestcrs');
12891: foreach my $item(@contexts) {
12892: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 12893: }
1.34 raeburn 12894: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12895: foreach my $item (@contexts) {
1.160.6.34 raeburn 12896: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
12897: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 12898: }
1.27 raeburn 12899: }
1.34 raeburn 12900: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
12901: foreach my $item (@contexts) {
1.43 raeburn 12902: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 12903: if ($cancreate{$item} ne 'any') {
12904: push(@{$changes{'cancreate'}},$item);
12905: }
12906: } else {
12907: if ($cancreate{$item} ne 'none') {
12908: push(@{$changes{'cancreate'}},$item);
12909: }
1.27 raeburn 12910: }
12911: }
12912: } else {
1.43 raeburn 12913: foreach my $item (@contexts) {
1.34 raeburn 12914: push(@{$changes{'cancreate'}},$item);
12915: }
1.27 raeburn 12916: }
1.34 raeburn 12917:
1.27 raeburn 12918: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
12919: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
12920: if (!grep(/^\Q$type\E$/,@username_rule)) {
12921: push(@{$changes{'username_rule'}},$type);
12922: }
12923: }
12924: foreach my $type (@username_rule) {
12925: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
12926: push(@{$changes{'username_rule'}},$type);
12927: }
12928: }
12929: } else {
12930: push(@{$changes{'username_rule'}},@username_rule);
12931: }
12932:
1.32 raeburn 12933: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
12934: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
12935: if (!grep(/^\Q$type\E$/,@id_rule)) {
12936: push(@{$changes{'id_rule'}},$type);
12937: }
12938: }
12939: foreach my $type (@id_rule) {
12940: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
12941: push(@{$changes{'id_rule'}},$type);
12942: }
12943: }
12944: } else {
12945: push(@{$changes{'id_rule'}},@id_rule);
12946: }
12947:
1.43 raeburn 12948: my @authen_contexts = ('author','course','domain');
1.28 raeburn 12949: my @authtypes = ('int','krb4','krb5','loc');
12950: my %authhash;
1.43 raeburn 12951: foreach my $item (@authen_contexts) {
1.28 raeburn 12952: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
12953: foreach my $auth (@authtypes) {
12954: if (grep(/^\Q$auth\E$/,@authallowed)) {
12955: $authhash{$item}{$auth} = 1;
12956: } else {
12957: $authhash{$item}{$auth} = 0;
12958: }
12959: }
12960: }
12961: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 12962: foreach my $item (@authen_contexts) {
1.28 raeburn 12963: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
12964: foreach my $auth (@authtypes) {
12965: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
12966: push(@{$changes{'authtypes'}},$item);
12967: last;
12968: }
12969: }
12970: }
12971: }
12972: } else {
1.43 raeburn 12973: foreach my $item (@authen_contexts) {
1.28 raeburn 12974: push(@{$changes{'authtypes'}},$item);
12975: }
12976: }
12977:
1.160.6.34 raeburn 12978: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
12979: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
12980: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
12981: $save_usercreate{'id_rule'} = \@id_rule;
12982: $save_usercreate{'username_rule'} = \@username_rule,
12983: $save_usercreate{'authtypes'} = \%authhash;
12984:
1.27 raeburn 12985: my %usercreation_hash = (
1.160.6.34 raeburn 12986: usercreation => \%save_usercreate,
12987: );
1.27 raeburn 12988:
12989: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
12990: $dom);
1.50 raeburn 12991:
1.160.6.34 raeburn 12992: if ($putresult eq 'ok') {
12993: if (keys(%changes) > 0) {
12994: $resulttext = &mt('Changes made:').'<ul>';
12995: if (ref($changes{'cancreate'}) eq 'ARRAY') {
12996: my %lt = &usercreation_types();
12997: foreach my $type (@{$changes{'cancreate'}}) {
12998: my $chgtext = $lt{$type}.', ';
12999: if ($cancreate{$type} eq 'none') {
13000: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13001: } elsif ($cancreate{$type} eq 'any') {
13002: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13003: } elsif ($cancreate{$type} eq 'official') {
13004: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13005: } elsif ($cancreate{$type} eq 'unofficial') {
13006: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13007: }
13008: $resulttext .= '<li>'.$chgtext.'</li>';
13009: }
13010: }
13011: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13012: my ($rules,$ruleorder) =
13013: &Apache::lonnet::inst_userrules($dom,'username');
13014: my $chgtext = '<ul>';
13015: foreach my $type (@username_rule) {
13016: if (ref($rules->{$type}) eq 'HASH') {
13017: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13018: }
13019: }
13020: $chgtext .= '</ul>';
13021: if (@username_rule > 0) {
13022: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13023: } else {
13024: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13025: }
13026: }
13027: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13028: my ($idrules,$idruleorder) =
13029: &Apache::lonnet::inst_userrules($dom,'id');
13030: my $chgtext = '<ul>';
13031: foreach my $type (@id_rule) {
13032: if (ref($idrules->{$type}) eq 'HASH') {
13033: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13034: }
13035: }
13036: $chgtext .= '</ul>';
13037: if (@id_rule > 0) {
13038: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13039: } else {
13040: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13041: }
13042: }
13043: my %authname = &authtype_names();
13044: my %context_title = &context_names();
13045: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13046: my $chgtext = '<ul>';
13047: foreach my $type (@{$changes{'authtypes'}}) {
13048: my @allowed;
13049: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13050: foreach my $auth (@authtypes) {
13051: if ($authhash{$type}{$auth}) {
13052: push(@allowed,$authname{$auth});
13053: }
13054: }
13055: if (@allowed > 0) {
13056: $chgtext .= join(', ',@allowed).'</li>';
13057: } else {
13058: $chgtext .= &mt('none').'</li>';
13059: }
13060: }
13061: $chgtext .= '</ul>';
13062: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13063: $resulttext .= '</li>';
13064: }
13065: $resulttext .= '</ul>';
13066: } else {
13067: $resulttext = &mt('No changes made to user creation settings');
13068: }
13069: } else {
13070: $resulttext = '<span class="LC_error">'.
13071: &mt('An error occurred: [_1]',$putresult).'</span>';
13072: }
13073: if ($warningmsg ne '') {
13074: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13075: }
13076: return $resulttext;
13077: }
13078:
13079: sub modify_selfcreation {
1.160.6.93 raeburn 13080: my ($dom,$lastactref,%domconfig) = @_;
13081: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13082: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13083: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13084: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13085: if (ref($typesref) eq 'ARRAY') {
13086: @types = @{$typesref};
13087: }
13088: if (ref($usertypesref) eq 'HASH') {
13089: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 13090: }
1.160.6.93 raeburn 13091: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 13092: #
13093: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13094: #
13095: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13096: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13097: if ($key eq 'cancreate') {
13098: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13099: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13100: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 13101: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13102: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13103: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13104: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
13105: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 13106: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13107: } else {
13108: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13109: }
13110: }
13111: }
13112: } elsif ($key eq 'email_rule') {
13113: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13114: } else {
13115: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13116: }
13117: }
13118: }
13119: #
13120: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13121: #
13122: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13123: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13124: if ($key eq 'selfcreate') {
13125: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13126: } else {
13127: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13128: }
13129: }
13130: }
1.160.6.93 raeburn 13131: #
13132: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13133: #
13134: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13135: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13136: if ($key eq 'inststatusguest') {
13137: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13138: } else {
13139: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13140: }
13141: }
13142: }
1.160.6.34 raeburn 13143:
13144: my @contexts = ('selfcreate');
13145: @{$cancreate{'selfcreate'}} = ();
13146: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 13147: if (@types) {
13148: @{$cancreate{'statustocreate'}} = ();
13149: }
1.160.6.40 raeburn 13150: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 13151: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 13152: %{$cancreate{'emailverified'}} = ();
13153: %{$cancreate{'emailoptions'}} = ();
13154: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13155: my %selfcreatetypes = (
13156: sso => 'users authenticated by institutional single sign on',
13157: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 13158: email => 'users verified by e-mail',
1.50 raeburn 13159: );
1.160.6.34 raeburn 13160: #
13161: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13162: # is permitted.
13163: #
1.160.6.40 raeburn 13164:
1.160.6.93 raeburn 13165: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 13166:
1.160.6.93 raeburn 13167: my (@statuses,%email_rule);
1.160.6.35 raeburn 13168: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 13169: if ($item eq 'email') {
1.160.6.40 raeburn 13170: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 13171: if (@types) {
13172: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13173: foreach my $status (@poss_statuses) {
13174: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13175: push(@statuses,$status);
13176: }
13177: }
13178: $save_inststatus{'inststatusguest'} = \@statuses;
13179: } else {
13180: push(@statuses,'default');
13181: }
13182: if (@statuses) {
13183: my %curr_rule;
13184: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13185: foreach my $type (@statuses) {
13186: $curr_rule{$type} = $curr_usercreation{'email_rule'};
13187: }
13188: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13189: foreach my $type (@statuses) {
13190: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13191: }
13192: }
13193: push(@{$cancreate{'selfcreate'}},'email');
13194: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13195: my %curremaildom;
13196: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13197: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13198: }
13199: foreach my $type (@statuses) {
13200: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13201: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13202: }
13203: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13204: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13205: }
13206: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13207: #
13208: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13209: #
13210: my $chosen = $1;
13211: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13212: my $emaildom;
13213: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13214: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13215: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13216: if (ref($curremaildom{$type}) eq 'HASH') {
13217: if (exists($curremaildom{$type}{$chosen})) {
13218: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13219: push(@{$changes{'cancreate'}},'emaildomain');
13220: }
13221: } elsif ($emaildom ne '') {
13222: push(@{$changes{'cancreate'}},'emaildomain');
13223: }
13224: } elsif ($emaildom ne '') {
13225: push(@{$changes{'cancreate'}},'emaildomain');
13226: }
13227: }
13228: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13229: } elsif ($chosen eq 'custom') {
13230: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13231: $email_rule{$type} = [];
13232: if (ref($emailrules) eq 'HASH') {
13233: foreach my $rule (@possemail_rules) {
13234: if (exists($emailrules->{$rule})) {
13235: push(@{$email_rule{$type}},$rule);
13236: }
13237: }
13238: }
13239: if (@{$email_rule{$type}}) {
13240: $cancreate{'emailoptions'}{$type} = 'custom';
13241: if (ref($curr_rule{$type}) eq 'ARRAY') {
13242: if (@{$curr_rule{$type}} > 0) {
13243: foreach my $rule (@{$curr_rule{$type}}) {
13244: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13245: push(@{$changes{'email_rule'}},$type);
13246: }
13247: }
13248: }
13249: foreach my $type (@{$email_rule{$type}}) {
13250: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13251: push(@{$changes{'email_rule'}},$type);
13252: }
13253: }
13254: } else {
13255: push(@{$changes{'email_rule'}},$type);
13256: }
13257: }
13258: } else {
13259: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13260: }
13261: }
13262: }
13263: if (@types) {
13264: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13265: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13266: if (@changed) {
13267: push(@{$changes{'inststatus'}},'inststatusguest');
13268: }
13269: } else {
13270: push(@{$changes{'inststatus'}},'inststatusguest');
13271: }
13272: }
13273: } else {
13274: delete($env{'form.cancreate_email'});
13275: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13276: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13277: push(@{$changes{'inststatus'}},'inststatusguest');
13278: }
13279: }
13280: }
13281: } else {
13282: $save_inststatus{'inststatusguest'} = [];
13283: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13284: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13285: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 13286: }
13287: }
1.160.6.34 raeburn 13288: }
13289: } else {
13290: if ($env{'form.cancreate_'.$item}) {
13291: push(@{$cancreate{'selfcreate'}},$item);
13292: }
13293: }
13294: }
1.160.6.93 raeburn 13295: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 13296: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13297: #
1.160.6.35 raeburn 13298: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13299: # 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 13300: #
1.160.6.40 raeburn 13301:
1.160.6.48 raeburn 13302: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 13303: push(@contexts,'emailusername');
1.160.6.93 raeburn 13304: if (@statuses) {
13305: foreach my $type (@statuses) {
1.160.6.35 raeburn 13306: if (ref($infofields) eq 'ARRAY') {
13307: foreach my $field (@{$infofields}) {
13308: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13309: $cancreate{'emailusername'}{$type}{$field} = $1;
13310: }
13311: }
1.160.6.34 raeburn 13312: }
13313: }
13314: }
13315: #
13316: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 13317: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 13318: #
13319:
13320: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13321: @approvalnotify = sort(@approvalnotify);
13322: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13323: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13324: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13325: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13326: push(@{$changes{'cancreate'}},'notify');
13327: }
13328: } else {
13329: if ($cancreate{'notify'}{'approval'}) {
13330: push(@{$changes{'cancreate'}},'notify');
13331: }
13332: }
13333: } elsif ($cancreate{'notify'}{'approval'}) {
13334: push(@{$changes{'cancreate'}},'notify');
13335: }
13336:
13337: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13338: }
13339: #
1.160.6.40 raeburn 13340: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 13341: # institutional log-in.
13342: #
13343: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13344: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13345: ($domdefaults{'auth_def'} eq 'localauth'))) {
13346: $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.').' '.
13347: &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.');
13348: }
13349: }
13350: my @fields = ('lastname','firstname','middlename','generation',
13351: 'permanentemail','id');
1.160.6.44 raeburn 13352: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 13353: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13354: #
13355: # Where usernames may created for institutional log-in and/or institutional single sign on:
13356: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13357: # may self-create accounts
13358: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13359: # which the user may supply, if institutional data is unavailable.
13360: #
13361: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 13362: if (@types) {
13363: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13364: push(@contexts,'statustocreate');
13365: foreach my $type (@types) {
1.160.6.34 raeburn 13366: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13367: foreach my $field (@fields) {
13368: if (grep(/^\Q$field\E$/,@modifiable)) {
13369: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13370: } else {
13371: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13372: }
13373: }
13374: }
13375: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 13376: foreach my $type (@types) {
1.160.6.34 raeburn 13377: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13378: foreach my $field (@fields) {
13379: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13380: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13381: push(@{$changes{'selfcreate'}},$type);
13382: last;
13383: }
13384: }
13385: }
13386: }
13387: } else {
1.160.6.93 raeburn 13388: foreach my $type (@types) {
1.160.6.34 raeburn 13389: push(@{$changes{'selfcreate'}},$type);
13390: }
13391: }
13392: }
1.160.6.44 raeburn 13393: foreach my $field (@shibfields) {
13394: if ($env{'form.shibenv_'.$field} ne '') {
13395: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13396: }
13397: }
13398: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13399: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13400: foreach my $field (@shibfields) {
13401: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13402: push(@{$changes{'cancreate'}},'shibenv');
13403: }
13404: }
13405: } else {
13406: foreach my $field (@shibfields) {
13407: if ($env{'form.shibenv_'.$field}) {
13408: push(@{$changes{'cancreate'}},'shibenv');
13409: last;
13410: }
13411: }
13412: }
13413: }
1.160.6.34 raeburn 13414: }
13415: foreach my $item (@contexts) {
13416: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13417: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13418: if (ref($cancreate{$item}) eq 'ARRAY') {
13419: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13420: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13421: push(@{$changes{'cancreate'}},$item);
13422: }
13423: }
13424: }
13425: }
13426: if (ref($cancreate{$item}) eq 'ARRAY') {
13427: foreach my $type (@{$cancreate{$item}}) {
13428: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13429: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13430: push(@{$changes{'cancreate'}},$item);
13431: }
13432: }
13433: }
13434: }
13435: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13436: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 13437: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13438: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13439: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13440: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13441: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13442: push(@{$changes{'cancreate'}},$item);
13443: }
13444: }
13445: }
1.160.6.93 raeburn 13446: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13447: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13448: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13449: push(@{$changes{'cancreate'}},$item);
13450: }
1.160.6.34 raeburn 13451: }
13452: }
13453: }
1.160.6.93 raeburn 13454: foreach my $type (keys(%{$cancreate{$item}})) {
13455: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13456: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13457: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13458: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13459: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13460: push(@{$changes{'cancreate'}},$item);
13461: }
13462: }
13463: } else {
13464: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13465: push(@{$changes{'cancreate'}},$item);
13466: }
13467: }
13468: }
1.160.6.93 raeburn 13469: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13470: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13471: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13472: push(@{$changes{'cancreate'}},$item);
13473: }
1.160.6.34 raeburn 13474: }
13475: }
13476: }
13477: }
13478: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13479: if (ref($cancreate{$item}) eq 'ARRAY') {
13480: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13481: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13482: push(@{$changes{'cancreate'}},$item);
13483: }
13484: }
1.160.6.93 raeburn 13485: }
13486: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13487: if (ref($cancreate{$item}) eq 'HASH') {
13488: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13489: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 13490: }
13491: }
13492: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 13493: if (ref($cancreate{$item}) eq 'HASH') {
13494: foreach my $type (keys(%{$cancreate{$item}})) {
13495: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13496: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13497: if ($cancreate{$item}{$type}{$field}) {
13498: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13499: push(@{$changes{'cancreate'}},$item);
13500: }
13501: last;
13502: }
13503: }
13504: }
13505: }
1.160.6.34 raeburn 13506: }
13507: }
13508: }
13509: #
13510: # Populate %save_usercreate hash with updates to self-creation configuration.
13511: #
13512: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13513: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 13514: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 13515: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13516: if (ref($cancreate{'notify'}) eq 'HASH') {
13517: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13518: }
1.160.6.40 raeburn 13519: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13520: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13521: }
1.160.6.93 raeburn 13522: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13523: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13524: }
13525: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13526: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13527: }
13528: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13529: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13530: }
1.160.6.34 raeburn 13531: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13532: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13533: }
1.160.6.44 raeburn 13534: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13535: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13536: }
1.160.6.34 raeburn 13537: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 13538: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 13539:
13540: my %userconfig_hash = (
13541: usercreation => \%save_usercreate,
13542: usermodification => \%save_usermodify,
1.160.6.93 raeburn 13543: inststatus => \%save_inststatus,
1.160.6.34 raeburn 13544: );
1.160.6.93 raeburn 13545:
1.160.6.34 raeburn 13546: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13547: $dom);
13548: #
1.160.6.93 raeburn 13549: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 13550: #
1.27 raeburn 13551: if ($putresult eq 'ok') {
13552: if (keys(%changes) > 0) {
13553: $resulttext = &mt('Changes made:').'<ul>';
13554: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 13555: my %lt = &selfcreation_types();
1.34 raeburn 13556: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 13557: my $chgtext = '';
1.45 raeburn 13558: if ($type eq 'selfcreate') {
1.50 raeburn 13559: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 13560: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13561: } else {
1.160.6.34 raeburn 13562: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13563: '<ul>';
1.50 raeburn 13564: foreach my $case (@{$cancreate{$type}}) {
13565: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13566: }
13567: $chgtext .= '</ul>';
1.100 raeburn 13568: if (ref($cancreate{$type}) eq 'ARRAY') {
13569: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13570: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13571: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 13572: $chgtext .= '<span class="LC_warning">'.
13573: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13574: '</span><br />';
1.100 raeburn 13575: }
13576: }
13577: }
1.160.6.93 raeburn 13578: if (grep(/^email$/,@{$cancreate{$type}})) {
13579: if (!@statuses) {
13580: $chgtext .= '<span class="LC_warning">'.
13581: &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.").
13582: '</span><br />';
13583:
13584: }
13585: }
1.100 raeburn 13586: }
1.43 raeburn 13587: }
1.160.6.44 raeburn 13588: } elsif ($type eq 'shibenv') {
13589: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 13590: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 13591: } else {
13592: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13593: '<ul>';
13594: foreach my $field (@shibfields) {
13595: next if ($cancreate{$type}{$field} eq '');
13596: if ($field eq 'inststatus') {
13597: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13598: } else {
13599: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13600: }
13601: }
13602: $chgtext .= '</ul>';
1.160.6.93 raeburn 13603: }
1.93 raeburn 13604: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13605: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13606: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13607: if (@{$cancreate{'selfcreate'}} > 0) {
13608: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13609: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13610: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 13611: $chgtext .= '<br />'.
13612: '<span class="LC_warning">'.
13613: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13614: '</span>';
13615: }
1.160.6.93 raeburn 13616: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13617: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13618: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13619: } else {
13620: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13621: }
13622: $chgtext .= '<ul>';
13623: foreach my $case (@{$cancreate{$type}}) {
13624: if ($case eq 'default') {
13625: $chgtext .= '<li>'.$othertitle.'</li>';
13626: } else {
1.160.6.93 raeburn 13627: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13628: }
13629: }
1.100 raeburn 13630: $chgtext .= '</ul>';
13631: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 13632: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 13633: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13634: '</span>';
1.100 raeburn 13635: }
13636: }
13637: } else {
13638: if (@{$cancreate{$type}} == 0) {
13639: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13640: } else {
13641: $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 13642: }
13643: }
1.160.6.93 raeburn 13644: $chgtext .= '<br />';
1.93 raeburn 13645: }
1.160.6.40 raeburn 13646: } elsif ($type eq 'selfcreateprocessing') {
13647: my %choices = &Apache::lonlocal::texthash (
13648: automatic => 'Automatic approval',
13649: approval => 'Queued for approval',
13650: );
1.160.6.93 raeburn 13651: if (@types) {
13652: if (@statuses) {
13653: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
13654: '<ul>';
13655: foreach my $status (@statuses) {
13656: if ($status eq 'default') {
13657: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
13658: } else {
13659: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
13660: }
13661: }
13662: $chgtext .= '</ul>';
13663: }
13664: } else {
13665: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13666: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13667: }
13668: } elsif ($type eq 'emailverified') {
13669: my %options = &Apache::lonlocal::texthash (
13670: all => 'Same as e-mail',
13671: first => 'Omit @domain',
13672: free => 'Free to choose',
13673: );
13674: if (@types) {
13675: if (@statuses) {
13676: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13677: '<ul>';
13678: foreach my $status (@statuses) {
13679: if ($status eq 'default') {
13680: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
13681: } else {
13682: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
13683: }
13684: }
13685: $chgtext .= '</ul>';
13686: }
1.160.6.40 raeburn 13687: } else {
1.160.6.93 raeburn 13688: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
13689: $options{$cancreate{'emailverified'}{'default'}});
13690: }
13691: } elsif ($type eq 'emailoptions') {
13692: my %options = &Apache::lonlocal::texthash (
13693: any => 'Any e-mail',
13694: inst => 'Institutional only',
13695: noninst => 'Non-institutional only',
13696: custom => 'Custom restrictions',
13697: );
13698: if (@types) {
13699: if (@statuses) {
13700: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13701: '<ul>';
13702: foreach my $status (@statuses) {
13703: if ($type eq 'default') {
13704: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13705: } else {
13706: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13707: }
13708: }
13709: $chgtext .= '</ul>';
13710: }
13711: } else {
13712: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13713: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13714: } else {
13715: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13716: $options{$cancreate{'emailoptions'}{'default'}});
13717: }
13718: }
13719: } elsif ($type eq 'emaildomain') {
13720: my $output;
13721: if (@statuses) {
13722: foreach my $type (@statuses) {
13723: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13724: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13725: if ($type eq 'default') {
13726: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13727: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13728: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13729: } else {
13730: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13731: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13732: }
13733: } else {
13734: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13735: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13736: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13737: } else {
13738: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13739: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13740: }
13741: }
13742: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13743: if ($type eq 'default') {
13744: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13745: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13746: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13747: } else {
13748: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13749: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13750: }
13751: } else {
13752: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13753: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13754: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13755: } else {
13756: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13757: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13758: }
13759: }
13760: }
13761: }
13762: }
13763: }
13764: if ($output ne '') {
13765: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
13766: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 13767: }
1.160.6.5 raeburn 13768: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 13769: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 13770: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
13771: } else {
13772: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 13773: if ($captchas{$savecaptcha{$type}}) {
13774: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 13775: } else {
13776: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
13777: }
13778: }
13779: } elsif ($type eq 'recaptchakeys') {
13780: my ($privkey,$pubkey);
1.160.6.34 raeburn 13781: if (ref($savecaptcha{$type}) eq 'HASH') {
13782: $pubkey = $savecaptcha{$type}{'public'};
13783: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 13784: }
13785: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
13786: if (!$pubkey) {
13787: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
13788: } else {
13789: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13790: }
13791: if (!$privkey) {
13792: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
13793: } else {
13794: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
13795: }
13796: $chgtext .= '</ul>';
1.160.6.69 raeburn 13797: } elsif ($type eq 'recaptchaversion') {
13798: if ($savecaptcha{'captcha'} eq 'recaptcha') {
13799: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
13800: }
1.160.6.34 raeburn 13801: } elsif ($type eq 'emailusername') {
13802: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 13803: if (@statuses) {
13804: foreach my $type (@statuses) {
1.160.6.35 raeburn 13805: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
13806: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 13807: $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 13808: '<ul>';
13809: foreach my $field (@{$infofields}) {
13810: if ($cancreate{'emailusername'}{$type}{$field}) {
13811: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
13812: }
13813: }
1.160.6.50 raeburn 13814: $chgtext .= '</ul>';
13815: } else {
1.160.6.93 raeburn 13816: $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 13817: }
13818: } else {
1.160.6.93 raeburn 13819: $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 13820: }
13821: }
13822: }
13823: }
13824: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 13825: my $numapprove = 0;
1.160.6.34 raeburn 13826: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13827: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
13828: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 13829: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
13830: $numapprove ++;
1.160.6.34 raeburn 13831: }
13832: }
1.43 raeburn 13833: }
1.160.6.93 raeburn 13834: unless ($numapprove) {
13835: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
13836: }
1.34 raeburn 13837: }
1.160.6.34 raeburn 13838: if ($chgtext) {
13839: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 13840: }
13841: }
13842: }
1.160.6.93 raeburn 13843: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 13844: my ($emailrules,$emailruleorder) =
13845: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 13846: foreach my $type (@{$changes{'email_rule'}}) {
13847: if (ref($email_rule{$type}) eq 'ARRAY') {
13848: my $chgtext = '<ul>';
13849: foreach my $rule (@{$email_rule{$type}}) {
13850: if (ref($emailrules->{$rule}) eq 'HASH') {
13851: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
13852: }
13853: }
13854: $chgtext .= '</ul>';
13855: my $typename;
13856: if (@types) {
13857: if ($type eq 'default') {
13858: $typename = $othertitle;
13859: } else {
13860: $typename = $usertypes{$type};
13861: }
13862: $chgtext .= &mt('(Affiliation: [_1])',$typename);
13863: }
13864: if (@{$email_rule{$type}} > 0) {
13865: $resulttext .= '<li>'.
13866: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
13867: $usertypes{$type}).
13868: $chgtext.
13869: '</li>';
13870: } else {
13871: $resulttext .= '<li>'.
13872: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
13873: '</li>'.
13874: &mt('(Affiliation: [_1])',$typename);
13875: }
1.43 raeburn 13876: }
13877: }
1.160.6.93 raeburn 13878: }
13879: if (ref($changes{'inststatus'}) eq 'ARRAY') {
13880: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
13881: if (@{$save_inststatus{'inststatusguest'}} > 0) {
13882: my $chgtext = '<ul>';
13883: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
13884: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
13885: }
13886: $chgtext .= '</ul>';
13887: $resulttext .= '<li>'.
13888: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
13889: $chgtext.
13890: '</li>';
13891: } else {
13892: $resulttext .= '<li>'.
13893: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
13894: '</li>';
13895: }
1.43 raeburn 13896: }
13897: }
1.160.6.34 raeburn 13898: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
13899: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
13900: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13901: foreach my $type (@{$changes{'selfcreate'}}) {
13902: my $typename = $type;
1.160.6.93 raeburn 13903: if (keys(%usertypes) > 0) {
13904: if ($usertypes{$type} ne '') {
13905: $typename = $usertypes{$type};
1.28 raeburn 13906: }
13907: }
1.160.6.34 raeburn 13908: my @modifiable;
13909: $resulttext .= '<li>'.
13910: &mt('Self-creation of account by users with status: [_1]',
13911: '<span class="LC_cusr_emph">'.$typename.'</span>').
13912: ' - '.&mt('modifiable fields (if institutional data blank): ');
13913: foreach my $field (@fields) {
13914: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
13915: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
13916: }
13917: }
13918: if (@modifiable > 0) {
13919: $resulttext .= join(', ',@modifiable);
1.43 raeburn 13920: } else {
1.160.6.34 raeburn 13921: $resulttext .= &mt('none');
1.43 raeburn 13922: }
1.160.6.34 raeburn 13923: $resulttext .= '</li>';
1.28 raeburn 13924: }
1.160.6.34 raeburn 13925: $resulttext .= '</ul></li>';
1.28 raeburn 13926: }
1.27 raeburn 13927: $resulttext .= '</ul>';
1.160.6.93 raeburn 13928: my $cachetime = 24*60*60;
13929: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
13930: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13931: if (ref($lastactref) eq 'HASH') {
13932: $lastactref->{'domdefaults'} = 1;
13933: }
1.27 raeburn 13934: } else {
1.160.6.34 raeburn 13935: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 13936: }
13937: } else {
13938: $resulttext = '<span class="LC_error">'.
1.23 raeburn 13939: &mt('An error occurred: [_1]',$putresult).'</span>';
13940: }
1.43 raeburn 13941: if ($warningmsg ne '') {
13942: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13943: }
1.23 raeburn 13944: return $resulttext;
13945: }
13946:
1.160.6.5 raeburn 13947: sub process_captcha {
1.160.6.102.2 3(raebur 13948:0): my ($container,$changes,$newsettings,$currsettings) = @_;
13949:0): return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 13950: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
13951: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
13952: $newsettings->{'captcha'} = 'original';
13953: }
1.160.6.102.2 3(raebur 13954:0): my %current;
13955:0): if (ref($currsettings) eq 'HASH') {
13956:0): %current = %{$currsettings};
13957:0): }
13958:0): if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 13959: if ($container eq 'cancreate') {
13960: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13961: push(@{$changes->{'cancreate'}},'captcha');
13962: } elsif (!defined($changes->{'cancreate'})) {
13963: $changes->{'cancreate'} = ['captcha'];
13964: }
1.160.6.102 raeburn 13965: } elsif ($container eq 'passwords') {
13966: $changes->{'reset'} = 1;
1.160.6.5 raeburn 13967: } else {
13968: $changes->{'captcha'} = 1;
13969: }
13970: }
1.160.6.69 raeburn 13971: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 13972: if ($newsettings->{'captcha'} eq 'recaptcha') {
13973: $newpub = $env{'form.'.$container.'_recaptchapub'};
13974: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 13975: $newpub =~ s/[^\w\-]//g;
13976: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 13977: $newsettings->{'recaptchakeys'} = {
13978: public => $newpub,
13979: private => $newpriv,
13980: };
1.160.6.69 raeburn 13981: $newversion = $env{'form.'.$container.'_recaptchaversion'};
13982: $newversion =~ s/\D//g;
13983: if ($newversion ne '2') {
13984: $newversion = 1;
13985: }
13986: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 13987: }
1.160.6.102.2 3(raebur 13988:0): if (ref($current{'recaptchakeys'}) eq 'HASH') {
13989:0): $currpub = $current{'recaptchakeys'}{'public'};
13990:0): $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 13991: unless ($newsettings->{'captcha'} eq 'recaptcha') {
13992: $newsettings->{'recaptchakeys'} = {
13993: public => '',
13994: private => '',
13995: }
13996: }
1.160.6.5 raeburn 13997: }
1.160.6.102.2 3(raebur 13998:0): if ($current{'captcha'} eq 'recaptcha') {
13999:0): $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 14000: if ($currversion ne '2') {
14001: $currversion = 1;
14002: }
14003: }
14004: if ($currversion ne $newversion) {
14005: if ($container eq 'cancreate') {
14006: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14007: push(@{$changes->{'cancreate'}},'recaptchaversion');
14008: } elsif (!defined($changes->{'cancreate'})) {
14009: $changes->{'cancreate'} = ['recaptchaversion'];
14010: }
1.160.6.102 raeburn 14011: } elsif ($container eq 'passwords') {
14012: $changes->{'reset'} = 1;
1.160.6.69 raeburn 14013: } else {
14014: $changes->{'recaptchaversion'} = 1;
14015: }
14016: }
1.160.6.5 raeburn 14017: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
14018: if ($container eq 'cancreate') {
14019: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14020: push(@{$changes->{'cancreate'}},'recaptchakeys');
14021: } elsif (!defined($changes->{'cancreate'})) {
14022: $changes->{'cancreate'} = ['recaptchakeys'];
14023: }
1.160.6.102 raeburn 14024: } elsif ($container eq 'passwords') {
14025: $changes->{'reset'} = 1;
1.160.6.5 raeburn 14026: } else {
14027: $changes->{'recaptchakeys'} = 1;
14028: }
14029: }
14030: return;
14031: }
14032:
1.33 raeburn 14033: sub modify_usermodification {
14034: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 14035: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14036: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14037: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 14038: if ($key eq 'selfcreate') {
14039: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14040: } else {
14041: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14042: }
1.33 raeburn 14043: }
14044: }
1.160.6.34 raeburn 14045: my @contexts = ('author','course');
1.33 raeburn 14046: my %context_title = (
14047: author => 'In author context',
14048: course => 'In course context',
14049: );
14050: my @fields = ('lastname','firstname','middlename','generation',
14051: 'permanentemail','id');
14052: my %roles = (
14053: author => ['ca','aa'],
14054: course => ['st','ep','ta','in','cr'],
14055: );
14056: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14057: foreach my $context (@contexts) {
14058: foreach my $role (@{$roles{$context}}) {
14059: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14060: foreach my $item (@fields) {
14061: if (grep(/^\Q$item\E$/,@modifiable)) {
14062: $modifyhash{$context}{$role}{$item} = 1;
14063: } else {
14064: $modifyhash{$context}{$role}{$item} = 0;
14065: }
14066: }
14067: }
14068: if (ref($curr_usermodification{$context}) eq 'HASH') {
14069: foreach my $role (@{$roles{$context}}) {
14070: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14071: foreach my $field (@fields) {
14072: if ($modifyhash{$context}{$role}{$field} ne
14073: $curr_usermodification{$context}{$role}{$field}) {
14074: push(@{$changes{$context}},$role);
14075: last;
14076: }
14077: }
14078: }
14079: }
14080: } else {
14081: foreach my $context (@contexts) {
14082: foreach my $role (@{$roles{$context}}) {
14083: push(@{$changes{$context}},$role);
14084: }
14085: }
14086: }
14087: }
14088: my %usermodification_hash = (
14089: usermodification => \%modifyhash,
14090: );
14091: my $putresult = &Apache::lonnet::put_dom('configuration',
14092: \%usermodification_hash,$dom);
14093: if ($putresult eq 'ok') {
14094: if (keys(%changes) > 0) {
14095: $resulttext = &mt('Changes made: ').'<ul>';
14096: foreach my $context (@contexts) {
14097: if (ref($changes{$context}) eq 'ARRAY') {
14098: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14099: if (ref($changes{$context}) eq 'ARRAY') {
14100: foreach my $role (@{$changes{$context}}) {
14101: my $rolename;
1.160.6.34 raeburn 14102: if ($role eq 'cr') {
14103: $rolename = &mt('Custom');
1.33 raeburn 14104: } else {
1.160.6.34 raeburn 14105: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14106: }
14107: my @modifiable;
1.160.6.34 raeburn 14108: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14109: foreach my $field (@fields) {
14110: if ($modifyhash{$context}{$role}{$field}) {
14111: push(@modifiable,$fieldtitles{$field});
14112: }
14113: }
14114: if (@modifiable > 0) {
14115: $resulttext .= join(', ',@modifiable);
14116: } else {
14117: $resulttext .= &mt('none');
14118: }
14119: $resulttext .= '</li>';
14120: }
14121: $resulttext .= '</ul></li>';
14122: }
14123: }
14124: }
14125: $resulttext .= '</ul>';
14126: } else {
14127: $resulttext = &mt('No changes made to user modification settings');
14128: }
14129: } else {
14130: $resulttext = '<span class="LC_error">'.
14131: &mt('An error occurred: [_1]',$putresult).'</span>';
14132: }
14133: return $resulttext;
14134: }
14135:
1.43 raeburn 14136: sub modify_defaults {
1.160.6.27 raeburn 14137: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14138: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 14139: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 14140: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 14141: 'portal_def');
1.43 raeburn 14142: my @authtypes = ('internal','krb4','krb5','localauth');
14143: foreach my $item (@items) {
14144: $newvalues{$item} = $env{'form.'.$item};
14145: if ($item eq 'auth_def') {
14146: if ($newvalues{$item} ne '') {
14147: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14148: push(@errors,$item);
14149: }
14150: }
14151: } elsif ($item eq 'lang_def') {
14152: if ($newvalues{$item} ne '') {
14153: if ($newvalues{$item} =~ /^(\w+)/) {
14154: my $langcode = $1;
1.103 raeburn 14155: if ($langcode ne 'x_chef') {
14156: if (code2language($langcode) eq '') {
14157: push(@errors,$item);
14158: }
1.43 raeburn 14159: }
14160: } else {
14161: push(@errors,$item);
14162: }
14163: }
1.54 raeburn 14164: } elsif ($item eq 'timezone_def') {
14165: if ($newvalues{$item} ne '') {
1.62 raeburn 14166: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14167: push(@errors,$item);
14168: }
14169: }
1.68 raeburn 14170: } elsif ($item eq 'datelocale_def') {
14171: if ($newvalues{$item} ne '') {
14172: my @datelocale_ids = DateTime::Locale->ids();
14173: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14174: push(@errors,$item);
14175: }
14176: }
1.141 raeburn 14177: } elsif ($item eq 'portal_def') {
14178: if ($newvalues{$item} ne '') {
14179: 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])\/?$/) {
14180: push(@errors,$item);
14181: }
14182: }
1.43 raeburn 14183: }
14184: if (grep(/^\Q$item\E$/,@errors)) {
14185: $newvalues{$item} = $domdefaults{$item};
14186: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14187: $changes{$item} = 1;
14188: }
1.72 raeburn 14189: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14190: }
1.160.6.98 raeburn 14191: my %staticdefaults = (
14192: 'intauth_cost' => 10,
14193: 'intauth_check' => 0,
14194: 'intauth_switch' => 0,
14195: );
14196: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
14197: if (exists($domdefaults{$item})) {
14198: $newvalues{$item} = $domdefaults{$item};
14199: } else {
14200: $newvalues{$item} = $staticdefaults{$item};
14201: }
14202: }
1.43 raeburn 14203: my %defaults_hash = (
1.72 raeburn 14204: defaults => \%newvalues,
14205: );
1.43 raeburn 14206: my $title = &defaults_titles();
1.160.6.40 raeburn 14207:
14208: my $currinststatus;
14209: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14210: $currinststatus = $domconfig{'inststatus'};
14211: } else {
14212: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14213: $currinststatus = {
14214: inststatustypes => $usertypes,
14215: inststatusorder => $types,
14216: inststatusguest => [],
14217: };
14218: }
14219: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14220: my @allpos;
14221: my %alltypes;
1.160.6.93 raeburn 14222: my @inststatusguest;
14223: if (ref($currinststatus) eq 'HASH') {
14224: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14225: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14226: unless (grep(/^\Q$type\E$/,@todelete)) {
14227: push(@inststatusguest,$type);
14228: }
14229: }
14230: }
14231: }
14232: my ($currtitles,$currorder);
1.160.6.40 raeburn 14233: if (ref($currinststatus) eq 'HASH') {
14234: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14235: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14236: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14237: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14238: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14239: }
14240: }
14241: unless (grep(/^\Q$type\E$/,@todelete)) {
14242: my $position = $env{'form.inststatus_pos_'.$type};
14243: $position =~ s/\D+//g;
14244: $allpos[$position] = $type;
14245: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14246: $alltypes{$type} =~ s/`//g;
14247: }
14248: }
14249: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14250: $currtitles =~ s/,$//;
14251: }
14252: }
14253: if ($env{'form.addinststatus'}) {
14254: my $newtype = $env{'form.addinststatus'};
14255: $newtype =~ s/\W//g;
14256: unless (exists($alltypes{$newtype})) {
14257: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14258: $alltypes{$newtype} =~ s/`//g;
14259: my $position = $env{'form.addinststatus_pos'};
14260: $position =~ s/\D+//g;
14261: if ($position ne '') {
14262: $allpos[$position] = $newtype;
14263: }
14264: }
14265: }
1.160.6.93 raeburn 14266: my @orderedstatus;
1.160.6.40 raeburn 14267: foreach my $type (@allpos) {
14268: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14269: push(@orderedstatus,$type);
14270: }
14271: }
14272: foreach my $type (keys(%alltypes)) {
14273: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14274: delete($alltypes{$type});
14275: }
14276: }
14277: $defaults_hash{'inststatus'} = {
14278: inststatustypes => \%alltypes,
14279: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 14280: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 14281: };
14282: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14283: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14284: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14285: }
14286: }
14287: if ($currorder ne join(',',@orderedstatus)) {
14288: $changes{'inststatus'}{'inststatusorder'} = 1;
14289: }
14290: my $newtitles;
14291: foreach my $item (@orderedstatus) {
14292: $newtitles .= $alltypes{$item}.',';
14293: }
14294: $newtitles =~ s/,$//;
14295: if ($currtitles ne $newtitles) {
14296: $changes{'inststatus'}{'inststatustypes'} = 1;
14297: }
1.43 raeburn 14298: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14299: $dom);
14300: if ($putresult eq 'ok') {
14301: if (keys(%changes) > 0) {
14302: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 14303: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14304: 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";
14305: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 14306: if ($item eq 'inststatus') {
14307: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 14308: if (@orderedstatus) {
1.160.6.40 raeburn 14309: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14310: foreach my $type (@orderedstatus) {
14311: $resulttext .= $alltypes{$type}.', ';
14312: }
14313: $resulttext =~ s/, $//;
14314: $resulttext .= '</li>';
1.160.6.93 raeburn 14315: } else {
14316: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 14317: }
14318: }
14319: } else {
14320: my $value = $env{'form.'.$item};
14321: if ($value eq '') {
14322: $value = &mt('none');
14323: } elsif ($item eq 'auth_def') {
14324: my %authnames = &authtype_names();
14325: my %shortauth = (
14326: internal => 'int',
14327: krb4 => 'krb4',
14328: krb5 => 'krb5',
14329: localauth => 'loc',
14330: );
14331: $value = $authnames{$shortauth{$value}};
14332: }
14333: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14334: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14335: }
14336: }
14337: $resulttext .= '</ul>';
14338: $mailmsgtext .= "\n";
14339: my $cachetime = 24*60*60;
1.72 raeburn 14340: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 14341: if (ref($lastactref) eq 'HASH') {
14342: $lastactref->{'domdefaults'} = 1;
14343: }
1.68 raeburn 14344: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 14345: my $notify = 1;
14346: if (ref($domconfig{'contacts'}) eq 'HASH') {
14347: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14348: $notify = 0;
14349: }
14350: }
14351: if ($notify) {
14352: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14353: "LON-CAPA Domain Settings Change - $dom",
14354: $mailmsgtext);
14355: }
1.54 raeburn 14356: }
1.43 raeburn 14357: } else {
1.54 raeburn 14358: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14359: }
14360: } else {
14361: $resulttext = '<span class="LC_error">'.
14362: &mt('An error occurred: [_1]',$putresult).'</span>';
14363: }
14364: if (@errors > 0) {
14365: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14366: foreach my $item (@errors) {
14367: $resulttext .= ' "'.$title->{$item}.'",';
14368: }
14369: $resulttext =~ s/,$//;
14370: }
14371: return $resulttext;
14372: }
14373:
1.46 raeburn 14374: sub modify_scantron {
1.160.6.24 raeburn 14375: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14376: my ($resulttext,%confhash,%changes,$errors);
14377: my $custom = 'custom.tab';
14378: my $default = 'default.tab';
14379: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 14380: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 14381: &config_check($dom,$confname,$servadm);
14382: if ($env{'form.scantronformat.filename'} ne '') {
14383: my $error;
14384: if ($configuserok eq 'ok') {
14385: if ($switchserver) {
1.130 raeburn 14386: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14387: } else {
14388: if ($author_ok eq 'ok') {
14389: my ($result,$scantronurl) =
14390: &publishlogo($r,'upload','scantronformat',$dom,
14391: $confname,'scantron','','',$custom);
14392: if ($result eq 'ok') {
14393: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14394: $changes{'scantronformat'} = 1;
1.46 raeburn 14395: } else {
14396: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14397: }
14398: } else {
14399: $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);
14400: }
14401: }
14402: } else {
14403: $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);
14404: }
14405: if ($error) {
14406: &Apache::lonnet::logthis($error);
14407: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14408: }
14409: }
1.48 raeburn 14410: if (ref($domconfig{'scantron'}) eq 'HASH') {
14411: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14412: if ($env{'form.scantronformat_del'}) {
14413: $confhash{'scantron'}{'scantronformat'} = '';
14414: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 14415: } else {
14416: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
14417: }
14418: }
14419: }
14420: my @options = ('hdr','pad','rem');
14421: my @fields = &scantroncsv_fields();
14422: my %titles = &scantronconfig_titles();
14423: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
14424: my ($newdat,$currdat,%newcol,%currcol);
14425: if (grep(/^dat$/,@formats)) {
14426: $confhash{'scantron'}{config}{dat} = 1;
14427: $newdat = 1;
14428: } else {
14429: $newdat = 0;
14430: }
14431: if (grep(/^csv$/,@formats)) {
14432: my %bynum;
14433: foreach my $field (@fields) {
14434: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
14435: my $posscol = $1;
14436: if (($posscol < 20) && (!$bynum{$posscol})) {
14437: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
14438: $bynum{$posscol} = $field;
14439: $newcol{$field} = $posscol;
14440: }
14441: }
14442: }
14443: if (keys(%newcol)) {
14444: foreach my $option (@options) {
14445: if ($env{'form.scantroncsv_'.$option}) {
14446: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
14447: }
14448: }
14449: }
14450: }
14451: $currdat = 1;
14452: if (ref($domconfig{'scantron'}) eq 'HASH') {
14453: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
14454: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
14455: $currdat = 0;
14456: }
14457: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14458: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14459: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
14460: }
14461: }
14462: }
14463: }
14464: if ($currdat != $newdat) {
14465: $changes{'config'} = 1;
14466: } else {
14467: foreach my $field (@fields) {
14468: if ($currcol{$field} ne '') {
14469: if ($currcol{$field} ne $newcol{$field}) {
14470: $changes{'config'} = 1;
14471: last;
14472: }
14473: } elsif ($newcol{$field} ne '') {
14474: $changes{'config'} = 1;
14475: last;
1.46 raeburn 14476: }
14477: }
14478: }
14479: if (keys(%confhash) > 0) {
14480: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14481: $dom);
14482: if ($putresult eq 'ok') {
14483: if (keys(%changes) > 0) {
1.48 raeburn 14484: if (ref($confhash{'scantron'}) eq 'HASH') {
14485: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 14486: if ($changes{'scantronformat'}) {
14487: if ($confhash{'scantron'}{'scantronformat'} eq '') {
14488: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
14489: } else {
14490: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
14491: }
14492: }
14493: if ($changes{'config'}) {
14494: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
14495: if ($confhash{'scantron'}{'config'}{'dat'}) {
14496: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
14497: }
14498: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14499: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14500: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
14501: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
14502: foreach my $field (@fields) {
14503: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
14504: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
14505: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
14506: }
14507: }
14508: $resulttext .= '</ul></li>';
14509: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
14510: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
14511: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
14512: foreach my $option (@options) {
14513: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
14514: $resulttext .= '<li>'.$titles{$option}.'</li>';
14515: }
14516: }
14517: $resulttext .= '</ul></li>';
14518: }
14519: }
14520: }
14521: }
14522: }
14523: } else {
14524: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
14525: }
1.46 raeburn 14526: }
1.48 raeburn 14527: $resulttext .= '</ul>';
14528: } else {
1.130 raeburn 14529: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14530: }
14531: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14532: if (ref($lastactref) eq 'HASH') {
14533: $lastactref->{'domainconfig'} = 1;
14534: }
1.46 raeburn 14535: } else {
1.160.6.97 raeburn 14536: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 14537: }
14538: } else {
14539: $resulttext = '<span class="LC_error">'.
14540: &mt('An error occurred: [_1]',$putresult).'</span>';
14541: }
14542: } else {
1.160.6.97 raeburn 14543: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 14544: }
14545: if ($errors) {
14546: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14547: $errors.'</ul>';
14548: }
14549: return $resulttext;
14550: }
14551:
1.48 raeburn 14552: sub modify_coursecategories {
1.160.6.43 raeburn 14553: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14554: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14555: $cathash);
1.48 raeburn 14556: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 14557: my @catitems = ('unauth','auth');
14558: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14559: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14560: $cathash = $domconfig{'coursecategories'}{'cats'};
14561: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14562: $changes{'togglecats'} = 1;
14563: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14564: }
14565: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14566: $changes{'categorize'} = 1;
14567: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14568: }
1.120 raeburn 14569: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14570: $changes{'togglecatscomm'} = 1;
14571: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14572: }
14573: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14574: $changes{'categorizecomm'} = 1;
14575: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
14576: }
1.160.6.42 raeburn 14577: foreach my $item (@catitems) {
14578: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14579: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14580: $changes{$item} = 1;
14581: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14582: }
14583: }
14584: }
1.57 raeburn 14585: } else {
14586: $changes{'togglecats'} = 1;
14587: $changes{'categorize'} = 1;
1.124 raeburn 14588: $changes{'togglecatscomm'} = 1;
14589: $changes{'categorizecomm'} = 1;
1.87 raeburn 14590: $domconfig{'coursecategories'} = {
14591: togglecats => $env{'form.togglecats'},
14592: categorize => $env{'form.categorize'},
1.124 raeburn 14593: togglecatscomm => $env{'form.togglecatscomm'},
14594: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 14595: };
1.160.6.42 raeburn 14596: foreach my $item (@catitems) {
14597: if ($env{'form.coursecat_'.$item} ne 'std') {
14598: $changes{$item} = 1;
14599: }
14600: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14601: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14602: }
14603: }
1.57 raeburn 14604: }
14605: if (ref($cathash) eq 'HASH') {
14606: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14607: push (@deletecategory,'instcode::0');
14608: }
1.120 raeburn 14609: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14610: push(@deletecategory,'communities::0');
14611: }
1.48 raeburn 14612: }
1.57 raeburn 14613: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14614: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14615: if (@deletecategory > 0) {
14616: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14617: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14618: foreach my $item (@deletecategory) {
1.57 raeburn 14619: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14620: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14621: $deletions{$item} = 1;
1.57 raeburn 14622: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14623: }
14624: }
14625: }
1.57 raeburn 14626: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14627: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14628: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14629: $reorderings{$item} = 1;
1.57 raeburn 14630: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14631: }
14632: if ($env{'form.addcategory_name_'.$item} ne '') {
14633: my $newcat = $env{'form.addcategory_name_'.$item};
14634: my $newdepth = $depth+1;
14635: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14636: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14637: $adds{$newitem} = 1;
14638: }
14639: if ($env{'form.subcat_'.$item} ne '') {
14640: my $newcat = $env{'form.subcat_'.$item};
14641: my $newdepth = $depth+1;
14642: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14643: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14644: $adds{$newitem} = 1;
14645: }
14646: }
14647: }
14648: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14649: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14650: my $newitem = 'instcode::0';
1.57 raeburn 14651: if ($cathash->{$newitem} eq '') {
14652: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14653: $adds{$newitem} = 1;
14654: }
14655: } else {
14656: my $newitem = 'instcode::0';
1.57 raeburn 14657: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14658: $adds{$newitem} = 1;
14659: }
14660: }
1.120 raeburn 14661: if ($env{'form.communities'} eq '1') {
14662: if (ref($cathash) eq 'HASH') {
14663: my $newitem = 'communities::0';
14664: if ($cathash->{$newitem} eq '') {
14665: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14666: $adds{$newitem} = 1;
14667: }
14668: } else {
14669: my $newitem = 'communities::0';
14670: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14671: $adds{$newitem} = 1;
14672: }
14673: }
1.48 raeburn 14674: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14675: if (($env{'form.addcategory_name'} ne 'instcode') &&
14676: ($env{'form.addcategory_name'} ne 'communities')) {
14677: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14678: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14679: $adds{$newitem} = 1;
14680: }
1.48 raeburn 14681: }
1.57 raeburn 14682: my $putresult;
1.48 raeburn 14683: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14684: if (keys(%deletions) > 0) {
14685: foreach my $key (keys(%deletions)) {
14686: if ($predelallitems{$key} ne '') {
14687: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14688: }
14689: }
14690: }
14691: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14692: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14693: if (ref($chkcats[0]) eq 'ARRAY') {
14694: my $depth = 0;
14695: my $chg = 0;
14696: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14697: my $name = $chkcats[0][$i];
14698: my $item;
14699: if ($name eq '') {
14700: $chg ++;
14701: } else {
14702: $item = &escape($name).'::0';
14703: if ($chg) {
1.57 raeburn 14704: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14705: }
14706: $depth ++;
1.57 raeburn 14707: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14708: $depth --;
14709: }
14710: }
14711: }
1.57 raeburn 14712: }
14713: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14714: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14715: if ($putresult eq 'ok') {
1.57 raeburn 14716: my %title = (
1.120 raeburn 14717: togglecats => 'Show/Hide a course in catalog',
14718: categorize => 'Assign a category to a course',
14719: togglecatscomm => 'Show/Hide a community in catalog',
14720: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14721: );
14722: my %level = (
1.120 raeburn 14723: dom => 'set in Domain ("Modify Course/Community")',
14724: crs => 'set in Course ("Course Configuration")',
14725: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 14726: none => 'No catalog',
14727: std => 'Standard catalog',
14728: domonly => 'Domain-only catalog',
14729: codesrch => 'Code search form',
1.57 raeburn 14730: );
1.48 raeburn 14731: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14732: if ($changes{'togglecats'}) {
14733: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14734: }
14735: if ($changes{'categorize'}) {
14736: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14737: }
1.120 raeburn 14738: if ($changes{'togglecatscomm'}) {
14739: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14740: }
14741: if ($changes{'categorizecomm'}) {
14742: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14743: }
1.160.6.42 raeburn 14744: if ($changes{'unauth'}) {
14745: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14746: }
14747: if ($changes{'auth'}) {
14748: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14749: }
1.57 raeburn 14750: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14751: my $cathash;
14752: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14753: $cathash = $domconfig{'coursecategories'}{'cats'};
14754: } else {
14755: $cathash = {};
14756: }
14757: my (@cats,@trails,%allitems);
14758: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
14759: if (keys(%deletions) > 0) {
14760: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
14761: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
14762: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
14763: }
14764: $resulttext .= '</ul></li>';
14765: }
14766: if (keys(%reorderings) > 0) {
14767: my %sort_by_trail;
14768: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
14769: foreach my $key (keys(%reorderings)) {
14770: if ($allitems{$key} ne '') {
14771: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14772: }
1.48 raeburn 14773: }
1.57 raeburn 14774: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14775: $resulttext .= '<li>'.$trails[$trail].'</li>';
14776: }
14777: $resulttext .= '</ul></li>';
1.48 raeburn 14778: }
1.57 raeburn 14779: if (keys(%adds) > 0) {
14780: my %sort_by_trail;
14781: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
14782: foreach my $key (keys(%adds)) {
14783: if ($allitems{$key} ne '') {
14784: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14785: }
14786: }
14787: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14788: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 14789: }
1.57 raeburn 14790: $resulttext .= '</ul></li>';
1.48 raeburn 14791: }
1.160.6.92 raeburn 14792: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
14793: if (ref($lastactref) eq 'HASH') {
14794: $lastactref->{'cats'} = 1;
14795: }
1.48 raeburn 14796: }
14797: $resulttext .= '</ul>';
1.160.6.43 raeburn 14798: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 14799: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14800: if ($changes{'auth'}) {
14801: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
14802: }
14803: if ($changes{'unauth'}) {
14804: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
14805: }
14806: my $cachetime = 24*60*60;
14807: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 14808: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 14809: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 14810: }
14811: }
1.48 raeburn 14812: } else {
14813: $resulttext = '<span class="LC_error">'.
1.57 raeburn 14814: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 14815: }
14816: } else {
1.120 raeburn 14817: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 14818: }
14819: return $resulttext;
14820: }
14821:
1.69 raeburn 14822: sub modify_serverstatuses {
14823: my ($dom,%domconfig) = @_;
14824: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
14825: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
14826: %currserverstatus = %{$domconfig{'serverstatuses'}};
14827: }
14828: my @pages = &serverstatus_pages();
14829: foreach my $type (@pages) {
14830: $newserverstatus{$type}{'namedusers'} = '';
14831: $newserverstatus{$type}{'machines'} = '';
14832: if (defined($env{'form.'.$type.'_namedusers'})) {
14833: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
14834: my @okusers;
14835: foreach my $user (@users) {
14836: my ($uname,$udom) = split(/:/,$user);
14837: if (($udom =~ /^$match_domain$/) &&
14838: (&Apache::lonnet::domain($udom)) &&
14839: ($uname =~ /^$match_username$/)) {
14840: if (!grep(/^\Q$user\E/,@okusers)) {
14841: push(@okusers,$user);
14842: }
14843: }
14844: }
14845: if (@okusers > 0) {
14846: @okusers = sort(@okusers);
14847: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
14848: }
14849: }
14850: if (defined($env{'form.'.$type.'_machines'})) {
14851: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
14852: my @okmachines;
14853: foreach my $ip (@machines) {
14854: my @parts = split(/\./,$ip);
14855: next if (@parts < 4);
14856: my $badip = 0;
14857: for (my $i=0; $i<4; $i++) {
14858: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
14859: $badip = 1;
14860: last;
14861: }
14862: }
14863: if (!$badip) {
14864: push(@okmachines,$ip);
14865: }
14866: }
14867: @okmachines = sort(@okmachines);
14868: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
14869: }
14870: }
14871: my %serverstatushash = (
14872: serverstatuses => \%newserverstatus,
14873: );
14874: foreach my $type (@pages) {
1.83 raeburn 14875: foreach my $setting ('namedusers','machines') {
1.84 raeburn 14876: my (@current,@new);
1.83 raeburn 14877: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 14878: if ($currserverstatus{$type}{$setting} ne '') {
14879: @current = split(/,/,$currserverstatus{$type}{$setting});
14880: }
14881: }
14882: if ($newserverstatus{$type}{$setting} ne '') {
14883: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 14884: }
14885: if (@current > 0) {
14886: if (@new > 0) {
14887: foreach my $item (@current) {
14888: if (!grep(/^\Q$item\E$/,@new)) {
14889: $changes{$type}{$setting} = 1;
1.82 raeburn 14890: last;
14891: }
14892: }
1.84 raeburn 14893: foreach my $item (@new) {
14894: if (!grep(/^\Q$item\E$/,@current)) {
14895: $changes{$type}{$setting} = 1;
14896: last;
1.82 raeburn 14897: }
14898: }
14899: } else {
1.83 raeburn 14900: $changes{$type}{$setting} = 1;
1.69 raeburn 14901: }
1.83 raeburn 14902: } elsif (@new > 0) {
14903: $changes{$type}{$setting} = 1;
1.69 raeburn 14904: }
14905: }
14906: }
14907: if (keys(%changes) > 0) {
1.81 raeburn 14908: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 14909: my $putresult = &Apache::lonnet::put_dom('configuration',
14910: \%serverstatushash,$dom);
14911: if ($putresult eq 'ok') {
14912: $resulttext .= &mt('Changes made:').'<ul>';
14913: foreach my $type (@pages) {
1.84 raeburn 14914: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 14915: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 14916: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 14917: if ($newserverstatus{$type}{'namedusers'} eq '') {
14918: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
14919: } else {
14920: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
14921: }
1.84 raeburn 14922: }
14923: if ($changes{$type}{'machines'}) {
1.69 raeburn 14924: if ($newserverstatus{$type}{'machines'} eq '') {
14925: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
14926: } else {
14927: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
14928: }
14929:
14930: }
14931: $resulttext .= '</ul></li>';
14932: }
14933: }
14934: $resulttext .= '</ul>';
14935: } else {
14936: $resulttext = '<span class="LC_error">'.
14937: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
14938:
14939: }
14940: } else {
14941: $resulttext = &mt('No changes made to access to server status pages');
14942: }
14943: return $resulttext;
14944: }
14945:
1.118 jms 14946: sub modify_helpsettings {
1.160.6.77 raeburn 14947: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 14948: my ($resulttext,$errors,%changes,%helphash);
14949: my %defaultchecked = ('submitbugs' => 'on');
14950: my @offon = ('off','on');
1.118 jms 14951: my @toggles = ('submitbugs');
1.160.6.77 raeburn 14952: my %current = ('submitbugs' => '',
14953: 'adhoc' => {},
14954: );
1.118 jms 14955: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 14956: %current = %{$domconfig{'helpsettings'}};
14957: }
1.160.6.77 raeburn 14958: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 14959: foreach my $item (@toggles) {
14960: if ($defaultchecked{$item} eq 'on') {
14961: if ($current{$item} eq '') {
14962: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 14963: $changes{$item} = 1;
14964: }
1.160.6.73 raeburn 14965: } elsif ($current{$item} ne $env{'form.'.$item}) {
14966: $changes{$item} = 1;
14967: }
14968: } elsif ($defaultchecked{$item} eq 'off') {
14969: if ($current{$item} eq '') {
14970: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 14971: $changes{$item} = 1;
14972: }
1.160.6.73 raeburn 14973: } elsif ($current{$item} ne $env{'form.'.$item}) {
14974: $changes{$item} = 1;
14975: }
14976: }
14977: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
14978: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
14979: }
14980: }
1.160.6.77 raeburn 14981: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 14982: my $confname = $dom.'-domainconfig';
14983: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 14984: my (@allpos,%newsettings,%changedprivs,$newrole);
14985: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 14986: my @accesstypes = ('all','dh','da','none','status','inc','exc');
14987: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 14988: my %lt = &Apache::lonlocal::texthash(
14989: s => 'system',
14990: d => 'domain',
14991: order => 'Display order',
14992: access => 'Role usage',
1.160.6.79 raeburn 14993: all => 'All with domain helpdesk or helpdesk assistant role',
14994: dh => 'All with domain helpdesk role',
14995: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 14996: none => 'None',
14997: status => 'Determined based on institutional status',
14998: inc => 'Include all, but exclude specific personnel',
14999: exc => 'Exclude all, but include specific personnel',
15000: );
15001: for (my $num=0; $num<=$maxnum; $num++) {
15002: my ($prefix,$identifier,$rolename,%curr);
15003: if ($num == $maxnum) {
15004: next unless ($env{'form.newcusthelp'} == $maxnum);
15005: $identifier = 'custhelp'.$num;
15006: $prefix = 'helproles_'.$num;
15007: $rolename = $env{'form.custhelpname'.$num};
15008: $rolename=~s/[^A-Za-z0-9]//gs;
15009: next if ($rolename eq '');
15010: next if (exists($existing{'rolesdef_'.$rolename}));
15011: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15012: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15013: $newprivs{'c'},$confname,$dom);
15014: if ($result ne 'ok') {
15015: $errors .= '<li><span class="LC_error">'.
15016: &mt('An error occurred storing the new custom role: [_1]',
15017: $result).'</span></li>';
15018: next;
15019: } else {
15020: $changedprivs{$rolename} = \%newprivs;
15021: $newrole = $rolename;
15022: }
15023: } else {
15024: $prefix = 'helproles_'.$num;
15025: $rolename = $env{'form.'.$prefix};
15026: next if ($rolename eq '');
15027: next unless (exists($existing{'rolesdef_'.$rolename}));
15028: $identifier = 'custhelp'.$num;
15029: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15030: my %currprivs;
15031: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
15032: split(/\_/,$existing{'rolesdef_'.$rolename});
15033: foreach my $level ('c','d','s') {
15034: if ($newprivs{$level} ne $currprivs{$level}) {
15035: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15036: $newprivs{'c'},$confname,$dom);
15037: if ($result ne 'ok') {
15038: $errors .= '<li><span class="LC_error">'.
15039: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15040: $rolename,$result).'</span></li>';
15041: } else {
15042: $changedprivs{$rolename} = \%newprivs;
15043: }
15044: last;
15045: }
15046: }
15047: if (ref($current{'adhoc'}) eq 'HASH') {
15048: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15049: %curr = %{$current{'adhoc'}{$rolename}};
15050: }
15051: }
15052: }
15053: my $newpos = $env{'form.'.$prefix.'_pos'};
15054: $newpos =~ s/\D+//g;
15055: $allpos[$newpos] = $rolename;
15056: my $newdesc = $env{'form.'.$prefix.'_desc'};
15057: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15058: if ($curr{'desc'}) {
15059: if ($curr{'desc'} ne $newdesc) {
15060: $changes{'customrole'}{$rolename}{'desc'} = 1;
15061: $newsettings{$rolename}{'desc'} = $newdesc;
15062: }
15063: } elsif ($newdesc ne '') {
15064: $changes{'customrole'}{$rolename}{'desc'} = 1;
15065: $newsettings{$rolename}{'desc'} = $newdesc;
15066: }
15067: my $access = $env{'form.'.$prefix.'_access'};
15068: if (grep(/^\Q$access\E$/,@accesstypes)) {
15069: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15070: if ($access eq 'status') {
15071: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15072: if (scalar(@statuses) == 0) {
15073: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
15074: } else {
15075: my (@shownstatus,$numtypes);
15076: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15077: if (ref($types) eq 'ARRAY') {
15078: $numtypes = scalar(@{$types});
15079: foreach my $type (sort(@statuses)) {
15080: if ($type eq 'default') {
15081: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15082: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15083: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15084: push(@shownstatus,$usertypes->{$type});
15085: }
1.160.6.73 raeburn 15086: }
15087: }
1.160.6.77 raeburn 15088: if (grep(/^default$/,@statuses)) {
15089: push(@shownstatus,$othertitle);
15090: }
15091: if (scalar(@shownstatus) == 1+$numtypes) {
15092: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15093: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15094: } else {
15095: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15096: if (ref($curr{'status'}) eq 'ARRAY') {
15097: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15098: if (@diffs) {
15099: $changes{'customrole'}{$rolename}{$access} = 1;
15100: }
15101: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15102: $changes{'customrole'}{$rolename}{$access} = 1;
15103: }
15104: }
15105: }
15106: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15107: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15108: my @newspecstaff;
15109: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15110: foreach my $person (sort(@personnel)) {
15111: if ($domhelpdesk{$person}) {
15112: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15113: }
15114: }
15115: if (ref($curr{$access}) eq 'ARRAY') {
15116: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15117: if (@diffs) {
15118: $changes{'customrole'}{$rolename}{$access} = 1;
15119: }
15120: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15121: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 15122: }
1.160.6.77 raeburn 15123: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15124: my ($uname,$udom) = split(/:/,$person);
15125: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15126: }
15127: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 15128: }
1.160.6.77 raeburn 15129: } else {
15130: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15131: }
15132: unless ($curr{'access'} eq $access) {
15133: $changes{'customrole'}{$rolename}{'access'} = 1;
15134: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 15135: }
15136: }
1.160.6.77 raeburn 15137: if (@allpos > 0) {
15138: my $idx = 0;
15139: foreach my $rolename (@allpos) {
15140: if ($rolename ne '') {
15141: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15142: if (ref($current{'adhoc'}) eq 'HASH') {
15143: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15144: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15145: $changes{'customrole'}{$rolename}{'order'} = 1;
15146: $newsettings{$rolename}{'order'} = $idx+1;
15147: }
15148: }
1.160.6.73 raeburn 15149: }
1.160.6.77 raeburn 15150: $idx ++;
1.122 jms 15151: }
15152: }
1.118 jms 15153: }
1.123 jms 15154: my $putresult;
15155: if (keys(%changes) > 0) {
1.160.6.5 raeburn 15156: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
15157: if ($putresult eq 'ok') {
1.160.6.77 raeburn 15158: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15159: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15160: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15161: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15162: }
15163: }
15164: my $cachetime = 24*60*60;
15165: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15166: if (ref($lastactref) eq 'HASH') {
15167: $lastactref->{'domdefaults'} = 1;
15168: }
15169: } else {
15170: $errors .= '<li><span class="LC_error">'.
15171: &mt('An error occurred storing the settings: [_1]',
15172: $putresult).'</span></li>';
15173: }
15174: }
15175: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15176: $resulttext = &mt('Changes made:').'<ul>';
15177: my (%shownprivs,@levelorder);
15178: @levelorder = ('c','d','s');
15179: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 15180: foreach my $item (sort(keys(%changes))) {
15181: if ($item eq 'submitbugs') {
15182: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15183: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15184: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 15185: } elsif ($item eq 'customrole') {
15186: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 15187: my @keyorder = ('order','desc','access','status','exc','inc');
15188: my %keytext = &Apache::lonlocal::texthash(
15189: order => 'Order',
15190: desc => 'Role description',
15191: access => 'Role usage',
1.160.6.83 raeburn 15192: status => 'Allowed institutional types',
1.160.6.77 raeburn 15193: exc => 'Allowed personnel',
15194: inc => 'Disallowed personnel',
15195: );
1.160.6.73 raeburn 15196: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 15197: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15198: if ($role eq $newrole) {
15199: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15200: $role).'<ul>';
15201: } else {
15202: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15203: $role).'<ul>';
15204: }
15205: foreach my $key (@keyorder) {
15206: if ($changes{'customrole'}{$role}{$key}) {
15207: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15208: $keytext{$key},$newsettings{$role}{$key}).
15209: '</li>';
15210: }
15211: }
15212: if (ref($changedprivs{$role}) eq 'HASH') {
15213: $shownprivs{$role} = 1;
15214: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15215: foreach my $level (@levelorder) {
15216: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15217: next if ($item eq '');
15218: my ($priv) = split(/\&/,$item,2);
15219: if (&Apache::lonnet::plaintext($priv)) {
15220: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15221: unless ($level eq 'c') {
15222: $resulttext .= ' ('.$lt{$level}.')';
15223: }
15224: $resulttext .= '</li>';
15225: }
15226: }
15227: }
15228: $resulttext .= '</ul>';
15229: }
15230: $resulttext .= '</ul></li>';
15231: }
1.160.6.73 raeburn 15232: }
15233: }
1.160.6.5 raeburn 15234: }
15235: }
15236: }
1.160.6.77 raeburn 15237: if (keys(%changedprivs)) {
15238: foreach my $role (sort(keys(%changedprivs))) {
15239: unless ($shownprivs{$role}) {
15240: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15241: $role).'<ul>'.
15242: '<li>'.&mt('Privileges set to :').'<ul>';
15243: foreach my $level (@levelorder) {
15244: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15245: next if ($item eq '');
15246: my ($priv) = split(/\&/,$item,2);
15247: if (&Apache::lonnet::plaintext($priv)) {
15248: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15249: unless ($level eq 'c') {
15250: $resulttext .= ' ('.$lt{$level}.')';
15251: }
15252: $resulttext .= '</li>';
15253: }
15254: }
15255: }
15256: $resulttext .= '</ul></li></ul></li>';
15257: }
15258: }
15259: }
15260: $resulttext .= '</ul>';
15261: } else {
15262: $resulttext = &mt('No changes made to help settings');
1.118 jms 15263: }
15264: if ($errors) {
1.160.6.5 raeburn 15265: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 15266: $errors.'</ul>';
1.118 jms 15267: }
15268: return $resulttext;
15269: }
15270:
1.121 raeburn 15271: sub modify_coursedefaults {
1.160.6.27 raeburn 15272: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15273: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 15274: my %defaultchecked = (
15275: 'uselcmath' => 'on',
15276: 'usejsme' => 'on'
15277: );
15278: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 15279: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 15280: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
15281: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 15282: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 15283: my %staticdefaults = (
15284: anonsurvey_threshold => 10,
15285: uploadquota => 500,
1.160.6.57 raeburn 15286: postsubmit => 60,
1.160.6.70 raeburn 15287: mysqltables => 172800,
1.160.6.21 raeburn 15288: );
1.160.6.90 raeburn 15289: my %texoptions = (
15290: MathJax => 'MathJax',
15291: mimetex => &mt('Convert to Images'),
15292: tth => &mt('TeX to HTML'),
15293: );
1.121 raeburn 15294: $defaultshash{'coursedefaults'} = {};
15295:
15296: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15297: if ($domconfig{'coursedefaults'} eq '') {
15298: $domconfig{'coursedefaults'} = {};
15299: }
15300: }
15301:
15302: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15303: foreach my $item (@toggles) {
15304: if ($defaultchecked{$item} eq 'on') {
15305: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15306: ($env{'form.'.$item} eq '0')) {
15307: $changes{$item} = 1;
1.160.6.16 raeburn 15308: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15309: $changes{$item} = 1;
15310: }
15311: } elsif ($defaultchecked{$item} eq 'off') {
15312: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15313: ($env{'form.'.$item} eq '1')) {
15314: $changes{$item} = 1;
15315: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15316: $changes{$item} = 1;
15317: }
15318: }
15319: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15320: }
1.160.6.21 raeburn 15321: foreach my $item (@numbers) {
15322: my ($currdef,$newdef);
1.160.6.26 raeburn 15323: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 15324: if ($item eq 'anonsurvey_threshold') {
15325: $currdef = $domconfig{'coursedefaults'}{$item};
15326: $newdef =~ s/\D//g;
15327: if ($newdef eq '' || $newdef < 1) {
15328: $newdef = 1;
15329: }
15330: $defaultshash{'coursedefaults'}{$item} = $newdef;
15331: } else {
1.160.6.70 raeburn 15332: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15333: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15334: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 15335: }
15336: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 15337: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 15338: }
15339: if ($currdef ne $newdef) {
15340: if ($item eq 'anonsurvey_threshold') {
15341: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15342: $changes{$item} = 1;
15343: }
1.160.6.70 raeburn 15344: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
15345: my $setting = $1;
15346: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15347: $changes{$setting} = 1;
1.160.6.21 raeburn 15348: }
15349: }
1.139 raeburn 15350: }
15351: }
1.160.6.90 raeburn 15352: my $texengine;
15353: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15354: $texengine = $env{'form.texengine'};
15355: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
15356: if ($currdef eq '') {
15357: unless ($texengine eq $Apache::lonnet::deftex) {
15358: $changes{'texengine'} = 1;
15359: }
15360: } elsif ($currdef ne $texengine) {
15361: $changes{'texengine'} = 1;
15362: }
15363: }
15364: if ($texengine ne '') {
15365: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15366: }
1.160.6.64 raeburn 15367: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15368: my @currclonecode;
15369: if (ref($currclone) eq 'HASH') {
15370: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15371: @currclonecode = @{$currclone->{'instcode'}};
15372: }
15373: }
15374: my $newclone;
15375: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
15376: $newclone = $env{'form.canclone'};
15377: }
15378: if ($newclone eq 'instcode') {
15379: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15380: my (%codedefaults,@code_order,@clonecode);
15381: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15382: \@code_order);
15383: foreach my $item (@code_order) {
15384: if (grep(/^\Q$item\E$/,@newcodes)) {
15385: push(@clonecode,$item);
15386: }
15387: }
15388: if (@clonecode) {
15389: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15390: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15391: if (@diffs) {
15392: $changes{'canclone'} = 1;
15393: }
15394: } else {
15395: $newclone eq '';
15396: }
15397: } elsif ($newclone ne '') {
15398: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15399: }
15400: if ($newclone ne $currclone) {
15401: $changes{'canclone'} = 1;
15402: }
1.160.6.57 raeburn 15403: my %credits;
15404: foreach my $type (@types) {
15405: unless ($type eq 'community') {
15406: $credits{$type} = $env{'form.'.$type.'_credits'};
15407: $credits{$type} =~ s/[^\d.]+//g;
15408: }
15409: }
15410: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15411: ($env{'form.coursecredits'} eq '1')) {
15412: $changes{'coursecredits'} = 1;
15413: foreach my $type (keys(%credits)) {
15414: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15415: }
15416: } else {
15417: if ($env{'form.coursecredits'} eq '1') {
15418: foreach my $type (@types) {
15419: unless ($type eq 'community') {
15420: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
15421: $changes{'coursecredits'} = 1;
15422: }
15423: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15424: }
15425: }
15426: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15427: foreach my $type (@types) {
15428: unless ($type eq 'community') {
15429: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15430: $changes{'coursecredits'} = 1;
15431: last;
15432: }
15433: }
15434: }
15435: }
15436: }
15437: if ($env{'form.postsubmit'} eq '1') {
15438: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15439: my %currtimeout;
15440: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15441: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15442: $changes{'postsubmit'} = 1;
15443: }
15444: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15445: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15446: }
15447: } else {
15448: $changes{'postsubmit'} = 1;
15449: }
15450: foreach my $type (@types) {
15451: my $timeout = $env{'form.'.$type.'_timeout'};
15452: $timeout =~ s/\D//g;
15453: if ($timeout == $staticdefaults{'postsubmit'}) {
15454: $timeout = '';
15455: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15456: $timeout = '0';
15457: }
15458: unless ($timeout eq '') {
15459: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15460: }
15461: if (exists($currtimeout{$type})) {
15462: if ($timeout ne $currtimeout{$type}) {
15463: $changes{'postsubmit'} = 1;
15464: }
15465: } elsif ($timeout ne '') {
15466: $changes{'postsubmit'} = 1;
15467: }
15468: }
15469: } else {
15470: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15471: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15472: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15473: $changes{'postsubmit'} = 1;
15474: }
15475: } else {
15476: $changes{'postsubmit'} = 1;
15477: }
1.160.6.16 raeburn 15478: }
1.121 raeburn 15479: }
15480: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15481: $dom);
15482: if ($putresult eq 'ok') {
15483: if (keys(%changes) > 0) {
1.160.6.27 raeburn 15484: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 15485: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 15486: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.90 raeburn 15487: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15488: foreach my $item ('uselcmath','usejsme','texengine') {
1.160.6.57 raeburn 15489: if ($changes{$item}) {
15490: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15491: }
1.160.6.16 raeburn 15492: }
15493: if ($changes{'coursecredits'}) {
15494: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 15495: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15496: $domdefaults{$type.'credits'} =
15497: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15498: }
15499: }
15500: }
15501: if ($changes{'postsubmit'}) {
15502: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15503: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15504: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15505: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15506: $domdefaults{$type.'postsubtimeout'} =
15507: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15508: }
15509: }
1.160.6.16 raeburn 15510: }
15511: }
1.160.6.21 raeburn 15512: if ($changes{'uploadquota'}) {
15513: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15514: foreach my $type (@types) {
15515: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15516: }
15517: }
15518: }
1.160.6.64 raeburn 15519: if ($changes{'canclone'}) {
15520: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15521: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15522: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15523: if (@clonecodes) {
15524: $domdefaults{'canclone'} = join('+',@clonecodes);
15525: }
15526: }
15527: } else {
15528: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15529: }
15530: }
1.121 raeburn 15531: my $cachetime = 24*60*60;
15532: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 15533: if (ref($lastactref) eq 'HASH') {
15534: $lastactref->{'domdefaults'} = 1;
15535: }
1.121 raeburn 15536: }
15537: $resulttext = &mt('Changes made:').'<ul>';
15538: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 15539: if ($item eq 'uselcmath') {
1.121 raeburn 15540: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 15541: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 15542: } else {
1.160.6.57 raeburn 15543: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15544: }
15545: } elsif ($item eq 'usejsme') {
15546: if ($env{'form.'.$item} eq '1') {
15547: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15548: } else {
15549: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 15550: }
1.160.6.90 raeburn 15551: } elsif ($item eq 'texengine') {
15552: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15553: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15554: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15555: }
1.139 raeburn 15556: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 15557: $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 15558: } elsif ($item eq 'uploadquota') {
15559: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15560: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15561: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15562: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 15563: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
15564:
1.160.6.21 raeburn 15565: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15566: '</ul>'.
15567: '</li>';
15568: } else {
15569: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15570: }
1.160.6.70 raeburn 15571: } elsif ($item eq 'mysqltables') {
15572: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15573: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15574: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15575: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15576: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15577: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15578: '</ul>'.
15579: '</li>';
15580: } else {
15581: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15582: }
1.160.6.57 raeburn 15583: } elsif ($item eq 'postsubmit') {
15584: if ($domdefaults{'postsubmit'} eq 'off') {
15585: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15586: } else {
15587: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
15588: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15589: $resulttext .= &mt('durations:').'<ul>';
15590: foreach my $type (@types) {
15591: $resulttext .= '<li>';
15592: my $timeout;
15593: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15594: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15595: }
15596: my $display;
15597: if ($timeout eq '0') {
15598: $display = &mt('unlimited');
15599: } elsif ($timeout eq '') {
15600: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15601: } else {
15602: $display = &mt('[quant,_1,second]',$timeout);
15603: }
15604: if ($type eq 'community') {
15605: $resulttext .= &mt('Communities');
15606: } elsif ($type eq 'official') {
15607: $resulttext .= &mt('Official courses');
15608: } elsif ($type eq 'unofficial') {
15609: $resulttext .= &mt('Unofficial courses');
15610: } elsif ($type eq 'textbook') {
15611: $resulttext .= &mt('Textbook courses');
15612: }
15613: $resulttext .= ' -- '.$display.'</li>';
15614: }
15615: $resulttext .= '</ul>';
15616: }
15617: $resulttext .= '</li>';
15618: }
1.160.6.16 raeburn 15619: } elsif ($item eq 'coursecredits') {
15620: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15621: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 15622: ($domdefaults{'unofficialcredits'} eq '') &&
15623: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 15624: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15625: } else {
15626: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15627: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15628: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 15629: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 15630: '</ul>'.
15631: '</li>';
15632: }
15633: } else {
15634: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15635: }
1.160.6.64 raeburn 15636: } elsif ($item eq 'canclone') {
15637: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15638: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15639: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15640: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15641: }
15642: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15643: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15644: } else {
15645: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
15646: }
1.140 raeburn 15647: }
1.121 raeburn 15648: }
15649: $resulttext .= '</ul>';
15650: } else {
15651: $resulttext = &mt('No changes made to course defaults');
15652: }
15653: } else {
15654: $resulttext = '<span class="LC_error">'.
15655: &mt('An error occurred: [_1]',$putresult).'</span>';
15656: }
15657: return $resulttext;
15658: }
15659:
1.160.6.37 raeburn 15660: sub modify_selfenrollment {
15661: my ($dom,$lastactref,%domconfig) = @_;
15662: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
15663: my @types = ('official','unofficial','community','textbook');
15664: my %titles = &tool_titles();
15665: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15666: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
15667: $ordered{'default'} = ['types','registered','approval','limit'];
15668:
15669: my (%roles,%shown,%toplevel);
15670: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15671:
15672: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15673: if ($domconfig{'selfenrollment'} eq '') {
15674: $domconfig{'selfenrollment'} = {};
15675: }
15676: }
15677: %toplevel = (
15678: admin => 'Configuration Rights',
15679: default => 'Default settings',
15680: validation => 'Validation of self-enrollment requests',
15681: );
15682: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
15683:
15684: if (ref($ordered{'admin'}) eq 'ARRAY') {
15685: foreach my $item (@{$ordered{'admin'}}) {
15686: foreach my $type (@types) {
15687: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15688: $selfenrollhash{'admin'}{$type}{$item} = 1;
15689: } else {
15690: $selfenrollhash{'admin'}{$type}{$item} = 0;
15691: }
15692: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15693: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15694: if ($selfenrollhash{'admin'}{$type}{$item} ne
15695: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15696: push(@{$changes{'admin'}{$type}},$item);
15697: }
15698: } else {
15699: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15700: push(@{$changes{'admin'}{$type}},$item);
15701: }
15702: }
15703: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15704: push(@{$changes{'admin'}{$type}},$item);
15705: }
15706: }
15707: }
15708: }
15709:
15710: foreach my $item (@{$ordered{'default'}}) {
15711: foreach my $type (@types) {
15712: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15713: if ($item eq 'types') {
15714: unless (($value eq 'all') || ($value eq 'dom')) {
15715: $value = '';
15716: }
15717: } elsif ($item eq 'registered') {
15718: unless ($value eq '1') {
15719: $value = 0;
15720: }
15721: } elsif ($item eq 'approval') {
15722: unless ($value =~ /^[012]$/) {
15723: $value = 0;
15724: }
15725: } else {
15726: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15727: $value = 'none';
15728: }
15729: }
15730: $selfenrollhash{'default'}{$type}{$item} = $value;
15731: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15732: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15733: if ($selfenrollhash{'default'}{$type}{$item} ne
15734: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15735: push(@{$changes{'default'}{$type}},$item);
15736: }
15737: } else {
15738: push(@{$changes{'default'}{$type}},$item);
15739: }
15740: } else {
15741: push(@{$changes{'default'}{$type}},$item);
15742: }
15743: if ($item eq 'limit') {
15744: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15745: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15746: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15747: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15748: }
15749: } else {
15750: $selfenrollhash{'default'}{$type}{'cap'} = '';
15751: }
15752: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15753: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15754: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15755: push(@{$changes{'default'}{$type}},'cap');
15756: }
15757: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
15758: push(@{$changes{'default'}{$type}},'cap');
15759: }
15760: }
15761: }
15762: }
15763:
15764: foreach my $item (@{$itemsref}) {
15765: if ($item eq 'fields') {
15766: my @changed;
15767: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
15768: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
15769: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
15770: }
15771: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15772: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
15773: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
15774: $domconfig{'selfenrollment'}{'validation'}{$item});
15775: } else {
15776: @changed = @{$selfenrollhash{'validation'}{$item}};
15777: }
15778: } else {
15779: @changed = @{$selfenrollhash{'validation'}{$item}};
15780: }
15781: if (@changed) {
15782: if ($selfenrollhash{'validation'}{$item}) {
15783: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
15784: } else {
15785: $changes{'validation'}{$item} = &mt('None');
15786: }
15787: }
15788: } else {
15789: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
15790: if ($item eq 'markup') {
15791: if ($env{'form.selfenroll_validation_'.$item}) {
15792: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
15793: }
15794: }
15795: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15796: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
15797: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
15798: }
15799: }
15800: }
15801: }
15802:
15803: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
15804: $dom);
15805: if ($putresult eq 'ok') {
15806: if (keys(%changes) > 0) {
15807: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15808: $resulttext = &mt('Changes made:').'<ul>';
15809: foreach my $key ('admin','default','validation') {
15810: if (ref($changes{$key}) eq 'HASH') {
15811: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
15812: if ($key eq 'validation') {
15813: foreach my $item (@{$itemsref}) {
15814: if (exists($changes{$key}{$item})) {
15815: if ($item eq 'markup') {
15816: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15817: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
15818: } else {
15819: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15820: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
15821: }
15822: }
15823: }
15824: } else {
15825: foreach my $type (@types) {
15826: if ($type eq 'community') {
15827: $roles{'1'} = &mt('Community personnel');
15828: } else {
15829: $roles{'1'} = &mt('Course personnel');
15830: }
15831: if (ref($changes{$key}{$type}) eq 'ARRAY') {
15832: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15833: if ($key eq 'admin') {
15834: my @mgrdc = ();
15835: if (ref($ordered{$key}) eq 'ARRAY') {
15836: foreach my $item (@{$ordered{'admin'}}) {
15837: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15838: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
15839: push(@mgrdc,$item);
15840: }
15841: }
15842: }
15843: if (@mgrdc) {
15844: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
15845: } else {
15846: delete($domdefaults{$type.'selfenrolladmdc'});
15847: }
15848: }
15849: } else {
15850: if (ref($ordered{$key}) eq 'ARRAY') {
15851: foreach my $item (@{$ordered{$key}}) {
15852: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15853: $domdefaults{$type.'selfenroll'.$item} =
15854: $selfenrollhash{$key}{$type}{$item};
15855: }
15856: }
15857: }
15858: }
15859: }
15860: $resulttext .= '<li>'.$titles{$type}.'<ul>';
15861: foreach my $item (@{$ordered{$key}}) {
15862: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15863: $resulttext .= '<li>';
15864: if ($key eq 'admin') {
15865: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
15866: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
15867: } else {
15868: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
15869: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
15870: }
15871: $resulttext .= '</li>';
15872: }
15873: }
15874: $resulttext .= '</ul></li>';
15875: }
15876: }
15877: $resulttext .= '</ul></li>';
15878: }
15879: }
1.160.6.93 raeburn 15880: }
15881: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
15882: my $cachetime = 24*60*60;
15883: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15884: if (ref($lastactref) eq 'HASH') {
15885: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 15886: }
15887: }
15888: $resulttext .= '</ul>';
15889: } else {
15890: $resulttext = &mt('No changes made to self-enrollment settings');
15891: }
15892: } else {
15893: $resulttext = '<span class="LC_error">'.
15894: &mt('An error occurred: [_1]',$putresult).'</span>';
15895: }
15896: return $resulttext;
15897: }
15898:
1.137 raeburn 15899: sub modify_usersessions {
1.160.6.27 raeburn 15900: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 15901: my @hostingtypes = ('version','excludedomain','includedomain');
15902: my @offloadtypes = ('primary','default');
15903: my %types = (
15904: remote => \@hostingtypes,
15905: hosted => \@hostingtypes,
15906: spares => \@offloadtypes,
15907: );
15908: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 15909: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 15910: my (%by_ip,%by_location,@intdoms);
15911: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
15912: my @locations = sort(keys(%by_location));
1.137 raeburn 15913: my (%defaultshash,%changes);
15914: foreach my $prefix (@prefixes) {
15915: $defaultshash{'usersessions'}{$prefix} = {};
15916: }
1.160.6.27 raeburn 15917: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 15918: my $resulttext;
1.138 raeburn 15919: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 15920: foreach my $prefix (@prefixes) {
1.145 raeburn 15921: next if ($prefix eq 'spares');
15922: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 15923: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
15924: if ($type eq 'version') {
15925: my $value = $env{'form.'.$prefix.'_'.$type};
15926: my $okvalue;
15927: if ($value ne '') {
15928: if (grep(/^\Q$value\E$/,@lcversions)) {
15929: $okvalue = $value;
15930: }
15931: }
15932: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15933: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15934: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
15935: if ($inuse == 0) {
15936: $changes{$prefix}{$type} = 1;
15937: } else {
15938: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
15939: $changes{$prefix}{$type} = 1;
15940: }
15941: if ($okvalue ne '') {
15942: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15943: }
15944: }
15945: } else {
15946: if (($inuse == 1) && ($okvalue ne '')) {
15947: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15948: $changes{$prefix}{$type} = 1;
15949: }
15950: }
15951: } else {
15952: if (($inuse == 1) && ($okvalue ne '')) {
15953: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15954: $changes{$prefix}{$type} = 1;
15955: }
15956: }
15957: } else {
15958: if (($inuse == 1) && ($okvalue ne '')) {
15959: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15960: $changes{$prefix}{$type} = 1;
15961: }
15962: }
15963: } else {
15964: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
15965: my @okvals;
15966: foreach my $val (@vals) {
1.138 raeburn 15967: if ($val =~ /:/) {
15968: my @items = split(/:/,$val);
15969: foreach my $item (@items) {
15970: if (ref($by_location{$item}) eq 'ARRAY') {
15971: push(@okvals,$item);
15972: }
15973: }
15974: } else {
15975: if (ref($by_location{$val}) eq 'ARRAY') {
15976: push(@okvals,$val);
15977: }
1.137 raeburn 15978: }
15979: }
15980: @okvals = sort(@okvals);
15981: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15982: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15983: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
15984: if ($inuse == 0) {
15985: $changes{$prefix}{$type} = 1;
15986: } else {
15987: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15988: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
15989: if (@changed > 0) {
15990: $changes{$prefix}{$type} = 1;
15991: }
15992: }
15993: } else {
15994: if ($inuse == 1) {
15995: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15996: $changes{$prefix}{$type} = 1;
15997: }
15998: }
15999: } else {
16000: if ($inuse == 1) {
16001: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16002: $changes{$prefix}{$type} = 1;
16003: }
16004: }
16005: } else {
16006: if ($inuse == 1) {
16007: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16008: $changes{$prefix}{$type} = 1;
16009: }
16010: }
16011: }
16012: }
16013: }
1.145 raeburn 16014:
16015: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16016: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16017: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16018: my $savespares;
16019:
16020: foreach my $lonhost (sort(keys(%servers))) {
16021: my $serverhomeID =
16022: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16023: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16024: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16025: my %spareschg;
16026: foreach my $type (@{$types{'spares'}}) {
16027: my @okspares;
16028: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16029: foreach my $server (@checked) {
1.152 raeburn 16030: if (&Apache::lonnet::hostname($server) ne '') {
16031: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16032: unless (grep(/^\Q$server\E$/,@okspares)) {
16033: push(@okspares,$server);
16034: }
1.145 raeburn 16035: }
16036: }
16037: }
16038: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16039: my $newspare;
1.152 raeburn 16040: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16041: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16042: $newspare = $new;
16043: }
16044: }
1.152 raeburn 16045: my @spares;
16046: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16047: @spares = sort(@okspares,$newspare);
16048: } else {
16049: @spares = sort(@okspares);
16050: }
16051: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16052: if (ref($spareid{$lonhost}) eq 'HASH') {
16053: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16054: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16055: if (@diffs > 0) {
16056: $spareschg{$type} = 1;
16057: }
16058: }
16059: }
16060: }
16061: if (keys(%spareschg) > 0) {
16062: $changes{'spares'}{$lonhost} = \%spareschg;
16063: }
16064: }
1.160.6.61 raeburn 16065: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.102.2 4(raebur 16066:0): $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 16067: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16068: my @okoffload;
16069: if (@offloadnow) {
16070: foreach my $server (@offloadnow) {
16071: if (&Apache::lonnet::hostname($server) ne '') {
16072: unless (grep(/^\Q$server\E$/,@okoffload)) {
16073: push(@okoffload,$server);
16074: }
16075: }
16076: }
16077: if (@okoffload) {
16078: foreach my $lonhost (@okoffload) {
16079: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16080: }
16081: }
16082: }
1.160.6.102.2 4(raebur 16083:0): my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
16084:0): my @okoffloadoth;
16085:0): if (@offloadoth) {
16086:0): foreach my $server (@offloadoth) {
16087:0): if (&Apache::lonnet::hostname($server) ne '') {
16088:0): unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
16089:0): push(@okoffloadoth,$server);
16090:0): }
16091:0): }
16092:0): }
16093:0): if (@okoffloadoth) {
16094:0): foreach my $lonhost (@okoffloadoth) {
16095:0): $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
16096:0): }
16097:0): }
16098:0): }
1.145 raeburn 16099: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16100: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16101: if (ref($changes{'spares'}) eq 'HASH') {
16102: if (keys(%{$changes{'spares'}}) > 0) {
16103: $savespares = 1;
16104: }
16105: }
16106: } else {
16107: $savespares = 1;
16108: }
1.160.6.102.2 4(raebur 16109:0): foreach my $offload ('offloadnow','offloadoth') {
16110:0): if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
16111:0): foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
16112:0): unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
16113:0): $changes{$offload} = 1;
1.160.6.61 raeburn 16114: last;
16115: }
16116: }
1.160.6.102.2 4(raebur 16117:0): unless ($changes{$offload}) {
16118:0): foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
16119:0): unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
16120:0): $changes{$offload} = 1;
16121:0): last;
16122:0): }
16123:0): }
16124:0): }
16125:0): } else {
16126:0): if (($offload eq 'offloadnow') && (@okoffload)) {
16127:0): $changes{'offloadnow'} = 1;
16128:0): }
16129:0): if (($offload eq 'offloadoth') && (@okoffloadoth)) {
16130:0): $changes{'offloadoth'} = 1;
16131:0): }
1.160.6.61 raeburn 16132: }
1.160.6.102.2 4(raebur 16133:0): }
16134:0): } else {
16135:0): if (@okoffload) {
1.160.6.61 raeburn 16136: $changes{'offloadnow'} = 1;
16137: }
1.160.6.102.2 4(raebur 16138:0): if (@okoffloadoth) {
16139:0): $changes{'offloadoth'} = 1;
16140:0): }
1.145 raeburn 16141: }
1.147 raeburn 16142: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16143: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16144: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16145: $dom);
16146: if ($putresult eq 'ok') {
16147: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16148: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16149: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16150: }
16151: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16152: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16153: }
1.160.6.61 raeburn 16154: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16155: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16156: }
1.160.6.102.2 4(raebur 16157:0): if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
16158:0): $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
16159:0): }
1.137 raeburn 16160: }
16161: my $cachetime = 24*60*60;
16162: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 16163: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 16164: if (ref($lastactref) eq 'HASH') {
16165: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 16166: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 16167: }
1.147 raeburn 16168: if (keys(%changes) > 0) {
16169: my %lt = &usersession_titles();
16170: $resulttext = &mt('Changes made:').'<ul>';
16171: foreach my $prefix (@prefixes) {
16172: if (ref($changes{$prefix}) eq 'HASH') {
16173: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16174: if ($prefix eq 'spares') {
16175: if (ref($changes{$prefix}) eq 'HASH') {
16176: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16177: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16178: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 16179: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16180: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16181: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16182: foreach my $type (@{$types{$prefix}}) {
16183: if ($changes{$prefix}{$lonhost}{$type}) {
16184: my $offloadto = &mt('None');
16185: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16186: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16187: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16188: }
1.145 raeburn 16189: }
1.147 raeburn 16190: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16191: }
1.137 raeburn 16192: }
16193: }
1.147 raeburn 16194: $resulttext .= '</li>';
1.137 raeburn 16195: }
16196: }
1.147 raeburn 16197: } else {
16198: foreach my $type (@{$types{$prefix}}) {
16199: if (defined($changes{$prefix}{$type})) {
16200: my $newvalue;
16201: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16202: if (ref($defaultshash{'usersessions'}{$prefix})) {
16203: if ($type eq 'version') {
16204: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
16205: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16206: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16207: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16208: }
1.145 raeburn 16209: }
16210: }
16211: }
1.147 raeburn 16212: if ($newvalue eq '') {
16213: if ($type eq 'version') {
16214: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
16215: } else {
16216: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16217: }
1.145 raeburn 16218: } else {
1.147 raeburn 16219: if ($type eq 'version') {
16220: $newvalue .= ' '.&mt('(or later)');
16221: }
16222: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 16223: }
1.137 raeburn 16224: }
16225: }
16226: }
1.147 raeburn 16227: $resulttext .= '</ul>';
1.137 raeburn 16228: }
16229: }
1.160.6.61 raeburn 16230: if ($changes{'offloadnow'}) {
16231: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16232: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.102.2 4(raebur 16233:0): $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 16234: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
16235: $resulttext .= '<li>'.$lonhost.'</li>';
16236: }
16237: $resulttext .= '</ul>';
16238: } else {
1.160.6.102.2 4(raebur 16239:0): $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
16240:0): }
16241:0): } else {
16242:0): $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
16243:0): }
16244:0): }
16245:0): if ($changes{'offloadoth'}) {
16246:0): if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
16247:0): if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
16248:0): $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
16249:0): foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
16250:0): $resulttext .= '<li>'.$lonhost.'</li>';
16251:0): }
16252:0): $resulttext .= '</ul>';
16253:0): } else {
16254:0): $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 16255: }
16256: } else {
1.160.6.102.2 4(raebur 16257:0): $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 16258: }
16259: }
1.147 raeburn 16260: $resulttext .= '</ul>';
16261: } else {
16262: $resulttext = $nochgmsg;
1.137 raeburn 16263: }
16264: } else {
16265: $resulttext = '<span class="LC_error">'.
16266: &mt('An error occurred: [_1]',$putresult).'</span>';
16267: }
16268: } else {
1.147 raeburn 16269: $resulttext = $nochgmsg;
1.137 raeburn 16270: }
16271: return $resulttext;
16272: }
16273:
1.150 raeburn 16274: sub modify_loadbalancing {
16275: my ($dom,%domconfig) = @_;
16276: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16277: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16278: my ($othertitle,$usertypes,$types) =
16279: &Apache::loncommon::sorted_inst_types($dom);
16280: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 16281: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 16282: my @sparestypes = ('primary','default');
16283: my %typetitles = &sparestype_titles();
16284: my $resulttext;
1.160.6.94 raeburn 16285: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 16286: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16287: %existing = %{$domconfig{'loadbalancing'}};
16288: }
16289: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 16290: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 16291: my ($saveloadbalancing,%defaultshash,%changes);
16292: my ($alltypes,$othertypes,$titles) =
16293: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16294: my %ruletitles = &offloadtype_text();
16295: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16296: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16297: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16298: if ($balancer eq '') {
16299: next;
16300: }
16301: if (!exists($servers{$balancer})) {
16302: if (exists($currbalancer{$balancer})) {
16303: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 16304: }
1.160.6.7 raeburn 16305: next;
16306: }
16307: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16308: push(@{$changes{'delete'}},$balancer);
16309: next;
16310: }
16311: if (!exists($currbalancer{$balancer})) {
16312: push(@{$changes{'add'}},$balancer);
16313: }
16314: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16315: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16316: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16317: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16318: $saveloadbalancing = 1;
16319: }
16320: foreach my $sparetype (@sparestypes) {
16321: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16322: my @offloadto;
16323: foreach my $target (@targets) {
16324: if (($servers{$target}) && ($target ne $balancer)) {
16325: if ($sparetype eq 'default') {
16326: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16327: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 16328: }
16329: }
1.160.6.7 raeburn 16330: unless(grep(/^\Q$target\E$/,@offloadto)) {
16331: push(@offloadto,$target);
16332: }
1.150 raeburn 16333: }
16334: }
1.160.6.76 raeburn 16335: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16336: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16337: push(@offloadto,$balancer);
16338: }
16339: }
16340: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 16341: }
1.160.6.94 raeburn 16342: if ($env{'form.loadbalancing_cookie_'.$i}) {
16343: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
16344: if (exists($currbalancer{$balancer})) {
16345: unless ($currcookies{$balancer}) {
16346: $changes{'curr'}{$balancer}{'cookie'} = 1;
16347: }
16348: }
16349: } elsif (exists($currbalancer{$balancer})) {
16350: if ($currcookies{$balancer}) {
16351: $changes{'curr'}{$balancer}{'cookie'} = 1;
16352: }
16353: }
1.160.6.7 raeburn 16354: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 16355: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 16356: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16357: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 16358: if (@targetdiffs > 0) {
1.160.6.7 raeburn 16359: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16360: }
1.160.6.7 raeburn 16361: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16362: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16363: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16364: }
16365: }
16366: }
16367: } else {
1.160.6.7 raeburn 16368: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
16369: foreach my $sparetype (@sparestypes) {
16370: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16371: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16372: $changes{'curr'}{$balancer}{'targets'} = 1;
16373: }
1.150 raeburn 16374: }
16375: }
1.160.6.7 raeburn 16376: }
1.150 raeburn 16377: }
16378: my $ishomedom;
1.160.6.7 raeburn 16379: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16380: $ishomedom = 1;
1.150 raeburn 16381: }
16382: if (ref($alltypes) eq 'ARRAY') {
16383: foreach my $type (@{$alltypes}) {
16384: my $rule;
1.160.6.7 raeburn 16385: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 16386: (!$ishomedom)) {
1.160.6.7 raeburn 16387: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16388: }
16389: if ($rule eq 'specific') {
1.160.6.55 raeburn 16390: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
16391: if (exists($servers{$specifiedhost})) {
16392: $rule = $specifiedhost;
16393: }
1.150 raeburn 16394: }
1.160.6.7 raeburn 16395: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16396: if (ref($currrules{$balancer}) eq 'HASH') {
16397: if ($rule ne $currrules{$balancer}{$type}) {
16398: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16399: }
16400: } elsif ($rule ne '') {
1.160.6.7 raeburn 16401: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16402: }
16403: }
16404: }
1.160.6.7 raeburn 16405: }
16406: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
16407: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
16408: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
16409: $defaultshash{'loadbalancing'} = {};
16410: }
16411: my $putresult = &Apache::lonnet::put_dom('configuration',
16412: \%defaultshash,$dom);
16413: if ($putresult eq 'ok') {
16414: if (keys(%changes) > 0) {
1.160.6.54 raeburn 16415: my %toupdate;
1.160.6.7 raeburn 16416: if (ref($changes{'delete'}) eq 'ARRAY') {
16417: foreach my $balancer (sort(@{$changes{'delete'}})) {
16418: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 16419: $toupdate{$balancer} = 1;
1.150 raeburn 16420: }
1.160.6.7 raeburn 16421: }
16422: if (ref($changes{'add'}) eq 'ARRAY') {
16423: foreach my $balancer (sort(@{$changes{'add'}})) {
16424: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 16425: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 16426: }
16427: }
16428: if (ref($changes{'curr'}) eq 'HASH') {
16429: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 16430: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 16431: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
16432: if ($changes{'curr'}{$balancer}{'targets'}) {
16433: my %offloadstr;
16434: foreach my $sparetype (@sparestypes) {
16435: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16436: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16437: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16438: }
16439: }
1.150 raeburn 16440: }
1.160.6.7 raeburn 16441: if (keys(%offloadstr) == 0) {
16442: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 16443: } else {
1.160.6.7 raeburn 16444: my $showoffload;
16445: foreach my $sparetype (@sparestypes) {
16446: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
16447: if (defined($offloadstr{$sparetype})) {
16448: $showoffload .= $offloadstr{$sparetype};
16449: } else {
16450: $showoffload .= &mt('None');
16451: }
16452: $showoffload .= (' 'x3);
16453: }
16454: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 16455: }
16456: }
16457: }
1.160.6.7 raeburn 16458: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
16459: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
16460: foreach my $type (@{$alltypes}) {
16461: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
16462: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16463: my $balancetext;
16464: if ($rule eq '') {
16465: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 16466: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 16467: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
16468: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 16469: foreach my $sparetype (@sparestypes) {
16470: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16471: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16472: }
16473: }
1.160.6.55 raeburn 16474: foreach my $item (@{$alltypes}) {
16475: next if ($item =~ /^_LC_ipchange/);
16476: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
16477: if ($hasrule eq 'homeserver') {
16478: map { $toupdate{$_} = 1; } (keys(%libraryservers));
16479: } else {
16480: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
16481: if ($servers{$hasrule}) {
16482: $toupdate{$hasrule} = 1;
16483: }
16484: }
16485: }
16486: }
16487: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
16488: $balancetext = $ruletitles{$rule};
16489: } else {
16490: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16491: $balancetext = $ruletitles{'particular'}.' '.$receiver;
16492: if ($receiver) {
16493: $toupdate{$receiver};
16494: }
16495: }
16496: } else {
16497: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 16498: }
1.160.6.7 raeburn 16499: } else {
16500: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
16501: }
1.160.6.26 raeburn 16502: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 16503: }
16504: }
16505: }
16506: }
1.160.6.94 raeburn 16507: if ($changes{'curr'}{$balancer}{'cookie'}) {
16508: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
16509: $balancer).'</li>';
16510: }
1.160.6.102.2 6(raebur 16511:1): }
16512:1): }
16513:1): if (keys(%toupdate)) {
16514:1): my %thismachine;
16515:1): my $updatedhere;
16516:1): my $cachetime = 60*60*24;
16517:1): map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
16518:1): foreach my $lonhost (keys(%toupdate)) {
16519:1): if ($thismachine{$lonhost}) {
16520:1): unless ($updatedhere) {
16521:1): &Apache::lonnet::do_cache_new('loadbalancing',$dom,
16522:1): $defaultshash{'loadbalancing'},
16523:1): $cachetime);
16524:1): $updatedhere = 1;
1.160.6.54 raeburn 16525: }
1.160.6.102.2 6(raebur 16526:1): } else {
16527:1): my $cachekey = &escape('loadbalancing').':'.&escape($dom);
16528:1): &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 16529: }
1.150 raeburn 16530: }
1.160.6.7 raeburn 16531: }
16532: if ($resulttext ne '') {
16533: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 16534: } else {
16535: $resulttext = $nochgmsg;
16536: }
16537: } else {
1.160.6.7 raeburn 16538: $resulttext = $nochgmsg;
1.150 raeburn 16539: }
16540: } else {
1.160.6.7 raeburn 16541: $resulttext = '<span class="LC_error">'.
16542: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 16543: }
16544: } else {
1.160.6.7 raeburn 16545: $resulttext = $nochgmsg;
1.150 raeburn 16546: }
16547: return $resulttext;
16548: }
16549:
1.48 raeburn 16550: sub recurse_check {
16551: my ($chkcats,$categories,$depth,$name) = @_;
16552: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
16553: my $chg = 0;
16554: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
16555: my $category = $chkcats->[$depth]{$name}[$j];
16556: my $item;
16557: if ($category eq '') {
16558: $chg ++;
16559: } else {
16560: my $deeper = $depth + 1;
16561: $item = &escape($category).':'.&escape($name).':'.$depth;
16562: if ($chg) {
16563: $categories->{$item} -= $chg;
16564: }
16565: &recurse_check($chkcats,$categories,$deeper,$category);
16566: $deeper --;
16567: }
16568: }
16569: }
16570: return;
16571: }
16572:
16573: sub recurse_cat_deletes {
16574: my ($item,$coursecategories,$deletions) = @_;
16575: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16576: my $subdepth = $depth + 1;
16577: if (ref($coursecategories) eq 'HASH') {
16578: foreach my $subitem (keys(%{$coursecategories})) {
16579: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
16580: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
16581: delete($coursecategories->{$subitem});
16582: $deletions->{$subitem} = 1;
16583: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 16584: }
1.48 raeburn 16585: }
16586: }
16587: return;
16588: }
16589:
1.125 raeburn 16590: sub active_dc_picker {
1.160.6.16 raeburn 16591: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 16592: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 16593: my @domcoord = keys(%domcoords);
16594: if (keys(%currhash)) {
16595: foreach my $dc (keys(%currhash)) {
16596: unless (exists($domcoords{$dc})) {
16597: push(@domcoord,$dc);
16598: }
16599: }
16600: }
16601: @domcoord = sort(@domcoord);
16602: my $numdcs = scalar(@domcoord);
16603: my $rows = 0;
16604: my $table;
1.125 raeburn 16605: if ($numdcs > 1) {
1.160.6.16 raeburn 16606: $table = '<table>';
16607: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 16608: my $rem = $i%($numinrow);
16609: if ($rem == 0) {
16610: if ($i > 0) {
1.160.6.16 raeburn 16611: $table .= '</tr>';
1.125 raeburn 16612: }
1.160.6.16 raeburn 16613: $table .= '<tr>';
16614: $rows ++;
1.125 raeburn 16615: }
1.160.6.16 raeburn 16616: my $check = '';
16617: if ($inputtype eq 'radio') {
16618: if (keys(%currhash) == 0) {
16619: if (!$i) {
16620: $check = ' checked="checked"';
16621: }
16622: } elsif (exists($currhash{$domcoord[$i]})) {
16623: $check = ' checked="checked"';
16624: }
16625: } else {
16626: if (exists($currhash{$domcoord[$i]})) {
16627: $check = ' checked="checked"';
1.125 raeburn 16628: }
16629: }
1.160.6.16 raeburn 16630: if ($i == @domcoord - 1) {
1.125 raeburn 16631: my $colsleft = $numinrow - $rem;
16632: if ($colsleft > 1) {
1.160.6.16 raeburn 16633: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 16634: } else {
1.160.6.16 raeburn 16635: $table .= '<td class="LC_left_item">';
1.125 raeburn 16636: }
16637: } else {
1.160.6.16 raeburn 16638: $table .= '<td class="LC_left_item">';
16639: }
16640: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
16641: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
16642: $table .= '<span class="LC_nobreak"><label>'.
16643: '<input type="'.$inputtype.'" name="'.$name.'"'.
16644: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
16645: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 16646: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 16647: }
1.160.6.33 raeburn 16648: $table .= '</label></span></td>';
1.125 raeburn 16649: }
1.160.6.16 raeburn 16650: $table .= '</tr></table>';
16651: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 16652: my ($dcname,$dcdom) = split(':',$domcoord[0]);
16653: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 16654: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 16655: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 16656: if ($user ne $dcname.':'.$dcdom) {
16657: $table .= ' ('.$dcname.':'.$dcdom.')';
16658: }
1.160.6.16 raeburn 16659: } else {
16660: my $check;
16661: if (exists($currhash{$domcoord[0]})) {
16662: $check = ' checked="checked"';
16663: }
1.160.6.50 raeburn 16664: $table = '<span class="LC_nobreak"><label>'.
16665: '<input type="checkbox" name="'.$name.'" '.
16666: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 16667: if ($user ne $dcname.':'.$dcdom) {
16668: $table .= ' ('.$dcname.':'.$dcdom.')';
16669: }
16670: $table .= '</label></span>';
1.160.6.16 raeburn 16671: $rows ++;
16672: }
1.125 raeburn 16673: }
1.160.6.16 raeburn 16674: return ($numdcs,$table,$rows);
1.125 raeburn 16675: }
16676:
1.137 raeburn 16677: sub usersession_titles {
16678: return &Apache::lonlocal::texthash(
16679: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
16680: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 16681: spares => 'Servers offloaded to, when busy',
1.137 raeburn 16682: version => 'LON-CAPA version requirement',
1.138 raeburn 16683: excludedomain => 'Allow all, but exclude specific domains',
16684: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 16685: primary => 'Primary (checked first)',
1.154 raeburn 16686: default => 'Default',
1.137 raeburn 16687: );
16688: }
16689:
1.152 raeburn 16690: sub id_for_thisdom {
16691: my (%servers) = @_;
16692: my %altids;
16693: foreach my $server (keys(%servers)) {
16694: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
16695: if ($serverhome ne $server) {
16696: $altids{$serverhome} = $server;
16697: }
16698: }
16699: return %altids;
16700: }
16701:
1.150 raeburn 16702: sub count_servers {
16703: my ($currbalancer,%servers) = @_;
16704: my (@spares,$numspares);
16705: foreach my $lonhost (sort(keys(%servers))) {
16706: next if ($currbalancer eq $lonhost);
16707: push(@spares,$lonhost);
16708: }
16709: if ($currbalancer) {
16710: $numspares = scalar(@spares);
16711: } else {
16712: $numspares = scalar(@spares) - 1;
16713: }
16714: return ($numspares,@spares);
16715: }
16716:
16717: sub lonbalance_targets_js {
1.160.6.7 raeburn 16718: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 16719: my $select = &mt('Select');
16720: my ($alltargets,$allishome,$allinsttypes,@alltypes);
16721: if (ref($servers) eq 'HASH') {
16722: $alltargets = join("','",sort(keys(%{$servers})));
16723: my @homedoms;
16724: foreach my $server (sort(keys(%{$servers}))) {
16725: if (&Apache::lonnet::host_domain($server) eq $dom) {
16726: push(@homedoms,'1');
16727: } else {
16728: push(@homedoms,'0');
16729: }
16730: }
16731: $allishome = join("','",@homedoms);
16732: }
16733: if (ref($types) eq 'ARRAY') {
16734: if (@{$types} > 0) {
16735: @alltypes = @{$types};
16736: }
16737: }
16738: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
16739: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 16740: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 16741: if (ref($settings) eq 'HASH') {
16742: %existing = %{$settings};
16743: }
16744: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 16745: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 16746: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 16747: return <<"END";
16748:
16749: <script type="text/javascript">
16750: // <![CDATA[
16751:
1.160.6.7 raeburn 16752: currBalancers = new Array('$balancers');
16753:
16754: function toggleTargets(balnum) {
16755: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
16756: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
16757: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
16758: var prevbalancer = prevhostitem.value;
16759: var baltotal = document.getElementById('loadbalancing_total').value;
16760: prevhostitem.value = balancer;
16761: if (prevbalancer != '') {
16762: var prevIdx = currBalancers.indexOf(prevbalancer);
16763: if (prevIdx != -1) {
16764: currBalancers.splice(prevIdx,1);
16765: }
16766: }
1.150 raeburn 16767: if (balancer == '') {
1.160.6.7 raeburn 16768: hideSpares(balnum);
1.150 raeburn 16769: } else {
1.160.6.7 raeburn 16770: var currIdx = currBalancers.indexOf(balancer);
16771: if (currIdx == -1) {
16772: currBalancers.push(balancer);
16773: }
1.150 raeburn 16774: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 16775: var ishomedom = homedoms[lonhostitem.selectedIndex];
16776: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 16777: }
1.160.6.7 raeburn 16778: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 16779: return;
16780: }
16781:
1.160.6.7 raeburn 16782: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 16783: var alltargets = new Array('$alltargets');
16784: var insttypes = new Array('$allinsttypes');
1.151 raeburn 16785: var offloadtypes = new Array('primary','default');
16786:
1.160.6.7 raeburn 16787: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
16788: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 16789:
1.151 raeburn 16790: for (var i=0; i<offloadtypes.length; i++) {
16791: var count = 0;
16792: for (var j=0; j<alltargets.length; j++) {
16793: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 16794: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
16795: item.value = alltargets[j];
16796: item.style.textAlign='left';
16797: item.style.textFace='normal';
16798: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
16799: if (currBalancers.indexOf(alltargets[j]) == -1) {
16800: item.disabled = '';
16801: } else {
16802: item.disabled = 'disabled';
16803: item.checked = false;
16804: }
1.151 raeburn 16805: count ++;
16806: }
1.150 raeburn 16807: }
16808: }
1.151 raeburn 16809: for (var k=0; k<insttypes.length; k++) {
16810: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 16811: if (ishomedom == 1) {
1.160.6.7 raeburn 16812: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
16813: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 16814: } else {
1.160.6.7 raeburn 16815: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
16816: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 16817: }
16818: } else {
1.160.6.7 raeburn 16819: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
16820: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 16821: }
1.151 raeburn 16822: if ((insttypes[k] != '_LC_external') &&
16823: ((insttypes[k] != '_LC_internetdom') ||
16824: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 16825: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
16826: item.options.length = 0;
16827: item.options[0] = new Option("","",true,true);
16828: var idx = 0;
1.151 raeburn 16829: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 16830: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
16831: idx ++;
16832: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 16833: }
16834: }
16835: }
16836: }
16837: return;
16838: }
16839:
1.160.6.7 raeburn 16840: function hideSpares(balnum) {
1.150 raeburn 16841: var alltargets = new Array('$alltargets');
16842: var insttypes = new Array('$allinsttypes');
16843: var offloadtypes = new Array('primary','default');
16844:
1.160.6.7 raeburn 16845: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
16846: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 16847:
16848: var total = alltargets.length - 1;
16849: for (var i=0; i<offloadtypes; i++) {
16850: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 16851: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
16852: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
16853: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 16854: }
1.150 raeburn 16855: }
16856: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 16857: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
16858: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 16859: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 16860: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
16861: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 16862: }
16863: }
16864: return;
16865: }
16866:
1.160.6.7 raeburn 16867: function checkOffloads(item,balnum,type) {
1.150 raeburn 16868: var alltargets = new Array('$alltargets');
16869: var offloadtypes = new Array('primary','default');
16870: if (item.checked) {
16871: var total = alltargets.length - 1;
16872: var other;
16873: if (type == offloadtypes[0]) {
1.151 raeburn 16874: other = offloadtypes[1];
1.150 raeburn 16875: } else {
1.151 raeburn 16876: other = offloadtypes[0];
1.150 raeburn 16877: }
16878: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 16879: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 16880: if (server == item.value) {
1.160.6.7 raeburn 16881: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
16882: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 16883: }
16884: }
16885: }
16886: }
16887: return;
16888: }
16889:
1.160.6.7 raeburn 16890: function singleServerToggle(balnum,type) {
16891: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 16892: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 16893: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
16894: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 16895:
16896: } else {
1.160.6.7 raeburn 16897: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
16898: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 16899: }
16900: return;
16901: }
16902:
1.160.6.7 raeburn 16903: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 16904: if (type == '_LC_external') {
1.160.6.26 raeburn 16905: return;
1.150 raeburn 16906: }
1.160.6.7 raeburn 16907: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 16908: for (var i=0; i<typesRules.length; i++) {
16909: if (formname.elements[typesRules[i]].checked) {
16910: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 16911: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
16912: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 16913: } else {
1.160.6.7 raeburn 16914: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
16915: }
16916: }
16917: }
16918: return;
16919: }
16920:
16921: function balancerDeleteChange(balnum) {
16922: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
16923: var baltotal = document.getElementById('loadbalancing_total').value;
16924: var addtarget;
16925: var removetarget;
16926: var action = 'delete';
16927: if (document.getElementById('loadbalancing_delete_'+balnum)) {
16928: var lonhost = hostitem.value;
16929: var currIdx = currBalancers.indexOf(lonhost);
16930: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
16931: if (currIdx != -1) {
16932: currBalancers.splice(currIdx,1);
16933: }
16934: addtarget = lonhost;
16935: } else {
16936: if (currIdx == -1) {
16937: currBalancers.push(lonhost);
16938: }
16939: removetarget = lonhost;
16940: action = 'undelete';
16941: }
16942: balancerChange(balnum,baltotal,action,addtarget,removetarget);
16943: }
16944: return;
16945: }
16946:
16947: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
16948: if (baltotal > 1) {
16949: var offloadtypes = new Array('primary','default');
16950: var alltargets = new Array('$alltargets');
16951: var insttypes = new Array('$allinsttypes');
16952: for (var i=0; i<baltotal; i++) {
16953: if (i != balnum) {
16954: for (var j=0; j<offloadtypes.length; j++) {
16955: var total = alltargets.length - 1;
16956: for (var k=0; k<total; k++) {
16957: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
16958: var server = serveritem.value;
16959: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16960: if (server == addtarget) {
16961: serveritem.disabled = '';
16962: }
16963: }
16964: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16965: if (server == removetarget) {
16966: serveritem.disabled = 'disabled';
16967: serveritem.checked = false;
16968: }
16969: }
16970: }
16971: }
16972: for (var j=0; j<insttypes.length; j++) {
16973: if (insttypes[j] != '_LC_external') {
16974: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
16975: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
16976: var currSel = singleserver.selectedIndex;
16977: var currVal = singleserver.options[currSel].value;
16978: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16979: var numoptions = singleserver.options.length;
16980: var needsnew = 1;
16981: for (var k=0; k<numoptions; k++) {
16982: if (singleserver.options[k] == addtarget) {
16983: needsnew = 0;
16984: break;
16985: }
16986: }
16987: if (needsnew == 1) {
16988: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
16989: }
16990: }
16991: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16992: singleserver.options.length = 0;
16993: if ((currVal) && (currVal != removetarget)) {
16994: singleserver.options[0] = new Option("","",false,false);
16995: } else {
16996: singleserver.options[0] = new Option("","",true,true);
16997: }
16998: var idx = 0;
16999: for (var m=0; m<alltargets.length; m++) {
17000: if (currBalancers.indexOf(alltargets[m]) == -1) {
17001: idx ++;
17002: if (currVal == alltargets[m]) {
17003: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17004: } else {
17005: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17006: }
17007: }
17008: }
17009: }
17010: }
17011: }
17012: }
1.150 raeburn 17013: }
17014: }
17015: }
17016: return;
17017: }
17018:
1.152 raeburn 17019: // ]]>
17020: </script>
17021:
17022: END
17023: }
17024:
17025: sub new_spares_js {
17026: my @sparestypes = ('primary','default');
17027: my $types = join("','",@sparestypes);
17028: my $select = &mt('Select');
17029: return <<"END";
17030:
17031: <script type="text/javascript">
17032: // <![CDATA[
17033:
17034: function updateNewSpares(formname,lonhost) {
17035: var types = new Array('$types');
17036: var include = new Array();
17037: var exclude = new Array();
17038: for (var i=0; i<types.length; i++) {
17039: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17040: for (var j=0; j<spareboxes.length; j++) {
17041: if (formname.elements[spareboxes[j]].checked) {
17042: exclude.push(formname.elements[spareboxes[j]].value);
17043: } else {
17044: include.push(formname.elements[spareboxes[j]].value);
17045: }
17046: }
17047: }
17048: for (var i=0; i<types.length; i++) {
17049: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17050: var selIdx = newSpare.selectedIndex;
17051: var currnew = newSpare.options[selIdx].value;
17052: var okSpares = new Array();
17053: for (var j=0; j<newSpare.options.length; j++) {
17054: var possible = newSpare.options[j].value;
17055: if (possible != '') {
17056: if (exclude.indexOf(possible) == -1) {
17057: okSpares.push(possible);
17058: } else {
17059: if (currnew == possible) {
17060: selIdx = 0;
17061: }
17062: }
17063: }
17064: }
17065: for (var k=0; k<include.length; k++) {
17066: if (okSpares.indexOf(include[k]) == -1) {
17067: okSpares.push(include[k]);
17068: }
17069: }
17070: okSpares.sort();
17071: newSpare.options.length = 0;
17072: if (selIdx == 0) {
17073: newSpare.options[0] = new Option("$select","",true,true);
17074: } else {
17075: newSpare.options[0] = new Option("$select","",false,false);
17076: }
17077: for (var m=0; m<okSpares.length; m++) {
17078: var idx = m+1;
17079: var selThis = 0;
17080: if (selIdx != 0) {
17081: if (okSpares[m] == currnew) {
17082: selThis = 1;
17083: }
17084: }
17085: if (selThis == 1) {
17086: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17087: } else {
17088: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17089: }
17090: }
17091: }
17092: return;
17093: }
17094:
17095: function checkNewSpares(lonhost,type) {
17096: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17097: var chosen = newSpare.options[newSpare.selectedIndex].value;
17098: if (chosen != '') {
17099: var othertype;
17100: var othernewSpare;
17101: if (type == 'primary') {
17102: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17103: }
17104: if (type == 'default') {
17105: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17106: }
17107: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17108: othernewSpare.selectedIndex = 0;
17109: }
17110: }
17111: return;
17112: }
17113:
17114: // ]]>
17115: </script>
17116:
17117: END
17118:
17119: }
17120:
17121: sub common_domprefs_js {
17122: return <<"END";
17123:
17124: <script type="text/javascript">
17125: // <![CDATA[
17126:
1.150 raeburn 17127: function getIndicesByName(formname,item) {
1.152 raeburn 17128: var group = new Array();
1.150 raeburn 17129: for (var i=0;i<formname.elements.length;i++) {
17130: if (formname.elements[i].name == item) {
1.152 raeburn 17131: group.push(formname.elements[i].id);
1.150 raeburn 17132: }
17133: }
1.152 raeburn 17134: return group;
1.150 raeburn 17135: }
17136:
17137: // ]]>
17138: </script>
17139:
17140: END
1.152 raeburn 17141:
1.150 raeburn 17142: }
17143:
1.160.6.5 raeburn 17144: sub recaptcha_js {
17145: my %lt = &captcha_phrases();
17146: return <<"END";
17147:
17148: <script type="text/javascript">
17149: // <![CDATA[
17150:
17151: function updateCaptcha(caller,context) {
17152: var privitem;
17153: var pubitem;
17154: var privtext;
17155: var pubtext;
1.160.6.69 raeburn 17156: var versionitem;
17157: var versiontext;
1.160.6.5 raeburn 17158: if (document.getElementById(context+'_recaptchapub')) {
17159: pubitem = document.getElementById(context+'_recaptchapub');
17160: } else {
17161: return;
17162: }
17163: if (document.getElementById(context+'_recaptchapriv')) {
17164: privitem = document.getElementById(context+'_recaptchapriv');
17165: } else {
17166: return;
17167: }
17168: if (document.getElementById(context+'_recaptchapubtxt')) {
17169: pubtext = document.getElementById(context+'_recaptchapubtxt');
17170: } else {
17171: return;
17172: }
17173: if (document.getElementById(context+'_recaptchaprivtxt')) {
17174: privtext = document.getElementById(context+'_recaptchaprivtxt');
17175: } else {
17176: return;
17177: }
1.160.6.69 raeburn 17178: if (document.getElementById(context+'_recaptchaversion')) {
17179: versionitem = document.getElementById(context+'_recaptchaversion');
17180: } else {
17181: return;
17182: }
17183: if (document.getElementById(context+'_recaptchavertxt')) {
17184: versiontext = document.getElementById(context+'_recaptchavertxt');
17185: } else {
17186: return;
17187: }
1.160.6.5 raeburn 17188: if (caller.checked) {
17189: if (caller.value == 'recaptcha') {
17190: pubitem.type = 'text';
17191: privitem.type = 'text';
17192: pubitem.size = '40';
17193: privitem.size = '40';
17194: pubtext.innerHTML = "$lt{'pub'}";
17195: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 17196: versionitem.type = 'text';
17197: versionitem.size = '3';
17198: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 17199: } else {
17200: pubitem.type = 'hidden';
17201: privitem.type = 'hidden';
1.160.6.69 raeburn 17202: versionitem.type = 'hidden';
1.160.6.5 raeburn 17203: pubtext.innerHTML = '';
17204: privtext.innerHTML = '';
1.160.6.69 raeburn 17205: versiontext.innerHTML = '';
1.160.6.5 raeburn 17206: }
17207: }
17208: return;
17209: }
17210:
17211: // ]]>
17212: </script>
17213:
17214: END
17215:
17216: }
17217:
1.160.6.40 raeburn 17218: sub toggle_display_js {
1.160.6.16 raeburn 17219: return <<"END";
17220:
17221: <script type="text/javascript">
17222: // <![CDATA[
17223:
1.160.6.40 raeburn 17224: function toggleDisplay(domForm,caller) {
17225: if (document.getElementById(caller)) {
17226: var divitem = document.getElementById(caller);
17227: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 17228: var checkval = 1;
17229: var dispval = 'block';
1.160.6.93 raeburn 17230: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 17231: if (caller == 'emailoptions') {
17232: optionsElement = domForm.cancreate_email;
17233: }
1.160.6.57 raeburn 17234: if (caller == 'studentsubmission') {
17235: optionsElement = domForm.postsubmit;
17236: }
1.160.6.64 raeburn 17237: if (caller == 'cloneinstcode') {
17238: optionsElement = domForm.canclone;
17239: checkval = 'instcode';
17240: }
1.160.6.93 raeburn 17241: if (selfcreateRegExp.test(caller)) {
17242: optionsElement = domForm.elements[caller];
17243: checkval = 'other';
17244: dispval = 'inline'
17245: }
1.160.6.40 raeburn 17246: if (optionsElement.length) {
1.160.6.16 raeburn 17247: var currval;
1.160.6.40 raeburn 17248: for (var i=0; i<optionsElement.length; i++) {
17249: if (optionsElement[i].checked) {
17250: currval = optionsElement[i].value;
1.160.6.16 raeburn 17251: }
17252: }
1.160.6.64 raeburn 17253: if (currval == checkval) {
17254: divitem.style.display = dispval;
1.160.6.16 raeburn 17255: } else {
1.160.6.40 raeburn 17256: divitem.style.display = 'none';
1.160.6.16 raeburn 17257: }
17258: }
17259: }
17260: return;
17261: }
17262:
17263: // ]]>
17264: </script>
17265:
17266: END
17267:
17268: }
17269:
1.160.6.5 raeburn 17270: sub captcha_phrases {
17271: return &Apache::lonlocal::texthash (
17272: priv => 'Private key',
17273: pub => 'Public key',
17274: original => 'original (CAPTCHA)',
17275: recaptcha => 'successor (ReCAPTCHA)',
17276: notused => 'unused',
1.160.6.69 raeburn 17277: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 17278: );
17279: }
17280:
1.160.6.24 raeburn 17281: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 17282: my ($dom,$cachekeys) = @_;
17283: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 17284: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17285: my %thismachine;
17286: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.98 raeburn 17287: my @posscached = ('domainconfig','domdefaults','usersessions',
1.160.6.102.2 1(raebur 17288:0): 'ltitools','directorysrch','passwdconf','cats');
1.160.6.61 raeburn 17289: if (keys(%servers)) {
1.160.6.24 raeburn 17290: foreach my $server (keys(%servers)) {
17291: next if ($thismachine{$server});
1.160.6.27 raeburn 17292: my @cached;
17293: foreach my $name (@posscached) {
17294: if ($cachekeys->{$name}) {
17295: push(@cached,&escape($name).':'.&escape($dom));
17296: }
17297: }
17298: if (@cached) {
17299: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17300: }
1.160.6.24 raeburn 17301: }
17302: }
17303: return;
17304: }
17305:
1.3 raeburn 17306: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>