Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.102.2.7
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.102.2 7(raebur 4:1): # $Id: domainprefs.pm,v 1.160.6.102.2.6 2021/01/02 23:31:56 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') {
3229:1): $css_class = $rownum%2?' class="LC_odd_row"':'';
3230:1): my ($threshold,$sysmail,%excluded,%weights);
3231:1): my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3232:1): if ($lonstatus{'threshold'} =~ /^\d+$/) {
3233:1): $threshold = $lonstatus{'threshold'};
3234:1): } else {
3235:1): $threshold = $defaults->{'threshold'};
3236:1): }
3237:1): if ($lonstatus{'sysmail'} =~ /^\d+$/) {
3238:1): $sysmail = $lonstatus{'sysmail'};
3239:1): } else {
3240:1): $sysmail = $defaults->{'sysmail'};
3241:1): }
3242:1): if (ref($lonstatus{'weights'}) eq 'HASH') {
3243:1): foreach my $type ('E','W','N','U') {
3244:1): if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3245:1): $weights{$type} = $lonstatus{'weights'}{$type};
3246:1): } else {
3247:1): $weights{$type} = $defaults->{$type};
3248:1): }
3249:1): }
3250:1): } else {
3251:1): foreach my $type ('E','W','N','U') {
3252:1): $weights{$type} = $defaults->{$type};
3253:1): }
3254:1): }
3255:1): if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3256:1): if (@{$lonstatus{'excluded'}} > 0) {
3257:1): map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3258:1): }
3259:1): }
3260:1): $datatable .= '<tr'.$css_class.'>'.
3261:1): '<td class="LC_left_item"><span class="LC_nobreak">'.
3262:1): $titles->{'errorthreshold'}.
3263:1): '</span></td><td class="LC_left_item">'.
3264:1): '<input type="text" name="errorthreshold" value="'.
3265:1): $threshold.'" size="5" /></td></tr>';
3266:1): $rownum ++;
3267:1): $css_class = $rownum%2?' class="LC_odd_row"':'';
3268:1): $datatable .= '<tr'.$css_class.'>'.
3269:1): '<td class="LC_left_item">'.
3270:1): '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3271:1): '</span></td><td class="LC_left_item"><table><tr>';
3272:1): foreach my $type ('E','W','N','U') {
3273:1): $datatable .= '<td>'.$names->{$type}.'<br />'.
3274:1): '<input type="text" name="errorweights_'.$type.'" value="'.
3275:1): $weights{$type}.'" size="5" /></td>';
3276:1): }
3277:1): $datatable .= '</tr></table></tr>';
3278:1): $rownum ++;
3279:1): $css_class = $rownum%2?' class="LC_odd_row"':'';
3280:1): $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3281:1): $titles->{'errorexcluded'}.'</td>'.
3282:1): '<td class="LC_left_item"><table>';
3283:1): my $numinrow = 4;
3284:1): my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3285:1): for (my $i=0; $i<@ids; $i++) {
3286:1): my $rem = $i%($numinrow);
3287:1): if ($rem == 0) {
3288:1): if ($i > 0) {
3289:1): $datatable .= '</tr>';
3290:1): }
3291:1): $datatable .= '<tr>';
3292:1): }
3293:1): my $check;
3294:1): if ($excluded{$ids[$i]}) {
3295:1): $check = ' checked="checked" ';
3296:1): }
3297:1): $datatable .= '<td class="LC_left_item">'.
3298:1): '<span class="LC_nobreak"><label>'.
3299:1): '<input type="checkbox" name="errorexcluded" '.
3300:1): 'value="'.$ids[$i].'"'.$check.' />'.
3301:1): $ids[$i].'</label></span></td>';
3302:1): }
3303:1): my $colsleft = $numinrow - @ids%($numinrow);
3304:1): if ($colsleft > 1 ) {
3305:1): $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3306:1): ' </td>';
3307:1): } elsif ($colsleft == 1) {
3308:1): $datatable .= '<td class="LC_left_item"> </td>';
3309:1): }
3310:1): $datatable .= '</tr></table></td></tr>';
3311:1): $rownum ++;
3312:1): $css_class = $rownum%2?' class="LC_odd_row"':'';
3313:1): $datatable .= '<tr'.$css_class.'>'.
3314:1): '<td class="LC_left_item"><span class="LC_nobreak">'.
3315:1): $titles->{'errorsysmail'}.
3316:1): '</span></td><td class="LC_left_item">'.
3317:1): '<input type="text" name="errorsysmail" value="'.
3318:1): $sysmail.'" size="5" /></td></tr>';
3319:1): $rownum ++;
1.160.6.78 raeburn 3320: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 3321: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3322: my (@posstypes,%usertypeshash);
3323: if (ref($types) eq 'ARRAY') {
3324: @posstypes = @{$types};
3325: }
3326: if (@posstypes) {
3327: if (ref($usertypes) eq 'HASH') {
3328: %usertypeshash = %{$usertypes};
3329: }
3330: my @overridden;
3331: my $numinrow = 4;
3332: if (ref($settings) eq 'HASH') {
3333: if (ref($settings->{'overrides'}) eq 'HASH') {
3334: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3335: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3336: push(@overridden,$key);
3337: foreach my $item (@contacts) {
3338: if ($settings->{'overrides'}{$key}{$item}) {
3339: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3340: }
3341: }
3342: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3343: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3344: $includeloc{'override_'.$key} = '';
3345: $includestr{'override_'.$key} = '';
3346: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3347: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3348: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3349: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3350: }
1.160.6.78 raeburn 3351: }
3352: }
3353: }
1.160.6.101 raeburn 3354: }
3355: my $customclass = 'LC_helpdesk_override';
3356: my $optionsprefix = 'LC_options_helpdesk_';
3357:
3358: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3359:
3360: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3361: $numinrow,$othertitle,'overrides',
3362: \$rownum,$onclicktypes,$customclass);
3363: $rownum ++;
3364: $usertypeshash{'default'} = $othertitle;
3365: foreach my $status (@posstypes) {
3366: my $css_class;
3367: if ($rownum%2) {
3368: $css_class = 'LC_odd_row ';
3369: }
3370: $css_class .= $customclass;
3371: my $rowid = $optionsprefix.$status;
3372: my $hidden = 1;
3373: my $currstyle = 'display:none';
3374: if (grep(/^\Q$status\E$/,@overridden)) {
3375: $currstyle = 'display:table-row';
3376: $hidden = 0;
3377: }
3378: my $key = 'override_'.$status;
3379: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3380: $includeloc{$key},$includestr{$key},$status,$rowid,
3381: $usertypeshash{$status},$css_class,$currstyle,
3382: \@contacts,$short_titles);
3383: unless ($hidden) {
3384: $rownum ++;
1.160.6.78 raeburn 3385: }
3386: }
1.134 raeburn 3387: }
1.28 raeburn 3388: }
1.30 raeburn 3389: $$rowtotal += $rownum;
1.28 raeburn 3390: return $datatable;
3391: }
3392:
1.160.6.102.2 7(raebur 3393:1): sub core_link_msu {
3394:1): return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3395:1): &mt('LON-CAPA core group - MSU'),600,500);
3396:1): }
3397:1):
1.160.6.101 raeburn 3398: sub overridden_helpdesk {
3399: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3400: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3401: my $class = 'LC_left_item';
3402: if ($css_class) {
3403: $css_class = ' class="'.$css_class.'"';
3404: }
3405: if ($rowid) {
3406: $rowid = ' id="'.$rowid.'"';
3407: }
3408: if ($rowstyle) {
3409: $rowstyle = ' style="'.$rowstyle.'"';
3410: }
3411: my ($output,$description);
3412: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3413: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3414: "<td>$description</td>\n".
3415: '<td class="'.$class.'" colspan="2">'.
3416: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3417: '<span class="LC_nobreak">';
3418: if (ref($contacts) eq 'ARRAY') {
3419: foreach my $item (@{$contacts}) {
3420: my $check;
3421: if (ref($checked) eq 'HASH') {
3422: $check = $checked->{$item};
3423: }
3424: my $title;
3425: if (ref($short_titles) eq 'HASH') {
3426: $title = $short_titles->{$item};
3427: }
3428: $output .= '<label>'.
3429: '<input type="checkbox" name="override_'.$type.'"'.$check.
3430: ' value="'.$item.'" />'.$title.'</label> ';
3431: }
3432: }
3433: $output .= '</span><br />'.&mt('Others').': '.
3434: '<input type="text" name="override_'.$type.'_others" '.
3435: 'value="'.$otheremails.'" />';
3436: my %locchecked;
3437: foreach my $loc ('s','b') {
3438: if ($includeloc eq $loc) {
3439: $locchecked{$loc} = ' checked="checked"';
3440: last;
3441: }
3442: }
3443: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3444: '<input type="text" name="override_'.$type.'_bcc" '.
3445: 'value="'.$bccemails.'" /></fieldset>'.
3446: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3447: &mt('Text automatically added to e-mail:').' '.
3448: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
3449: '<span class="LC_nobreak">'.&mt('Location:').' '.
3450: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3451: (' 'x2).
3452: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3453: '</span></fieldset>'.
3454: '</td></tr>'."\n";
3455: return $output;
3456: }
3457:
1.160.6.78 raeburn 3458: sub contacts_javascript {
3459: return <<"ENDSCRIPT";
3460:
3461: <script type="text/javascript">
3462: // <![CDATA[
3463:
3464: function screenshotSize(field) {
3465: if (document.getElementById('help_screenshotsize')) {
3466: if (field.value == 'no') {
3467: document.getElementById('help_screenshotsize').style.display="none";
3468: } else {
3469: document.getElementById('help_screenshotsize').style.display="";
3470: }
3471: }
3472: return;
3473: }
3474:
1.160.6.101 raeburn 3475: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3476: if (form.elements[checkbox].length != undefined) {
3477: var count = 0;
3478: if (docount) {
3479: for (var i=0; i<form.elements[checkbox].length; i++) {
3480: if (form.elements[checkbox][i].checked) {
3481: count ++;
3482: }
3483: }
3484: }
3485: for (var i=0; i<form.elements[checkbox].length; i++) {
3486: var type = form.elements[checkbox][i].value;
3487: if (document.getElementById(prefix+type)) {
3488: if (form.elements[checkbox][i].checked) {
3489: document.getElementById(prefix+type).style.display = 'table-row';
3490: if (count % 2 == 1) {
3491: document.getElementById(prefix+type).className = target+' LC_odd_row';
3492: } else {
3493: document.getElementById(prefix+type).className = target;
3494: }
3495: count ++;
3496: } else {
3497: document.getElementById(prefix+type).style.display = 'none';
3498: }
3499: }
3500: }
3501: }
3502: return;
3503: }
3504:
1.160.6.78 raeburn 3505: // ]]>
3506: </script>
3507:
3508: ENDSCRIPT
3509: }
3510:
1.118 jms 3511: sub print_helpsettings {
1.160.6.73 raeburn 3512: my ($position,$dom,$settings,$rowtotal) = @_;
3513: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3514: my $formname = 'display';
1.160.6.5 raeburn 3515: my ($datatable,$itemcount);
1.160.6.73 raeburn 3516: if ($position eq 'top') {
3517: $itemcount = 1;
3518: my (%choices,%defaultchecked,@toggles);
3519: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3520: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3521: &mt('LON-CAPA bug tracker'),600,500));
3522: %defaultchecked = ('submitbugs' => 'on');
3523: @toggles = ('submitbugs');
3524: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3525: \%choices,$itemcount);
3526: $$rowtotal ++;
3527: } else {
3528: my $css_class;
3529: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3530: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 3531: if (ref($settings) eq 'HASH') {
3532: if (ref($settings->{'adhoc'}) eq 'HASH') {
3533: %current = %{$settings->{'adhoc'}};
3534: }
1.160.6.77 raeburn 3535: }
3536: my $count = 0;
3537: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3538: if ($key=~/^rolesdef\_(\w+)$/) {
3539: my $rolename = $1;
1.160.6.77 raeburn 3540: my (%privs,$order);
1.160.6.73 raeburn 3541: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3542: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3543: if (ref($current{$rolename}) eq 'HASH') {
3544: $order = $current{$rolename}{'order'};
3545: }
3546: if ($order eq '') {
3547: $order = $count;
3548: }
3549: $ordered{$order} = $rolename;
3550: $count++;
1.160.6.73 raeburn 3551: }
3552: }
1.160.6.77 raeburn 3553: my $maxnum = scalar(keys(%ordered));
3554: my @roles_by_num = ();
3555: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3556: push(@roles_by_num,$item);
3557: }
3558: my $context = 'domprefs';
3559: my $crstype = 'Course';
3560: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3561: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3562: my ($numstatustypes,@jsarray);
3563: if (ref($types) eq 'ARRAY') {
3564: if (@{$types} > 0) {
3565: $numstatustypes = scalar(@{$types});
3566: push(@accesstypes,'status');
3567: @jsarray = ('bystatus');
3568: }
3569: }
1.160.6.86 raeburn 3570: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3571: if (keys(%domhelpdesk)) {
3572: push(@accesstypes,('inc','exc'));
3573: push(@jsarray,('notinc','notexc'));
3574: }
3575: my $hiddenstr = join("','",@jsarray);
3576: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3577: my $context = 'domprefs';
3578: my $crstype = 'Course';
1.160.6.77 raeburn 3579: my $prefix = 'helproles_';
3580: my $add_class = 'LC_hidden';
3581: foreach my $num (@roles_by_num) {
3582: my $role = $ordered{$num};
3583: my ($desc,$access,@statuses);
3584: if (ref($current{$role}) eq 'HASH') {
3585: $desc = $current{$role}{'desc'};
3586: $access = $current{$role}{'access'};
3587: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3588: @statuses = @{$current{$role}{'insttypes'}};
3589: }
3590: }
3591: if ($desc eq '') {
3592: $desc = $role;
3593: }
3594: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3595: my %full=();
3596: my %levels= (
3597: course => {},
3598: domain => {},
3599: system => {},
3600: );
3601: my %levelscurrent=(
3602: course => {},
3603: domain => {},
3604: system => {},
3605: );
3606: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3607: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3608: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3609: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3610: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3611: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3612: for (my $k=0; $k<=$maxnum; $k++) {
3613: my $vpos = $k+1;
3614: my $selstr;
3615: if ($k == $num) {
3616: $selstr = ' selected="selected" ';
3617: }
3618: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3619: }
3620: $datatable .= '</select>'.(' 'x2).
3621: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3622: '</td>'.
3623: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3624: &mt('Name shown to users:').
3625: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3626: '</fieldset>'.
3627: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3628: $othertitle,$usertypes,$types,\%domhelpdesk).
3629: '<fieldset>'.
3630: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3631: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3632: \%levelscurrent,$identifier,
3633: 'LC_hidden',$prefix.$num.'_privs').
3634: '</fieldset></td>';
1.160.6.73 raeburn 3635: $itemcount ++;
3636: }
3637: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3638: my $newcust = 'custhelp'.$count;
3639: my (%privs,%levelscurrent);
3640: my %full=();
3641: my %levels= (
3642: course => {},
3643: domain => {},
3644: system => {},
3645: );
3646: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3647: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3648: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3649: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3650: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3651: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3652: for (my $k=0; $k<$maxnum+1; $k++) {
3653: my $vpos = $k+1;
3654: my $selstr;
3655: if ($k == $maxnum) {
3656: $selstr = ' selected="selected" ';
3657: }
3658: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3659: }
3660: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3661: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3662: '</label></span></td>'.
1.160.6.77 raeburn 3663: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3664: '<span class="LC_nobreak">'.
3665: &mt('Internal name:').
3666: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3667: '</span>'.(' 'x4).
3668: '<span class="LC_nobreak">'.
3669: &mt('Name shown to users:').
3670: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3671: '</span></fieldset>'.
3672: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3673: $usertypes,$types,\%domhelpdesk).
3674: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3675: &Apache::lonuserutils::custom_role_header($context,$crstype,
3676: \@templateroles,$newcust).
3677: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3678: \%levelscurrent,$newcust).
1.160.6.87 raeburn 3679: '</fieldset>'.
3680: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
3681: '</td></tr>';
1.160.6.73 raeburn 3682: $count ++;
3683: $$rowtotal += $count;
3684: }
1.160.6.5 raeburn 3685: return $datatable;
1.121 raeburn 3686: }
3687:
1.160.6.77 raeburn 3688: sub adhocbutton {
3689: my ($prefix,$num,$field,$visibility) = @_;
3690: my %lt = &Apache::lonlocal::texthash(
3691: show => 'Show details',
3692: hide => 'Hide details',
3693: );
3694: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3695: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3696: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3697: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3698: }
3699:
3700: sub helpsettings_javascript {
3701: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3702: return unless(ref($roles_by_num) eq 'ARRAY');
3703: my %html_js_lt = &Apache::lonlocal::texthash(
3704: show => 'Show details',
3705: hide => 'Hide details',
3706: );
3707: &html_escape(\%html_js_lt);
3708: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3709: return <<"ENDSCRIPT";
3710: <script type="text/javascript">
3711: // <![CDATA[
3712:
3713: function reorderHelpRoles(form,item) {
3714: var changedVal;
3715: $jstext
3716: var newpos = 'helproles_${total}_pos';
3717: var maxh = 1 + $total;
3718: var current = new Array();
3719: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3720: if (item == newpos) {
3721: changedVal = newitemVal;
3722: } else {
3723: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3724: current[newitemVal] = newpos;
3725: }
3726: for (var i=0; i<helproles.length; i++) {
3727: var elementName = 'helproles_'+helproles[i]+'_pos';
3728: if (elementName != item) {
3729: if (form.elements[elementName]) {
3730: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3731: current[currVal] = elementName;
3732: }
3733: }
3734: }
3735: var oldVal;
3736: for (var j=0; j<maxh; j++) {
3737: if (current[j] == undefined) {
3738: oldVal = j;
3739: }
3740: }
3741: if (oldVal < changedVal) {
3742: for (var k=oldVal+1; k<=changedVal ; k++) {
3743: var elementName = current[k];
3744: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3745: }
3746: } else {
3747: for (var k=changedVal; k<oldVal; k++) {
3748: var elementName = current[k];
3749: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3750: }
3751: }
3752: return;
3753: }
3754:
3755: function helpdeskAccess(num) {
3756: var curraccess = null;
3757: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3758: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3759: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3760: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3761: }
3762: }
3763: }
3764: var shown = Array();
3765: var hidden = Array();
3766: if (curraccess == 'none') {
3767: hidden = Array('$hiddenstr');
3768: } else {
3769: if (curraccess == 'status') {
3770: shown = Array('bystatus');
3771: hidden = Array('notinc','notexc');
3772: } else {
3773: if (curraccess == 'exc') {
3774: shown = Array('notexc');
3775: hidden = Array('notinc','bystatus');
3776: }
3777: if (curraccess == 'inc') {
3778: shown = Array('notinc');
3779: hidden = Array('notexc','bystatus');
3780: }
1.160.6.79 raeburn 3781: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3782: hidden = Array('notinc','notexc','bystatus');
3783: }
3784: }
3785: }
3786: if (hidden.length > 0) {
3787: for (var i=0; i<hidden.length; i++) {
3788: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3789: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3790: }
3791: }
3792: }
3793: if (shown.length > 0) {
3794: for (var i=0; i<shown.length; i++) {
3795: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3796: if (shown[i] == 'privs') {
3797: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3798: } else {
3799: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3800: }
3801: }
3802: }
3803: }
3804: return;
3805: }
3806:
3807: function toggleHelpdeskItem(num,field) {
3808: if (document.getElementById('helproles_'+num+'_'+field)) {
3809: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3810: document.getElementById('helproles_'+num+'_'+field).className =
3811: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3812: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3813: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3814: }
3815: } else {
3816: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3817: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3818: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3819: }
3820: }
3821: }
3822: return;
3823: }
3824:
3825: // ]]>
3826: </script>
3827:
3828: ENDSCRIPT
3829: }
3830:
3831: sub helpdeskroles_access {
3832: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3833: $usertypes,$types,$domhelpdesk) = @_;
3834: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3835: my %lt = &Apache::lonlocal::texthash(
3836: 'rou' => 'Role usage',
3837: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3838: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3839: 'dh' => 'All with domain helpdesk role',
3840: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3841: 'none' => 'None',
3842: 'status' => 'Determined based on institutional status',
3843: 'inc' => 'Include all, but exclude specific personnel',
3844: 'exc' => 'Exclude all, but include specific personnel',
3845: );
3846: my %usecheck = (
3847: all => ' checked="checked"',
3848: );
3849: my %displaydiv = (
3850: status => 'none',
3851: inc => 'none',
3852: exc => 'none',
3853: priv => 'block',
3854: );
3855: my $output;
3856: if (ref($current) eq 'HASH') {
3857: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3858: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3859: $usecheck{$current->{access}} = $usecheck{'all'};
3860: delete($usecheck{'all'});
3861: if ($current->{access} =~ /^(status|inc|exc)$/) {
3862: my $access = $1;
3863: $displaydiv{$access} = 'inline';
3864: } elsif ($current->{access} eq 'none') {
3865: $displaydiv{'priv'} = 'none';
3866: }
3867: }
3868: }
3869: }
3870: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3871: '<p>'.$lt{'whi'}.'</p>';
3872: foreach my $access (@{$accesstypes}) {
3873: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3874: ' onclick="helpdeskAccess('."'$num'".');" />'.
3875: $lt{$access}.'</label>';
3876: if ($access eq 'status') {
3877: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3878: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3879: $othertitle,$usertypes,$types).
3880: '</div>';
3881: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3882: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3883: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3884: '</div>';
3885: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3886: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3887: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3888: '</div>';
3889: }
3890: $output .= '</p>';
3891: }
3892: $output .= '</fieldset>';
3893: return $output;
3894: }
3895:
1.121 raeburn 3896: sub radiobutton_prefs {
1.160.6.16 raeburn 3897: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3898: $additional,$align) = @_;
1.121 raeburn 3899: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3900: (ref($choices) eq 'HASH'));
3901:
3902: my (%checkedon,%checkedoff,$datatable,$css_class);
3903:
3904: foreach my $item (@{$toggles}) {
3905: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3906: $checkedon{$item} = ' checked="checked" ';
3907: $checkedoff{$item} = ' ';
1.121 raeburn 3908: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3909: $checkedoff{$item} = ' checked="checked" ';
3910: $checkedon{$item} = ' ';
3911: }
3912: }
3913: if (ref($settings) eq 'HASH') {
1.121 raeburn 3914: foreach my $item (@{$toggles}) {
1.118 jms 3915: if ($settings->{$item} eq '1') {
3916: $checkedon{$item} = ' checked="checked" ';
3917: $checkedoff{$item} = ' ';
3918: } elsif ($settings->{$item} eq '0') {
3919: $checkedoff{$item} = ' checked="checked" ';
3920: $checkedon{$item} = ' ';
3921: }
3922: }
1.121 raeburn 3923: }
1.160.6.16 raeburn 3924: if ($onclick) {
3925: $onclick = ' onclick="'.$onclick.'"';
3926: }
1.121 raeburn 3927: foreach my $item (@{$toggles}) {
1.118 jms 3928: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3929: $datatable .=
1.160.6.16 raeburn 3930: '<tr'.$css_class.'><td valign="top">'.
3931: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3932: '</span></td>';
3933: if ($align eq 'left') {
3934: $datatable .= '<td class="LC_left_item">';
3935: } else {
3936: $datatable .= '<td class="LC_right_item">';
3937: }
3938: $datatable .=
3939: '<span class="LC_nobreak">'.
1.118 jms 3940: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3941: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3942: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3943: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3944: '</span>'.$additional.
3945: '</td>'.
1.118 jms 3946: '</tr>';
3947: $itemcount ++;
1.121 raeburn 3948: }
3949: return ($datatable,$itemcount);
3950: }
3951:
1.160.6.102.2 1(raebur 3952:0): sub print_ltitools {
3953:0): my ($dom,$settings,$rowtotal) = @_;
3954:0): my $rownum = 0;
3955:0): my $css_class;
3956:0): my $itemcount = 1;
3957:0): my $maxnum = 0;
3958:0): my %ordered;
3959:0): if (ref($settings) eq 'HASH') {
3960:0): foreach my $item (keys(%{$settings})) {
3961:0): if (ref($settings->{$item}) eq 'HASH') {
3962:0): my $num = $settings->{$item}{'order'};
3963:0): $ordered{$num} = $item;
3964:0): }
3965:0): }
3966:0): }
3967:0): my $confname = $dom.'-domainconfig';
3968:0): my $switchserver = &check_switchserver($dom,$confname);
3969:0): my $maxnum = scalar(keys(%ordered));
5(raebur 3970:0): my $datatable;
1(raebur 3971:0): my %lt = <itools_names();
3972:0): my @courseroles = ('cc','in','ta','ep','st');
3973:0): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
5(raebur 3974:0): my @fields = ('fullname','firstname','lastname','email','roles','user');
1(raebur 3975:0): if (keys(%ordered)) {
3976:0): my @items = sort { $a <=> $b } keys(%ordered);
3977:0): for (my $i=0; $i<@items; $i++) {
3978:0): $css_class = $itemcount%2?' class="LC_odd_row"':'';
3979:0): my $item = $ordered{$items[$i]};
5(raebur 3980:0): my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1(raebur 3981:0): if (ref($settings->{$item}) eq 'HASH') {
3982:0): $title = $settings->{$item}->{'title'};
3983:0): $url = $settings->{$item}->{'url'};
3984:0): $key = $settings->{$item}->{'key'};
3985:0): $secret = $settings->{$item}->{'secret'};
5(raebur 3986:0): $lifetime = $settings->{$item}->{'lifetime'};
1(raebur 3987:0): my $image = $settings->{$item}->{'image'};
3988:0): if ($image ne '') {
3989:0): $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3990:0): }
5(raebur 3991:0): if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
3992:0): $sigsel{'HMAC-256'} = ' selected="selected"';
3993:0): } else {
3994:0): $sigsel{'HMAC-SHA1'} = ' selected="selected"';
3995:0): }
1(raebur 3996:0): }
5(raebur 3997:0): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1(raebur 3998:0): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3999:0): .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4000:0): for (my $k=0; $k<=$maxnum; $k++) {
4001:0): my $vpos = $k+1;
4002:0): my $selstr;
4003:0): if ($k == $i) {
4004:0): $selstr = ' selected="selected" ';
4005:0): }
4006:0): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4007:0): }
4008:0): $datatable .= '</select>'.(' 'x2).
4009:0): '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4010:0): &mt('Delete?').'</label></span></td>'.
4011:0): '<td colspan="2">'.
4012:0): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5(raebur 4013:0): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1(raebur 4014:0): (' 'x2).
4015:0): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4016:0): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4017:0): (' 'x2).
4018:0): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4019:0): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
5(raebur 4020:0): (' 'x2).
4021:0): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4022:0): '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4023:0): '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1(raebur 4024:0): '<br /><br />'.
5(raebur 4025:0): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1(raebur 4026:0): ' value="'.$url.'" /></span>'.
4027:0): (' 'x2).
5(raebur 4028:0): '<span class="LC_nobreak">'.$lt{'key'}.':'.
1(raebur 4029:0): '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4030:0): (' 'x2).
5(raebur 4031:0): '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4032:0): '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4033:0): (' 'x2).
1(raebur 4034:0): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4035:0): '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4036: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>'.
4037:0): '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4038:0): '</fieldset>'.
4039:0): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4040:0): '<span class="LC_nobreak">'.&mt('Display target:');
4041:0): my %currdisp;
4042:0): if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4043:0): if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4044:0): $currdisp{'window'} = ' checked="checked"';
4045:0): } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4046:0): $currdisp{'tab'} = ' checked="checked"';
4047:0): } else {
4048:0): $currdisp{'iframe'} = ' checked="checked"';
4049:0): }
4050:0): if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4051:0): $currdisp{'width'} = $1;
4052:0): }
4053:0): if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4054:0): $currdisp{'height'} = $1;
4055:0): }
4056:0): $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4057:0): $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
4058:0): } else {
4059:0): $currdisp{'iframe'} = ' checked="checked"';
4060:0): }
4061:0): foreach my $disp ('iframe','tab','window') {
4062:0): $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4063:0): $lt{$disp}.'</label>'.(' 'x2);
4064:0): }
4065:0): $datatable .= (' 'x4);
4066:0): foreach my $dimen ('width','height') {
4067:0): $datatable .= '<label>'.$lt{$dimen}.' '.
4068:0): '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4069:0): (' 'x2);
4070:0): }
5(raebur 4071:0): $datatable .= '</span><br />'.
1(raebur 4072:0): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
5(raebur 4073:0): '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1(raebur 4074:0): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4075:0): '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
5(raebur 4076:0): '</textarea></div><div style=""></div>'.
4077:0): '<div style="padding:0;clear:both;margin:0;border:0"></div>';
4078:0): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1(raebur 4079:0): if ($imgsrc) {
4080:0): $datatable .= $imgsrc.
4081:0): '<label><input type="checkbox" name="ltitools_image_del"'.
4082:0): ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4083:0): '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4084:0): } else {
4085:0): $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4086:0): }
4087:0): if ($switchserver) {
4088:0): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4089:0): } else {
4090:0): $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4091:0): }
4092:0): $datatable .= '</span></fieldset>';
5(raebur 4093:0): my (%checkedfields,%rolemaps,$userincdom);
1(raebur 4094:0): if (ref($settings->{$item}) eq 'HASH') {
4095:0): if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4096:0): %checkedfields = %{$settings->{$item}->{'fields'}};
4097:0): }
5(raebur 4098:0): $userincdom = $settings->{$item}->{'incdom'};
1(raebur 4099:0): if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4100:0): %rolemaps = %{$settings->{$item}->{'roles'}};
4101:0): $checkedfields{'roles'} = 1;
4102:0): }
4103:0): }
4104:0): $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4105:0): '<span class="LC_nobreak">';
5(raebur 4106:0): my $userfieldstyle = 'display:none;';
4107:0): my $seluserdom = '';
4108:0): my $unseluserdom = ' selected="selected"';
1(raebur 4109:0): foreach my $field (@fields) {
5(raebur 4110:0): my ($checked,$onclick,$id,$spacer);
1(raebur 4111:0): if ($checkedfields{$field}) {
4112:0): $checked = ' checked="checked"';
4113:0): }
5(raebur 4114:0): if ($field eq 'user') {
4115:0): $id = ' id="ltitools_user_field_'.$i.'"';
4116:0): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4117:0): if ($checked) {
4118:0): $userfieldstyle = 'display:inline-block';
4119:0): if ($userincdom) {
4120:0): $seluserdom = $unseluserdom;
4121:0): $unseluserdom = '';
4122:0): }
4123:0): }
4124:0): } else {
4125:0): $spacer = (' ' x2);
4126:0): }
1(raebur 4127:0): $datatable .= '<label>'.
5(raebur 4128:0): '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4129:0): $lt{$field}.'</label>'.$spacer;
1(raebur 4130:0): }
5(raebur 4131:0): $datatable .= '</span>';
4132:0): $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4133:0): '<span class="LC_nobreak"> : '.
4134:0): '<select name="ltitools_userincdom_'.$i.'">'.
4135:0): '<option value="">'.&mt('Select').'</option>'.
4136:0): '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4137:0): '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4138:0): '</select></span></div>';
4139:0): $datatable .= '</fieldset>'.
1(raebur 4140:0): '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4141:0): foreach my $role (@courseroles) {
4142:0): my ($selected,$selectnone);
4143:0): if (!$rolemaps{$role}) {
4144:0): $selectnone = ' selected="selected"';
4145:0): }
4146:0): $datatable .= '<td align="center">'.
4147:0): &Apache::lonnet::plaintext($role,'Course').'<br />'.
4148:0): '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4149:0): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4150:0): foreach my $ltirole (@ltiroles) {
4151:0): unless ($selectnone) {
4152:0): if ($rolemaps{$role} eq $ltirole) {
4153:0): $selected = ' selected="selected"';
4154:0): } else {
4155:0): $selected = '';
4156:0): }
4157:0): }
4158:0): $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4159:0): }
4160:0): $datatable .= '</select></td>';
4161:0): }
4162:0): $datatable .= '</tr></table></fieldset>';
4163:0): my %courseconfig;
4164:0): if (ref($settings->{$item}) eq 'HASH') {
4165:0): if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4166:0): %courseconfig = %{$settings->{$item}->{'crsconf'}};
4167:0): }
4168:0): }
4169:0): $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
5(raebur 4170:0): foreach my $item ('label','title','target','linktext','explanation','append') {
1(raebur 4171:0): my $checked;
4172:0): if ($courseconfig{$item}) {
4173:0): $checked = ' checked="checked"';
4174:0): }
4175:0): $datatable .= '<label>'.
4176:0): '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4177:0): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4178:0): }
4179:0): $datatable .= '</span></fieldset>'.
4180:0): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4181:0): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4182:0): if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4183:0): my %custom = %{$settings->{$item}->{'custom'}};
4184:0): if (keys(%custom) > 0) {
4185:0): foreach my $key (sort(keys(%custom))) {
4186:0): $datatable .= '<tr><td><span class="LC_nobreak">'.
4187:0): '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4188:0): $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4189:0): '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4190:0): ' value="'.$custom{$key}.'" /></td></tr>';
4191:0): }
4192:0): }
4193:0): }
4194:0): $datatable .= '<tr><td><span class="LC_nobreak">'.
4195:0): '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4196:0): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4197:0): '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4198:0): $datatable .= '</table></fieldset></td></tr>'."\n";
4199:0): $itemcount ++;
4200:0): }
4201:0): }
4202:0): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5(raebur 4203:0): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1(raebur 4204:0): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4205:0): '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4206:0): '<select name="ltitools_add_pos"'.$chgstr.'>';
4207:0): for (my $k=0; $k<$maxnum+1; $k++) {
4208:0): my $vpos = $k+1;
4209:0): my $selstr;
4210:0): if ($k == $maxnum) {
4211:0): $selstr = ' selected="selected" ';
4212:0): }
4213:0): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4214:0): }
4215:0): $datatable .= '</select> '."\n".
5(raebur 4216:0): '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1(raebur 4217:0): '<td colspan="2">'.
4218:0): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5(raebur 4219:0): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1(raebur 4220:0): (' 'x2).
4221:0): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4222:0): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4223:0): (' 'x2).
4224:0): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4225:0): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
5(raebur 4226:0): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4227:0): '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4228:0): '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1(raebur 4229:0): '<br />'.
5(raebur 4230:0): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1(raebur 4231:0): (' 'x2).
4232:0): '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4233:0): (' 'x2).
5(raebur 4234:0): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4235:0): (' 'x2).
1(raebur 4236:0): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4237: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".
4238:0): '</fieldset>'.
4239:0): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4240:0): '<span class="LC_nobreak">'.&mt('Display target:');
4241:0): my %defaultdisp;
4242:0): $defaultdisp{'iframe'} = ' checked="checked"';
4243:0): foreach my $disp ('iframe','tab','window') {
4244:0): $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4245:0): $lt{$disp}.'</label>'.(' 'x2);
4246:0): }
4247:0): $datatable .= (' 'x4);
4248:0): foreach my $dimen ('width','height') {
4249:0): $datatable .= '<label>'.$lt{$dimen}.' '.
4250:0): '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4251:0): (' 'x2);
4252:0): }
5(raebur 4253:0): $datatable .= '</span><br />'.
1(raebur 4254:0): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
5(raebur 4255:0): '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1(raebur 4256:0): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
5(raebur 4257:0): '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4258:0): '</div><div style=""></div>'.
4259:0): '<div style="padding:0;clear:both;margin:0;border:0"></div>';
4260:0): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1(raebur 4261:0): '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4262:0): if ($switchserver) {
4263:0): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4264:0): } else {
4265:0): $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4266:0): }
4267:0): $datatable .= '</span></fieldset>'.
4268:0): '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4269:0): '<span class="LC_nobreak">';
4270:0): foreach my $field (@fields) {
5(raebur 4271:0): my ($id,$onclick,$spacer);
4272:0): if ($field eq 'user') {
4273:0): $id = ' id="ltitools_user_field_add"';
4274:0): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4275:0): } else {
4276:0): $spacer = (' ' x2);
4277:0): }
1(raebur 4278:0): $datatable .= '<label>'.
5(raebur 4279:0): '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4280:0): $lt{$field}.'</label>'.$spacer;
1(raebur 4281:0): }
5(raebur 4282:0): $datatable .= '</span>'.
4283:0): '<div style="display:none;" id="ltitools_user_div_add">'.
4284:0): '<span class="LC_nobreak"> : '.
4285:0): '<select name="ltitools_userincdom_add">'.
4286:0): '<option value="" selected="selected">'.&mt('Select').'</option>'.
4287:0): '<option value="0">'.&mt('username').'</option>'.
4288:0): '<option value="1">'.&mt('username:domain').'</option>'.
4289:0): '</select></span></div></fieldset>';
4290:0): $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1(raebur 4291:0): foreach my $role (@courseroles) {
4292:0): my ($checked,$checkednone);
4293:0): $datatable .= '<td align="center">'.
4294:0): &Apache::lonnet::plaintext($role,'Course').'<br />'.
4295:0): '<select name="ltitools_add_roles_'.$role.'">'.
4296:0): '<option value="" selected="selected">'.&mt('Select').'</option>';
4297:0): foreach my $ltirole (@ltiroles) {
4298:0): $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4299:0): }
4300:0): $datatable .= '</select></td>';
4301:0): }
4302:0): $datatable .= '</tr></table></fieldset>'.
4303:0): '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
5(raebur 4304:0): foreach my $item ('label','title','target','linktext','explanation','append') {
1(raebur 4305:0): $datatable .= '<label>'.
4306:0): '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4307:0): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4308:0): }
4309:0): $datatable .= '</span></fieldset>'.
4310:0): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4311:0): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4312:0): '<tr><td><span class="LC_nobreak">'.
4313:0): '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4314:0): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4315:0): '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
5(raebur 4316:0): '</table></fieldset>'."\n".
1(raebur 4317:0): '</td>'."\n".
4318:0): '</tr>'."\n";
4319:0): $itemcount ++;
4320:0): return $datatable;
4321:0): }
4322:0):
4323:0): sub ltitools_names {
4324:0): my %lt = &Apache::lonlocal::texthash(
4325:0): 'title' => 'Title',
4326:0): 'version' => 'Version',
4327:0): 'msgtype' => 'Message Type',
5(raebur 4328:0): 'sigmethod' => 'Signature Method',
1(raebur 4329:0): 'url' => 'URL',
4330:0): 'key' => 'Key',
5(raebur 4331:0): 'lifetime' => 'Nonce lifetime (s)',
1(raebur 4332:0): 'secret' => 'Secret',
4333:0): 'icon' => 'Icon',
5(raebur 4334:0): 'user' => 'User',
1(raebur 4335:0): 'fullname' => 'Full Name',
4336:0): 'firstname' => 'First Name',
4337:0): 'lastname' => 'Last Name',
4338:0): 'email' => 'E-mail',
4339:0): 'roles' => 'Role',
4340:0): 'window' => 'Window',
4341:0): 'tab' => 'Tab',
4342:0): 'iframe' => 'iFrame',
4343:0): 'height' => 'Height',
4344:0): 'width' => 'Width',
4345:0): 'linktext' => 'Default Link Text',
4346:0): 'explanation' => 'Default Explanation',
4347:0): 'crstarget' => 'Display target',
4348:0): 'crslabel' => 'Course label',
4349:0): 'crstitle' => 'Course title',
4350:0): 'crslinktext' => 'Link Text',
4351:0): 'crsexplanation' => 'Explanation',
5(raebur 4352:0): 'crsappend' => 'Provider URL',
1(raebur 4353:0): );
4354:0):
4355:0): return %lt;
4356:0): }
4357:0):
1.121 raeburn 4358: sub print_coursedefaults {
1.139 raeburn 4359: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 4360: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4361: my $itemcount = 1;
1.160.6.16 raeburn 4362: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 4363: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 4364: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4365: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 4366: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4367: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.90 raeburn 4368: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 4369: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 4370: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 4371: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 4372: );
1.160.6.21 raeburn 4373: my %staticdefaults = (
4374: anonsurvey_threshold => 10,
4375: uploadquota => 500,
1.160.6.57 raeburn 4376: postsubmit => 60,
1.160.6.70 raeburn 4377: mysqltables => 172800,
1.160.6.21 raeburn 4378: );
1.139 raeburn 4379: if ($position eq 'top') {
1.160.6.57 raeburn 4380: %defaultchecked = (
4381: 'uselcmath' => 'on',
4382: 'usejsme' => 'on',
1.160.6.64 raeburn 4383: 'canclone' => 'none',
1.160.6.57 raeburn 4384: );
4385: @toggles = ('uselcmath','usejsme');
1.160.6.90 raeburn 4386: my $deftex = $Apache::lonnet::deftex;
4387: if (ref($settings) eq 'HASH') {
4388: if ($settings->{'texengine'}) {
4389: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4390: $deftex = $settings->{'texengine'};
4391: }
4392: }
4393: }
4394: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4395: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4396: '<span class="LC_nobreak">'.$choices{'texengine'}.
4397: '</span></td><td class="LC_right_item">'.
4398: '<select name="texengine">'."\n";
4399: my %texoptions = (
4400: MathJax => 'MathJax',
4401: mimetex => &mt('Convert to Images'),
4402: tth => &mt('TeX to HTML'),
4403: );
4404: foreach my $renderer ('MathJax','mimetex','tth') {
4405: my $selected = '';
4406: if ($renderer eq $deftex) {
4407: $selected = ' selected="selected"';
4408: }
4409: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
4410: }
4411: $mathdisp .= '</select></td></tr>'."\n";
4412: $itemcount ++;
1.139 raeburn 4413: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4414: \%choices,$itemcount);
1.160.6.90 raeburn 4415: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 4416: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4417: $datatable .=
4418: '<tr'.$css_class.'><td valign="top">'.
4419: '<span class="LC_nobreak">'.$choices{'canclone'}.
4420: '</span></td><td class="LC_left_item">';
4421: my $currcanclone = 'none';
4422: my $onclick;
4423: my @cloneoptions = ('none','domain');
4424: my %clonetitles = (
4425: none => 'No additional course requesters',
4426: domain => "Any course requester in course's domain",
4427: instcode => 'Course requests for official courses ...',
4428: );
4429: my (%codedefaults,@code_order,@posscodes);
4430: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4431: \@code_order) eq 'ok') {
4432: if (@code_order > 0) {
4433: push(@cloneoptions,'instcode');
4434: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4435: }
4436: }
4437: if (ref($settings) eq 'HASH') {
4438: if ($settings->{'canclone'}) {
4439: if (ref($settings->{'canclone'}) eq 'HASH') {
4440: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4441: if (@code_order > 0) {
4442: $currcanclone = 'instcode';
4443: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4444: }
4445: }
4446: } elsif ($settings->{'canclone'} eq 'domain') {
4447: $currcanclone = $settings->{'canclone'};
4448: }
4449: }
4450: }
4451: foreach my $option (@cloneoptions) {
4452: my ($checked,$additional);
4453: if ($currcanclone eq $option) {
4454: $checked = ' checked="checked"';
4455: }
4456: if ($option eq 'instcode') {
4457: if (@code_order) {
4458: my $show = 'none';
4459: if ($checked) {
4460: $show = 'block';
4461: }
4462: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4463: &mt('Institutional codes for new and cloned course have identical:').
4464: '<br />';
4465: foreach my $item (@code_order) {
4466: my $codechk;
4467: if ($checked) {
4468: if (grep(/^\Q$item\E$/,@posscodes)) {
4469: $codechk = ' checked="checked"';
4470: }
4471: }
4472: $additional .= '<label>'.
4473: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4474: $item.'</label>';
4475: }
4476: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4477: }
4478: }
4479: $datatable .=
4480: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4481: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4482: '</label> '.$additional.'</span><br />';
4483: }
4484: $datatable .= '</td>'.
4485: '</tr>';
4486: $itemcount ++;
1.139 raeburn 4487: } else {
4488: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 4489: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 4490: my $currusecredits = 0;
1.160.6.57 raeburn 4491: my $postsubmitclient = 1;
1.160.6.30 raeburn 4492: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 4493: if (ref($settings) eq 'HASH') {
4494: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 4495: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4496: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4497: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4498: }
4499: }
1.160.6.16 raeburn 4500: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 4501: foreach my $type (@types) {
4502: next if ($type eq 'community');
4503: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4504: if ($defcredits{$type} ne '') {
4505: $currusecredits = 1;
4506: }
4507: }
4508: }
4509: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4510: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4511: $postsubmitclient = 0;
4512: foreach my $type (@types) {
4513: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4514: }
4515: } else {
4516: foreach my $type (@types) {
4517: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4518: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4519: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4520: } else {
4521: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4522: }
4523: } else {
4524: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4525: }
4526: }
4527: }
4528: } else {
4529: foreach my $type (@types) {
4530: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 4531: }
4532: }
1.160.6.70 raeburn 4533: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4534: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4535: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4536: }
4537: } else {
4538: foreach my $type (@types) {
4539: $currmysql{$type} = $staticdefaults{'mysqltables'};
4540: }
4541: }
1.160.6.58 raeburn 4542: } else {
4543: foreach my $type (@types) {
4544: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4545: }
1.139 raeburn 4546: }
4547: if (!$currdefresponder) {
1.160.6.21 raeburn 4548: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4549: } elsif ($currdefresponder < 1) {
4550: $currdefresponder = 1;
4551: }
1.160.6.21 raeburn 4552: foreach my $type (@types) {
4553: if ($curruploadquota{$type} eq '') {
4554: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4555: }
4556: }
1.139 raeburn 4557: $datatable .=
1.160.6.16 raeburn 4558: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4559: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4560: '</span></td>'.
4561: '<td class="LC_right_item"><span class="LC_nobreak">'.
4562: '<input type="text" name="anonsurvey_threshold"'.
4563: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 4564: '</td></tr>'."\n";
4565: $itemcount ++;
4566: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4567: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4568: $choices{'uploadquota'}.
4569: '</span></td>'.
4570: '<td align="right" class="LC_right_item">'.
4571: '<table><tr>';
1.160.6.21 raeburn 4572: foreach my $type (@types) {
4573: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4574: '<input type="text" name="uploadquota_'.$type.'"'.
4575: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4576: }
4577: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 4578: $itemcount ++;
1.160.6.40 raeburn 4579: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 4580: my $display = 'none';
4581: if ($currusecredits) {
4582: $display = 'block';
4583: }
4584: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 4585: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4586: foreach my $type (@types) {
4587: next if ($type eq 'community');
4588: $additional .= '<td align="center">'.&mt($type).'<br />'.
4589: '<input type="text" name="'.$type.'_credits"'.
4590: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4591: }
4592: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 4593: %defaultchecked = ('coursecredits' => 'off');
4594: @toggles = ('coursecredits');
4595: my $current = {
4596: 'coursecredits' => $currusecredits,
4597: };
4598: (my $table,$itemcount) =
4599: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4600: \%choices,$itemcount,$onclick,$additional,'left');
4601: $datatable .= $table;
4602: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4603: my $display = 'none';
4604: if ($postsubmitclient) {
4605: $display = 'block';
4606: }
4607: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 4608: &mt('Number of seconds submit is disabled').'<br />'.
4609: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4610: '<table><tr>';
1.160.6.57 raeburn 4611: foreach my $type (@types) {
4612: $additional .= '<td align="center">'.&mt($type).'<br />'.
4613: '<input type="text" name="'.$type.'_timeout" value="'.
4614: $deftimeout{$type}.'" size="5" /></td>';
4615: }
4616: $additional .= '</tr></table></div>'."\n";
4617: %defaultchecked = ('postsubmit' => 'on');
4618: @toggles = ('postsubmit');
1.160.6.70 raeburn 4619: $current = {
4620: 'postsubmit' => $postsubmitclient,
4621: };
1.160.6.57 raeburn 4622: ($table,$itemcount) =
4623: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4624: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 4625: $datatable .= $table;
1.160.6.70 raeburn 4626: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4627: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4628: $choices{'mysqltables'}.
4629: '</span></td>'.
4630: '<td align="right" class="LC_right_item">'.
4631: '<table><tr>';
4632: foreach my $type (@types) {
4633: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4634: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 4635: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 4636: }
4637: $datatable .= '</tr></table></td></tr>'."\n";
4638: $itemcount ++;
4639:
1.160.6.37 raeburn 4640: }
4641: $$rowtotal += $itemcount;
4642: return $datatable;
4643: }
4644:
4645: sub print_selfenrollment {
4646: my ($position,$dom,$settings,$rowtotal) = @_;
4647: my ($css_class,$datatable);
4648: my $itemcount = 1;
4649: my @types = ('official','unofficial','community','textbook');
4650: if (($position eq 'top') || ($position eq 'middle')) {
4651: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4652: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4653: my @rows;
4654: my $key;
4655: if ($position eq 'top') {
4656: $key = 'admin';
4657: if (ref($rowsref) eq 'ARRAY') {
4658: @rows = @{$rowsref};
4659: }
4660: } elsif ($position eq 'middle') {
4661: $key = 'default';
4662: @rows = ('types','registered','approval','limit');
4663: }
4664: foreach my $row (@rows) {
4665: if (defined($titlesref->{$row})) {
4666: $itemcount ++;
4667: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4668: $datatable .= '<tr'.$css_class.'>'.
4669: '<td>'.$titlesref->{$row}.'</td>'.
4670: '<td class="LC_left_item">'.
4671: '<table><tr>';
4672: my (%current,%currentcap);
4673: if (ref($settings) eq 'HASH') {
4674: if (ref($settings->{$key}) eq 'HASH') {
4675: foreach my $type (@types) {
4676: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4677: $current{$type} = $settings->{$key}->{$type}->{$row};
4678: }
4679: if (($row eq 'limit') && ($key eq 'default')) {
4680: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4681: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4682: }
4683: }
4684: }
4685: }
4686: }
4687: my %roles = (
4688: '0' => &Apache::lonnet::plaintext('dc'),
4689: );
4690:
4691: foreach my $type (@types) {
4692: unless (($row eq 'registered') && ($key eq 'default')) {
4693: $datatable .= '<th>'.&mt($type).'</th>';
4694: }
4695: }
4696: unless (($row eq 'registered') && ($key eq 'default')) {
4697: $datatable .= '</tr><tr>';
4698: }
4699: foreach my $type (@types) {
4700: if ($type eq 'community') {
4701: $roles{'1'} = &mt('Community personnel');
4702: } else {
4703: $roles{'1'} = &mt('Course personnel');
4704: }
4705: $datatable .= '<td style="vertical-align: top">';
4706: if ($position eq 'top') {
4707: my %checked;
4708: if ($current{$type} eq '0') {
4709: $checked{'0'} = ' checked="checked"';
4710: } else {
4711: $checked{'1'} = ' checked="checked"';
4712: }
4713: foreach my $role ('1','0') {
4714: $datatable .= '<span class="LC_nobreak"><label>'.
4715: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4716: 'value="'.$role.'"'.$checked{$role}.' />'.
4717: $roles{$role}.'</label></span> ';
4718: }
4719: } else {
4720: if ($row eq 'types') {
4721: my %checked;
4722: if ($current{$type} =~ /^(all|dom)$/) {
4723: $checked{$1} = ' checked="checked"';
4724: } else {
4725: $checked{''} = ' checked="checked"';
4726: }
4727: foreach my $val ('','dom','all') {
4728: $datatable .= '<span class="LC_nobreak"><label>'.
4729: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4730: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4731: }
4732: } elsif ($row eq 'registered') {
4733: my %checked;
4734: if ($current{$type} eq '1') {
4735: $checked{'1'} = ' checked="checked"';
4736: } else {
4737: $checked{'0'} = ' checked="checked"';
4738: }
4739: foreach my $val ('0','1') {
4740: $datatable .= '<span class="LC_nobreak"><label>'.
4741: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4742: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4743: }
4744: } elsif ($row eq 'approval') {
4745: my %checked;
4746: if ($current{$type} =~ /^([12])$/) {
4747: $checked{$1} = ' checked="checked"';
4748: } else {
4749: $checked{'0'} = ' checked="checked"';
4750: }
4751: for my $val (0..2) {
4752: $datatable .= '<span class="LC_nobreak"><label>'.
4753: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4754: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4755: }
4756: } elsif ($row eq 'limit') {
4757: my %checked;
4758: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4759: $checked{$1} = ' checked="checked"';
4760: } else {
4761: $checked{'none'} = ' checked="checked"';
4762: }
4763: my $cap;
4764: if ($currentcap{$type} =~ /^\d+$/) {
4765: $cap = $currentcap{$type};
4766: }
4767: foreach my $val ('none','allstudents','selfenrolled') {
4768: $datatable .= '<span class="LC_nobreak"><label>'.
4769: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4770: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4771: }
4772: $datatable .= '<br />'.
4773: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4774: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4775: '</span>';
4776: }
4777: }
4778: $datatable .= '</td>';
4779: }
4780: $datatable .= '</tr>';
4781: }
4782: $datatable .= '</table></td></tr>';
4783: }
4784: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 4785: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4786: }
4787: $$rowtotal += $itemcount;
4788: return $datatable;
4789: }
4790:
4791: sub print_validation_rows {
4792: my ($caller,$dom,$settings,$rowtotal) = @_;
4793: my ($itemsref,$namesref,$fieldsref);
4794: if ($caller eq 'selfenroll') {
4795: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4796: } elsif ($caller eq 'requestcourses') {
4797: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4798: }
4799: my %currvalidation;
4800: if (ref($settings) eq 'HASH') {
4801: if (ref($settings->{'validation'}) eq 'HASH') {
4802: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 4803: }
1.160.6.39 raeburn 4804: }
4805: my $datatable;
4806: my $itemcount = 0;
4807: foreach my $item (@{$itemsref}) {
4808: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4809: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4810: $namesref->{$item}.
4811: '</span></td>'.
4812: '<td class="LC_left_item">';
4813: if (($item eq 'url') || ($item eq 'button')) {
4814: $datatable .= '<span class="LC_nobreak">'.
4815: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4816: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4817: } elsif ($item eq 'fields') {
4818: my @currfields;
4819: if (ref($currvalidation{$item}) eq 'ARRAY') {
4820: @currfields = @{$currvalidation{$item}};
4821: }
4822: foreach my $field (@{$fieldsref}) {
4823: my $check = '';
4824: if (grep(/^\Q$field\E$/,@currfields)) {
4825: $check = ' checked="checked"';
4826: }
4827: $datatable .= '<span class="LC_nobreak"><label>'.
4828: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4829: ' value="'.$field.'"'.$check.' />'.$field.
4830: '</label></span> ';
4831: }
4832: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 4833: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 4834: $currvalidation{$item}.
1.160.6.37 raeburn 4835: '</textarea>';
1.160.6.39 raeburn 4836: }
4837: $datatable .= '</td></tr>'."\n";
4838: if (ref($rowtotal)) {
1.160.6.37 raeburn 4839: $itemcount ++;
4840: }
1.139 raeburn 4841: }
1.160.6.39 raeburn 4842: if ($caller eq 'requestcourses') {
4843: my %currhash;
1.160.6.51 raeburn 4844: if (ref($settings) eq 'HASH') {
4845: if (ref($settings->{'validation'}) eq 'HASH') {
4846: if ($settings->{'validation'}{'dc'} ne '') {
4847: $currhash{$settings->{'validation'}{'dc'}} = 1;
4848: }
1.160.6.39 raeburn 4849: }
4850: }
4851: my $numinrow = 2;
4852: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4853: 'validationdc',%currhash);
1.160.6.50 raeburn 4854: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 4855: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 4856: if ($numdc > 1) {
1.160.6.50 raeburn 4857: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 4858: } else {
1.160.6.50 raeburn 4859: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 4860: }
1.160.6.50 raeburn 4861: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 4862: $itemcount ++;
4863: }
4864: if (ref($rowtotal)) {
4865: $$rowtotal += $itemcount;
4866: }
1.121 raeburn 4867: return $datatable;
1.118 jms 4868: }
4869:
1.160.6.98 raeburn 4870: sub print_passwords {
4871: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
4872: my ($datatable,$css_class);
4873: my $itemcount = 0;
4874: my %titles = &Apache::lonlocal::texthash (
4875: captcha => '"Forgot Password" CAPTCHA validation',
4876: link => 'Reset link expiration (hours)',
4877: case => 'Case-sensitive usernames/e-mail',
4878: prelink => 'Information required (form 1)',
4879: postlink => 'Information required (form 2)',
4880: emailsrc => 'LON-CAPA e-mail address type(s)',
4881: customtext => 'Domain specific text (HTML)',
4882: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
4883: intauth_check => 'Check bcrypt cost if authenticated',
4884: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
4885: permanent => 'Permanent e-mail address',
4886: critical => 'Critical notification address',
4887: notify => 'Notification address',
4888: min => 'Minimum password length',
4889: max => 'Maximum password length',
4890: chars => 'Required characters',
4891: numsaved => 'Number of previous passwords to save and disallow reuse',
4892: );
4893: if ($position eq 'top') {
4894: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4895: my $shownlinklife = 2;
4896: my $prelink = 'both';
4897: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
4898: if (ref($settings) eq 'HASH') {
4899: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
4900: $shownlinklife = $settings->{resetlink};
4901: }
4902: if (ref($settings->{resetcase}) eq 'ARRAY') {
4903: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
4904: }
4905: if ($settings->{resetprelink} =~ /^(both|either)$/) {
4906: $prelink = $settings->{resetprelink};
4907: }
4908: if (ref($settings->{resetpostlink}) eq 'HASH') {
4909: %postlink = %{$settings->{resetpostlink}};
4910: }
4911: if (ref($settings->{resetemail}) eq 'ARRAY') {
4912: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
4913: }
4914: if ($settings->{resetremove}) {
4915: $nostdtext = 1;
4916: }
4917: if ($settings->{resetcustom}) {
4918: $customurl = $settings->{resetcustom};
4919: }
4920: } else {
4921: if (ref($types) eq 'ARRAY') {
4922: foreach my $item (@{$types}) {
4923: $casesens{$item} = 1;
4924: $postlink{$item} = ['username','email'];
4925: }
4926: }
4927: $casesens{'default'} = 1;
4928: $postlink{'default'} = ['username','email'];
4929: $prelink = 'both';
4930: %emailsrc = (
4931: permanent => 1,
4932: critical => 1,
4933: notify => 1,
4934: );
4935: }
4936: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
4937: $itemcount ++;
4938: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4939: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
4940: '<td class="LC_left_item">'.
4941: '<input type="textbox" value="'.$shownlinklife.'" '.
4942: 'name="passwords_link" size="3" /></td></tr>';
4943: $itemcount ++;
4944: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4945: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
4946: '<td class="LC_left_item">';
4947: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4948: foreach my $item (@{$types}) {
4949: my $checkedcase;
4950: if ($casesens{$item}) {
4951: $checkedcase = ' checked="checked"';
4952: }
4953: $datatable .= '<span class="LC_nobreak"><label>'.
4954: '<input type="checkbox" name="passwords_case_sensitive" value="'.
4955: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.102.2 3(raebur 4956:0): '</span> ';
1.160.6.98 raeburn 4957: }
4958: }
4959: my $checkedcase;
4960: if ($casesens{'default'}) {
4961: $checkedcase = ' checked="checked"';
4962: }
4963: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
4964: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
4965: $othertitle.'</label></span></td>';
4966: $itemcount ++;
4967: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4968: my %checkedpre = (
4969: both => ' checked="checked"',
4970: either => '',
4971: );
4972: if ($prelink eq 'either') {
4973: $checkedpre{either} = ' checked="checked"';
4974: $checkedpre{both} = '';
4975: }
4976: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
4977: '<td class="LC_left_item"><span class="LC_nobreak">'.
4978: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
4979: &mt('Both username and e-mail address').'</label></span> '.
4980: '<span class="LC_nobreak"><label>'.
4981: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
4982: &mt('Either username or e-mail address').'</label></span></td></tr>';
4983: $itemcount ++;
4984: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4985: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
4986: '<td class="LC_left_item">';
4987: my %postlinked;
4988: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4989: foreach my $item (@{$types}) {
4990: undef(%postlinked);
4991: $datatable .= '<fieldset style="display: inline-block;">'.
4992: '<legend>'.$usertypes->{$item}.'</legend>';
4993: if (ref($postlink{$item}) eq 'ARRAY') {
4994: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
4995: }
4996: foreach my $field ('email','username') {
4997: my $checked;
4998: if ($postlinked{$field}) {
4999: $checked = ' checked="checked"';
5000: }
5001: $datatable .= '<span class="LC_nobreak"><label>'.
5002: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
5003: $field.'"'.$checked.' />'.$field.'</label>'.
5004: '<span> ';
5005: }
5006: $datatable .= '</fieldset>';
5007: }
5008: }
5009: if (ref($postlink{'default'}) eq 'ARRAY') {
5010: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
5011: }
5012: $datatable .= '<fieldset style="display: inline-block;">'.
5013: '<legend>'.$othertitle.'</legend>';
5014: foreach my $field ('email','username') {
5015: my $checked;
5016: if ($postlinked{$field}) {
5017: $checked = ' checked="checked"';
5018: }
5019: $datatable .= '<span class="LC_nobreak"><label>'.
5020: '<input type="checkbox" name="passwords_postlink_default" value="'.
5021: $field.'"'.$checked.' />'.$field.'</label>'.
5022: '<span> ';
5023: }
5024: $datatable .= '</fieldset></td></tr>';
5025: $itemcount ++;
5026: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5027: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
5028: '<td class="LC_left_item">';
5029: foreach my $type ('permanent','critical','notify') {
5030: my $checkedemail;
5031: if ($emailsrc{$type}) {
5032: $checkedemail = ' checked="checked"';
5033: }
5034: $datatable .= '<span class="LC_nobreak"><label>'.
5035: '<input type="checkbox" name="passwords_emailsrc" value="'.
5036: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
5037: '<span> ';
5038: }
5039: $datatable .= '</td></tr>';
5040: $itemcount ++;
5041: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5042: my $switchserver = &check_switchserver($dom,$confname);
5043: my ($showstd,$noshowstd);
5044: if ($nostdtext) {
5045: $noshowstd = ' checked="checked"';
5046: } else {
5047: $showstd = ' checked="checked"';
5048: }
5049: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
5050: '<td class="LC_left_item"><span class="LC_nobreak">'.
5051: &mt('Retain standard text:').
5052: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
5053: &mt('Yes').'</label>'.' '.
5054: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
5055: &mt('No').'</label></span><br />'.
5056: '<span class="LC_fontsize_small">'.
5057: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
5058: &mt('Include custom text:');
5059: if ($customurl) {
1.160.6.102.2 3(raebur 5060:0): my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 5061: undef,undef,undef,undef,'background-color:#ffffff');
5062: $datatable .= '<span class="LC_nobreak"> '.$link.
5063: '<label><input type="checkbox" name="passwords_custom_del"'.
5064: ' value="1" />'.&mt('Delete?').'</label></span>'.
5065: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
5066: }
5067: if ($switchserver) {
5068: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
5069: } else {
5070: $datatable .='<span class="LC_nobreak"> '.
5071: '<input type="file" name="passwords_customfile" /></span>';
5072: }
5073: $datatable .= '</td></tr>';
5074: } elsif ($position eq 'middle') {
5075: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
5076: my @items = ('intauth_cost','intauth_check','intauth_switch');
5077: my %defaults;
5078: if (ref($domconf{'defaults'}) eq 'HASH') {
5079: %defaults = %{$domconf{'defaults'}};
5080: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5081: $defaults{'intauth_cost'} = 10;
5082: }
5083: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5084: $defaults{'intauth_check'} = 0;
5085: }
5086: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5087: $defaults{'intauth_switch'} = 0;
5088: }
5089: } else {
5090: %defaults = (
5091: 'intauth_cost' => 10,
5092: 'intauth_check' => 0,
5093: 'intauth_switch' => 0,
5094: );
5095: }
5096: foreach my $item (@items) {
5097: if ($itemcount%2) {
5098: $css_class = '';
5099: } else {
5100: $css_class = ' class="LC_odd_row" ';
5101: }
5102: $datatable .= '<tr'.$css_class.'>'.
5103: '<td><span class="LC_nobreak">'.$titles{$item}.
5104: '</span></td><td class="LC_left_item" colspan="3">';
5105: if ($item eq 'intauth_switch') {
5106: my @options = (0,1,2);
5107: my %optiondesc = &Apache::lonlocal::texthash (
5108: 0 => 'No',
5109: 1 => 'Yes',
5110: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5111: );
5112: $datatable .= '<table width="100%">';
5113: foreach my $option (@options) {
5114: my $checked = ' ';
5115: if ($defaults{$item} eq $option) {
5116: $checked = ' checked="checked"';
5117: }
5118: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5119: '<label><input type="radio" name="'.$item.
5120: '" value="'.$option.'"'.$checked.' />'.
5121: $optiondesc{$option}.'</label></span></td></tr>';
5122: }
5123: $datatable .= '</table>';
5124: } elsif ($item eq 'intauth_check') {
5125: my @options = (0,1,2);
5126: my %optiondesc = &Apache::lonlocal::texthash (
5127: 0 => 'No',
5128: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5129: 2 => 'Yes, disallow login if stored cost is less than domain default',
5130: );
5131: $datatable .= '<table width="100%">';
5132: foreach my $option (@options) {
5133: my $checked = ' ';
5134: my $onclick;
5135: if ($defaults{$item} eq $option) {
5136: $checked = ' checked="checked"';
5137: }
5138: if ($option == 2) {
5139: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5140: }
5141: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5142: '<label><input type="radio" name="'.$item.
5143: '" value="'.$option.'"'.$checked.$onclick.' />'.
5144: $optiondesc{$option}.'</label></span></td></tr>';
5145: }
5146: $datatable .= '</table>';
5147: } else {
5148: $datatable .= '<input type="text" name="'.$item.'" value="'.
5149: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5150: }
5151: $datatable .= '</td></tr>';
5152: $itemcount ++;
5153: }
5154: } elsif ($position eq 'lower') {
5155: my ($min,$max,%chars,$numsaved);
1.160.6.99 raeburn 5156: $min = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 5157: if (ref($settings) eq 'HASH') {
5158: if ($settings->{min}) {
5159: $min = $settings->{min};
5160: }
5161: if ($settings->{max}) {
5162: $max = $settings->{max};
5163: }
5164: if (ref($settings->{chars}) eq 'ARRAY') {
5165: map { $chars{$_} = 1; } (@{$settings->{chars}});
5166: }
5167: if ($settings->{numsaved}) {
5168: $numsaved = $settings->{numsaved};
5169: }
5170: }
5171: my %rulenames = &Apache::lonlocal::texthash(
5172: uc => 'At least one upper case letter',
5173: lc => 'At least one lower case letter',
5174: num => 'At least one number',
5175: spec => 'At least one non-alphanumeric',
5176: );
5177: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5178: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
5179: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5180: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
5181: 'onblur="javascript:warnIntPass(this);" />'.
5182: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.160.6.98 raeburn 5183: '</span></td></tr>';
5184: $itemcount ++;
5185: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5186: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
5187: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5188: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
5189: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5190: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
5191: '</span></td></tr>';
5192: $itemcount ++;
5193: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5194: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
5195: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
5196: '</span></td>';
5197: my $numinrow = 2;
5198: my @possrules = ('uc','lc','num','spec');
5199: $datatable .= '<td class="LC_left_item"><table>';
5200: for (my $i=0; $i<@possrules; $i++) {
5201: my ($rem,$checked);
5202: if ($chars{$possrules[$i]}) {
5203: $checked = ' checked="checked"';
5204: }
5205: $rem = $i%($numinrow);
5206: if ($rem == 0) {
5207: if ($i > 0) {
5208: $datatable .= '</tr>';
5209: }
5210: $datatable .= '<tr>';
5211: }
5212: $datatable .= '<td><span class="LC_nobreak"><label>'.
5213: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
5214: $rulenames{$possrules[$i]}.'</label></span></td>';
5215: }
5216: my $rem = @possrules%($numinrow);
5217: my $colsleft = $numinrow - $rem;
5218: if ($colsleft > 1 ) {
5219: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5220: ' </td>';
5221: } elsif ($colsleft == 1) {
5222: $datatable .= '<td class="LC_left_item"> </td>';
5223: }
5224: $datatable .='</table></td></tr>';
5225: $itemcount ++;
5226: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5227: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
5228: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.100 raeburn 5229: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
1.160.6.99 raeburn 5230: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5231: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
5232: '</span></td></tr>';
5233: } else {
5234: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5235: my %ownerchg = (
5236: by => {},
5237: for => {},
5238: );
5239: my %ownertitles = &Apache::lonlocal::texthash (
5240: by => 'Course owner status(es) allowed',
5241: for => 'Student status(es) allowed',
5242: );
5243: if (ref($settings) eq 'HASH') {
5244: if (ref($settings->{crsownerchg}) eq 'HASH') {
5245: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
5246: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
5247: }
5248: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
5249: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
5250: }
5251: }
5252: }
5253: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5254: $datatable .= '<tr '.$css_class.'>'.
5255: '<td>'.
5256: &mt('Requirements').'<ul>'.
5257: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
5258: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
5259: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
5260: '<li>'.&mt('User, course, and student share same domain').'</li>'.
5261: '</ul>'.
5262: '</td>'.
5263: '<td class="LC_left_item">';
5264: foreach my $item ('by','for') {
5265: $datatable .= '<fieldset style="display: inline-block;">'.
5266: '<legend>'.$ownertitles{$item}.'</legend>';
5267: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5268: foreach my $type (@{$types}) {
5269: my $checked;
5270: if ($ownerchg{$item}{$type}) {
5271: $checked = ' checked="checked"';
5272: }
5273: $datatable .= '<span class="LC_nobreak"><label>'.
5274: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
5275: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.102.2 3(raebur 5276:0): '</span> ';
1.160.6.98 raeburn 5277: }
5278: }
5279: my $checked;
5280: if ($ownerchg{$item}{'default'}) {
5281: $checked = ' checked="checked"';
5282: }
5283: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5284: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
5285: $othertitle.'</label></span></fieldset>';
5286: }
5287: $datatable .= '</td></tr>';
5288: }
5289: return $datatable;
5290: }
5291:
1.137 raeburn 5292: sub print_usersessions {
5293: my ($position,$dom,$settings,$rowtotal) = @_;
5294: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 5295: my (%by_ip,%by_location,@intdoms);
5296: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 5297:
5298: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5299: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5300: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5301: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5302: my $itemcount = 1;
5303: if ($position eq 'top') {
1.152 raeburn 5304: if (keys(%serverhomes) > 1) {
1.145 raeburn 5305: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.102.2 4(raebur 5306:0): my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 5307: if (ref($settings) eq 'HASH') {
5308: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5309: $curroffloadnow = $settings->{'offloadnow'};
5310: }
1.160.6.102.2 4(raebur 5311:0): if (ref($settings->{'offloadoth'}) eq 'HASH') {
5312:0): $curroffloadoth = $settings->{'offloadoth'};
5313:0): }
1.160.6.61 raeburn 5314: }
1.160.6.102.2 4(raebur 5315:0): my $other_insts = scalar(keys(%by_location));
5316:0): $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
5317:0): $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 5318: } else {
1.140 raeburn 5319: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 5320: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 5321: }
1.137 raeburn 5322: } else {
1.145 raeburn 5323: if (keys(%by_location) == 0) {
5324: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 5325: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 5326: } else {
5327: my %lt = &usersession_titles();
5328: my $numinrow = 5;
5329: my $prefix;
5330: my @types;
5331: if ($position eq 'bottom') {
5332: $prefix = 'remote';
5333: @types = ('version','excludedomain','includedomain');
5334: } else {
5335: $prefix = 'hosted';
5336: @types = ('excludedomain','includedomain');
5337: }
5338: my (%current,%checkedon,%checkedoff);
5339: my @lcversions = &Apache::lonnet::all_loncaparevs();
5340: my @locations = sort(keys(%by_location));
5341: foreach my $type (@types) {
5342: $checkedon{$type} = '';
5343: $checkedoff{$type} = ' checked="checked"';
5344: }
5345: if (ref($settings) eq 'HASH') {
5346: if (ref($settings->{$prefix}) eq 'HASH') {
5347: foreach my $key (keys(%{$settings->{$prefix}})) {
5348: $current{$key} = $settings->{$prefix}{$key};
5349: if ($key eq 'version') {
5350: if ($current{$key} ne '') {
5351: $checkedon{$key} = ' checked="checked"';
5352: $checkedoff{$key} = '';
5353: }
5354: } elsif (ref($current{$key}) eq 'ARRAY') {
5355: $checkedon{$key} = ' checked="checked"';
5356: $checkedoff{$key} = '';
5357: }
1.137 raeburn 5358: }
5359: }
5360: }
1.145 raeburn 5361: foreach my $type (@types) {
5362: next if ($type ne 'version' && !@locations);
5363: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5364: $datatable .= '<tr'.$css_class.'>
5365: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
5366: <span class="LC_nobreak">
5367: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5368: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5369: if ($type eq 'version') {
5370: my $selector = '<select name="'.$prefix.'_version">';
5371: foreach my $version (@lcversions) {
5372: my $selected = '';
5373: if ($current{'version'} eq $version) {
5374: $selected = ' selected="selected"';
5375: }
5376: $selector .= ' <option value="'.$version.'"'.
5377: $selected.'>'.$version.'</option>';
5378: }
5379: $selector .= '</select> ';
5380: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5381: } else {
5382: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5383: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5384: ' />'.(' 'x2).
5385: '<input type="button" value="'.&mt('uncheck all').'" '.
5386: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5387: "\n".
5388: '</div><div><table>';
5389: my $rem;
5390: for (my $i=0; $i<@locations; $i++) {
5391: my ($showloc,$value,$checkedtype);
5392: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
5393: my $ip = $by_location{$locations[$i]}->[0];
5394: if (ref($by_ip{$ip}) eq 'ARRAY') {
5395: $value = join(':',@{$by_ip{$ip}});
5396: $showloc = join(', ',@{$by_ip{$ip}});
5397: if (ref($current{$type}) eq 'ARRAY') {
5398: foreach my $loc (@{$by_ip{$ip}}) {
5399: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5400: $checkedtype = ' checked="checked"';
5401: last;
5402: }
5403: }
1.138 raeburn 5404: }
5405: }
5406: }
1.145 raeburn 5407: $rem = $i%($numinrow);
5408: if ($rem == 0) {
5409: if ($i > 0) {
5410: $datatable .= '</tr>';
5411: }
5412: $datatable .= '<tr>';
5413: }
5414: $datatable .= '<td class="LC_left_item">'.
5415: '<span class="LC_nobreak"><label>'.
5416: '<input type="checkbox" name="'.$prefix.'_'.$type.
5417: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5418: '</label></span></td>';
1.137 raeburn 5419: }
1.145 raeburn 5420: $rem = @locations%($numinrow);
5421: my $colsleft = $numinrow - $rem;
5422: if ($colsleft > 1 ) {
5423: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5424: ' </td>';
5425: } elsif ($colsleft == 1) {
5426: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5427: }
1.145 raeburn 5428: $datatable .= '</tr></table>';
1.137 raeburn 5429: }
1.145 raeburn 5430: $datatable .= '</td></tr>';
5431: $itemcount ++;
1.137 raeburn 5432: }
5433: }
5434: }
5435: $$rowtotal += $itemcount;
5436: return $datatable;
5437: }
5438:
1.138 raeburn 5439: sub build_location_hashes {
5440: my ($intdoms,$by_ip,$by_location) = @_;
5441: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
5442: (ref($by_location) eq 'HASH'));
5443: my %iphost = &Apache::lonnet::get_iphost();
5444: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5445: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5446: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5447: foreach my $id (@{$iphost{$primary_ip}}) {
5448: my $intdom = &Apache::lonnet::internet_dom($id);
5449: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5450: push(@{$intdoms},$intdom);
5451: }
5452: }
5453: }
5454: foreach my $ip (keys(%iphost)) {
5455: if (ref($iphost{$ip}) eq 'ARRAY') {
5456: foreach my $id (@{$iphost{$ip}}) {
5457: my $location = &Apache::lonnet::internet_dom($id);
5458: if ($location) {
5459: next if (grep(/^\Q$location\E$/,@{$intdoms}));
5460: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5461: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5462: push(@{$by_ip->{$ip}},$location);
5463: }
5464: } else {
5465: $by_ip->{$ip} = [$location];
5466: }
5467: }
5468: }
5469: }
5470: }
5471: foreach my $ip (sort(keys(%{$by_ip}))) {
5472: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5473: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5474: my $first = $by_ip->{$ip}->[0];
5475: if (ref($by_location->{$first}) eq 'ARRAY') {
5476: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5477: push(@{$by_location->{$first}},$ip);
5478: }
5479: } else {
5480: $by_location->{$first} = [$ip];
5481: }
5482: }
5483: }
5484: return;
5485: }
5486:
1.145 raeburn 5487: sub current_offloads_to {
5488: my ($dom,$settings,$servers) = @_;
5489: my (%spareid,%otherdomconfigs);
1.152 raeburn 5490: if (ref($servers) eq 'HASH') {
1.145 raeburn 5491: foreach my $lonhost (sort(keys(%{$servers}))) {
5492: my $gotspares;
1.152 raeburn 5493: if (ref($settings) eq 'HASH') {
5494: if (ref($settings->{'spares'}) eq 'HASH') {
5495: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5496: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5497: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5498: $gotspares = 1;
5499: }
1.145 raeburn 5500: }
5501: }
5502: unless ($gotspares) {
5503: my $gotspares;
5504: my $serverhomeID =
5505: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5506: my $serverhomedom =
5507: &Apache::lonnet::host_domain($serverhomeID);
5508: if ($serverhomedom ne $dom) {
5509: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5510: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5511: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5512: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5513: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5514: $gotspares = 1;
5515: }
5516: }
5517: } else {
5518: $otherdomconfigs{$serverhomedom} =
5519: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5520: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5521: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5522: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5523: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5524: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5525: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5526: $gotspares = 1;
5527: }
5528: }
5529: }
5530: }
5531: }
5532: }
5533: }
5534: unless ($gotspares) {
5535: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5536: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5537: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5538: } else {
5539: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5540: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5541: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5542: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5543: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5544: } else {
1.150 raeburn 5545: my %what = (
5546: spareid => 1,
5547: );
5548: my ($result,$returnhash) =
5549: &Apache::lonnet::get_remote_globals($lonhost,\%what);
5550: if ($result eq 'ok') {
5551: if (ref($returnhash) eq 'HASH') {
5552: if (ref($returnhash->{'spareid'}) eq 'HASH') {
5553: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5554: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5555: }
5556: }
1.145 raeburn 5557: }
5558: }
5559: }
5560: }
5561: }
5562: }
5563: return %spareid;
5564: }
5565:
5566: sub spares_row {
1.160.6.102.2 4(raebur 5567:0): my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
5568:0): $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 5569: my $css_class;
5570: my $numinrow = 4;
5571: my $itemcount = 1;
5572: my $datatable;
1.152 raeburn 5573: my %typetitles = &sparestype_titles();
5574: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5575: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5576: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5577: my ($othercontrol,$serverdom);
5578: if ($serverhome ne $server) {
5579: $serverdom = &Apache::lonnet::host_domain($serverhome);
5580: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5581: } else {
5582: $serverdom = &Apache::lonnet::host_domain($server);
5583: if ($serverdom ne $dom) {
5584: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5585: }
5586: }
5587: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.102.2 4(raebur 5588:0): my ($checkednow,$checkedoth);
1.160.6.61 raeburn 5589: if (ref($curroffloadnow) eq 'HASH') {
5590: if ($curroffloadnow->{$server}) {
5591: $checkednow = ' checked="checked"';
5592: }
5593: }
1.160.6.102.2 4(raebur 5594:0): if (ref($curroffloadoth) eq 'HASH') {
5595:0): if ($curroffloadoth->{$server}) {
5596:0): $checkedoth = ' checked="checked"';
5597:0): }
5598:0): }
1.145 raeburn 5599: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5600: $datatable .= '<tr'.$css_class.'>
5601: <td rowspan="2">
1.160.6.13 raeburn 5602: <span class="LC_nobreak">'.
5603: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 5604: ,'<b>'.$server.'</b>').'</span><br />'.
5605: '<span class="LC_nobreak">'."\n".
5606: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.102.2 4(raebur 5607:0): ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 5608: "\n";
1.160.6.102.2 4(raebur 5609:0): if ($other_insts) {
5610:0): $datatable .= '<br />'.
5611:0): '<span class="LC_nobreak">'."\n".
5612:0): '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
5613:0): ' '.&mt('Switch other institutions on next access').'</label></span>'.
5614:0): "\n";
5615:0): }
1.145 raeburn 5616: my (%current,%canselect);
1.152 raeburn 5617: my @choices =
5618: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5619: foreach my $type ('primary','default') {
5620: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5621: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5622: my @spares = @{$spareid->{$server}{$type}};
5623: if (@spares > 0) {
1.152 raeburn 5624: if ($othercontrol) {
5625: $current{$type} = join(', ',@spares);
5626: } else {
5627: $current{$type} .= '<table>';
5628: my $numspares = scalar(@spares);
5629: for (my $i=0; $i<@spares; $i++) {
5630: my $rem = $i%($numinrow);
5631: if ($rem == 0) {
5632: if ($i > 0) {
5633: $current{$type} .= '</tr>';
5634: }
5635: $current{$type} .= '<tr>';
1.145 raeburn 5636: }
1.152 raeburn 5637: $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'".');" /> '.
5638: $spareid->{$server}{$type}[$i].
5639: '</label></td>'."\n";
5640: }
5641: my $rem = @spares%($numinrow);
5642: my $colsleft = $numinrow - $rem;
5643: if ($colsleft > 1 ) {
5644: $current{$type} .= '<td colspan="'.$colsleft.
5645: '" class="LC_left_item">'.
5646: ' </td>';
5647: } elsif ($colsleft == 1) {
5648: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5649: }
1.152 raeburn 5650: $current{$type} .= '</tr></table>';
1.150 raeburn 5651: }
1.145 raeburn 5652: }
5653: }
5654: if ($current{$type} eq '') {
5655: $current{$type} = &mt('None specified');
5656: }
1.152 raeburn 5657: if ($othercontrol) {
5658: if ($type eq 'primary') {
5659: $canselect{$type} = $othercontrol;
5660: }
5661: } else {
5662: $canselect{$type} =
5663: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5664: '<select name="newspare_'.$type.'_'.$server.'" '.
5665: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5666: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5667: if (@choices > 0) {
5668: foreach my $lonhost (@choices) {
5669: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5670: }
5671: }
5672: $canselect{$type} .= '</select>'."\n";
5673: }
5674: } else {
5675: $current{$type} = &mt('Could not be determined');
5676: if ($type eq 'primary') {
5677: $canselect{$type} = $othercontrol;
5678: }
1.145 raeburn 5679: }
1.152 raeburn 5680: if ($type eq 'default') {
5681: $datatable .= '<tr'.$css_class.'>';
5682: }
5683: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5684: '<td>'.$current{$type}.'</td>'."\n".
5685: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5686: }
5687: $itemcount ++;
5688: }
5689: }
5690: $$rowtotal += $itemcount;
5691: return $datatable;
5692: }
5693:
1.152 raeburn 5694: sub possible_newspares {
5695: my ($server,$currspares,$serverhomes,$altids) = @_;
5696: my $serverhostname = &Apache::lonnet::hostname($server);
5697: my %excluded;
5698: if ($serverhostname ne '') {
5699: %excluded = (
5700: $serverhostname => 1,
5701: );
5702: }
5703: if (ref($currspares) eq 'HASH') {
5704: foreach my $type (keys(%{$currspares})) {
5705: if (ref($currspares->{$type}) eq 'ARRAY') {
5706: if (@{$currspares->{$type}} > 0) {
5707: foreach my $curr (@{$currspares->{$type}}) {
5708: my $hostname = &Apache::lonnet::hostname($curr);
5709: $excluded{$hostname} = 1;
5710: }
5711: }
5712: }
5713: }
5714: }
5715: my @choices;
5716: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5717: if (keys(%{$serverhomes}) > 1) {
5718: foreach my $name (sort(keys(%{$serverhomes}))) {
5719: unless ($excluded{$name}) {
5720: if (exists($altids->{$serverhomes->{$name}})) {
5721: push(@choices,$altids->{$serverhomes->{$name}});
5722: } else {
5723: push(@choices,$serverhomes->{$name});
1.145 raeburn 5724: }
5725: }
5726: }
5727: }
5728: }
1.152 raeburn 5729: return sort(@choices);
1.145 raeburn 5730: }
5731:
1.150 raeburn 5732: sub print_loadbalancing {
5733: my ($dom,$settings,$rowtotal) = @_;
5734: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5735: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5736: my $numinrow = 1;
5737: my $datatable;
5738: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 5739: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 5740: if (ref($settings) eq 'HASH') {
5741: %existing = %{$settings};
5742: }
5743: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5744: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 5745: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 5746: } else {
5747: return;
5748: }
5749: my ($othertitle,$usertypes,$types) =
5750: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 5751: my $rownum = 8;
1.150 raeburn 5752: if (ref($types) eq 'ARRAY') {
5753: $rownum += scalar(@{$types});
5754: }
1.160.6.7 raeburn 5755: my @css_class = ('LC_odd_row','LC_even_row');
5756: my $balnum = 0;
5757: my $islast;
5758: my (@toshow,$disabledtext);
5759: if (keys(%currbalancer) > 0) {
5760: @toshow = sort(keys(%currbalancer));
5761: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5762: push(@toshow,'');
5763: }
5764: } else {
5765: @toshow = ('');
5766: $disabledtext = &mt('No existing load balancer');
5767: }
5768: foreach my $lonhost (@toshow) {
5769: if ($balnum == scalar(@toshow)-1) {
5770: $islast = 1;
5771: } else {
5772: $islast = 0;
5773: }
5774: my $cssidx = $balnum%2;
5775: my $targets_div_style = 'display: none';
5776: my $disabled_div_style = 'display: block';
5777: my $homedom_div_style = 'display: none';
5778: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5779: '<td rowspan="'.$rownum.'" valign="top">'.
5780: '<p>';
5781: if ($lonhost eq '') {
5782: $datatable .= '<span class="LC_nobreak">';
5783: if (keys(%currbalancer) > 0) {
5784: $datatable .= &mt('Add balancer:');
5785: } else {
5786: $datatable .= &mt('Enable balancer:');
5787: }
5788: $datatable .= ' '.
5789: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5790: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5791: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5792: '<option value="" selected="selected">'.&mt('None').
5793: '</option>'."\n";
5794: foreach my $server (sort(keys(%servers))) {
5795: next if ($currbalancer{$server});
5796: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5797: }
5798: $datatable .=
5799: '</select>'."\n".
5800: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5801: } else {
5802: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5803: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5804: &mt('Stop balancing').'</label>'.
5805: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5806: $targets_div_style = 'display: block';
5807: $disabled_div_style = 'display: none';
5808: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5809: $homedom_div_style = 'display: block';
5810: }
5811: }
5812: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5813: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5814: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5815: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5816: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5817: my @sparestypes = ('primary','default');
5818: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 5819: my %hostherechecked = (
5820: no => ' checked="checked"',
5821: );
1.160.6.94 raeburn 5822: my %balcookiechecked = (
5823: no => ' checked="checked"',
5824: );
1.160.6.7 raeburn 5825: foreach my $sparetype (@sparestypes) {
5826: my $targettable;
5827: for (my $i=0; $i<$numspares; $i++) {
5828: my $checked;
5829: if (ref($currtargets{$lonhost}) eq 'HASH') {
5830: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5831: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5832: $checked = ' checked="checked"';
5833: }
5834: }
5835: }
5836: my ($chkboxval,$disabled);
5837: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5838: $chkboxval = $spares[$i];
5839: }
5840: if (exists($currbalancer{$spares[$i]})) {
5841: $disabled = ' disabled="disabled"';
5842: }
5843: $targettable .=
1.160.6.55 raeburn 5844: '<td><span class="LC_nobreak"><label>'.
5845: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 5846: $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 5847: '</span></label></span></td>';
1.160.6.7 raeburn 5848: my $rem = $i%($numinrow);
5849: if ($rem == 0) {
5850: if (($i > 0) && ($i < $numspares-1)) {
5851: $targettable .= '</tr>';
5852: }
5853: if ($i < $numspares-1) {
5854: $targettable .= '<tr>';
1.150 raeburn 5855: }
5856: }
5857: }
1.160.6.7 raeburn 5858: if ($targettable ne '') {
5859: my $rem = $numspares%($numinrow);
5860: my $colsleft = $numinrow - $rem;
5861: if ($colsleft > 1 ) {
5862: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5863: ' </td>';
5864: } elsif ($colsleft == 1) {
5865: $targettable .= '<td class="LC_left_item"> </td>';
5866: }
5867: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5868: '<table><tr>'.$targettable.'</tr></table><br />';
5869: }
1.160.6.76 raeburn 5870: $hostherechecked{$sparetype} = '';
5871: if (ref($currtargets{$lonhost}) eq 'HASH') {
5872: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5873: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5874: $hostherechecked{$sparetype} = ' checked="checked"';
5875: $hostherechecked{'no'} = '';
5876: }
5877: }
5878: }
5879: }
1.160.6.94 raeburn 5880: if ($currcookies{$lonhost}) {
5881: %balcookiechecked = (
5882: yes => ' checked="checked"',
5883: );
5884: }
1.160.6.76 raeburn 5885: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5886: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5887: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5888: foreach my $sparetype (@sparestypes) {
5889: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5890: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5891: '</i></label><br />';
1.160.6.7 raeburn 5892: }
1.160.6.94 raeburn 5893: $datatable .= &mt('Use balancer cookie').'<br />'.
5894: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
5895: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
5896: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
5897: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
5898: '</div></td></tr>'.
1.160.6.7 raeburn 5899: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5900: $othertitle,$usertypes,$types,\%servers,
5901: \%currbalancer,$lonhost,
5902: $targets_div_style,$homedom_div_style,
5903: $css_class[$cssidx],$balnum,$islast);
5904: $$rowtotal += $rownum;
5905: $balnum ++;
5906: }
5907: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5908: return $datatable;
5909: }
5910:
5911: sub get_loadbalancers_config {
1.160.6.94 raeburn 5912: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 5913: return unless ((ref($servers) eq 'HASH') &&
5914: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 5915: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
5916: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 5917: if (keys(%{$existing}) > 0) {
5918: my $oldlonhost;
5919: foreach my $key (sort(keys(%{$existing}))) {
5920: if ($key eq 'lonhost') {
5921: $oldlonhost = $existing->{'lonhost'};
5922: $currbalancer->{$oldlonhost} = 1;
5923: } elsif ($key eq 'targets') {
5924: if ($oldlonhost) {
5925: $currtargets->{$oldlonhost} = $existing->{'targets'};
5926: }
5927: } elsif ($key eq 'rules') {
5928: if ($oldlonhost) {
5929: $currrules->{$oldlonhost} = $existing->{'rules'};
5930: }
5931: } elsif (ref($existing->{$key}) eq 'HASH') {
5932: $currbalancer->{$key} = 1;
5933: $currtargets->{$key} = $existing->{$key}{'targets'};
5934: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 5935: if ($existing->{$key}{'cookie'}) {
5936: $currcookies->{$key} = 1;
5937: }
1.150 raeburn 5938: }
5939: }
1.160.6.7 raeburn 5940: } else {
5941: my ($balancerref,$targetsref) =
5942: &Apache::lonnet::get_lonbalancer_config($servers);
5943: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5944: foreach my $server (sort(keys(%{$balancerref}))) {
5945: $currbalancer->{$server} = 1;
5946: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5947: }
5948: }
5949: }
1.160.6.7 raeburn 5950: return;
1.150 raeburn 5951: }
5952:
5953: sub loadbalancing_rules {
5954: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 5955: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5956: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5957: my $output;
1.160.6.7 raeburn 5958: my $num = 0;
5959: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5960: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5961: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5962: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 5963: $num ++;
1.150 raeburn 5964: my $current;
5965: if (ref($currrules) eq 'HASH') {
5966: $current = $currrules->{$type};
5967: }
1.160.6.55 raeburn 5968: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 5969: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5970: $current = '';
5971: }
5972: }
5973: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 5974: $servers,$currbalancer,$lonhost,$dom,
5975: $targets_div_style,$homedom_div_style,
5976: $css_class,$balnum,$num,$islast);
1.150 raeburn 5977: }
5978: }
5979: return $output;
5980: }
5981:
5982: sub loadbalancing_titles {
5983: my ($dom,$intdom,$usertypes,$types) = @_;
5984: my %othertypes = (
5985: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5986: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5987: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5988: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 5989: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5990: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5991: );
1.160.6.26 raeburn 5992: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 5993: my @available;
1.150 raeburn 5994: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 5995: @available = @{$types};
1.150 raeburn 5996: }
1.160.6.89 raeburn 5997: unless (grep(/^default$/,@available)) {
5998: push(@available,'default');
5999: }
6000: unshift(@alltypes,@available);
1.150 raeburn 6001: my %titles;
6002: foreach my $type (@alltypes) {
6003: if ($type =~ /^_LC_/) {
6004: $titles{$type} = $othertypes{$type};
6005: } elsif ($type eq 'default') {
6006: $titles{$type} = &mt('All users from [_1]',$dom);
6007: if (ref($types) eq 'ARRAY') {
6008: if (@{$types} > 0) {
6009: $titles{$type} = &mt('Other users from [_1]',$dom);
6010: }
6011: }
6012: } elsif (ref($usertypes) eq 'HASH') {
6013: $titles{$type} = $usertypes->{$type};
6014: }
6015: }
6016: return (\@alltypes,\%othertypes,\%titles);
6017: }
6018:
6019: sub loadbalance_rule_row {
1.160.6.7 raeburn 6020: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6021: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 6022: my @rulenames;
1.150 raeburn 6023: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 6024: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 6025: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6026: } else {
1.160.6.26 raeburn 6027: @rulenames = ('default','homeserver');
6028: if ($type eq '_LC_external') {
6029: push(@rulenames,'externalbalancer');
6030: } else {
6031: push(@rulenames,'specific');
6032: }
6033: push(@rulenames,'none');
1.150 raeburn 6034: }
6035: my $style = $targets_div_style;
1.160.6.55 raeburn 6036: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6037: $style = $homedom_div_style;
6038: }
1.160.6.7 raeburn 6039: my $space;
6040: if ($islast && $num == 1) {
6041: $space = '<div display="inline-block"> </div>';
6042: }
6043: my $output =
6044: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
6045: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6046: '<td valaign="top">'.$space.
6047: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6048: for (my $i=0; $i<@rulenames; $i++) {
6049: my $rule = $rulenames[$i];
6050: my ($checked,$extra);
6051: if ($rulenames[$i] eq 'default') {
6052: $rule = '';
6053: }
6054: if ($rulenames[$i] eq 'specific') {
6055: if (ref($servers) eq 'HASH') {
6056: my $default;
6057: if (($current ne '') && (exists($servers->{$current}))) {
6058: $checked = ' checked="checked"';
6059: }
6060: unless ($checked) {
6061: $default = ' selected="selected"';
6062: }
1.160.6.7 raeburn 6063: $extra =
6064: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6065: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6066: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6067: '<option value=""'.$default.'></option>'."\n";
6068: foreach my $server (sort(keys(%{$servers}))) {
6069: if (ref($currbalancer) eq 'HASH') {
6070: next if (exists($currbalancer->{$server}));
6071: }
1.150 raeburn 6072: my $selected;
1.160.6.7 raeburn 6073: if ($server eq $current) {
1.150 raeburn 6074: $selected = ' selected="selected"';
6075: }
1.160.6.7 raeburn 6076: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6077: }
6078: $extra .= '</select>';
6079: }
6080: } elsif ($rule eq $current) {
6081: $checked = ' checked="checked"';
6082: }
6083: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 6084: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6085: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6086: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 6087: ')"'.$checked.' /> ';
1.160.6.56 raeburn 6088: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 6089: $output .= $ruletitles{'particular'};
6090: } else {
6091: $output .= $ruletitles{$rulenames[$i]};
6092: }
6093: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6094: }
6095: $output .= '</div></td></tr>'."\n";
6096: return $output;
6097: }
6098:
6099: sub offloadtype_text {
6100: my %ruletitles = &Apache::lonlocal::texthash (
6101: 'default' => 'Offloads to default destinations',
6102: 'homeserver' => "Offloads to user's home server",
6103: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6104: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 6105: 'none' => 'No offload',
1.160.6.26 raeburn 6106: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6107: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 6108: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6109: );
6110: return %ruletitles;
6111: }
6112:
6113: sub sparestype_titles {
6114: my %typestitles = &Apache::lonlocal::texthash (
6115: 'primary' => 'primary',
6116: 'default' => 'default',
6117: );
6118: return %typestitles;
6119: }
6120:
1.28 raeburn 6121: sub contact_titles {
6122: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 6123: 'supportemail' => 'Support E-mail address',
6124: 'adminemail' => 'Default Server Admin E-mail address',
6125: 'errormail' => 'Error reports to be e-mailed to',
6126: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 6127: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6128: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 6129: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6130: 'requestsmail' => 'E-mail from course requests requiring approval',
6131: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 6132: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 6133: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.102.2 7(raebur 6134:1): 'errorthreshold' => 'Error/warning threshold for status e-mail',
6135:1): 'errorsysmail' => 'Error threshold for e-mail to core group',
6136:1): 'errorweights' => 'Weights used to compute error count',
6137:1): 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 6138: );
6139: my %short_titles = &Apache::lonlocal::texthash (
6140: adminemail => 'Admin E-mail address',
6141: supportemail => 'Support E-mail',
6142: );
6143: return (\%titles,\%short_titles);
6144: }
6145:
1.160.6.78 raeburn 6146: sub helpform_fields {
6147: my %titles = &Apache::lonlocal::texthash (
6148: 'username' => 'Name',
6149: 'user' => 'Username/domain',
6150: 'phone' => 'Phone',
6151: 'cc' => 'Cc e-mail',
6152: 'course' => 'Course Details',
6153: 'section' => 'Sections',
6154: 'screenshot' => 'File upload',
6155: );
6156: my @fields = ('username','phone','user','course','section','cc','screenshot');
6157: my %possoptions = (
6158: username => ['yes','no','req'],
6159: phone => ['yes','no','req'],
6160: user => ['yes','no'],
6161: cc => ['yes','no'],
6162: course => ['yes','no'],
6163: section => ['yes','no'],
6164: screenshot => ['yes','no'],
6165: );
6166: my %fieldoptions = &Apache::lonlocal::texthash (
6167: 'yes' => 'Optional',
6168: 'req' => 'Required',
6169: 'no' => "Not shown",
6170: );
6171: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6172: }
6173:
1.72 raeburn 6174: sub tool_titles {
6175: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 6176: aboutme => 'Personal web page',
1.86 raeburn 6177: blog => 'Blog',
1.160.6.4 raeburn 6178: webdav => 'WebDAV',
1.86 raeburn 6179: portfolio => 'Portfolio',
1.88 bisitz 6180: official => 'Official courses (with institutional codes)',
6181: unofficial => 'Unofficial courses',
1.98 raeburn 6182: community => 'Communities',
1.160.6.30 raeburn 6183: textbook => 'Textbook courses',
1.86 raeburn 6184: );
1.72 raeburn 6185: return %titles;
6186: }
6187:
1.101 raeburn 6188: sub courserequest_titles {
6189: my %titles = &Apache::lonlocal::texthash (
6190: official => 'Official',
6191: unofficial => 'Unofficial',
6192: community => 'Communities',
1.160.6.30 raeburn 6193: textbook => 'Textbook',
1.101 raeburn 6194: norequest => 'Not allowed',
1.104 raeburn 6195: approval => 'Approval by Dom. Coord.',
1.101 raeburn 6196: validate => 'With validation',
6197: autolimit => 'Numerical limit',
1.103 raeburn 6198: unlimited => '(blank for unlimited)',
1.101 raeburn 6199: );
6200: return %titles;
6201: }
6202:
1.160.6.5 raeburn 6203: sub authorrequest_titles {
6204: my %titles = &Apache::lonlocal::texthash (
6205: norequest => 'Not allowed',
6206: approval => 'Approval by Dom. Coord.',
6207: automatic => 'Automatic approval',
6208: );
6209: return %titles;
6210: }
6211:
1.101 raeburn 6212: sub courserequest_conditions {
6213: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6214: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 6215: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6216: );
6217: return %conditions;
6218: }
6219:
6220:
1.27 raeburn 6221: sub print_usercreation {
1.30 raeburn 6222: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6223: my $numinrow = 4;
1.28 raeburn 6224: my $datatable;
6225: if ($position eq 'top') {
1.30 raeburn 6226: $$rowtotal ++;
1.34 raeburn 6227: my $rowcount = 0;
1.32 raeburn 6228: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6229: if (ref($rules) eq 'HASH') {
6230: if (keys(%{$rules}) > 0) {
1.32 raeburn 6231: $datatable .= &user_formats_row('username',$settings,$rules,
6232: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6233: $$rowtotal ++;
1.32 raeburn 6234: $rowcount ++;
6235: }
6236: }
6237: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6238: if (ref($idrules) eq 'HASH') {
6239: if (keys(%{$idrules}) > 0) {
6240: $datatable .= &user_formats_row('id',$settings,$idrules,
6241: $idruleorder,$numinrow,$rowcount);
6242: $$rowtotal ++;
6243: $rowcount ++;
1.28 raeburn 6244: }
6245: }
1.39 raeburn 6246: if ($rowcount == 0) {
6247: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6248: $$rowtotal ++;
6249: $rowcount ++;
6250: }
1.34 raeburn 6251: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 6252: my @creators = ('author','course','requestcrs');
1.37 raeburn 6253: my ($rules,$ruleorder) =
6254: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6255: my %lt = &usercreation_types();
6256: my %checked;
6257: if (ref($settings) eq 'HASH') {
6258: if (ref($settings->{'cancreate'}) eq 'HASH') {
6259: foreach my $item (@creators) {
6260: $checked{$item} = $settings->{'cancreate'}{$item};
6261: }
6262: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6263: foreach my $item (@creators) {
6264: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6265: $checked{$item} = 'none';
6266: }
6267: }
6268: }
6269: }
6270: my $rownum = 0;
6271: foreach my $item (@creators) {
6272: $rownum ++;
1.160.6.34 raeburn 6273: if ($checked{$item} eq '') {
6274: $checked{$item} = 'any';
1.34 raeburn 6275: }
6276: my $css_class;
6277: if ($rownum%2) {
6278: $css_class = '';
6279: } else {
6280: $css_class = ' class="LC_odd_row" ';
6281: }
6282: $datatable .= '<tr'.$css_class.'>'.
6283: '<td><span class="LC_nobreak">'.$lt{$item}.
6284: '</span></td><td align="right">';
1.160.6.34 raeburn 6285: my @options = ('any');
6286: if (ref($rules) eq 'HASH') {
6287: if (keys(%{$rules}) > 0) {
6288: push(@options,('official','unofficial'));
1.37 raeburn 6289: }
6290: }
1.160.6.34 raeburn 6291: push(@options,'none');
1.37 raeburn 6292: foreach my $option (@options) {
1.50 raeburn 6293: my $type = 'radio';
1.34 raeburn 6294: my $check = ' ';
1.160.6.34 raeburn 6295: if ($checked{$item} eq $option) {
6296: $check = ' checked="checked" ';
1.34 raeburn 6297: }
6298: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6299: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6300: $item.'" value="'.$option.'"'.$check.'/> '.
6301: $lt{$option}.'</label> </span>';
6302: }
6303: $datatable .= '</td></tr>';
6304: }
1.28 raeburn 6305: } else {
6306: my @contexts = ('author','course','domain');
6307: my @authtypes = ('int','krb4','krb5','loc');
6308: my %checked;
6309: if (ref($settings) eq 'HASH') {
6310: if (ref($settings->{'authtypes'}) eq 'HASH') {
6311: foreach my $item (@contexts) {
6312: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6313: foreach my $auth (@authtypes) {
6314: if ($settings->{'authtypes'}{$item}{$auth}) {
6315: $checked{$item}{$auth} = ' checked="checked" ';
6316: }
6317: }
6318: }
6319: }
1.27 raeburn 6320: }
1.35 raeburn 6321: } else {
6322: foreach my $item (@contexts) {
1.36 raeburn 6323: foreach my $auth (@authtypes) {
1.35 raeburn 6324: $checked{$item}{$auth} = ' checked="checked" ';
6325: }
6326: }
1.27 raeburn 6327: }
1.28 raeburn 6328: my %title = &context_names();
6329: my %authname = &authtype_names();
6330: my $rownum = 0;
6331: my $css_class;
6332: foreach my $item (@contexts) {
6333: if ($rownum%2) {
6334: $css_class = '';
6335: } else {
6336: $css_class = ' class="LC_odd_row" ';
6337: }
1.30 raeburn 6338: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6339: '<td>'.$title{$item}.
6340: '</td><td class="LC_left_item">'.
6341: '<span class="LC_nobreak">';
6342: foreach my $auth (@authtypes) {
6343: $datatable .= '<label>'.
6344: '<input type="checkbox" name="'.$item.'_auth" '.
6345: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6346: $authname{$auth}.'</label> ';
6347: }
6348: $datatable .= '</span></td></tr>';
6349: $rownum ++;
1.27 raeburn 6350: }
1.30 raeburn 6351: $$rowtotal += $rownum;
1.27 raeburn 6352: }
6353: return $datatable;
6354: }
6355:
1.160.6.34 raeburn 6356: sub print_selfcreation {
6357: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 6358: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6359: $emaildomain,$datatable);
1.160.6.34 raeburn 6360: if (ref($settings) eq 'HASH') {
6361: if (ref($settings->{'cancreate'}) eq 'HASH') {
6362: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 6363: if (ref($createsettings) eq 'HASH') {
6364: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6365: @selfcreate = @{$createsettings->{'selfcreate'}};
6366: } elsif ($createsettings->{'selfcreate'} ne '') {
6367: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6368: @selfcreate = ('email','login','sso');
6369: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6370: @selfcreate = ($createsettings->{'selfcreate'});
6371: }
6372: }
6373: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6374: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 6375: }
1.160.6.93 raeburn 6376: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6377: $emailoptions = $createsettings->{'emailoptions'};
6378: }
6379: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6380: $emailverified = $createsettings->{'emailverified'};
6381: }
6382: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6383: $emaildomain = $createsettings->{'emaildomain'};
6384: }
1.160.6.34 raeburn 6385: }
6386: }
6387: }
6388: my %radiohash;
6389: my $numinrow = 4;
6390: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 6391: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 6392: if ($position eq 'top') {
6393: my %choices = &Apache::lonlocal::texthash (
6394: cancreate_login => 'Institutional Login',
6395: cancreate_sso => 'Institutional Single Sign On',
6396: );
6397: my @toggles = sort(keys(%choices));
6398: my %defaultchecked = (
6399: 'cancreate_login' => 'off',
6400: 'cancreate_sso' => 'off',
6401: );
1.160.6.35 raeburn 6402: my ($onclick,$itemcount);
1.160.6.34 raeburn 6403: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6404: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 6405: $$rowtotal += $itemcount;
1.160.6.34 raeburn 6406:
6407: if (ref($usertypes) eq 'HASH') {
6408: if (keys(%{$usertypes}) > 0) {
6409: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6410: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 6411: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 6412: $$rowtotal ++;
6413: }
6414: }
1.160.6.44 raeburn 6415: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6416: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6417: $fieldtitles{'inststatus'} = &mt('Institutional status');
6418: my $rem;
6419: my $numperrow = 2;
6420: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6421: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 6422: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 6423: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 6424: '<table>'."\n";
1.160.6.44 raeburn 6425: for (my $i=0; $i<@fields; $i++) {
6426: $rem = $i%($numperrow);
6427: if ($rem == 0) {
6428: if ($i > 0) {
6429: $datatable .= '</tr>';
6430: }
6431: $datatable .= '<tr>';
6432: }
6433: my $currval;
1.160.6.51 raeburn 6434: if (ref($createsettings) eq 'HASH') {
6435: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6436: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6437: }
1.160.6.44 raeburn 6438: }
6439: $datatable .= '<td class="LC_left_item">'.
6440: '<span class="LC_nobreak">'.
6441: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6442: 'value="'.$currval.'" size="10" /> '.
6443: $fieldtitles{$fields[$i]}.'</span></td>';
6444: }
6445: my $colsleft = $numperrow - $rem;
6446: if ($colsleft > 1 ) {
6447: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6448: ' </td>';
6449: } elsif ($colsleft == 1) {
6450: $datatable .= '<td class="LC_left_item"> </td>';
6451: }
6452: $datatable .= '</tr></table></td></tr>';
6453: $$rowtotal ++;
1.160.6.34 raeburn 6454: } elsif ($position eq 'middle') {
6455: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 6456: my @posstypes;
1.160.6.34 raeburn 6457: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 6458: @posstypes = @{$types};
6459: }
6460: unless (grep(/^default$/,@posstypes)) {
6461: push(@posstypes,'default');
6462: }
6463: my %usertypeshash;
6464: if (ref($usertypes) eq 'HASH') {
6465: %usertypeshash = %{$usertypes};
6466: }
6467: $usertypeshash{'default'} = $othertitle;
6468: foreach my $status (@posstypes) {
6469: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6470: $numinrow,$$rowtotal,\%usertypeshash);
6471: $$rowtotal ++;
1.160.6.34 raeburn 6472: }
6473: } else {
1.160.6.40 raeburn 6474: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 6475: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 6476: );
6477: my @toggles = sort(keys(%choices));
6478: my %defaultchecked = (
6479: 'cancreate_email' => 'off',
6480: );
1.160.6.93 raeburn 6481: my $customclass = 'LC_selfcreate_email';
6482: my $classprefix = 'LC_canmodify_emailusername_';
6483: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 6484: my $display = 'none';
1.160.6.93 raeburn 6485: my $rowstyle = 'display:none';
1.160.6.40 raeburn 6486: if (grep(/^\Qemail\E$/,@selfcreate)) {
6487: $display = 'block';
1.160.6.93 raeburn 6488: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 6489: }
1.160.6.93 raeburn 6490: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6491: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6492: \%choices,$$rowtotal,$onclick);
6493: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6494: $rowstyle);
6495: $$rowtotal ++;
6496: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6497: $rowstyle);
6498: $$rowtotal ++;
6499: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 6500: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 6501: my ($emailrules,$emailruleorder) =
6502: &Apache::lonnet::inst_userrules($dom,'email');
6503: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6504: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6505: if (ref($types) eq 'ARRAY') {
6506: @posstypes = @{$types};
6507: }
6508: if (@posstypes) {
6509: unless (grep(/^default$/,@posstypes)) {
6510: push(@posstypes,'default');
1.160.6.89 raeburn 6511: }
6512: if (ref($usertypes) eq 'HASH') {
6513: %usertypeshash = %{$usertypes};
6514: }
1.160.6.93 raeburn 6515: my $currassign;
6516: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6517: $currassign = {
6518: selfassign => $domdefaults{'inststatusguest'},
6519: };
6520: @ordered = @{$domdefaults{'inststatusguest'}};
6521: } else {
6522: $currassign = { selfassign => [] };
6523: }
6524: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6525: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6526: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6527: $numinrow,$othertitle,'selfassign',
6528: $rowtotal,$onclicktypes,$customclass,
6529: $rowstyle);
6530: $$rowtotal ++;
1.160.6.89 raeburn 6531: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 6532: foreach my $status (@posstypes) {
6533: my $css_class;
6534: if ($$rowtotal%2) {
6535: $css_class = 'LC_odd_row ';
6536: }
6537: $css_class .= $customclass;
6538: my $rowid = $optionsprefix.$status;
6539: my $hidden = 1;
6540: my $currstyle = 'display:none';
6541: if (grep(/^\Q$status\E$/,@ordered)) {
6542: $currstyle = $rowstyle;
6543: $hidden = 0;
6544: }
6545: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6546: $emailrules,$emailruleorder,$settings,$status,$rowid,
6547: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6548: unless ($hidden) {
6549: $$rowtotal ++;
6550: }
1.160.6.89 raeburn 6551: }
6552: } else {
1.160.6.93 raeburn 6553: my $css_class;
6554: if ($$rowtotal%2) {
6555: $css_class = 'LC_odd_row ';
6556: }
6557: $css_class .= $customclass;
1.160.6.89 raeburn 6558: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 6559: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6560: $emailrules,$emailruleorder,$settings,'default','',
6561: $othertitle,$css_class,$rowstyle,$intdom);
6562: $$rowtotal ++;
1.160.6.34 raeburn 6563: }
1.160.6.35 raeburn 6564: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
6565: $numinrow = 1;
1.160.6.93 raeburn 6566: if (@posstypes) {
6567: foreach my $status (@posstypes) {
6568: my $rowid = $classprefix.$status;
6569: my $datarowstyle = 'display:none';
6570: if (grep(/^\Q$status\E$/,@ordered)) {
6571: $datarowstyle = $rowstyle;
6572: }
6573: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6574: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6575: $infotitles,$rowid,$customclass,$datarowstyle);
6576: unless ($datarowstyle eq 'display:none') {
6577: $$rowtotal ++;
6578: }
1.160.6.34 raeburn 6579: }
1.160.6.93 raeburn 6580: } else {
6581: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
6582: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6583: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 6584: }
6585: }
6586: return $datatable;
6587: }
6588:
1.160.6.93 raeburn 6589: sub selfcreate_javascript {
6590: return <<"ENDSCRIPT";
6591:
6592: <script type="text/javascript">
6593: // <![CDATA[
6594:
6595: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6596: var x = document.getElementsByClassName(target);
6597: var insttypes = 0;
6598: var insttypeRegExp = new RegExp(prefix);
6599: if ((x.length != undefined) && (x.length > 0)) {
6600: if (form.elements[radio].length != undefined) {
6601: for (var i=0; i<form.elements[radio].length; i++) {
6602: if (form.elements[radio][i].checked) {
6603: if (form.elements[radio][i].value == 1) {
6604: for (var j=0; j<x.length; j++) {
6605: if (x[j].id == 'undefined') {
6606: x[j].style.display = 'table-row';
6607: } else if (insttypeRegExp.test(x[j].id)) {
6608: insttypes ++;
6609: } else {
6610: x[j].style.display = 'table-row';
6611: }
6612: }
6613: } else {
6614: for (var j=0; j<x.length; j++) {
6615: x[j].style.display = 'none';
6616: }
1.160.6.40 raeburn 6617: }
1.160.6.93 raeburn 6618: break;
6619: }
6620: }
6621: if (insttypes > 0) {
6622: toggleDataRow(form,checkbox,target,altprefix);
6623: toggleDataRow(form,checkbox,target,prefix,1);
6624: }
6625: }
6626: }
6627: return;
6628: }
6629:
6630: function toggleDataRow(form,checkbox,target,prefix,docount) {
6631: if (form.elements[checkbox].length != undefined) {
6632: var count = 0;
6633: if (docount) {
6634: for (var i=0; i<form.elements[checkbox].length; i++) {
6635: if (form.elements[checkbox][i].checked) {
6636: count ++;
6637: }
6638: }
6639: }
6640: for (var i=0; i<form.elements[checkbox].length; i++) {
6641: var type = form.elements[checkbox][i].value;
6642: if (document.getElementById(prefix+type)) {
6643: if (form.elements[checkbox][i].checked) {
6644: document.getElementById(prefix+type).style.display = 'table-row';
6645: if (count % 2 == 1) {
6646: document.getElementById(prefix+type).className = target+' LC_odd_row';
6647: } else {
6648: document.getElementById(prefix+type).className = target;
6649: }
6650: count ++;
1.160.6.40 raeburn 6651: } else {
1.160.6.93 raeburn 6652: document.getElementById(prefix+type).style.display = 'none';
6653: }
6654: }
6655: }
6656: }
6657: return;
6658: }
6659:
6660: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
6661: var caller = radio+'_'+status;
6662: if (form.elements[caller].length != undefined) {
6663: for (var i=0; i<form.elements[caller].length; i++) {
6664: if (form.elements[caller][i].checked) {
6665: if (document.getElementById(altprefix+'_inst_'+status)) {
6666: var curr = form.elements[caller][i].value;
6667: if (prefix) {
6668: document.getElementById(prefix+'_'+status).style.display = 'none';
6669: }
6670: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
6671: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
6672: if (curr == 'custom') {
6673: if (prefix) {
6674: document.getElementById(prefix+'_'+status).style.display = 'inline';
6675: }
6676: } else if (curr == 'inst') {
6677: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
6678: } else if (curr == 'noninst') {
6679: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 6680: }
1.160.6.93 raeburn 6681: break;
1.160.6.40 raeburn 6682: }
1.160.6.93 raeburn 6683: }
6684: }
6685: }
6686: }
6687:
6688: // ]]>
6689: </script>
6690:
6691: ENDSCRIPT
6692: }
6693:
6694: sub noninst_users {
6695: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
6696: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
6697: my $class = 'LC_left_item';
6698: if ($css_class) {
6699: $css_class = ' class="'.$css_class.'"';
6700: }
6701: if ($rowid) {
6702: $rowid = ' id="'.$rowid.'"';
6703: }
6704: if ($rowstyle) {
6705: $rowstyle = ' style="'.$rowstyle.'"';
6706: }
6707: my ($output,$description);
6708: if ($type eq 'default') {
6709: $description = &mt('Requests for: [_1]',$typetitle);
6710: } else {
6711: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
6712: }
6713: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
6714: "<td>$description</td>\n".
6715: '<td class="'.$class.'" colspan="2">'.
6716: '<table><tr>';
6717: my %headers = &Apache::lonlocal::texthash(
6718: approve => 'Processing',
6719: email => 'E-mail',
6720: username => 'Username',
6721: );
6722: foreach my $item ('approve','email','username') {
6723: $output .= '<th>'.$headers{$item}.'</th>';
6724: }
6725: $output .= '</tr><tr>';
6726: foreach my $item ('approve','email','username') {
6727: $output .= '<td valign="top">';
6728: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
6729: if ($item eq 'approve') {
6730: %choices = &Apache::lonlocal::texthash (
6731: automatic => 'Automatically approved',
6732: approval => 'Queued for approval',
6733: );
6734: @options = ('automatic','approval');
6735: $hashref = $processing;
6736: $defoption = 'automatic';
6737: $name = 'cancreate_emailprocess_'.$type;
6738: } elsif ($item eq 'email') {
6739: %choices = &Apache::lonlocal::texthash (
6740: any => 'Any e-mail',
6741: inst => 'Institutional only',
6742: noninst => 'Non-institutional only',
6743: custom => 'Custom restrictions',
6744: );
6745: @options = ('any','inst','noninst');
6746: my $showcustom;
6747: if (ref($emailrules) eq 'HASH') {
6748: if (keys(%{$emailrules}) > 0) {
6749: push(@options,'custom');
6750: $showcustom = 'cancreate_emailrule';
6751: if (ref($settings) eq 'HASH') {
6752: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
6753: foreach my $rule (@{$settings->{'email_rule'}}) {
6754: if (exists($emailrules->{$rule})) {
6755: $hascustom ++;
6756: }
6757: }
6758: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
6759: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
6760: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
6761: if (exists($emailrules->{$rule})) {
6762: $hascustom ++;
6763: }
6764: }
6765: }
6766: }
6767: }
6768: }
6769: }
6770: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
6771: "'cancreate_emaildomain','$type'".');"';
6772: $hashref = $emailoptions;
6773: $defoption = 'any';
6774: $name = 'cancreate_emailoptions_'.$type;
6775: } elsif ($item eq 'username') {
6776: %choices = &Apache::lonlocal::texthash (
6777: all => 'Same as e-mail',
6778: first => 'Omit @domain',
6779: free => 'Free to choose',
6780: );
6781: @options = ('all','first','free');
6782: $hashref = $emailverified;
6783: $defoption = 'all';
6784: $name = 'cancreate_usernameoptions_'.$type;
6785: }
6786: foreach my $option (@options) {
6787: my $checked;
6788: if (ref($hashref) eq 'HASH') {
6789: if ($type eq '') {
6790: if (!exists($hashref->{'default'})) {
6791: if ($option eq $defoption) {
6792: $checked = ' checked="checked"';
6793: }
6794: } else {
6795: if ($hashref->{'default'} eq $option) {
6796: $checked = ' checked="checked"';
6797: }
1.160.6.40 raeburn 6798: }
6799: } else {
1.160.6.93 raeburn 6800: if (!exists($hashref->{$type})) {
6801: if ($option eq $defoption) {
6802: $checked = ' checked="checked"';
6803: }
6804: } else {
6805: if ($hashref->{$type} eq $option) {
6806: $checked = ' checked="checked"';
6807: }
1.160.6.40 raeburn 6808: }
6809: }
1.160.6.93 raeburn 6810: } elsif (($item eq 'email') && ($hascustom)) {
6811: if ($option eq 'custom') {
6812: $checked = ' checked="checked"';
6813: }
6814: } elsif ($option eq $defoption) {
6815: $checked = ' checked="checked"';
6816: }
6817: $output .= '<span class="LC_nobreak"><label>'.
6818: '<input type="radio" name="'.$name.'"'.
6819: $checked.' value="'.$option.'"'.$onclick.' />'.
6820: $choices{$option}.'</label></span><br />';
6821: if ($item eq 'email') {
6822: if ($option eq 'custom') {
6823: my $id = 'cancreate_emailrule_'.$type;
6824: my $display = 'none';
6825: if ($checked) {
6826: $display = 'inline';
6827: }
6828: my $numinrow = 2;
6829: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
6830: '<legend>'.&mt('Disallow').'</legend><table>'.
6831: &user_formats_row('email',$settings,$emailrules,
6832: $emailruleorder,$numinrow,'',$type);
6833: '</table></fieldset>';
6834: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
6835: my %text = &Apache::lonlocal::texthash (
6836: inst => 'must end:',
6837: noninst => 'cannot end:',
6838: );
6839: my $value;
6840: if (ref($emaildomain) eq 'HASH') {
6841: if (ref($emaildomain->{$type}) eq 'HASH') {
6842: $value = $emaildomain->{$type}->{$option};
6843: }
6844: }
6845: if ($value eq '') {
6846: $value = '@'.$intdom;
6847: }
6848: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
6849: my $display = 'none';
6850: if ($checked) {
6851: $display = 'inline';
6852: }
6853: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
6854: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
6855: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
6856: '</div>';
6857: }
1.160.6.40 raeburn 6858: }
6859: }
1.160.6.93 raeburn 6860: $output .= '</td>'."\n";
1.160.6.40 raeburn 6861: }
1.160.6.93 raeburn 6862: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 6863: return $output;
6864: }
6865:
1.160.6.5 raeburn 6866: sub captcha_choice {
1.160.6.93 raeburn 6867: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 6868: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
6869: $vertext,$currver);
1.160.6.5 raeburn 6870: my %lt = &captcha_phrases();
6871: $keyentry = 'hidden';
1.160.6.98 raeburn 6872: my $colspan=2;
1.160.6.5 raeburn 6873: if ($context eq 'cancreate') {
1.160.6.34 raeburn 6874: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 6875: } elsif ($context eq 'login') {
6876: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 6877: } elsif ($context eq 'passwords') {
6878: $rowname = &mt('"Forgot Password" CAPTCHA validation');
6879: $colspan=1;
1.160.6.5 raeburn 6880: }
6881: if (ref($settings) eq 'HASH') {
6882: if ($settings->{'captcha'}) {
6883: $checked{$settings->{'captcha'}} = ' checked="checked"';
6884: } else {
6885: $checked{'original'} = ' checked="checked"';
6886: }
6887: if ($settings->{'captcha'} eq 'recaptcha') {
6888: $pubtext = $lt{'pub'};
6889: $privtext = $lt{'priv'};
6890: $keyentry = 'text';
1.160.6.69 raeburn 6891: $vertext = $lt{'ver'};
6892: $currver = $settings->{'recaptchaversion'};
6893: if ($currver ne '2') {
6894: $currver = 1;
6895: }
1.160.6.5 raeburn 6896: }
6897: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
6898: $currpub = $settings->{'recaptchakeys'}{'public'};
6899: $currpriv = $settings->{'recaptchakeys'}{'private'};
6900: }
6901: } else {
6902: $checked{'original'} = ' checked="checked"';
6903: }
1.160.6.93 raeburn 6904: my $css_class;
6905: if ($itemcount%2) {
6906: $css_class = 'LC_odd_row';
6907: }
6908: if ($customcss) {
6909: $css_class .= " $customcss";
6910: }
6911: $css_class =~ s/^\s+//;
6912: if ($css_class) {
6913: $css_class = ' class="'.$css_class.'"';
6914: }
6915: if ($rowstyle) {
6916: $css_class .= ' style="'.$rowstyle.'"';
6917: }
1.160.6.5 raeburn 6918: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 6919: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 6920: '<table><tr><td>'."\n";
6921: foreach my $option ('original','recaptcha','notused') {
6922: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6923: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6924: $lt{$option}.'</label></span>';
6925: unless ($option eq 'notused') {
6926: $output .= (' 'x2)."\n";
6927: }
6928: }
6929: #
6930: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6931: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
6932: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
6933: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
6934: #
6935: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 6936: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 6937: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6938: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6939: $currpub.'" size="40" /></span><br />'."\n".
6940: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6941: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 6942: $currpriv.'" size="40" /></span><br />'.
6943: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6944: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6945: $currver.'" size="3" /></span><br />'.
6946: '</td></tr></table>'."\n".
1.160.6.5 raeburn 6947: '</td></tr>';
6948: return $output;
6949: }
6950:
1.32 raeburn 6951: sub user_formats_row {
1.160.6.93 raeburn 6952: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 6953: my $output;
6954: my %text = (
6955: 'username' => 'new usernames',
6956: 'id' => 'IDs',
6957: );
1.160.6.93 raeburn 6958: unless ($type eq 'email') {
6959: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6960: $output = '<tr '.$css_class.'>'.
6961: '<td><span class="LC_nobreak">'.
6962: &mt("Format rules to check for $text{$type}: ").
6963: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 6964: }
1.27 raeburn 6965: my $rem;
6966: if (ref($ruleorder) eq 'ARRAY') {
6967: for (my $i=0; $i<@{$ruleorder}; $i++) {
6968: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6969: my $rem = $i%($numinrow);
6970: if ($rem == 0) {
6971: if ($i > 0) {
6972: $output .= '</tr>';
6973: }
6974: $output .= '<tr>';
6975: }
6976: my $check = ' ';
1.39 raeburn 6977: if (ref($settings) eq 'HASH') {
6978: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6979: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6980: $check = ' checked="checked" ';
6981: }
1.160.6.93 raeburn 6982: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
6983: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
6984: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
6985: $check = ' checked="checked" ';
6986: }
6987: }
1.27 raeburn 6988: }
6989: }
1.160.6.93 raeburn 6990: my $name = $type.'_rule';
6991: if ($type eq 'email') {
6992: $name .= '_'.$status;
6993: }
1.27 raeburn 6994: $output .= '<td class="LC_left_item">'.
6995: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 6996: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 6997: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6998: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6999: }
7000: }
7001: $rem = @{$ruleorder}%($numinrow);
7002: }
1.160.6.93 raeburn 7003: my $colsleft;
7004: if ($rem) {
7005: $colsleft = $numinrow - $rem;
7006: }
1.27 raeburn 7007: if ($colsleft > 1 ) {
7008: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7009: ' </td>';
7010: } elsif ($colsleft == 1) {
7011: $output .= '<td class="LC_left_item"> </td>';
7012: }
1.160.6.93 raeburn 7013: $output .= '</tr></table>';
7014: unless ($type eq 'email') {
7015: $output .= '</td></tr>';
7016: }
1.27 raeburn 7017: return $output;
7018: }
7019:
1.34 raeburn 7020: sub usercreation_types {
7021: my %lt = &Apache::lonlocal::texthash (
7022: author => 'When adding a co-author',
7023: course => 'When adding a user to a course',
1.100 raeburn 7024: requestcrs => 'When requesting a course',
1.34 raeburn 7025: any => 'Any',
7026: official => 'Institutional only ',
7027: unofficial => 'Non-institutional only',
7028: none => 'None',
7029: );
7030: return %lt;
1.48 raeburn 7031: }
1.34 raeburn 7032:
1.160.6.34 raeburn 7033: sub selfcreation_types {
7034: my %lt = &Apache::lonlocal::texthash (
7035: selfcreate => 'User creates own account',
7036: any => 'Any',
7037: official => 'Institutional only ',
7038: unofficial => 'Non-institutional only',
7039: email => 'E-mail address',
7040: login => 'Institutional Login',
7041: sso => 'SSO',
7042: );
7043: }
7044:
1.28 raeburn 7045: sub authtype_names {
7046: my %lt = &Apache::lonlocal::texthash(
7047: int => 'Internal',
7048: krb4 => 'Kerberos 4',
7049: krb5 => 'Kerberos 5',
7050: loc => 'Local',
7051: );
7052: return %lt;
7053: }
7054:
7055: sub context_names {
7056: my %context_title = &Apache::lonlocal::texthash(
7057: author => 'Creating users when an Author',
7058: course => 'Creating users when in a course',
7059: domain => 'Creating users when a Domain Coordinator',
7060: );
7061: return %context_title;
7062: }
7063:
1.33 raeburn 7064: sub print_usermodification {
7065: my ($position,$dom,$settings,$rowtotal) = @_;
7066: my $numinrow = 4;
7067: my ($context,$datatable,$rowcount);
7068: if ($position eq 'top') {
7069: $rowcount = 0;
7070: $context = 'author';
7071: foreach my $role ('ca','aa') {
7072: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7073: $numinrow,$rowcount);
7074: $$rowtotal ++;
7075: $rowcount ++;
7076: }
1.160.6.37 raeburn 7077: } elsif ($position eq 'bottom') {
1.33 raeburn 7078: $context = 'course';
7079: $rowcount = 0;
7080: foreach my $role ('st','ep','ta','in','cr') {
7081: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7082: $numinrow,$rowcount);
7083: $$rowtotal ++;
7084: $rowcount ++;
7085: }
7086: }
7087: return $datatable;
7088: }
7089:
1.43 raeburn 7090: sub print_defaults {
1.160.6.40 raeburn 7091: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7092: my $rownum = 0;
1.160.6.80 raeburn 7093: my ($datatable,$css_class,$titles);
7094: unless ($position eq 'bottom') {
7095: $titles = &defaults_titles($dom);
7096: }
1.160.6.40 raeburn 7097: if ($position eq 'top') {
7098: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7099: 'datelocale_def','portal_def');
7100: my %defaults;
7101: if (ref($settings) eq 'HASH') {
7102: %defaults = %{$settings};
1.43 raeburn 7103: } else {
1.160.6.40 raeburn 7104: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7105: foreach my $item (@items) {
7106: $defaults{$item} = $domdefaults{$item};
7107: }
1.43 raeburn 7108: }
1.160.6.40 raeburn 7109: foreach my $item (@items) {
7110: if ($rownum%2) {
7111: $css_class = '';
7112: } else {
7113: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 7114: }
1.160.6.40 raeburn 7115: $datatable .= '<tr'.$css_class.'>'.
7116: '<td><span class="LC_nobreak">'.$titles->{$item}.
7117: '</span></td><td class="LC_right_item" colspan="3">';
7118: if ($item eq 'auth_def') {
7119: my @authtypes = ('internal','krb4','krb5','localauth');
7120: my %shortauth = (
7121: internal => 'int',
7122: krb4 => 'krb4',
7123: krb5 => 'krb5',
7124: localauth => 'loc'
7125: );
7126: my %authnames = &authtype_names();
7127: foreach my $auth (@authtypes) {
7128: my $checked = ' ';
7129: if ($defaults{$item} eq $auth) {
7130: $checked = ' checked="checked" ';
7131: }
7132: $datatable .= '<label><input type="radio" name="'.$item.
7133: '" value="'.$auth.'"'.$checked.'/>'.
7134: $authnames{$shortauth{$auth}}.'</label> ';
7135: }
7136: } elsif ($item eq 'timezone_def') {
7137: my $includeempty = 1;
7138: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7139: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 7140: my $includeempty = 1;
7141: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7142: } elsif ($item eq 'lang_def') {
7143: my $includeempty = 1;
7144: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 7145: } else {
1.160.6.98 raeburn 7146: my $size;
7147: if ($item eq 'portal_def') {
7148: $size = ' size="25"';
7149: }
1.160.6.80 raeburn 7150: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98 raeburn 7151: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 7152: }
7153: $datatable .= '</td></tr>';
7154: $rownum ++;
7155: }
1.160.6.40 raeburn 7156: } else {
1.160.6.80 raeburn 7157: my %defaults;
1.160.6.40 raeburn 7158: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 7159: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 7160: my $maxnum = @{$settings->{'inststatusorder'}};
7161: for (my $i=0; $i<$maxnum; $i++) {
7162: $css_class = $rownum%2?' class="LC_odd_row"':'';
7163: my $item = $settings->{'inststatusorder'}->[$i];
7164: my $title = $settings->{'inststatustypes'}->{$item};
7165: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7166: $datatable .= '<tr'.$css_class.'>'.
7167: '<td><span class="LC_nobreak">'.
7168: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7169: for (my $k=0; $k<=$maxnum; $k++) {
7170: my $vpos = $k+1;
7171: my $selstr;
7172: if ($k == $i) {
7173: $selstr = ' selected="selected" ';
7174: }
7175: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7176: }
7177: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7178: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7179: &mt('delete').'</span></td>'.
7180: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
7181: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 7182: '</span></td></tr>';
1.160.6.40 raeburn 7183: }
7184: $css_class = $rownum%2?' class="LC_odd_row"':'';
7185: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7186: $datatable .= '<tr '.$css_class.'>'.
7187: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7188: for (my $k=0; $k<=$maxnum; $k++) {
7189: my $vpos = $k+1;
7190: my $selstr;
7191: if ($k == $maxnum) {
7192: $selstr = ' selected="selected" ';
7193: }
7194: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7195: }
7196: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 7197: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 7198: ' '.&mt('(new)').
7199: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
7200: &mt('Name displayed:').
7201: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7202: '</tr>'."\n";
7203: $rownum ++;
1.141 raeburn 7204: }
1.43 raeburn 7205: }
7206: }
7207: $$rowtotal += $rownum;
7208: return $datatable;
7209: }
7210:
1.160.6.5 raeburn 7211: sub get_languages_hash {
7212: my %langchoices;
7213: foreach my $id (&Apache::loncommon::languageids()) {
7214: my $code = &Apache::loncommon::supportedlanguagecode($id);
7215: if ($code ne '') {
7216: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7217: }
7218: }
7219: return %langchoices;
7220: }
7221:
1.43 raeburn 7222: sub defaults_titles {
1.141 raeburn 7223: my ($dom) = @_;
1.43 raeburn 7224: my %titles = &Apache::lonlocal::texthash (
7225: 'auth_def' => 'Default authentication type',
7226: 'auth_arg_def' => 'Default authentication argument',
7227: 'lang_def' => 'Default language',
1.54 raeburn 7228: 'timezone_def' => 'Default timezone',
1.68 raeburn 7229: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7230: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 7231: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7232: 'intauth_check' => 'Check bcrypt cost if authenticated',
7233: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7234: );
1.141 raeburn 7235: if ($dom) {
7236: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7237: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7238: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7239: $protocol = 'http' if ($protocol ne 'https');
7240: if ($uint_dom) {
7241: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7242: $uint_dom);
7243: }
7244: }
1.43 raeburn 7245: return (\%titles);
7246: }
7247:
1.160.6.97 raeburn 7248: sub print_scantron {
7249: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
7250: if ($position eq 'top') {
7251: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
7252: } else {
7253: return &print_scantronconfig($dom,$settings,\$rowtotal);
7254: }
7255: }
7256:
7257: sub scantron_javascript {
7258: return <<"ENDSCRIPT";
7259:
7260: <script type="text/javascript">
7261: // <![CDATA[
7262:
7263: function toggleScantron(form) {
7264: var csvfieldset = new Array();
7265: if (document.getElementById('scantroncsv_cols')) {
7266: csvfieldset.push(document.getElementById('scantroncsv_cols'));
7267: }
7268: if (document.getElementById('scantroncsv_options')) {
7269: csvfieldset.push(document.getElementById('scantroncsv_options'));
7270: }
7271: if (csvfieldset.length) {
7272: if (document.getElementById('scantronconfcsv')) {
7273: var scantroncsv = document.getElementById('scantronconfcsv');
7274: if (scantroncsv.checked) {
7275: for (var i=0; i<csvfieldset.length; i++) {
7276: csvfieldset[i].style.display = 'block';
7277: }
7278: } else {
7279: for (var i=0; i<csvfieldset.length; i++) {
7280: csvfieldset[i].style.display = 'none';
7281: }
7282: var csvselects = document.getElementsByClassName('scantronconfig_csv');
7283: if (csvselects.length) {
7284: for (var j=0; j<csvselects.length; j++) {
7285: csvselects[j].selectedIndex = 0;
7286: }
7287: }
7288: }
7289: }
7290: }
7291: return;
7292: }
7293: // ]]>
7294: </script>
7295:
7296: ENDSCRIPT
7297:
7298: }
7299:
1.46 raeburn 7300: sub print_scantronformat {
7301: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7302: my $itemcount = 1;
1.60 raeburn 7303: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7304: %confhash);
1.46 raeburn 7305: my $switchserver = &check_switchserver($dom,$confname);
7306: my %lt = &Apache::lonlocal::texthash (
1.95 www 7307: default => 'Default bubblesheet format file error',
7308: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7309: );
7310: my %scantronfiles = (
7311: default => 'default.tab',
7312: custom => 'custom.tab',
7313: );
7314: foreach my $key (keys(%scantronfiles)) {
7315: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7316: .$scantronfiles{$key};
7317: }
7318: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7319: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7320: if (!$switchserver) {
7321: my $servadm = $r->dir_config('lonAdmEMail');
7322: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7323: if ($configuserok eq 'ok') {
7324: if ($author_ok eq 'ok') {
7325: my %legacyfile = (
1.160.6.97 raeburn 7326: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7327: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 7328: );
7329: my %md5chk;
7330: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7331: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7332: chomp($md5chk{$type});
1.46 raeburn 7333: }
7334: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7335: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 7336: ($scantronurls{$type},my $error) =
1.46 raeburn 7337: &legacy_scantronformat($r,$dom,$confname,
7338: $type,$legacyfile{$type},
7339: $scantronurls{$type},
7340: $scantronfiles{$type});
1.60 raeburn 7341: if ($error ne '') {
7342: $error{$type} = $error;
7343: }
7344: }
7345: if (keys(%error) == 0) {
7346: $is_custom = 1;
1.160.6.97 raeburn 7347: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 7348: $scantronurls{'custom'};
1.160.6.97 raeburn 7349: my $putresult =
1.60 raeburn 7350: &Apache::lonnet::put_dom('configuration',
7351: \%confhash,$dom);
7352: if ($putresult ne 'ok') {
1.160.6.97 raeburn 7353: $error{'custom'} =
1.60 raeburn 7354: '<span class="LC_error">'.
7355: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7356: }
1.46 raeburn 7357: }
7358: } else {
1.60 raeburn 7359: ($scantronurls{'default'},my $error) =
1.46 raeburn 7360: &legacy_scantronformat($r,$dom,$confname,
7361: 'default',$legacyfile{'default'},
7362: $scantronurls{'default'},
7363: $scantronfiles{'default'});
1.60 raeburn 7364: if ($error eq '') {
7365: $confhash{'scantron'}{'scantronformat'} = '';
7366: my $putresult =
7367: &Apache::lonnet::put_dom('configuration',
7368: \%confhash,$dom);
7369: if ($putresult ne 'ok') {
7370: $error{'default'} =
7371: '<span class="LC_error">'.
7372: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7373: }
7374: } else {
7375: $error{'default'} = $error;
7376: }
1.46 raeburn 7377: }
7378: }
7379: }
7380: } else {
1.95 www 7381: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7382: }
7383: }
7384: if (ref($settings) eq 'HASH') {
7385: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7386: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7387: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7388: $scantronurl = '';
7389: } else {
7390: $scantronurl = $settings->{'scantronformat'};
7391: }
7392: $is_custom = 1;
7393: } else {
7394: $scantronurl = $scantronurls{'default'};
7395: }
7396: } else {
1.60 raeburn 7397: if ($is_custom) {
7398: $scantronurl = $scantronurls{'custom'};
7399: } else {
7400: $scantronurl = $scantronurls{'default'};
7401: }
1.46 raeburn 7402: }
7403: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7404: $datatable .= '<tr'.$css_class.'>';
7405: if (!$is_custom) {
1.65 raeburn 7406: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7407: '<span class="LC_nobreak">';
1.46 raeburn 7408: if ($scantronurl) {
1.160.6.21 raeburn 7409: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7410: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7411: } else {
7412: $datatable = &mt('File unavailable for display');
7413: }
1.65 raeburn 7414: $datatable .= '</span></td>';
1.60 raeburn 7415: if (keys(%error) == 0) {
7416: $datatable .= '<td valign="bottom">';
7417: if (!$switchserver) {
7418: $datatable .= &mt('Upload:').'<br />';
7419: }
7420: } else {
7421: my $errorstr;
7422: foreach my $key (sort(keys(%error))) {
7423: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7424: }
7425: $datatable .= '<td>'.$errorstr;
7426: }
1.46 raeburn 7427: } else {
7428: if (keys(%error) > 0) {
7429: my $errorstr;
7430: foreach my $key (sort(keys(%error))) {
7431: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7432: }
1.60 raeburn 7433: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7434: } elsif ($scantronurl) {
1.160.6.26 raeburn 7435: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 7436: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7437: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 7438: $link.
7439: '<label><input type="checkbox" name="scantronformat_del"'.
7440: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7441: '<td><span class="LC_nobreak"> '.
7442: &mt('Replace:').'</span><br />';
1.46 raeburn 7443: }
7444: }
7445: if (keys(%error) == 0) {
7446: if ($switchserver) {
7447: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7448: } else {
1.65 raeburn 7449: $datatable .='<span class="LC_nobreak"> '.
7450: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7451: }
7452: }
7453: $datatable .= '</td></tr>';
7454: $$rowtotal ++;
7455: return $datatable;
7456: }
7457:
7458: sub legacy_scantronformat {
7459: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7460: my ($url,$error);
7461: my @statinfo = &Apache::lonnet::stat_file($newurl);
7462: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7463: (my $result,$url) =
7464: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7465: '','',$newfile);
7466: if ($result ne 'ok') {
1.130 raeburn 7467: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7468: }
7469: }
7470: return ($url,$error);
7471: }
1.43 raeburn 7472:
1.160.6.97 raeburn 7473: sub print_scantronconfig {
7474: my ($dom,$settings,$rowtotal) = @_;
7475: my $itemcount = 2;
7476: my $is_checked = ' checked="checked"';
7477: my %optionson = (
7478: hdr => ' checked="checked"',
7479: pad => ' checked="checked"',
7480: rem => ' checked="checked"',
7481: );
7482: my %optionsoff = (
7483: hdr => '',
7484: pad => '',
7485: rem => '',
7486: );
7487: my $currcsvsty = 'none';
7488: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
7489: my @fields = &scantroncsv_fields();
7490: my %titles = &scantronconfig_titles();
7491: if (ref($settings) eq 'HASH') {
7492: if (ref($settings->{config}) eq 'HASH') {
7493: if ($settings->{config}->{dat}) {
7494: $checked{'dat'} = $is_checked;
7495: }
7496: if (ref($settings->{config}->{csv}) eq 'HASH') {
7497: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
7498: %csvfields = %{$settings->{config}->{csv}->{fields}};
7499: if (keys(%csvfields) > 0) {
7500: $checked{'csv'} = $is_checked;
7501: $currcsvsty = 'block';
7502: }
7503: }
7504: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
7505: %csvoptions = %{$settings->{config}->{csv}->{options}};
7506: foreach my $option (keys(%optionson)) {
7507: unless ($csvoptions{$option}) {
7508: $optionsoff{$option} = $optionson{$option};
7509: $optionson{$option} = '';
7510: }
7511: }
7512: }
7513: }
7514: } else {
7515: $checked{'dat'} = $is_checked;
7516: }
7517: } else {
7518: $checked{'dat'} = $is_checked;
7519: }
7520: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
7521: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7522: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
7523: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
7524: foreach my $item ('dat','csv') {
7525: my $id;
7526: if ($item eq 'csv') {
7527: $id = 'id="scantronconfcsv" ';
7528: }
7529: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
7530: $titles{$item}.'</label>'.(' 'x3);
7531: if ($item eq 'csv') {
7532: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
7533: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
7534: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
7535: foreach my $col (@fields) {
7536: my $selnone;
7537: if ($csvfields{$col} eq '') {
7538: $selnone = ' selected="selected"';
7539: }
7540: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
7541: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
7542: '<option value=""'.$selnone.'></option>';
7543: for (my $i=0; $i<20; $i++) {
7544: my $shown = $i+1;
7545: my $sel;
7546: unless ($selnone) {
7547: if (exists($csvfields{$col})) {
7548: if ($csvfields{$col} == $i) {
7549: $sel = ' selected="selected"';
7550: }
7551: }
7552: }
7553: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
7554: }
7555: $datatable .= '</select></td></tr>';
7556: }
7557: $datatable .= '</table></fieldset>'.
7558: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
7559: '<legend>'.&mt('CSV Options').'</legend>';
7560: foreach my $option ('hdr','pad','rem') {
7561: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
7562: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
7563: &mt('Yes').'</label>'.(' 'x2)."\n".
7564: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
7565: }
7566: $datatable .= '</fieldset>';
7567: $itemcount ++;
7568: }
7569: }
7570: $datatable .= '</td></tr>';
7571: $$rowtotal ++;
7572: return $datatable;
7573: }
7574:
7575: sub scantronconfig_titles {
7576: return &Apache::lonlocal::texthash(
7577: dat => 'Standard format (.dat)',
7578: csv => 'Comma separated values (.csv)',
7579: hdr => 'Remove first line in file (contains column titles)',
7580: pad => 'Prepend 0s to PaperID',
7581: rem => 'Remove leading spaces (except Question Response columns)',
7582: CODE => 'CODE',
7583: ID => 'Student ID',
7584: PaperID => 'Paper ID',
7585: FirstName => 'First Name',
7586: LastName => 'Last Name',
7587: FirstQuestion => 'First Question Response',
7588: Section => 'Section',
7589: );
7590: }
7591:
7592: sub scantroncsv_fields {
7593: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
7594: }
7595:
1.49 raeburn 7596: sub print_coursecategories {
1.57 raeburn 7597: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7598: my $datatable;
7599: if ($position eq 'top') {
1.160.6.42 raeburn 7600: my (%checked);
7601: my @catitems = ('unauth','auth');
7602: my @cattypes = ('std','domonly','codesrch','none');
7603: $checked{'unauth'} = 'std';
7604: $checked{'auth'} = 'std';
7605: if (ref($settings) eq 'HASH') {
7606: foreach my $type (@cattypes) {
7607: if ($type eq $settings->{'unauth'}) {
7608: $checked{'unauth'} = $type;
7609: }
7610: if ($type eq $settings->{'auth'}) {
7611: $checked{'auth'} = $type;
7612: }
7613: }
7614: }
7615: my %lt = &Apache::lonlocal::texthash (
7616: unauth => 'Catalog type for unauthenticated users',
7617: auth => 'Catalog type for authenticated users',
7618: none => 'No catalog',
7619: std => 'Standard catalog',
7620: domonly => 'Domain-only catalog',
7621: codesrch => "Code search form",
7622: );
7623: my $itemcount = 0;
7624: foreach my $item (@catitems) {
7625: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7626: $datatable .= '<tr '.$css_class.'>'.
7627: '<td>'.$lt{$item}.'</td>'.
7628: '<td class="LC_right_item"><span class="LC_nobreak">';
7629: foreach my $type (@cattypes) {
7630: my $ischecked;
7631: if ($checked{$item} eq $type) {
7632: $ischecked=' checked="checked"';
7633: }
7634: $datatable .= '<label>'.
7635: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
7636: ' />'.$lt{$type}.'</label> ';
7637: }
1.160.6.87 raeburn 7638: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 7639: $itemcount ++;
7640: }
7641: $$rowtotal += $itemcount;
7642: } elsif ($position eq 'middle') {
1.57 raeburn 7643: my $toggle_cats_crs = ' ';
7644: my $toggle_cats_dom = ' checked="checked" ';
7645: my $can_cat_crs = ' ';
7646: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 7647: my $toggle_catscomm_comm = ' ';
7648: my $toggle_catscomm_dom = ' checked="checked" ';
7649: my $can_catcomm_comm = ' ';
7650: my $can_catcomm_dom = ' checked="checked" ';
7651:
1.57 raeburn 7652: if (ref($settings) eq 'HASH') {
7653: if ($settings->{'togglecats'} eq 'crs') {
7654: $toggle_cats_crs = $toggle_cats_dom;
7655: $toggle_cats_dom = ' ';
7656: }
7657: if ($settings->{'categorize'} eq 'crs') {
7658: $can_cat_crs = $can_cat_dom;
7659: $can_cat_dom = ' ';
7660: }
1.120 raeburn 7661: if ($settings->{'togglecatscomm'} eq 'comm') {
7662: $toggle_catscomm_comm = $toggle_catscomm_dom;
7663: $toggle_catscomm_dom = ' ';
7664: }
7665: if ($settings->{'categorizecomm'} eq 'comm') {
7666: $can_catcomm_comm = $can_catcomm_dom;
7667: $can_catcomm_dom = ' ';
7668: }
1.57 raeburn 7669: }
7670: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 7671: togglecats => 'Show/Hide a course in catalog',
7672: togglecatscomm => 'Show/Hide a community in catalog',
7673: categorize => 'Assign a category to a course',
7674: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7675: );
7676: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 7677: dom => 'Set in Domain',
7678: crs => 'Set in Course',
7679: comm => 'Set in Community',
1.57 raeburn 7680: );
7681: $datatable = '<tr class="LC_odd_row">'.
7682: '<td>'.$title{'togglecats'}.'</td>'.
7683: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7684: '<input type="radio" name="togglecats"'.
7685: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7686: '<label><input type="radio" name="togglecats"'.
7687: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
7688: '</tr><tr>'.
7689: '<td>'.$title{'categorize'}.'</td>'.
7690: '<td class="LC_right_item"><span class="LC_nobreak">'.
7691: '<label><input type="radio" name="categorize"'.
7692: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7693: '<label><input type="radio" name="categorize"'.
7694: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 7695: '</tr><tr class="LC_odd_row">'.
7696: '<td>'.$title{'togglecatscomm'}.'</td>'.
7697: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7698: '<input type="radio" name="togglecatscomm"'.
7699: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7700: '<label><input type="radio" name="togglecatscomm"'.
7701: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
7702: '</tr><tr>'.
7703: '<td>'.$title{'categorizecomm'}.'</td>'.
7704: '<td class="LC_right_item"><span class="LC_nobreak">'.
7705: '<label><input type="radio" name="categorizecomm"'.
7706: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7707: '<label><input type="radio" name="categorizecomm"'.
7708: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 7709: '</tr>';
1.120 raeburn 7710: $$rowtotal += 4;
1.57 raeburn 7711: } else {
7712: my $css_class;
7713: my $itemcount = 1;
7714: my $cathash;
7715: if (ref($settings) eq 'HASH') {
7716: $cathash = $settings->{'cats'};
7717: }
7718: if (ref($cathash) eq 'HASH') {
7719: my (@cats,@trails,%allitems,%idx,@jsarray);
7720: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
7721: \%allitems,\%idx,\@jsarray);
7722: my $maxdepth = scalar(@cats);
7723: my $colattrib = '';
7724: if ($maxdepth > 2) {
7725: $colattrib = ' colspan="2" ';
7726: }
7727: my @path;
7728: if (@cats > 0) {
7729: if (ref($cats[0]) eq 'ARRAY') {
7730: my $numtop = @{$cats[0]};
7731: my $maxnum = $numtop;
1.120 raeburn 7732: my %default_names = (
7733: instcode => &mt('Official courses'),
7734: communities => &mt('Communities'),
7735: );
7736:
7737: if ((!grep(/^instcode$/,@{$cats[0]})) ||
7738: ($cathash->{'instcode::0'} eq '') ||
7739: (!grep(/^communities$/,@{$cats[0]})) ||
7740: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 7741: $maxnum ++;
7742: }
7743: my $lastidx;
7744: for (my $i=0; $i<$numtop; $i++) {
7745: my $parent = $cats[0][$i];
7746: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7747: my $item = &escape($parent).'::0';
7748: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
7749: $lastidx = $idx{$item};
7750: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7751: .'<select name="'.$item.'"'.$chgstr.'>';
7752: for (my $k=0; $k<=$maxnum; $k++) {
7753: my $vpos = $k+1;
7754: my $selstr;
7755: if ($k == $i) {
7756: $selstr = ' selected="selected" ';
7757: }
7758: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7759: }
1.160.6.29 raeburn 7760: $datatable .= '</select></span></td><td>';
1.120 raeburn 7761: if ($parent eq 'instcode' || $parent eq 'communities') {
7762: $datatable .= '<span class="LC_nobreak">'
7763: .$default_names{$parent}.'</span>';
7764: if ($parent eq 'instcode') {
7765: $datatable .= '<br /><span class="LC_nobreak">('
7766: .&mt('with institutional codes')
7767: .')</span></td><td'.$colattrib.'>';
7768: } else {
7769: $datatable .= '<table><tr><td>';
7770: }
7771: $datatable .= '<span class="LC_nobreak">'
7772: .'<label><input type="radio" name="'
7773: .$parent.'" value="1" checked="checked" />'
7774: .&mt('Display').'</label>';
7775: if ($parent eq 'instcode') {
7776: $datatable .= ' ';
7777: } else {
7778: $datatable .= '</span></td></tr><tr><td>'
7779: .'<span class="LC_nobreak">';
7780: }
7781: $datatable .= '<label><input type="radio" name="'
7782: .$parent.'" value="0" />'
7783: .&mt('Do not display').'</label></span>';
7784: if ($parent eq 'communities') {
7785: $datatable .= '</td></tr></table>';
7786: }
7787: $datatable .= '</td>';
1.57 raeburn 7788: } else {
7789: $datatable .= $parent
1.160.6.29 raeburn 7790: .' <span class="LC_nobreak"><label>'
7791: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 7792: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
7793: }
7794: my $depth = 1;
7795: push(@path,$parent);
7796: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
7797: pop(@path);
7798: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
7799: $itemcount ++;
7800: }
1.48 raeburn 7801: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 7802: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
7803: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 7804: for (my $k=0; $k<=$maxnum; $k++) {
7805: my $vpos = $k+1;
7806: my $selstr;
1.57 raeburn 7807: if ($k == $numtop) {
1.48 raeburn 7808: $selstr = ' selected="selected" ';
7809: }
7810: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7811: }
1.59 bisitz 7812: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 7813: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
7814: .'</tr>'."\n";
1.48 raeburn 7815: $itemcount ++;
1.120 raeburn 7816: foreach my $default ('instcode','communities') {
7817: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
7818: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7819: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
7820: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
7821: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
7822: for (my $k=0; $k<=$maxnum; $k++) {
7823: my $vpos = $k+1;
7824: my $selstr;
7825: if ($k == $maxnum) {
7826: $selstr = ' selected="selected" ';
7827: }
7828: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 7829: }
1.120 raeburn 7830: $datatable .= '</select></span></td>'.
7831: '<td><span class="LC_nobreak">'.
7832: $default_names{$default}.'</span>';
7833: if ($default eq 'instcode') {
7834: $datatable .= '<br /><span class="LC_nobreak">('
7835: .&mt('with institutional codes').')</span>';
7836: }
7837: $datatable .= '</td>'
7838: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
7839: .&mt('Display').'</label> '
7840: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
7841: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 7842: }
7843: }
7844: }
1.57 raeburn 7845: } else {
7846: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 7847: }
7848: } else {
1.160.6.87 raeburn 7849: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 7850: .&initialize_categories($itemcount);
1.48 raeburn 7851: }
1.57 raeburn 7852: $$rowtotal += $itemcount;
1.48 raeburn 7853: }
7854: return $datatable;
7855: }
7856:
1.69 raeburn 7857: sub print_serverstatuses {
7858: my ($dom,$settings,$rowtotal) = @_;
7859: my $datatable;
7860: my @pages = &serverstatus_pages();
7861: my (%namedaccess,%machineaccess);
7862: foreach my $type (@pages) {
7863: $namedaccess{$type} = '';
7864: $machineaccess{$type}= '';
7865: }
7866: if (ref($settings) eq 'HASH') {
7867: foreach my $type (@pages) {
7868: if (exists($settings->{$type})) {
7869: if (ref($settings->{$type}) eq 'HASH') {
7870: foreach my $key (keys(%{$settings->{$type}})) {
7871: if ($key eq 'namedusers') {
7872: $namedaccess{$type} = $settings->{$type}->{$key};
7873: } elsif ($key eq 'machines') {
7874: $machineaccess{$type} = $settings->{$type}->{$key};
7875: }
7876: }
7877: }
7878: }
7879: }
7880: }
1.81 raeburn 7881: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7882: my $rownum = 0;
7883: my $css_class;
7884: foreach my $type (@pages) {
7885: $rownum ++;
7886: $css_class = $rownum%2?' class="LC_odd_row"':'';
7887: $datatable .= '<tr'.$css_class.'>'.
7888: '<td><span class="LC_nobreak">'.
7889: $titles->{$type}.'</span></td>'.
7890: '<td class="LC_left_item">'.
7891: '<input type="text" name="'.$type.'_namedusers" '.
7892: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
7893: '<td class="LC_right_item">'.
7894: '<span class="LC_nobreak">'.
7895: '<input type="text" name="'.$type.'_machines" '.
7896: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 7897: '</span></td></tr>'."\n";
1.69 raeburn 7898: }
7899: $$rowtotal += $rownum;
7900: return $datatable;
7901: }
7902:
7903: sub serverstatus_pages {
7904: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 7905: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 7906: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 7907: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 7908: }
7909:
1.160.6.40 raeburn 7910: sub defaults_javascript {
7911: my ($settings) = @_;
1.160.6.98 raeburn 7912: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 7913: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
7914: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
7915: if ($maxnum eq '') {
7916: $maxnum = 0;
7917: }
7918: $maxnum ++;
1.160.6.51 raeburn 7919: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 7920: return <<"ENDSCRIPT";
7921: <script type="text/javascript">
7922: // <![CDATA[
7923: function reorderTypes(form,caller) {
7924: var changedVal;
7925: $jstext
7926: var newpos = 'addinststatus_pos';
7927: var current = new Array;
7928: var maxh = $maxnum;
7929: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7930: var oldVal;
7931: if (caller == newpos) {
7932: changedVal = newitemVal;
7933: } else {
7934: var curritem = 'inststatus_pos_'+caller;
7935: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
7936: current[newitemVal] = newpos;
7937: }
7938: for (var i=0; i<inststatuses.length; i++) {
7939: if (inststatuses[i] != caller) {
7940: var elementName = 'inststatus_pos_'+inststatuses[i];
7941: if (form.elements[elementName]) {
7942: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7943: current[currVal] = elementName;
7944: }
7945: }
7946: }
7947: for (var j=0; j<maxh; j++) {
7948: if (current[j] == undefined) {
7949: oldVal = j;
7950: }
7951: }
7952: if (oldVal < changedVal) {
7953: for (var k=oldVal+1; k<=changedVal ; k++) {
7954: var elementName = current[k];
7955: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7956: }
7957: } else {
7958: for (var k=changedVal; k<oldVal; k++) {
7959: var elementName = current[k];
7960: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7961: }
7962: }
7963: return;
7964: }
7965:
7966: // ]]>
7967: </script>
7968:
7969: ENDSCRIPT
7970: }
7971: }
7972:
1.160.6.98 raeburn 7973: sub passwords_javascript {
1.160.6.99 raeburn 7974: my %intalert = &Apache::lonlocal::texthash (
7975: 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.',
7976: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
7977: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
7978: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
7979: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
7980: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
7981: );
7982: &js_escape(\%intalert);
7983: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 7984: my $intauthjs = <<"ENDSCRIPT";
7985:
7986: function warnIntAuth(field) {
7987: if (field.name == 'intauth_check') {
7988: if (field.value == '2') {
1.160.6.99 raeburn 7989: alert('$intalert{authcheck}');
1.160.6.98 raeburn 7990: }
7991: }
7992: if (field.name == 'intauth_cost') {
7993: field.value.replace(/\s/g,'');
7994: if (field.value != '') {
7995: var regexdigit=/^\\d+\$/;
7996: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 7997: alert('$intalert{authcost}');
7998: }
7999: }
8000: }
8001: return;
8002: }
8003:
8004: function warnIntPass(field) {
8005: field.value.replace(/^\s+/,'');
8006: field.value.replace(/\s+\$/,'');
8007: var regexdigit=/^\\d+\$/;
8008: if (field.name == 'passwords_min') {
8009: if (field.value == '') {
8010: alert('$intalert{passmin}');
8011: field.value = '$defmin';
8012: } else {
8013: if (!regexdigit.test(field.value)) {
8014: alert('$intalert{passmin}');
8015: field.value = '$defmin';
8016: }
8017: var minval = parseInt(field.value,10);
8018: if (minval < $defmin) {
8019: alert('$intalert{passmin}');
8020: field.value = '$defmin';
8021: }
8022: }
8023: } else {
8024: if (field.value == '0') {
8025: field.value = '';
8026: }
8027: if (field.value != '') {
8028: if (field.name == 'passwords_expire') {
8029: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
8030: if (!regexpposnum.test(field.value)) {
8031: alert('$intalert{passexp}');
8032: field.value = '';
8033: } else {
8034: var expval = parseFloat(field.value);
8035: if (expval == 0) {
8036: alert('$intalert{passexp}');
8037: field.value = '';
8038: }
8039: }
8040: } else {
8041: if (!regexdigit.test(field.value)) {
8042: if (field.name == 'passwords_max') {
8043: alert('$intalert{passmax}');
8044: } else {
8045: if (field.name == 'passwords_numsaved') {
8046: alert('$intalert{passnum}');
8047: }
8048: }
1.160.6.102.2 3(raebur 8049:0): field.value = '';
1.160.6.99 raeburn 8050: }
1.160.6.98 raeburn 8051: }
8052: }
8053: }
8054: return;
8055: }
8056:
8057: ENDSCRIPT
8058: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8059: }
8060:
1.49 raeburn 8061: sub coursecategories_javascript {
8062: my ($settings) = @_;
1.57 raeburn 8063: my ($output,$jstext,$cathash);
1.49 raeburn 8064: if (ref($settings) eq 'HASH') {
1.57 raeburn 8065: $cathash = $settings->{'cats'};
8066: }
8067: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8068: my (@cats,@jsarray,%idx);
1.57 raeburn 8069: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8070: if (@jsarray > 0) {
8071: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8072: for (my $i=0; $i<@jsarray; $i++) {
8073: if (ref($jsarray[$i]) eq 'ARRAY') {
8074: my $catstr = join('","',@{$jsarray[$i]});
8075: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8076: }
8077: }
8078: }
8079: } else {
8080: $jstext = ' var categories = Array(1);'."\n".
8081: ' categories[0] = Array("instcode_pos");'."\n";
8082: }
1.160.6.42 raeburn 8083: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8084: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 8085: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8086: &js_escape(\$instcode_reserved);
8087: &js_escape(\$communities_reserved);
8088: &js_escape(\$choose_again);
1.49 raeburn 8089: $output = <<"ENDSCRIPT";
8090: <script type="text/javascript">
1.109 raeburn 8091: // <![CDATA[
1.49 raeburn 8092: function reorderCats(form,parent,item,idx) {
8093: var changedVal;
8094: $jstext
8095: var newpos = 'addcategory_pos';
8096: if (parent == '') {
8097: var has_instcode = 0;
8098: var maxtop = categories[idx].length;
8099: for (var j=0; j<maxtop; j++) {
8100: if (categories[idx][j] == 'instcode::0') {
8101: has_instcode == 1;
8102: }
8103: }
8104: if (has_instcode == 0) {
8105: categories[idx][maxtop] = 'instcode_pos';
8106: }
8107: } else {
8108: newpos += '_'+parent;
8109: }
8110: var maxh = 1 + categories[idx].length;
8111: var current = new Array;
8112: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8113: if (item == newpos) {
8114: changedVal = newitemVal;
8115: } else {
8116: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8117: current[newitemVal] = newpos;
8118: }
8119: for (var i=0; i<categories[idx].length; i++) {
8120: var elementName = categories[idx][i];
8121: if (elementName != item) {
8122: if (form.elements[elementName]) {
8123: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8124: current[currVal] = elementName;
8125: }
8126: }
8127: }
8128: var oldVal;
8129: for (var j=0; j<maxh; j++) {
8130: if (current[j] == undefined) {
8131: oldVal = j;
8132: }
8133: }
8134: if (oldVal < changedVal) {
8135: for (var k=oldVal+1; k<=changedVal ; k++) {
8136: var elementName = current[k];
8137: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8138: }
8139: } else {
8140: for (var k=changedVal; k<oldVal; k++) {
8141: var elementName = current[k];
8142: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8143: }
8144: }
8145: return;
8146: }
1.120 raeburn 8147:
8148: function categoryCheck(form) {
8149: if (form.elements['addcategory_name'].value == 'instcode') {
8150: alert('$instcode_reserved\\n$choose_again');
8151: return false;
8152: }
8153: if (form.elements['addcategory_name'].value == 'communities') {
8154: alert('$communities_reserved\\n$choose_again');
8155: return false;
8156: }
8157: return true;
8158: }
8159:
1.109 raeburn 8160: // ]]>
1.49 raeburn 8161: </script>
8162:
8163: ENDSCRIPT
8164: return $output;
8165: }
8166:
1.48 raeburn 8167: sub initialize_categories {
8168: my ($itemcount) = @_;
1.120 raeburn 8169: my ($datatable,$css_class,$chgstr);
8170: my %default_names = (
8171: instcode => 'Official courses (with institutional codes)',
8172: communities => 'Communities',
8173: );
8174: my $select0 = ' selected="selected"';
8175: my $select1 = '';
8176: foreach my $default ('instcode','communities') {
8177: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 8178: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 8179: if ($default eq 'communities') {
8180: $select1 = $select0;
8181: $select0 = '';
8182: }
8183: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8184: .'<select name="'.$default.'_pos">'
8185: .'<option value="0"'.$select0.'>1</option>'
8186: .'<option value="1"'.$select1.'>2</option>'
8187: .'<option value="2">3</option></select> '
8188: .$default_names{$default}
8189: .'</span></td><td><span class="LC_nobreak">'
8190: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8191: .&mt('Display').'</label> <label>'
8192: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8193: .'</label></span></td></tr>';
1.120 raeburn 8194: $itemcount ++;
8195: }
1.48 raeburn 8196: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8197: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8198: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8199: .'<select name="addcategory_pos"'.$chgstr.'>'
8200: .'<option value="0">1</option>'
8201: .'<option value="1">2</option>'
8202: .'<option value="2" selected="selected">3</option></select> '
1.160.6.102.2 2(raebur 8203:0): .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 8204: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8205: .'</td></tr>';
1.48 raeburn 8206: return $datatable;
8207: }
8208:
8209: sub build_category_rows {
1.49 raeburn 8210: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8211: my ($text,$name,$item,$chgstr);
1.48 raeburn 8212: if (ref($cats) eq 'ARRAY') {
8213: my $maxdepth = scalar(@{$cats});
8214: if (ref($cats->[$depth]) eq 'HASH') {
8215: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8216: my $numchildren = @{$cats->[$depth]{$parent}};
8217: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 8218: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8219: my ($idxnum,$parent_name,$parent_item);
8220: my $higher = $depth - 1;
8221: if ($higher == 0) {
8222: $parent_name = &escape($parent).'::'.$higher;
8223: } else {
8224: if (ref($path) eq 'ARRAY') {
8225: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8226: }
8227: }
8228: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8229: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8230: if ($j < $numchildren) {
1.48 raeburn 8231: $name = $cats->[$depth]{$parent}[$j];
8232: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8233: $idxnum = $idx->{$item};
8234: } else {
8235: $name = $parent_name;
8236: $item = $parent_item;
1.48 raeburn 8237: }
1.49 raeburn 8238: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8239: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8240: for (my $i=0; $i<=$numchildren; $i++) {
8241: my $vpos = $i+1;
8242: my $selstr;
8243: if ($j == $i) {
8244: $selstr = ' selected="selected" ';
8245: }
8246: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8247: }
8248: $text .= '</select> ';
8249: if ($j < $numchildren) {
8250: my $deeper = $depth+1;
8251: $text .= $name.' '
8252: .'<label><input type="checkbox" name="deletecategory" value="'
8253: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8254: if(ref($path) eq 'ARRAY') {
8255: push(@{$path},$name);
1.49 raeburn 8256: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8257: pop(@{$path});
8258: }
8259: } else {
1.160.6.87 raeburn 8260: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 8261: if ($j == $numchildren) {
8262: $text .= $name;
8263: } else {
8264: $text .= $item;
8265: }
8266: $text .= '" value="" />';
8267: }
8268: $text .= '</td></tr>';
8269: }
8270: $text .= '</table></td>';
8271: } else {
8272: my $higher = $depth-1;
8273: if ($higher == 0) {
8274: $name = &escape($parent).'::'.$higher;
8275: } else {
8276: if (ref($path) eq 'ARRAY') {
8277: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8278: }
8279: }
8280: my $colspan;
8281: if ($parent ne 'instcode') {
8282: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 8283: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 8284: }
8285: }
8286: }
8287: }
8288: return $text;
8289: }
8290:
1.33 raeburn 8291: sub modifiable_userdata_row {
1.160.6.93 raeburn 8292: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8293: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 8294: my ($role,$rolename,$statustype);
8295: $role = $item;
1.160.6.34 raeburn 8296: if ($context eq 'cancreate') {
1.160.6.93 raeburn 8297: if ($item =~ /^(emailusername)_(.+)$/) {
8298: $role = $1;
8299: $statustype = $2;
1.160.6.35 raeburn 8300: if (ref($usertypes) eq 'HASH') {
8301: if ($usertypes->{$statustype}) {
8302: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8303: } else {
8304: $rolename = &mt('Data provided by user');
8305: }
8306: }
1.160.6.34 raeburn 8307: }
8308: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8309: if (ref($usertypes) eq 'HASH') {
8310: $rolename = $usertypes->{$role};
8311: } else {
8312: $rolename = $role;
8313: }
1.33 raeburn 8314: } else {
1.63 raeburn 8315: if ($role eq 'cr') {
8316: $rolename = &mt('Custom role');
8317: } else {
8318: $rolename = &Apache::lonnet::plaintext($role);
8319: }
1.33 raeburn 8320: }
1.160.6.34 raeburn 8321: my (@fields,%fieldtitles);
8322: if (ref($fieldsref) eq 'ARRAY') {
8323: @fields = @{$fieldsref};
8324: } else {
8325: @fields = ('lastname','firstname','middlename','generation',
8326: 'permanentemail','id');
8327: }
8328: if ((ref($titlesref) eq 'HASH')) {
8329: %fieldtitles = %{$titlesref};
8330: } else {
8331: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8332: }
1.33 raeburn 8333: my $output;
1.160.6.93 raeburn 8334: my $css_class;
8335: if ($rowcount%2) {
8336: $css_class = 'LC_odd_row';
8337: }
8338: if ($customcss) {
8339: $css_class .= " $customcss";
8340: }
8341: $css_class =~ s/^\s+//;
8342: if ($css_class) {
8343: $css_class = ' class="'.$css_class.'"';
8344: }
8345: if ($rowstyle) {
8346: $css_class .= ' style="'.$rowstyle.'"';
8347: }
8348: if ($rowid) {
8349: $rowid = ' id="'.$rowid.'"';
8350: }
8351:
8352: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8353: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8354: '<td class="LC_left_item" colspan="2"><table>';
8355: my $rem;
8356: my %checks;
8357: if (ref($settings) eq 'HASH') {
8358: if (ref($settings->{$context}) eq 'HASH') {
8359: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 8360: my $hashref = $settings->{$context}->{$role};
8361: if ($role eq 'emailusername') {
8362: if ($statustype) {
8363: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8364: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 8365: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 8366: foreach my $field (@fields) {
8367: if ($hashref->{$field}) {
8368: $checks{$field} = $hashref->{$field};
8369: }
8370: }
8371: }
8372: }
8373: }
8374: } else {
8375: if (ref($hashref) eq 'HASH') {
8376: foreach my $field (@fields) {
8377: if ($hashref->{$field}) {
8378: $checks{$field} = ' checked="checked" ';
8379: }
8380: }
1.33 raeburn 8381: }
8382: }
8383: }
8384: }
8385: }
1.160.6.93 raeburn 8386:
8387: my $total = scalar(@fields);
8388: for (my $i=0; $i<$total; $i++) {
8389: $rem = $i%($numinrow);
1.33 raeburn 8390: if ($rem == 0) {
8391: if ($i > 0) {
8392: $output .= '</tr>';
8393: }
8394: $output .= '<tr>';
8395: }
8396: my $check = ' ';
1.160.6.35 raeburn 8397: unless ($role eq 'emailusername') {
8398: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 8399: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 8400: } else {
8401: if ($role eq 'st') {
8402: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 8403: $check = ' checked="checked" ';
1.160.6.35 raeburn 8404: }
1.33 raeburn 8405: }
8406: }
8407: }
8408: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 8409: '<span class="LC_nobreak">';
8410: if ($role eq 'emailusername') {
8411: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8412: $checks{$fields[$i]} = 'omit';
8413: }
8414: foreach my $option ('required','optional','omit') {
8415: my $checked='';
8416: if ($checks{$fields[$i]} eq $option) {
8417: $checked='checked="checked" ';
8418: }
8419: $output .= '<label>'.
8420: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
8421: &mt($option).'</label>'.(' ' x2);
8422: }
8423: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8424: } else {
8425: $output .= '<label>'.
8426: '<input type="checkbox" name="canmodify_'.$role.'" '.
8427: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8428: '</label>';
8429: }
8430: $output .= '</span></td>';
1.33 raeburn 8431: }
1.160.6.93 raeburn 8432: $rem = $total%$numinrow;
8433: my $colsleft;
8434: if ($rem) {
8435: $colsleft = $numinrow - $rem;
8436: }
8437: if ($colsleft > 1) {
1.33 raeburn 8438: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8439: ' </td>';
8440: } elsif ($colsleft == 1) {
8441: $output .= '<td class="LC_left_item"> </td>';
8442: }
8443: $output .= '</tr></table></td></tr>';
8444: return $output;
8445: }
1.28 raeburn 8446:
1.93 raeburn 8447: sub insttypes_row {
1.160.6.93 raeburn 8448: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8449: $customcss,$rowstyle) = @_;
1.93 raeburn 8450: my %lt = &Apache::lonlocal::texthash (
8451: cansearch => 'Users allowed to search',
8452: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8453: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 8454: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 8455: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8456: );
8457: my $showdom;
8458: if ($context eq 'cansearch') {
8459: $showdom = ' ('.$dom.')';
8460: }
1.160.6.5 raeburn 8461: my $class = 'LC_left_item';
8462: if ($context eq 'statustocreate') {
8463: $class = 'LC_right_item';
8464: }
1.160.6.93 raeburn 8465: my $css_class;
8466: if ($$rowtotal%2) {
8467: $css_class = 'LC_odd_row';
8468: }
8469: if ($customcss) {
8470: $css_class .= ' '.$customcss;
8471: }
8472: $css_class =~ s/^\s+//;
8473: if ($css_class) {
8474: $css_class = ' class="'.$css_class.'"';
8475: }
8476: if ($rowstyle) {
8477: $css_class .= ' style="'.$rowstyle.'"';
8478: }
8479: if ($onclick) {
8480: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 8481: }
8482: my $output = '<tr'.$css_class.'>'.
8483: '<td>'.$lt{$context}.$showdom.
8484: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8485: my $rem;
8486: if (ref($types) eq 'ARRAY') {
8487: for (my $i=0; $i<@{$types}; $i++) {
8488: if (defined($usertypes->{$types->[$i]})) {
8489: my $rem = $i%($numinrow);
8490: if ($rem == 0) {
8491: if ($i > 0) {
8492: $output .= '</tr>';
8493: }
8494: $output .= '<tr>';
1.23 raeburn 8495: }
1.26 raeburn 8496: my $check = ' ';
1.99 raeburn 8497: if (ref($settings) eq 'HASH') {
8498: if (ref($settings->{$context}) eq 'ARRAY') {
8499: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8500: $check = ' checked="checked" ';
8501: }
1.160.6.101 raeburn 8502: } elsif (ref($settings->{$context}) eq 'HASH') {
8503: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8504: $check = ' checked="checked" ';
8505: }
1.99 raeburn 8506: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8507: $check = ' checked="checked" ';
8508: }
1.23 raeburn 8509: }
1.26 raeburn 8510: $output .= '<td class="LC_left_item">'.
8511: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8512: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 8513: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 8514: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8515: }
8516: }
1.26 raeburn 8517: $rem = @{$types}%($numinrow);
1.23 raeburn 8518: }
8519: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 8520: if ($context eq 'overrides') {
8521: if ($colsleft > 1) {
8522: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8523: } else {
8524: $output .= '<td class="LC_left_item">';
8525: }
8526: $output .= ' ';
1.23 raeburn 8527: } else {
1.160.6.101 raeburn 8528: if ($rem == 0) {
8529: $output .= '<tr>';
8530: }
8531: if ($colsleft > 1) {
8532: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8533: } else {
8534: $output .= '<td class="LC_left_item">';
8535: }
8536: my $defcheck = ' ';
8537: if (ref($settings) eq 'HASH') {
8538: if (ref($settings->{$context}) eq 'ARRAY') {
8539: if (grep(/^default$/,@{$settings->{$context}})) {
8540: $defcheck = ' checked="checked" ';
8541: }
8542: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8543: $defcheck = ' checked="checked" ';
8544: }
1.26 raeburn 8545: }
1.160.6.101 raeburn 8546: $output .= '<span class="LC_nobreak"><label>'.
8547: '<input type="checkbox" name="'.$context.'" '.
8548: 'value="default"'.$defcheck.$onclick.' />'.
8549: $othertitle.'</label></span>';
1.23 raeburn 8550: }
1.160.6.101 raeburn 8551: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8552: return $output;
1.23 raeburn 8553: }
8554:
8555: sub sorted_searchtitles {
8556: my %searchtitles = &Apache::lonlocal::texthash(
8557: 'uname' => 'username',
8558: 'lastname' => 'last name',
8559: 'lastfirst' => 'last name, first name',
8560: );
8561: my @titleorder = ('uname','lastname','lastfirst');
8562: return (\%searchtitles,\@titleorder);
8563: }
8564:
1.25 raeburn 8565: sub sorted_searchtypes {
8566: my %srchtypes_desc = (
8567: exact => 'is exact match',
8568: contains => 'contains ..',
8569: begins => 'begins with ..',
8570: );
8571: my @srchtypeorder = ('exact','begins','contains');
8572: return (\%srchtypes_desc,\@srchtypeorder);
8573: }
8574:
1.3 raeburn 8575: sub usertype_update_row {
8576: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8577: my $datatable;
8578: my $numinrow = 4;
8579: foreach my $type (@{$types}) {
8580: if (defined($usertypes->{$type})) {
8581: $$rownums ++;
8582: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8583: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8584: '</td><td class="LC_left_item"><table>';
8585: for (my $i=0; $i<@{$fields}; $i++) {
8586: my $rem = $i%($numinrow);
8587: if ($rem == 0) {
8588: if ($i > 0) {
8589: $datatable .= '</tr>';
8590: }
8591: $datatable .= '<tr>';
8592: }
8593: my $check = ' ';
1.39 raeburn 8594: if (ref($settings) eq 'HASH') {
8595: if (ref($settings->{'fields'}) eq 'HASH') {
8596: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8597: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8598: $check = ' checked="checked" ';
8599: }
1.3 raeburn 8600: }
8601: }
8602: }
8603:
8604: if ($i == @{$fields}-1) {
8605: my $colsleft = $numinrow - $rem;
8606: if ($colsleft > 1) {
8607: $datatable .= '<td colspan="'.$colsleft.'">';
8608: } else {
8609: $datatable .= '<td>';
8610: }
8611: } else {
8612: $datatable .= '<td>';
8613: }
1.8 raeburn 8614: $datatable .= '<span class="LC_nobreak"><label>'.
8615: '<input type="checkbox" name="updateable_'.$type.
8616: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8617: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8618: }
8619: $datatable .= '</tr></table></td></tr>';
8620: }
8621: }
8622: return $datatable;
1.1 raeburn 8623: }
8624:
8625: sub modify_login {
1.160.6.24 raeburn 8626: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 8627: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8628: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8629: %title = ( coursecatalog => 'Display course catalog',
8630: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 8631: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 8632: newuser => 'Link for visitors to create a user account',
8633: loginheader => 'Log-in box header');
8634: @offon = ('off','on');
1.112 raeburn 8635: if (ref($domconfig{login}) eq 'HASH') {
8636: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8637: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8638: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8639: }
8640: }
8641: }
1.9 raeburn 8642: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8643: \%domconfig,\%loginhash);
1.160.6.14 raeburn 8644: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8645: foreach my $item (@toggles) {
8646: $loginhash{login}{$item} = $env{'form.'.$item};
8647: }
1.41 raeburn 8648: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 8649: if (ref($colchanges{'login'}) eq 'HASH') {
8650: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8651: \%loginhash);
8652: }
1.110 raeburn 8653:
1.149 raeburn 8654: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 8655: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 8656: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 8657: if (keys(%servers) > 1) {
8658: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 8659: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8660: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8661: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8662: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8663: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8664: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8665: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8666: $changes{'loginvia'}{$lonhost} = 1;
8667: } else {
8668: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8669: $changes{'loginvia'}{$lonhost} = 1;
8670: }
8671: } else {
8672: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8673: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8674: $changes{'loginvia'}{$lonhost} = 1;
8675: }
8676: }
8677: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8678: foreach my $item (@loginvia_attribs) {
8679: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
8680: }
8681: } else {
8682: foreach my $item (@loginvia_attribs) {
8683: my $new = $env{'form.'.$lonhost.'_'.$item};
8684: if (($item eq 'serverpath') && ($new eq 'custom')) {
8685: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
8686: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8687: $new = '/';
8688: }
8689: }
8690: if (($item eq 'custompath') &&
8691: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8692: $new = '';
8693: }
8694: if ($new ne $curr_loginvia{$lonhost}{$item}) {
8695: $changes{'loginvia'}{$lonhost} = 1;
8696: }
8697: if ($item eq 'exempt') {
1.160.6.56 raeburn 8698: $new = &check_exempt_addresses($new);
1.128 raeburn 8699: }
8700: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8701: }
8702: }
1.112 raeburn 8703: } else {
1.128 raeburn 8704: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8705: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 8706: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 8707: foreach my $item (@loginvia_attribs) {
8708: my $new = $env{'form.'.$lonhost.'_'.$item};
8709: if (($item eq 'serverpath') && ($new eq 'custom')) {
8710: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8711: $new = '/';
8712: }
8713: }
8714: if (($item eq 'custompath') &&
8715: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8716: $new = '';
8717: }
8718: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8719: }
1.110 raeburn 8720: }
8721: }
8722: }
8723: }
1.119 raeburn 8724:
1.160.6.5 raeburn 8725: my $servadm = $r->dir_config('lonAdmEMail');
8726: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
8727: if (ref($domconfig{'login'}) eq 'HASH') {
8728: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
8729: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
8730: if ($lang eq 'nolang') {
8731: push(@currlangs,$lang);
8732: } elsif (defined($langchoices{$lang})) {
8733: push(@currlangs,$lang);
8734: } else {
8735: next;
8736: }
8737: }
8738: }
8739: }
8740: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
8741: if (@currlangs > 0) {
8742: foreach my $lang (@currlangs) {
8743: if (grep(/^\Q$lang\E$/,@delurls)) {
8744: $changes{'helpurl'}{$lang} = 1;
8745: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
8746: $changes{'helpurl'}{$lang} = 1;
8747: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
8748: push(@newlangs,$lang);
8749: } else {
8750: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8751: }
8752: }
8753: }
8754: unless (grep(/^nolang$/,@currlangs)) {
8755: if ($env{'form.loginhelpurl_nolang.filename'}) {
8756: $changes{'helpurl'}{'nolang'} = 1;
8757: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
8758: push(@newlangs,'nolang');
8759: }
8760: }
8761: if ($env{'form.loginhelpurl_add_lang'}) {
8762: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
8763: ($env{'form.loginhelpurl_add_file.filename'})) {
8764: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
8765: $addedfile = $env{'form.loginhelpurl_add_lang'};
8766: }
8767: }
8768: if ((@newlangs > 0) || ($addedfile)) {
8769: my $error;
8770: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8771: if ($configuserok eq 'ok') {
8772: if ($switchserver) {
8773: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
8774: } elsif ($author_ok eq 'ok') {
8775: my @allnew = @newlangs;
8776: if ($addedfile ne '') {
8777: push(@allnew,$addedfile);
8778: }
8779: foreach my $lang (@allnew) {
8780: my $formelem = 'loginhelpurl_'.$lang;
8781: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
8782: $formelem = 'loginhelpurl_add_file';
8783: }
8784: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8785: "help/$lang",'','',$newfile{$lang});
8786: if ($result eq 'ok') {
8787: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
8788: $changes{'helpurl'}{$lang} = 1;
8789: } else {
8790: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
8791: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8792: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
8793: (!grep(/^\Q$lang\E$/,@delurls))) {
8794: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8795: }
8796: }
8797: }
8798: } else {
8799: $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);
8800: }
8801: } else {
8802: $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);
8803: }
8804: if ($error) {
8805: &Apache::lonnet::logthis($error);
8806: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8807: }
8808: }
1.160.6.56 raeburn 8809:
8810: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
8811: if (ref($domconfig{'login'}) eq 'HASH') {
8812: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
8813: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
8814: if ($domservers{$lonhost}) {
8815: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8816: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 8817: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 8818: }
8819: }
8820: }
8821: }
8822: }
8823: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
8824: foreach my $lonhost (sort(keys(%domservers))) {
8825: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8826: $changes{'headtag'}{$lonhost} = 1;
8827: } else {
8828: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
8829: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
8830: }
8831: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
8832: push(@newhosts,$lonhost);
8833: } elsif ($currheadtagurls{$lonhost}) {
8834: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
8835: if ($currexempt{$lonhost}) {
8836: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
8837: $changes{'headtag'}{$lonhost} = 1;
8838: }
8839: } elsif ($possexempt{$lonhost}) {
8840: $changes{'headtag'}{$lonhost} = 1;
8841: }
8842: if ($possexempt{$lonhost}) {
8843: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8844: }
8845: }
8846: }
8847: }
8848: if (@newhosts) {
8849: my $error;
8850: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8851: if ($configuserok eq 'ok') {
8852: if ($switchserver) {
8853: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
8854: } elsif ($author_ok eq 'ok') {
8855: foreach my $lonhost (@newhosts) {
8856: my $formelem = 'loginheadtag_'.$lonhost;
8857: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8858: "login/headtag/$lonhost",'','',
8859: $env{'form.loginheadtag_'.$lonhost.'.filename'});
8860: if ($result eq 'ok') {
8861: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
8862: $changes{'headtag'}{$lonhost} = 1;
8863: if ($possexempt{$lonhost}) {
8864: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8865: }
8866: } else {
8867: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
8868: $newheadtagurls{$lonhost},$result);
8869: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8870: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
8871: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
8872: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
8873: }
8874: }
8875: }
8876: } else {
8877: $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);
8878: }
8879: } else {
8880: $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);
8881: }
8882: if ($error) {
8883: &Apache::lonnet::logthis($error);
8884: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8885: }
8886: }
1.160.6.5 raeburn 8887: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
8888:
8889: my $defaulthelpfile = '/adm/loginproblems.html';
8890: my $defaulttext = &mt('Default in use');
8891:
1.1 raeburn 8892: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
8893: $dom);
8894: if ($putresult eq 'ok') {
1.160.6.14 raeburn 8895: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8896: my %defaultchecked = (
8897: 'coursecatalog' => 'on',
1.160.6.14 raeburn 8898: 'helpdesk' => 'on',
1.42 raeburn 8899: 'adminmail' => 'off',
1.43 raeburn 8900: 'newuser' => 'off',
1.42 raeburn 8901: );
1.55 raeburn 8902: if (ref($domconfig{'login'}) eq 'HASH') {
8903: foreach my $item (@toggles) {
8904: if ($defaultchecked{$item} eq 'on') {
8905: if (($domconfig{'login'}{$item} eq '0') &&
8906: ($env{'form.'.$item} eq '1')) {
8907: $changes{$item} = 1;
8908: } elsif (($domconfig{'login'}{$item} eq '' ||
8909: $domconfig{'login'}{$item} eq '1') &&
8910: ($env{'form.'.$item} eq '0')) {
8911: $changes{$item} = 1;
8912: }
8913: } elsif ($defaultchecked{$item} eq 'off') {
8914: if (($domconfig{'login'}{$item} eq '1') &&
8915: ($env{'form.'.$item} eq '0')) {
8916: $changes{$item} = 1;
8917: } elsif (($domconfig{'login'}{$item} eq '' ||
8918: $domconfig{'login'}{$item} eq '0') &&
8919: ($env{'form.'.$item} eq '1')) {
8920: $changes{$item} = 1;
8921: }
1.42 raeburn 8922: }
8923: }
1.41 raeburn 8924: }
1.6 raeburn 8925: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 8926: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8927: if (ref($lastactref) eq 'HASH') {
8928: $lastactref->{'domainconfig'} = 1;
8929: }
1.1 raeburn 8930: $resulttext = &mt('Changes made:').'<ul>';
8931: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 8932: if ($item eq 'loginvia') {
1.112 raeburn 8933: if (ref($changes{$item}) eq 'HASH') {
8934: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
8935: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 8936: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
8937: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
8938: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
8939: $protocol = 'http' if ($protocol ne 'https');
8940: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
8941:
8942: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
8943: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
8944: } else {
8945: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
8946: }
8947: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
8948: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
8949: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
8950: }
8951: $resulttext .= '</li>';
8952: } else {
8953: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
8954: }
1.112 raeburn 8955: } else {
1.128 raeburn 8956: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 8957: }
8958: }
1.128 raeburn 8959: $resulttext .= '</ul></li>';
1.112 raeburn 8960: }
1.160.6.5 raeburn 8961: } elsif ($item eq 'helpurl') {
8962: if (ref($changes{$item}) eq 'HASH') {
8963: foreach my $lang (sort(keys(%{$changes{$item}}))) {
8964: if (grep(/^\Q$lang\E$/,@delurls)) {
8965: my ($chg,$link);
8966: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
8967: if ($lang eq 'nolang') {
8968: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
8969: } else {
8970: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
8971: }
8972: $resulttext .= '<li>'.$chg.'</li>';
8973: } else {
8974: my $chg;
8975: if ($lang eq 'nolang') {
8976: $chg = &mt('custom log-in help file for no preferred language');
8977: } else {
8978: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
8979: }
8980: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
8981: $loginhash{'login'}{'helpurl'}{$lang}.
8982: '?inhibitmenu=yes',$chg,600,500).
8983: '</li>';
8984: }
8985: }
8986: }
1.160.6.56 raeburn 8987: } elsif ($item eq 'headtag') {
8988: if (ref($changes{$item}) eq 'HASH') {
8989: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8990: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8991: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
8992: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8993: $resulttext .= '<li><a href="'.
8994: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
8995: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
8996: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
8997: if ($possexempt{$lonhost}) {
8998: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
8999: } else {
9000: $resulttext .= &mt('included for any client IP');
9001: }
9002: $resulttext .= '</li>';
9003: }
9004: }
9005: }
1.160.6.5 raeburn 9006: } elsif ($item eq 'captcha') {
9007: if (ref($loginhash{'login'}) eq 'HASH') {
9008: my $chgtxt;
9009: if ($loginhash{'login'}{$item} eq 'notused') {
9010: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9011: } else {
9012: my %captchas = &captcha_phrases();
9013: if ($captchas{$loginhash{'login'}{$item}}) {
9014: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9015: } else {
9016: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9017: }
9018: }
9019: $resulttext .= '<li>'.$chgtxt.'</li>';
9020: }
9021: } elsif ($item eq 'recaptchakeys') {
9022: if (ref($loginhash{'login'}) eq 'HASH') {
9023: my ($privkey,$pubkey);
9024: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9025: $pubkey = $loginhash{'login'}{$item}{'public'};
9026: $privkey = $loginhash{'login'}{$item}{'private'};
9027: }
9028: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9029: if (!$pubkey) {
9030: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9031: } else {
9032: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9033: }
9034: if (!$privkey) {
9035: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9036: } else {
1.160.6.53 raeburn 9037: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 9038: }
9039: $chgtxt .= '</ul>';
9040: $resulttext .= '<li>'.$chgtxt.'</li>';
9041: }
1.160.6.69 raeburn 9042: } elsif ($item eq 'recaptchaversion') {
9043: if (ref($loginhash{'login'}) eq 'HASH') {
9044: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
9045: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
9046: '</li>';
9047: }
9048: }
1.41 raeburn 9049: } else {
9050: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9051: }
1.1 raeburn 9052: }
1.6 raeburn 9053: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9054: } else {
9055: $resulttext = &mt('No changes made to log-in page settings');
9056: }
9057: } else {
1.11 albertel 9058: $resulttext = '<span class="LC_error">'.
9059: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9060: }
1.6 raeburn 9061: if ($errors) {
1.9 raeburn 9062: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9063: $errors.'</ul>';
9064: }
9065: return $resulttext;
9066: }
9067:
1.160.6.56 raeburn 9068: sub check_exempt_addresses {
9069: my ($iplist) = @_;
9070: $iplist =~ s/^\s+//;
9071: $iplist =~ s/\s+$//;
9072: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9073: my (@okips,$new);
9074: foreach my $ip (@poss_ips) {
9075: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9076: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9077: push(@okips,$ip);
9078: }
9079: }
9080: }
9081: if (@okips > 0) {
9082: $new = join(',',@okips);
9083: } else {
9084: $new = '';
9085: }
9086: return $new;
9087: }
9088:
1.6 raeburn 9089: sub color_font_choices {
9090: my %choices =
9091: &Apache::lonlocal::texthash (
9092: img => "Header",
9093: bgs => "Background colors",
9094: links => "Link colors",
1.55 raeburn 9095: images => "Images",
1.6 raeburn 9096: font => "Font color",
1.160.6.22 raeburn 9097: fontmenu => "Font menu",
1.76 raeburn 9098: pgbg => "Page",
1.6 raeburn 9099: tabbg => "Header",
9100: sidebg => "Border",
9101: link => "Link",
9102: alink => "Active link",
9103: vlink => "Visited link",
9104: );
9105: return %choices;
9106: }
9107:
9108: sub modify_rolecolors {
1.160.6.24 raeburn 9109: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9110: my ($resulttext,%rolehash);
9111: $rolehash{'rolecolors'} = {};
1.55 raeburn 9112: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9113: if ($domconfig{'rolecolors'} eq '') {
9114: $domconfig{'rolecolors'} = {};
9115: }
9116: }
1.9 raeburn 9117: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9118: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9119: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9120: $dom);
9121: if ($putresult eq 'ok') {
9122: if (keys(%changes) > 0) {
1.41 raeburn 9123: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9124: if (ref($lastactref) eq 'HASH') {
9125: $lastactref->{'domainconfig'} = 1;
9126: }
1.6 raeburn 9127: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9128: $rolehash{'rolecolors'});
9129: } else {
9130: $resulttext = &mt('No changes made to default color schemes');
9131: }
9132: } else {
1.11 albertel 9133: $resulttext = '<span class="LC_error">'.
9134: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9135: }
9136: if ($errors) {
9137: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9138: $errors.'</ul>';
9139: }
9140: return $resulttext;
9141: }
9142:
9143: sub modify_colors {
1.9 raeburn 9144: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9145: my (%changes,%choices);
1.51 raeburn 9146: my @bgs;
1.6 raeburn 9147: my @links = ('link','alink','vlink');
1.41 raeburn 9148: my @logintext;
1.6 raeburn 9149: my @images;
9150: my $servadm = $r->dir_config('lonAdmEMail');
9151: my $errors;
1.160.6.22 raeburn 9152: my %defaults;
1.6 raeburn 9153: foreach my $role (@{$roles}) {
9154: if ($role eq 'login') {
1.12 raeburn 9155: %choices = &login_choices();
1.41 raeburn 9156: @logintext = ('textcol','bgcol');
1.12 raeburn 9157: } else {
9158: %choices = &color_font_choices();
9159: }
9160: if ($role eq 'login') {
1.41 raeburn 9161: @images = ('img','logo','domlogo','login');
1.51 raeburn 9162: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9163: } else {
9164: @images = ('img');
1.160.6.22 raeburn 9165: @bgs = ('pgbg','tabbg','sidebg');
9166: }
9167: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9168: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9169: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9170: }
9171: if ($role eq 'login') {
9172: foreach my $item (@logintext) {
1.160.6.39 raeburn 9173: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9174: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9175: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9176: }
9177: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 9178: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9179: }
9180: }
9181: } else {
1.160.6.39 raeburn 9182: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9183: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9184: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9185: }
9186: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 9187: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9188: }
1.6 raeburn 9189: }
1.160.6.22 raeburn 9190: foreach my $item (@bgs) {
1.160.6.39 raeburn 9191: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9192: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9193: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9194: }
9195: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 9196: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9197: }
9198: }
9199: foreach my $item (@links) {
1.160.6.39 raeburn 9200: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9201: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9202: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9203: }
9204: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 9205: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9206: }
1.6 raeburn 9207: }
1.46 raeburn 9208: my ($configuserok,$author_ok,$switchserver) =
9209: &config_check($dom,$confname,$servadm);
1.9 raeburn 9210: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 9211: if (ref($domconfig->{$role}) ne 'HASH') {
9212: $domconfig->{$role} = {};
9213: }
1.8 raeburn 9214: foreach my $img (@images) {
1.70 raeburn 9215: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9216: if (defined($env{'form.login_showlogo_'.$img})) {
9217: $confhash->{$role}{'showlogo'}{$img} = 1;
9218: } else {
9219: $confhash->{$role}{'showlogo'}{$img} = 0;
9220: }
9221: }
1.18 albertel 9222: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9223: && !defined($domconfig->{$role}{$img})
9224: && !$env{'form.'.$role.'_del_'.$img}
9225: && $env{'form.'.$role.'_import_'.$img}) {
9226: # import the old configured image from the .tab setting
9227: # if they haven't provided a new one
9228: $domconfig->{$role}{$img} =
9229: $env{'form.'.$role.'_import_'.$img};
9230: }
1.6 raeburn 9231: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9232: my $error;
1.6 raeburn 9233: if ($configuserok eq 'ok') {
1.9 raeburn 9234: if ($switchserver) {
1.12 raeburn 9235: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9236: } else {
9237: if ($author_ok eq 'ok') {
9238: my ($result,$logourl) =
9239: &publishlogo($r,'upload',$role.'_'.$img,
9240: $dom,$confname,$img,$width,$height);
9241: if ($result eq 'ok') {
9242: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9243: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9244: } else {
1.12 raeburn 9245: $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 9246: }
9247: } else {
1.46 raeburn 9248: $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 9249: }
9250: }
9251: } else {
1.46 raeburn 9252: $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 9253: }
9254: if ($error) {
1.8 raeburn 9255: &Apache::lonnet::logthis($error);
1.11 albertel 9256: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9257: }
9258: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9259: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9260: my $error;
9261: if ($configuserok eq 'ok') {
9262: # is confname an author?
9263: if ($switchserver eq '') {
9264: if ($author_ok eq 'ok') {
9265: my ($result,$logourl) =
9266: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9267: $dom,$confname,$img,$width,$height);
9268: if ($result eq 'ok') {
9269: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9270: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9271: }
9272: }
9273: }
9274: }
1.6 raeburn 9275: }
9276: }
9277: }
9278: if (ref($domconfig) eq 'HASH') {
9279: if (ref($domconfig->{$role}) eq 'HASH') {
9280: foreach my $img (@images) {
9281: if ($domconfig->{$role}{$img} ne '') {
9282: if ($env{'form.'.$role.'_del_'.$img}) {
9283: $confhash->{$role}{$img} = '';
1.12 raeburn 9284: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9285: } else {
1.9 raeburn 9286: if ($confhash->{$role}{$img} eq '') {
9287: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
9288: }
1.6 raeburn 9289: }
9290: } else {
9291: if ($env{'form.'.$role.'_del_'.$img}) {
9292: $confhash->{$role}{$img} = '';
1.12 raeburn 9293: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9294: }
9295: }
1.70 raeburn 9296: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
9297: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
9298: if ($confhash->{$role}{'showlogo'}{$img} ne
9299: $domconfig->{$role}{'showlogo'}{$img}) {
9300: $changes{$role}{'showlogo'}{$img} = 1;
9301: }
9302: } else {
9303: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9304: $changes{$role}{'showlogo'}{$img} = 1;
9305: }
9306: }
9307: }
9308: }
1.6 raeburn 9309: if ($domconfig->{$role}{'font'} ne '') {
9310: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
9311: $changes{$role}{'font'} = 1;
9312: }
9313: } else {
9314: if ($confhash->{$role}{'font'}) {
9315: $changes{$role}{'font'} = 1;
9316: }
9317: }
1.107 raeburn 9318: if ($role ne 'login') {
9319: if ($domconfig->{$role}{'fontmenu'} ne '') {
9320: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
9321: $changes{$role}{'fontmenu'} = 1;
9322: }
9323: } else {
9324: if ($confhash->{$role}{'fontmenu'}) {
9325: $changes{$role}{'fontmenu'} = 1;
9326: }
1.97 tempelho 9327: }
9328: }
1.6 raeburn 9329: foreach my $item (@bgs) {
9330: if ($domconfig->{$role}{$item} ne '') {
9331: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9332: $changes{$role}{'bgs'}{$item} = 1;
9333: }
9334: } else {
9335: if ($confhash->{$role}{$item}) {
9336: $changes{$role}{'bgs'}{$item} = 1;
9337: }
9338: }
9339: }
9340: foreach my $item (@links) {
9341: if ($domconfig->{$role}{$item} ne '') {
9342: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9343: $changes{$role}{'links'}{$item} = 1;
9344: }
9345: } else {
9346: if ($confhash->{$role}{$item}) {
9347: $changes{$role}{'links'}{$item} = 1;
9348: }
9349: }
9350: }
1.41 raeburn 9351: foreach my $item (@logintext) {
9352: if ($domconfig->{$role}{$item} ne '') {
9353: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9354: $changes{$role}{'logintext'}{$item} = 1;
9355: }
9356: } else {
9357: if ($confhash->{$role}{$item}) {
9358: $changes{$role}{'logintext'}{$item} = 1;
9359: }
9360: }
9361: }
1.6 raeburn 9362: } else {
9363: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9364: \@logintext,$confhash,\%changes);
1.6 raeburn 9365: }
9366: } else {
9367: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9368: \@logintext,$confhash,\%changes);
1.6 raeburn 9369: }
9370: }
9371: return ($errors,%changes);
9372: }
9373:
1.46 raeburn 9374: sub config_check {
9375: my ($dom,$confname,$servadm) = @_;
9376: my ($configuserok,$author_ok,$switchserver,%currroles);
9377: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
9378: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
9379: $confname,$servadm);
9380: if ($configuserok eq 'ok') {
9381: $switchserver = &check_switchserver($dom,$confname);
9382: if ($switchserver eq '') {
9383: $author_ok = &check_authorstatus($dom,$confname,%currroles);
9384: }
9385: }
9386: return ($configuserok,$author_ok,$switchserver);
9387: }
9388:
1.6 raeburn 9389: sub default_change_checker {
1.41 raeburn 9390: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 9391: foreach my $item (@{$links}) {
9392: if ($confhash->{$role}{$item}) {
9393: $changes->{$role}{'links'}{$item} = 1;
9394: }
9395: }
9396: foreach my $item (@{$bgs}) {
9397: if ($confhash->{$role}{$item}) {
9398: $changes->{$role}{'bgs'}{$item} = 1;
9399: }
9400: }
1.41 raeburn 9401: foreach my $item (@{$logintext}) {
9402: if ($confhash->{$role}{$item}) {
9403: $changes->{$role}{'logintext'}{$item} = 1;
9404: }
9405: }
1.6 raeburn 9406: foreach my $img (@{$images}) {
9407: if ($env{'form.'.$role.'_del_'.$img}) {
9408: $confhash->{$role}{$img} = '';
1.12 raeburn 9409: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 9410: }
1.70 raeburn 9411: if ($role eq 'login') {
9412: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9413: $changes->{$role}{'showlogo'}{$img} = 1;
9414: }
9415: }
1.6 raeburn 9416: }
9417: if ($confhash->{$role}{'font'}) {
9418: $changes->{$role}{'font'} = 1;
9419: }
1.48 raeburn 9420: }
1.6 raeburn 9421:
9422: sub display_colorchgs {
9423: my ($dom,$changes,$roles,$confhash) = @_;
9424: my (%choices,$resulttext);
9425: if (!grep(/^login$/,@{$roles})) {
9426: $resulttext = &mt('Changes made:').'<br />';
9427: }
9428: foreach my $role (@{$roles}) {
9429: if ($role eq 'login') {
9430: %choices = &login_choices();
9431: } else {
9432: %choices = &color_font_choices();
9433: }
9434: if (ref($changes->{$role}) eq 'HASH') {
9435: if ($role ne 'login') {
9436: $resulttext .= '<h4>'.&mt($role).'</h4>';
9437: }
9438: foreach my $key (sort(keys(%{$changes->{$role}}))) {
9439: if ($role ne 'login') {
9440: $resulttext .= '<ul>';
9441: }
9442: if (ref($changes->{$role}{$key}) eq 'HASH') {
9443: if ($role ne 'login') {
9444: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9445: }
9446: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 9447: if (($role eq 'login') && ($key eq 'showlogo')) {
9448: if ($confhash->{$role}{$key}{$item}) {
9449: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9450: } else {
9451: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9452: }
9453: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 9454: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9455: } else {
1.12 raeburn 9456: my $newitem = $confhash->{$role}{$item};
9457: if ($key eq 'images') {
9458: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
9459: }
9460: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 9461: }
9462: }
9463: if ($role ne 'login') {
9464: $resulttext .= '</ul></li>';
9465: }
9466: } else {
9467: if ($confhash->{$role}{$key} eq '') {
9468: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9469: } else {
9470: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9471: }
9472: }
9473: if ($role ne 'login') {
9474: $resulttext .= '</ul>';
9475: }
9476: }
9477: }
9478: }
1.3 raeburn 9479: return $resulttext;
1.1 raeburn 9480: }
9481:
1.9 raeburn 9482: sub thumb_dimensions {
9483: return ('200','50');
9484: }
9485:
1.16 raeburn 9486: sub check_dimensions {
9487: my ($inputfile) = @_;
9488: my ($fullwidth,$fullheight);
9489: if ($inputfile =~ m|^[/\w.\-]+$|) {
9490: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9491: my $imageinfo = <PIPE>;
9492: if (!close(PIPE)) {
9493: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9494: }
9495: chomp($imageinfo);
9496: my ($fullsize) =
1.21 raeburn 9497: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 9498: if ($fullsize) {
9499: ($fullwidth,$fullheight) = split(/x/,$fullsize);
9500: }
9501: }
9502: }
9503: return ($fullwidth,$fullheight);
9504: }
9505:
1.9 raeburn 9506: sub check_configuser {
9507: my ($uhome,$dom,$confname,$servadm) = @_;
9508: my ($configuserok,%currroles);
9509: if ($uhome eq 'no_host') {
9510: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 9511: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 9512: $configuserok =
9513: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
9514: $configpass,'','','','','',undef,$servadm);
9515: } else {
9516: $configuserok = 'ok';
9517: %currroles =
9518: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9519: }
9520: return ($configuserok,%currroles);
9521: }
9522:
9523: sub check_authorstatus {
9524: my ($dom,$confname,%currroles) = @_;
9525: my $author_ok;
1.40 raeburn 9526: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 9527: my $start = time;
9528: my $end = 0;
9529: $author_ok =
9530: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 9531: 'au',$end,$start,'','','domconfig');
1.9 raeburn 9532: } else {
9533: $author_ok = 'ok';
9534: }
9535: return $author_ok;
9536: }
9537:
9538: sub publishlogo {
1.46 raeburn 9539: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 9540: my ($output,$fname,$logourl);
9541: if ($action eq 'upload') {
9542: $fname=$env{'form.'.$formname.'.filename'};
9543: chop($env{'form.'.$formname});
9544: } else {
9545: ($fname) = ($formname =~ /([^\/]+)$/);
9546: }
1.46 raeburn 9547: if ($savefileas ne '') {
9548: $fname = $savefileas;
9549: }
1.9 raeburn 9550: $fname=&Apache::lonnet::clean_filename($fname);
9551: # See if there is anything left
9552: unless ($fname) { return ('error: no uploaded file'); }
9553: $fname="$subdir/$fname";
1.160.6.5 raeburn 9554: my $docroot=$r->dir_config('lonDocRoot');
9555: my $filepath="$docroot/priv";
9556: my $relpath = "$dom/$confname";
1.9 raeburn 9557: my ($fnamepath,$file,$fetchthumb);
9558: $file=$fname;
9559: if ($fname=~m|/|) {
9560: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9561: }
1.160.6.26 raeburn 9562: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9563: my $count;
1.160.6.5 raeburn 9564: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9565: $filepath.="/$parts[$count]";
9566: if ((-e $filepath)!=1) {
9567: mkdir($filepath,02770);
9568: }
9569: }
9570: # Check for bad extension and disallow upload
9571: if ($file=~/\.(\w+)$/ &&
9572: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9573: $output =
1.160.6.25 raeburn 9574: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9575: } elsif ($file=~/\.(\w+)$/ &&
9576: !defined(&Apache::loncommon::fileembstyle($1))) {
9577: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9578: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 9579: $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 9580: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 9581: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9582: } else {
9583: my $source = $filepath.'/'.$file;
9584: my $logfile;
1.160.6.88 raeburn 9585: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 9586: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9587: }
9588: print $logfile
9589: "\n================= Publish ".localtime()." ================\n".
9590: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9591: # Save the file
1.160.6.88 raeburn 9592: if (!open(FH,">",$source)) {
1.9 raeburn 9593: &Apache::lonnet::logthis('Failed to create '.$source);
9594: return (&mt('Failed to create file'));
9595: }
9596: if ($action eq 'upload') {
9597: if (!print FH ($env{'form.'.$formname})) {
9598: &Apache::lonnet::logthis('Failed to write to '.$source);
9599: return (&mt('Failed to write file'));
9600: }
9601: } else {
9602: my $original = &Apache::lonnet::filelocation('',$formname);
9603: if(!copy($original,$source)) {
9604: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9605: return (&mt('Failed to write file'));
9606: }
9607: }
9608: close(FH);
9609: chmod(0660, $source); # Permissions to rw-rw---.
9610:
9611: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9612: my $copyfile=$targetdir.'/'.$file;
9613:
9614: my @parts=split(/\//,$targetdir);
9615: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9616: for (my $count=5;$count<=$#parts;$count++) {
9617: $path.="/$parts[$count]";
9618: if (!-e $path) {
9619: print $logfile "\nCreating directory ".$path;
9620: mkdir($path,02770);
9621: }
9622: }
9623: my $versionresult;
9624: if (-e $copyfile) {
9625: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9626: } else {
9627: $versionresult = 'ok';
9628: }
9629: if ($versionresult eq 'ok') {
9630: if (copy($source,$copyfile)) {
9631: print $logfile "\nCopied original source to ".$copyfile."\n";
9632: $output = 'ok';
9633: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9634: push(@{$modified_urls},[$copyfile,$source]);
9635: my $metaoutput =
9636: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9637: unless ($registered_cleanup) {
9638: my $handlers = $r->get_handlers('PerlCleanupHandler');
9639: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9640: $registered_cleanup=1;
9641: }
1.9 raeburn 9642: } else {
9643: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9644: $output = &mt('Failed to copy file to RES space').", $!";
9645: }
9646: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9647: my $inputfile = $filepath.'/'.$file;
9648: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 9649: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9650: if ($fullwidth ne '' && $fullheight ne '') {
9651: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9652: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 9653: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
9654: system({$args[0]} @args);
1.16 raeburn 9655: chmod(0660, $filepath.'/tn-'.$file);
9656: if (-e $outfile) {
9657: my $copyfile=$targetdir.'/tn-'.$file;
9658: if (copy($outfile,$copyfile)) {
9659: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 9660: my $thumb_metaoutput =
9661: &write_metadata($dom,$confname,$formname,
9662: $targetdir,'tn-'.$file,$logfile);
9663: push(@{$modified_urls},[$copyfile,$outfile]);
9664: unless ($registered_cleanup) {
9665: my $handlers = $r->get_handlers('PerlCleanupHandler');
9666: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9667: $registered_cleanup=1;
9668: }
1.16 raeburn 9669: } else {
9670: print $logfile "\nUnable to write ".$copyfile.
9671: ':'.$!."\n";
9672: }
9673: }
1.9 raeburn 9674: }
9675: }
9676: }
9677: } else {
9678: $output = $versionresult;
9679: }
9680: }
9681: return ($output,$logourl);
9682: }
9683:
9684: sub logo_versioning {
9685: my ($targetdir,$file,$logfile) = @_;
9686: my $target = $targetdir.'/'.$file;
9687: my ($maxversion,$fn,$extn,$output);
9688: $maxversion = 0;
9689: if ($file =~ /^(.+)\.(\w+)$/) {
9690: $fn=$1;
9691: $extn=$2;
9692: }
9693: opendir(DIR,$targetdir);
9694: while (my $filename=readdir(DIR)) {
9695: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
9696: $maxversion=($1>$maxversion)?$1:$maxversion;
9697: }
9698: }
9699: $maxversion++;
9700: print $logfile "\nCreating old version ".$maxversion."\n";
9701: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
9702: if (copy($target,$copyfile)) {
9703: print $logfile "Copied old target to ".$copyfile."\n";
9704: $copyfile=$copyfile.'.meta';
9705: if (copy($target.'.meta',$copyfile)) {
9706: print $logfile "Copied old target metadata to ".$copyfile."\n";
9707: $output = 'ok';
9708: } else {
9709: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
9710: $output = &mt('Failed to copy old meta').", $!, ";
9711: }
9712: } else {
9713: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
9714: $output = &mt('Failed to copy old target').", $!, ";
9715: }
9716: return $output;
9717: }
9718:
9719: sub write_metadata {
9720: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
9721: my (%metadatafields,%metadatakeys,$output);
9722: $metadatafields{'title'}=$formname;
9723: $metadatafields{'creationdate'}=time;
9724: $metadatafields{'lastrevisiondate'}=time;
9725: $metadatafields{'copyright'}='public';
9726: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
9727: $env{'user.domain'};
9728: $metadatafields{'authorspace'}=$confname.':'.$dom;
9729: $metadatafields{'domain'}=$dom;
9730: {
9731: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
9732: my $mfh;
1.160.6.88 raeburn 9733: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 9734: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 9735: unless ($_=~/\./) {
9736: my $unikey=$_;
9737: $unikey=~/^([A-Za-z]+)/;
9738: my $tag=$1;
9739: $tag=~tr/A-Z/a-z/;
9740: print $mfh "\n\<$tag";
9741: foreach (split(/\,/,$metadatakeys{$unikey})) {
9742: my $value=$metadatafields{$unikey.'.'.$_};
9743: $value=~s/\"/\'\'/g;
9744: print $mfh ' '.$_.'="'.$value.'"';
9745: }
9746: print $mfh '>'.
9747: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
9748: .'</'.$tag.'>';
9749: }
9750: }
9751: $output = 'ok';
9752: print $logfile "\nWrote metadata";
9753: close($mfh);
9754: } else {
9755: print $logfile "\nFailed to open metadata file";
1.9 raeburn 9756: $output = &mt('Could not write metadata');
9757: }
9758: }
1.155 raeburn 9759: return $output;
9760: }
9761:
9762: sub notifysubscribed {
9763: foreach my $targetsource (@{$modified_urls}){
9764: next unless (ref($targetsource) eq 'ARRAY');
9765: my ($target,$source)=@{$targetsource};
9766: if ($source ne '') {
1.160.6.88 raeburn 9767: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 9768: print $logfh "\nCleanup phase: Notifications\n";
9769: my @subscribed=&subscribed_hosts($target);
9770: foreach my $subhost (@subscribed) {
9771: print $logfh "\nNotifying host ".$subhost.':';
9772: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
9773: print $logfh $reply;
9774: }
9775: my @subscribedmeta=&subscribed_hosts("$target.meta");
9776: foreach my $subhost (@subscribedmeta) {
9777: print $logfh "\nNotifying host for metadata only ".$subhost.':';
9778: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
9779: $subhost);
9780: print $logfh $reply;
9781: }
9782: print $logfh "\n============ Done ============\n";
1.160 raeburn 9783: close($logfh);
1.155 raeburn 9784: }
9785: }
9786: }
9787: return OK;
9788: }
9789:
9790: sub subscribed_hosts {
9791: my ($target) = @_;
9792: my @subscribed;
1.160.6.88 raeburn 9793: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 9794: while (my $subline=<$fh>) {
9795: if ($subline =~ /^($match_lonid):/) {
9796: my $host = $1;
9797: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
9798: unless (grep(/^\Q$host\E$/,@subscribed)) {
9799: push(@subscribed,$host);
9800: }
9801: }
9802: }
9803: }
9804: }
9805: return @subscribed;
1.9 raeburn 9806: }
9807:
9808: sub check_switchserver {
9809: my ($dom,$confname) = @_;
9810: my ($allowed,$switchserver);
9811: my $home = &Apache::lonnet::homeserver($confname,$dom);
9812: if ($home eq 'no_host') {
9813: $home = &Apache::lonnet::domain($dom,'primary');
9814: }
9815: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 9816: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
9817: if (!$allowed) {
1.160.6.11 raeburn 9818: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 9819: }
9820: return $switchserver;
9821: }
9822:
1.1 raeburn 9823: sub modify_quotas {
1.160.6.30 raeburn 9824: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 9825: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 9826: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 9827: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
9828: $validationfieldsref);
1.86 raeburn 9829: if ($action eq 'quotas') {
9830: $context = 'tools';
1.160.6.26 raeburn 9831: } else {
1.86 raeburn 9832: $context = $action;
9833: }
9834: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 9835: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 9836: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 9837: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
9838: %titles = &courserequest_titles();
9839: $toolregexp = join('|',@usertools);
9840: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 9841: $confname = $dom.'-domainconfig';
9842: my $servadm = $r->dir_config('lonAdmEMail');
9843: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 9844: ($validationitemsref,$validationnamesref,$validationfieldsref) =
9845: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 9846: } elsif ($context eq 'requestauthor') {
9847: @usertools = ('author');
9848: %titles = &authorrequest_titles();
1.86 raeburn 9849: } else {
1.160.6.4 raeburn 9850: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 9851: %titles = &tool_titles();
1.86 raeburn 9852: }
1.160.6.27 raeburn 9853: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 9854: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9855: foreach my $key (keys(%env)) {
1.101 raeburn 9856: if ($context eq 'requestcourses') {
9857: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
9858: my $item = $1;
9859: my $type = $2;
9860: if ($type =~ /^limit_(.+)/) {
9861: $limithash{$item}{$1} = $env{$key};
9862: } else {
9863: $confhash{$item}{$type} = $env{$key};
9864: }
9865: }
1.160.6.5 raeburn 9866: } elsif ($context eq 'requestauthor') {
9867: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
9868: $confhash{$1} = $env{$key};
9869: }
1.101 raeburn 9870: } else {
1.86 raeburn 9871: if ($key =~ /^form\.quota_(.+)$/) {
9872: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 9873: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
9874: $confhash{'authorquota'}{$1} = $env{$key};
9875: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 9876: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
9877: }
1.72 raeburn 9878: }
9879: }
1.160.6.5 raeburn 9880: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 9881: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 9882: @approvalnotify = sort(@approvalnotify);
9883: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 9884: my @crstypes = ('official','unofficial','community','textbook');
9885: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
9886: foreach my $type (@hasuniquecode) {
9887: if (grep(/^\Q$type\E$/,@crstypes)) {
9888: $confhash{'uniquecode'}{$type} = 1;
9889: }
9890: }
1.160.6.46 raeburn 9891: my (%newbook,%allpos);
1.160.6.30 raeburn 9892: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9893: foreach my $type ('textbooks','templates') {
9894: @{$allpos{$type}} = ();
9895: my $invalid;
9896: if ($type eq 'textbooks') {
9897: $invalid = &mt('Invalid LON-CAPA course for textbook');
9898: } else {
9899: $invalid = &mt('Invalid LON-CAPA course for template');
9900: }
9901: if ($env{'form.'.$type.'_addbook'}) {
9902: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
9903: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
9904: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
9905: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
9906: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9907: } else {
9908: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9909: my $position = $env{'form.'.$type.'_addbook_pos'};
9910: $position =~ s/\D+//g;
9911: if ($position ne '') {
9912: $allpos{$type}[$position] = $newbook{$type};
9913: }
1.160.6.30 raeburn 9914: }
1.160.6.46 raeburn 9915: } else {
9916: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 9917: }
9918: }
1.160.6.46 raeburn 9919: }
1.160.6.30 raeburn 9920: }
1.102 raeburn 9921: if (ref($domconfig{$action}) eq 'HASH') {
9922: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
9923: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
9924: $changes{'notify'}{'approval'} = 1;
9925: }
9926: } else {
1.144 raeburn 9927: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9928: $changes{'notify'}{'approval'} = 1;
9929: }
9930: }
1.160.6.30 raeburn 9931: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
9932: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9933: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
9934: unless ($confhash{'uniquecode'}{$crstype}) {
9935: $changes{'uniquecode'} = 1;
9936: }
9937: }
9938: unless ($changes{'uniquecode'}) {
9939: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
9940: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
9941: $changes{'uniquecode'} = 1;
9942: }
9943: }
9944: }
9945: } else {
9946: $changes{'uniquecode'} = 1;
9947: }
9948: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
9949: $changes{'uniquecode'} = 1;
9950: }
9951: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9952: foreach my $type ('textbooks','templates') {
9953: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9954: my %deletions;
9955: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
9956: if (@todelete) {
9957: map { $deletions{$_} = 1; } @todelete;
9958: }
9959: my %imgdeletions;
9960: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
9961: if (@todeleteimages) {
9962: map { $imgdeletions{$_} = 1; } @todeleteimages;
9963: }
9964: my $maxnum = $env{'form.'.$type.'_maxnum'};
9965: for (my $i=0; $i<=$maxnum; $i++) {
9966: my $itemid = $env{'form.'.$type.'_id_'.$i};
9967: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
9968: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
9969: if ($deletions{$key}) {
9970: if ($domconfig{$action}{$type}{$key}{'image'}) {
9971: #FIXME need to obsolete item in RES space
9972: }
9973: next;
9974: } else {
9975: my $newpos = $env{'form.'.$itemid};
9976: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 9977: foreach my $item ('subject','title','publisher','author') {
9978: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9979: ($type eq 'templates'));
1.160.6.46 raeburn 9980: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
9981: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
9982: $changes{$type}{$key} = 1;
9983: }
9984: }
9985: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 9986: }
1.160.6.46 raeburn 9987: if ($imgdeletions{$key}) {
9988: $changes{$type}{$key} = 1;
9989: #FIXME need to obsolete item in RES space
9990: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
9991: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 9992: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9993: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9994: } else {
9995: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
9996: $cdom,$cnum,$type,$configuserok,
9997: $switchserver,$author_ok);
9998: if ($imgurl) {
9999: $confhash{$type}{$key}{'image'} = $imgurl;
10000: $changes{$type}{$key} = 1;
10001: }
10002: if ($error) {
10003: &Apache::lonnet::logthis($error);
10004: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10005: }
1.160.6.46 raeburn 10006: }
10007: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10008: $confhash{$type}{$key}{'image'} =
10009: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 10010: }
10011: }
10012: }
10013: }
10014: }
10015: }
1.102 raeburn 10016: } else {
1.144 raeburn 10017: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10018: $changes{'notify'}{'approval'} = 1;
10019: }
1.160.6.30 raeburn 10020: if (ref($confhash{'uniquecode'} eq 'HASH')) {
10021: $changes{'uniquecode'} = 1;
10022: }
10023: }
10024: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10025: foreach my $type ('textbooks','templates') {
10026: if ($newbook{$type}) {
10027: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 10028: foreach my $item ('subject','title','publisher','author') {
10029: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10030: ($type eq 'template'));
1.160.6.46 raeburn 10031: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10032: if ($env{'form.'.$type.'_addbook_'.$item}) {
10033: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10034: }
10035: }
10036: if ($type eq 'textbooks') {
10037: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10038: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 10039: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10040: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10041: } else {
10042: my ($imageurl,$error) =
10043: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10044: $configuserok,$switchserver,$author_ok);
10045: if ($imageurl) {
10046: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10047: }
10048: if ($error) {
10049: &Apache::lonnet::logthis($error);
10050: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10051: }
1.160.6.46 raeburn 10052: }
10053: }
1.160.6.30 raeburn 10054: }
10055: }
1.160.6.46 raeburn 10056: if (@{$allpos{$type}} > 0) {
10057: my $idx = 0;
10058: foreach my $item (@{$allpos{$type}}) {
10059: if ($item ne '') {
10060: $confhash{$type}{$item}{'order'} = $idx;
10061: if (ref($domconfig{$action}) eq 'HASH') {
10062: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10063: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10064: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10065: $changes{$type}{$item} = 1;
10066: }
1.160.6.30 raeburn 10067: }
10068: }
10069: }
1.160.6.46 raeburn 10070: $idx ++;
1.160.6.30 raeburn 10071: }
10072: }
10073: }
10074: }
1.160.6.39 raeburn 10075: if (ref($validationitemsref) eq 'ARRAY') {
10076: foreach my $item (@{$validationitemsref}) {
10077: if ($item eq 'fields') {
10078: my @changed;
10079: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10080: if (@{$confhash{'validation'}{$item}} > 0) {
10081: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10082: }
1.160.6.65 raeburn 10083: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10084: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10085: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10086: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10087: $domconfig{'requestcourses'}{'validation'}{$item});
10088: } else {
10089: @changed = @{$confhash{'validation'}{$item}};
10090: }
1.160.6.39 raeburn 10091: } else {
10092: @changed = @{$confhash{'validation'}{$item}};
10093: }
10094: } else {
10095: @changed = @{$confhash{'validation'}{$item}};
10096: }
10097: if (@changed) {
10098: if ($confhash{'validation'}{$item}) {
10099: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10100: } else {
10101: $changes{'validation'}{$item} = &mt('None');
10102: }
10103: }
10104: } else {
10105: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10106: if ($item eq 'markup') {
10107: if ($env{'form.requestcourses_validation_'.$item}) {
10108: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10109: }
10110: }
1.160.6.65 raeburn 10111: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10112: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10113: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10114: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10115: }
10116: } else {
10117: if ($confhash{'validation'}{$item} ne '') {
10118: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10119: }
1.160.6.39 raeburn 10120: }
10121: } else {
10122: if ($confhash{'validation'}{$item} ne '') {
10123: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10124: }
10125: }
10126: }
10127: }
10128: }
10129: if ($env{'form.validationdc'}) {
10130: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 10131: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 10132: if (exists($domcoords{$newval})) {
10133: $confhash{'validation'}{'dc'} = $newval;
10134: }
10135: }
10136: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 10137: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10138: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10139: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10140: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10141: if ($confhash{'validation'}{'dc'} eq '') {
10142: $changes{'validation'}{'dc'} = &mt('None');
10143: } else {
10144: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10145: }
1.160.6.39 raeburn 10146: }
1.160.6.65 raeburn 10147: } elsif ($confhash{'validation'}{'dc'} ne '') {
10148: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 10149: }
10150: } elsif ($confhash{'validation'}{'dc'} ne '') {
10151: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10152: }
10153: } elsif ($confhash{'validation'}{'dc'} ne '') {
10154: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10155: }
1.160.6.65 raeburn 10156: } else {
10157: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10158: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10159: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10160: $changes{'validation'}{'dc'} = &mt('None');
10161: }
10162: }
1.160.6.39 raeburn 10163: }
10164: }
1.102 raeburn 10165: }
10166: } else {
1.86 raeburn 10167: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 10168: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10169: }
1.72 raeburn 10170: foreach my $item (@usertools) {
10171: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10172: my $unset;
1.101 raeburn 10173: if ($context eq 'requestcourses') {
1.104 raeburn 10174: $unset = '0';
10175: if ($type eq '_LC_adv') {
10176: $unset = '';
10177: }
1.101 raeburn 10178: if ($confhash{$item}{$type} eq 'autolimit') {
10179: $confhash{$item}{$type} .= '=';
10180: unless ($limithash{$item}{$type} =~ /\D/) {
10181: $confhash{$item}{$type} .= $limithash{$item}{$type};
10182: }
10183: }
1.160.6.5 raeburn 10184: } elsif ($context eq 'requestauthor') {
10185: $unset = '0';
10186: if ($type eq '_LC_adv') {
10187: $unset = '';
10188: }
1.72 raeburn 10189: } else {
1.101 raeburn 10190: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10191: $confhash{$item}{$type} = 1;
10192: } else {
10193: $confhash{$item}{$type} = 0;
10194: }
1.72 raeburn 10195: }
1.86 raeburn 10196: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 10197: if ($action eq 'requestauthor') {
10198: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10199: $changes{$type} = 1;
10200: }
10201: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10202: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10203: $changes{$item}{$type} = 1;
10204: }
10205: } else {
10206: if ($context eq 'requestcourses') {
1.104 raeburn 10207: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 10208: $changes{$item}{$type} = 1;
10209: }
10210: } else {
10211: if (!$confhash{$item}{$type}) {
10212: $changes{$item}{$type} = 1;
10213: }
10214: }
10215: }
10216: } else {
10217: if ($context eq 'requestcourses') {
1.104 raeburn 10218: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10219: $changes{$item}{$type} = 1;
10220: }
1.160.6.5 raeburn 10221: } elsif ($context eq 'requestauthor') {
10222: if ($confhash{$type} ne $unset) {
10223: $changes{$type} = 1;
10224: }
1.72 raeburn 10225: } else {
10226: if (!$confhash{$item}{$type}) {
10227: $changes{$item}{$type} = 1;
10228: }
10229: }
10230: }
1.1 raeburn 10231: }
10232: }
1.160.6.5 raeburn 10233: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10234: if (ref($domconfig{'quotas'}) eq 'HASH') {
10235: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10236: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10237: if (exists($confhash{'defaultquota'}{$key})) {
10238: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10239: $changes{'defaultquota'}{$key} = 1;
10240: }
10241: } else {
10242: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10243: }
10244: }
1.86 raeburn 10245: } else {
10246: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10247: if (exists($confhash{'defaultquota'}{$key})) {
10248: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10249: $changes{'defaultquota'}{$key} = 1;
10250: }
10251: } else {
10252: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10253: }
1.1 raeburn 10254: }
10255: }
1.160.6.20 raeburn 10256: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10257: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10258: if (exists($confhash{'authorquota'}{$key})) {
10259: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10260: $changes{'authorquota'}{$key} = 1;
10261: }
10262: } else {
10263: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10264: }
10265: }
10266: }
1.1 raeburn 10267: }
1.86 raeburn 10268: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10269: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10270: if (ref($domconfig{'quotas'}) eq 'HASH') {
10271: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10272: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
10273: $changes{'defaultquota'}{$key} = 1;
10274: }
10275: } else {
10276: if (!exists($domconfig{'quotas'}{$key})) {
10277: $changes{'defaultquota'}{$key} = 1;
10278: }
1.72 raeburn 10279: }
10280: } else {
1.86 raeburn 10281: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 10282: }
1.1 raeburn 10283: }
10284: }
1.160.6.20 raeburn 10285: if (ref($confhash{'authorquota'}) eq 'HASH') {
10286: foreach my $key (keys(%{$confhash{'authorquota'}})) {
10287: if (ref($domconfig{'quotas'}) eq 'HASH') {
10288: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10289: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
10290: $changes{'authorquota'}{$key} = 1;
10291: }
10292: } else {
10293: $changes{'authorquota'}{$key} = 1;
10294: }
10295: } else {
10296: $changes{'authorquota'}{$key} = 1;
10297: }
10298: }
10299: }
1.1 raeburn 10300: }
1.72 raeburn 10301:
1.160.6.5 raeburn 10302: if ($context eq 'requestauthor') {
10303: $domdefaults{'requestauthor'} = \%confhash;
10304: } else {
10305: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 10306: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 10307: $domdefaults{$key} = $confhash{$key};
10308: }
1.160.6.5 raeburn 10309: }
1.72 raeburn 10310: }
1.160.6.5 raeburn 10311:
1.1 raeburn 10312: my %quotahash = (
1.86 raeburn 10313: $action => { %confhash }
1.1 raeburn 10314: );
10315: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
10316: $dom);
10317: if ($putresult eq 'ok') {
10318: if (keys(%changes) > 0) {
1.72 raeburn 10319: my $cachetime = 24*60*60;
10320: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10321: if (ref($lastactref) eq 'HASH') {
10322: $lastactref->{'domdefaults'} = 1;
10323: }
1.1 raeburn 10324: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 10325: unless (($context eq 'requestcourses') ||
10326: ($context eq 'requestauthor')) {
1.86 raeburn 10327: if (ref($changes{'defaultquota'}) eq 'HASH') {
10328: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
10329: foreach my $type (@{$types},'default') {
10330: if (defined($changes{'defaultquota'}{$type})) {
10331: my $typetitle = $usertypes->{$type};
10332: if ($type eq 'default') {
10333: $typetitle = $othertitle;
10334: }
1.160.6.28 raeburn 10335: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 10336: }
10337: }
1.86 raeburn 10338: $resulttext .= '</ul></li>';
1.72 raeburn 10339: }
1.160.6.20 raeburn 10340: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 10341: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 10342: foreach my $type (@{$types},'default') {
10343: if (defined($changes{'authorquota'}{$type})) {
10344: my $typetitle = $usertypes->{$type};
10345: if ($type eq 'default') {
10346: $typetitle = $othertitle;
10347: }
1.160.6.28 raeburn 10348: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 10349: }
10350: }
10351: $resulttext .= '</ul></li>';
10352: }
1.72 raeburn 10353: }
1.80 raeburn 10354: my %newenv;
1.72 raeburn 10355: foreach my $item (@usertools) {
1.160.6.5 raeburn 10356: my (%haschgs,%inconf);
10357: if ($context eq 'requestauthor') {
10358: %haschgs = %changes;
10359: %inconf = %confhash;
10360: } else {
10361: if (ref($changes{$item}) eq 'HASH') {
10362: %haschgs = %{$changes{$item}};
10363: }
10364: if (ref($confhash{$item}) eq 'HASH') {
10365: %inconf = %{$confhash{$item}};
10366: }
10367: }
10368: if (keys(%haschgs) > 0) {
1.80 raeburn 10369: my $newacc =
10370: &Apache::lonnet::usertools_access($env{'user.name'},
10371: $env{'user.domain'},
1.86 raeburn 10372: $item,'reload',$context);
1.160.6.5 raeburn 10373: if (($context eq 'requestcourses') ||
10374: ($context eq 'requestauthor')) {
1.108 raeburn 10375: if ($env{'environment.canrequest.'.$item} ne $newacc) {
10376: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 10377: }
10378: } else {
10379: if ($env{'environment.availabletools.'.$item} ne $newacc) {
10380: $newenv{'environment.availabletools.'.$item} = $newacc;
10381: }
1.80 raeburn 10382: }
1.160.6.5 raeburn 10383: unless ($context eq 'requestauthor') {
10384: $resulttext .= '<li>'.$titles{$item}.'<ul>';
10385: }
1.72 raeburn 10386: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 10387: if ($haschgs{$type}) {
1.72 raeburn 10388: my $typetitle = $usertypes->{$type};
10389: if ($type eq 'default') {
10390: $typetitle = $othertitle;
10391: } elsif ($type eq '_LC_adv') {
10392: $typetitle = 'LON-CAPA Advanced Users';
10393: }
1.160.6.5 raeburn 10394: if ($inconf{$type}) {
1.101 raeburn 10395: if ($context eq 'requestcourses') {
10396: my $cond;
1.160.6.5 raeburn 10397: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 10398: if ($1 eq '') {
10399: $cond = &mt('(Automatic processing of any request).');
10400: } else {
10401: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
10402: }
10403: } else {
1.160.6.5 raeburn 10404: $cond = $conditions{$inconf{$type}};
1.101 raeburn 10405: }
10406: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 10407: } elsif ($context eq 'requestauthor') {
10408: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
10409: $titles{$inconf{$type}},$typetitle);
10410:
1.101 raeburn 10411: } else {
10412: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
10413: }
1.72 raeburn 10414: } else {
1.104 raeburn 10415: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 10416: if ($inconf{$type} eq '0') {
1.104 raeburn 10417: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10418: } else {
10419: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
10420: }
10421: } else {
10422: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10423: }
1.72 raeburn 10424: }
10425: }
1.26 raeburn 10426: }
1.160.6.5 raeburn 10427: unless ($context eq 'requestauthor') {
10428: $resulttext .= '</ul></li>';
10429: }
1.26 raeburn 10430: }
1.1 raeburn 10431: }
1.160.6.5 raeburn 10432: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 10433: if (ref($changes{'notify'}) eq 'HASH') {
10434: if ($changes{'notify'}{'approval'}) {
10435: if (ref($confhash{'notify'}) eq 'HASH') {
10436: if ($confhash{'notify'}{'approval'}) {
10437: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
10438: } else {
1.160.6.5 raeburn 10439: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 10440: }
10441: }
10442: }
10443: }
10444: }
1.160.6.30 raeburn 10445: if ($action eq 'requestcourses') {
10446: my @offon = ('off','on');
10447: if ($changes{'uniquecode'}) {
10448: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10449: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10450: $resulttext .= '<li>'.
10451: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10452: '</li>';
10453: } else {
10454: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10455: '</li>';
10456: }
10457: }
1.160.6.46 raeburn 10458: foreach my $type ('textbooks','templates') {
10459: if (ref($changes{$type}) eq 'HASH') {
10460: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10461: foreach my $key (sort(keys(%{$changes{$type}}))) {
10462: my %coursehash = &Apache::lonnet::coursedescription($key);
10463: my $coursetitle = $coursehash{'description'};
10464: my $position = $confhash{$type}{$key}{'order'} + 1;
10465: $resulttext .= '<li>';
1.160.6.47 raeburn 10466: foreach my $item ('subject','title','publisher','author') {
10467: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10468: ($type eq 'templates'));
1.160.6.46 raeburn 10469: my $name = $item.':';
10470: $name =~ s/^(\w)/\U$1/;
10471: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10472: }
10473: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10474: if ($type eq 'textbooks') {
10475: if ($confhash{$type}{$key}{'image'}) {
10476: $resulttext .= ' '.&mt('Image: [_1]',
10477: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10478: ' alt="Textbook cover" />').'<br />';
10479: }
10480: }
10481: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 10482: }
1.160.6.46 raeburn 10483: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 10484: }
10485: }
1.160.6.39 raeburn 10486: if (ref($changes{'validation'}) eq 'HASH') {
10487: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10488: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10489: foreach my $item (@{$validationitemsref}) {
10490: if (exists($changes{'validation'}{$item})) {
10491: if ($item eq 'markup') {
10492: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10493: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10494: } else {
10495: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10496: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10497: }
10498: }
10499: }
10500: if (exists($changes{'validation'}{'dc'})) {
10501: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
10502: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
10503: }
10504: }
10505: }
1.160.6.30 raeburn 10506: }
1.1 raeburn 10507: $resulttext .= '</ul>';
1.80 raeburn 10508: if (keys(%newenv)) {
10509: &Apache::lonnet::appenv(\%newenv);
10510: }
1.1 raeburn 10511: } else {
1.86 raeburn 10512: if ($context eq 'requestcourses') {
10513: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 10514: } elsif ($context eq 'requestauthor') {
10515: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 10516: } else {
1.90 weissno 10517: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 10518: }
1.1 raeburn 10519: }
10520: } else {
1.11 albertel 10521: $resulttext = '<span class="LC_error">'.
10522: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10523: }
1.160.6.30 raeburn 10524: if ($errors) {
10525: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10526: '<ul>'.$errors.'</ul></p>';
10527: }
1.3 raeburn 10528: return $resulttext;
1.1 raeburn 10529: }
10530:
1.160.6.30 raeburn 10531: sub process_textbook_image {
1.160.6.46 raeburn 10532: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 10533: my $filename = $env{'form.'.$caller.'.filename'};
10534: my ($error,$url);
10535: my ($width,$height) = (50,50);
10536: if ($configuserok eq 'ok') {
10537: if ($switchserver) {
10538: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10539: $switchserver);
10540: } elsif ($author_ok eq 'ok') {
10541: my ($result,$imageurl) =
10542: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 10543: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 10544: if ($result eq 'ok') {
10545: $url = $imageurl;
10546: } else {
10547: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10548: }
10549: } else {
10550: $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);
10551: }
10552: } else {
10553: $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);
10554: }
10555: return ($url,$error);
10556: }
10557:
1.160.6.102.2 1(raebur 10558:0): sub modify_ltitools {
10559:0): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10560:0): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10561:0): my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
10562:0): my $confname = $dom.'-domainconfig';
10563:0): my $servadm = $r->dir_config('lonAdmEMail');
10564:0): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10565:0): my (%posslti,%possfield);
10566:0): my @courseroles = ('cc','in','ta','ep','st');
10567:0): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10568:0): map { $posslti{$_} = 1; } @ltiroles;
10569:0): my @allfields = ('fullname','firstname','lastname','email','user','roles');
10570:0): map { $possfield{$_} = 1; } @allfields;
10571:0): my %lt = <itools_names();
10572:0): if ($env{'form.ltitools_add'}) {
10573:0): my $title = $env{'form.ltitools_add_title'};
10574:0): $title =~ s/(`)/'/g;
10575:0): ($newid,my $error) = &get_ltitools_id($dom,$title);
10576:0): if ($newid) {
10577:0): my $position = $env{'form.ltitools_add_pos'};
10578:0): $position =~ s/\D+//g;
10579:0): if ($position ne '') {
10580:0): $allpos[$position] = $newid;
10581:0): }
10582:0): $changes{$newid} = 1;
5(raebur 10583:0): foreach my $item ('title','url','key','secret','lifetime') {
1(raebur 10584:0): $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
5(raebur 10585:0): if ($item eq 'lifetime') {
10586:0): $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
10587:0): }
1(raebur 10588:0): if ($env{'form.ltitools_add_'.$item}) {
10589:0): if (($item eq 'key') || ($item eq 'secret')) {
10590:0): $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10591:0): } else {
10592:0): $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10593:0): }
10594:0): }
10595:0): }
10596:0): if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10597:0): $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10598:0): }
10599:0): if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10600:0): $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10601:0): }
5(raebur 10602:0): if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
10603:0): $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
10604:0): } else {
10605:0): $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
10606:0): }
1(raebur 10607:0): foreach my $item ('width','height','linktext','explanation') {
10608:0): $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10609:0): $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
10610:0): if (($item eq 'width') || ($item eq 'height')) {
10611:0): if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10612:0): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10613:0): }
10614:0): } else {
10615:0): if ($env{'form.ltitools_add_'.$item} ne '') {
10616:0): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10617:0): }
10618:0): }
10619:0): }
10620:0): if ($env{'form.ltitools_add_target'} eq 'window') {
10621:0): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
10622:0): } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10623:0): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
10624:0): } else {
10625:0): $confhash{$newid}{'display'}{'target'} = 'iframe';
10626:0): }
10627:0): if ($env{'form.ltitools_add_image.filename'} ne '') {
10628:0): my ($imageurl,$error) =
10629:0): &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
10630:0): $configuserok,$switchserver,$author_ok);
10631:0): if ($imageurl) {
10632:0): $confhash{$newid}{'image'} = $imageurl;
10633:0): }
10634:0): if ($error) {
10635:0): &Apache::lonnet::logthis($error);
10636:0): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10637:0): }
10638:0): }
10639:0): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
10640:0): foreach my $field (@fields) {
10641:0): if ($possfield{$field}) {
10642:0): if ($field eq 'roles') {
10643:0): foreach my $role (@courseroles) {
10644:0): my $choice = $env{'form.ltitools_add_roles_'.$role};
10645:0): if (($choice ne '') && ($posslti{$choice})) {
10646:0): $confhash{$newid}{'roles'}{$role} = $choice;
10647:0): if ($role eq 'cc') {
10648:0): $confhash{$newid}{'roles'}{'co'} = $choice;
10649:0): }
10650:0): }
10651:0): }
10652:0): } else {
10653:0): $confhash{$newid}{'fields'}{$field} = 1;
10654:0): }
10655:0): }
10656:0): }
5(raebur 10657:0): if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
10658:0): if ($confhash{$newid}{'fields'}{'user'}) {
10659:0): if ($env{'form.ltitools_userincdom_add'}) {
10660:0): $confhash{$newid}{'incdom'} = 1;
10661:0): }
10662:0): }
10663:0): }
1(raebur 10664:0): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
10665:0): foreach my $item (@courseconfig) {
10666:0): $confhash{$newid}{'crsconf'}{$item} = 1;
10667:0): }
10668:0): if ($env{'form.ltitools_add_custom'}) {
10669:0): my $name = $env{'form.ltitools_add_custom_name'};
10670:0): my $value = $env{'form.ltitools_add_custom_value'};
10671:0): $value =~ s/(`)/'/g;
10672:0): $name =~ s/(`)/'/g;
10673:0): $confhash{$newid}{'custom'}{$name} = $value;
10674:0): }
10675:0): } else {
10676:0): my $error = &mt('Failed to acquire unique ID for new external tool');
10677:0): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10678:0): }
10679:0): }
10680:0): if (ref($domconfig{$action}) eq 'HASH') {
10681:0): my %deletions;
10682:0): my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
10683:0): if (@todelete) {
10684:0): map { $deletions{$_} = 1; } @todelete;
10685:0): }
10686:0): my %customadds;
10687:0): my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
10688:0): if (@newcustom) {
10689:0): map { $customadds{$_} = 1; } @newcustom;
10690:0): }
10691:0): my %imgdeletions;
10692:0): my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
10693:0): if (@todeleteimages) {
10694:0): map { $imgdeletions{$_} = 1; } @todeleteimages;
10695:0): }
10696:0): my $maxnum = $env{'form.ltitools_maxnum'};
10697:0): for (my $i=0; $i<=$maxnum; $i++) {
10698:0): my $itemid = $env{'form.ltitools_id_'.$i};
10699:0): $itemid =~ s/\D+//g;
10700:0): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10701:0): if ($deletions{$itemid}) {
10702:0): if ($domconfig{$action}{$itemid}{'image'}) {
10703:0): #FIXME need to obsolete item in RES space
10704:0): }
10705:0): $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
10706:0): next;
10707:0): } else {
10708:0): my $newpos = $env{'form.ltitools_'.$itemid};
10709:0): $newpos =~ s/\D+//g;
5(raebur 10710:0): foreach my $item ('title','url','lifetime') {
1(raebur 10711:0): $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10712:0): if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
10713:0): $changes{$itemid} = 1;
10714:0): }
10715:0): }
10716:0): foreach my $item ('key','secret') {
10717:0): $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10718:0): if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
10719:0): $changes{$itemid} = 1;
10720:0): }
10721:0): }
10722:0): if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
10723:0): $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
10724:0): }
10725:0): if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
10726:0): $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
10727:0): }
5(raebur 10728:0): if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
10729:0): $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
10730:0): } else {
10731:0): $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
10732:0): }
10733:0): if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
10734:0): if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
10735:0): $changes{$itemid} = 1;
10736:0): }
10737:0): } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
10738:0): $changes{$itemid} = 1;
10739:0): }
1(raebur 10740:0): foreach my $size ('width','height') {
10741:0): $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
10742:0): $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
10743:0): if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
10744:0): $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
10745:0): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10746:0): if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
10747:0): $changes{$itemid} = 1;
10748:0): }
10749:0): } else {
10750:0): $changes{$itemid} = 1;
10751:0): }
10752:0): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10753:0): if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
10754:0): $changes{$itemid} = 1;
10755:0): }
10756:0): }
10757:0): }
10758:0): foreach my $item ('linktext','explanation') {
10759:0): $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
10760:0): $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
10761:0): if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
10762:0): $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10763:0): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10764:0): if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
10765:0): $changes{$itemid} = 1;
10766:0): }
10767:0): } else {
10768:0): $changes{$itemid} = 1;
10769:0): }
10770:0): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10771:0): if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
10772:0): $changes{$itemid} = 1;
10773:0): }
10774:0): }
10775:0): }
10776:0): if ($env{'form.ltitools_target_'.$i} eq 'window') {
10777:0): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
10778:0): } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
10779:0): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
10780:0): } else {
10781:0): $confhash{$itemid}{'display'}{'target'} = 'iframe';
10782:0): }
10783:0): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10784:0): if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
10785:0): $changes{$itemid} = 1;
10786:0): }
10787:0): } else {
10788:0): $changes{$itemid} = 1;
10789:0): }
10790:0): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
5(raebur 10791:0): foreach my $item ('label','title','target','linktext','explanation','append') {
1(raebur 10792:0): if (grep(/^\Q$item\E$/,@courseconfig)) {
10793:0): $confhash{$itemid}{'crsconf'}{$item} = 1;
10794:0): if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
10795:0): if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
10796:0): $changes{$itemid} = 1;
10797:0): }
10798:0): } else {
10799:0): $changes{$itemid} = 1;
10800:0): }
10801:0): }
10802:0): }
10803:0): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
10804:0): foreach my $field (@fields) {
10805:0): if ($possfield{$field}) {
10806:0): if ($field eq 'roles') {
10807:0): foreach my $role (@courseroles) {
10808:0): my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
10809:0): if (($choice ne '') && ($posslti{$choice})) {
10810:0): $confhash{$itemid}{'roles'}{$role} = $choice;
10811:0): if ($role eq 'cc') {
10812:0): $confhash{$itemid}{'roles'}{'co'} = $choice;
10813:0): }
10814:0): }
10815:0): if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
10816:0): if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
10817:0): $changes{$itemid} = 1;
10818:0): }
10819:0): } elsif ($confhash{$itemid}{'roles'}{$role}) {
10820:0): $changes{$itemid} = 1;
10821:0): }
10822:0): }
10823:0): } else {
10824:0): $confhash{$itemid}{'fields'}{$field} = 1;
10825:0): if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
10826:0): if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
10827:0): $changes{$itemid} = 1;
10828:0): }
10829:0): } else {
10830:0): $changes{$itemid} = 1;
10831:0): }
10832:0): }
10833:0): }
10834:0): }
5(raebur 10835:0): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
10836:0): if ($confhash{$itemid}{'fields'}{'user'}) {
10837:0): if ($env{'form.ltitools_userincdom_'.$i}) {
10838:0): $confhash{$itemid}{'incdom'} = 1;
10839:0): }
10840:0): if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
10841:0): $changes{$itemid} = 1;
10842:0): }
10843:0): }
10844:0): }
1(raebur 10845:0): $allpos[$newpos] = $itemid;
10846:0): }
10847:0): if ($imgdeletions{$itemid}) {
10848:0): $changes{$itemid} = 1;
10849:0): #FIXME need to obsolete item in RES space
10850:0): } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
10851:0): my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
10852:0): $itemid,$configuserok,$switchserver,
10853:0): $author_ok);
10854:0): if ($imgurl) {
10855:0): $confhash{$itemid}{'image'} = $imgurl;
10856:0): $changes{$itemid} = 1;
10857:0): }
10858:0): if ($error) {
10859:0): &Apache::lonnet::logthis($error);
10860:0): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10861:0): }
10862:0): } elsif ($domconfig{$action}{$itemid}{'image'}) {
10863:0): $confhash{$itemid}{'image'} =
10864:0): $domconfig{$action}{$itemid}{'image'};
10865:0): }
10866:0): if ($customadds{$i}) {
10867:0): my $name = $env{'form.ltitools_custom_name_'.$i};
10868:0): $name =~ s/(`)/'/g;
10869:0): $name =~ s/^\s+//;
10870:0): $name =~ s/\s+$//;
10871:0): my $value = $env{'form.ltitools_custom_value_'.$i};
10872:0): $value =~ s/(`)/'/g;
10873:0): $value =~ s/^\s+//;
10874:0): $value =~ s/\s+$//;
10875:0): if ($name ne '') {
10876:0): $confhash{$itemid}{'custom'}{$name} = $value;
10877:0): $changes{$itemid} = 1;
10878:0): }
10879:0): }
10880:0): my %customdels;
10881:0): my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
10882:0): if (@customdeletions) {
10883:0): $changes{$itemid} = 1;
10884:0): }
10885:0): map { $customdels{$_} = 1; } @customdeletions;
10886:0): if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
10887:0): foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
10888:0): unless ($customdels{$key}) {
10889:0): if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
10890:0): $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
10891:0): }
10892:0): if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
10893:0): $changes{$itemid} = 1;
10894:0): }
10895:0): }
10896:0): }
10897:0): }
10898:0): unless ($changes{$itemid}) {
10899:0): foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
10900:0): if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
10901:0): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
10902:0): foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
10903:0): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
10904:0): $changes{$itemid} = 1;
10905:0): last;
10906:0): }
10907:0): }
10908:0): } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
10909:0): $changes{$itemid} = 1;
10910:0): }
10911:0): }
10912:0): last if ($changes{$itemid});
10913:0): }
10914:0): }
10915:0): }
10916:0): }
10917:0): }
10918:0): if (@allpos > 0) {
10919:0): my $idx = 0;
10920:0): foreach my $itemid (@allpos) {
10921:0): if ($itemid ne '') {
10922:0): $confhash{$itemid}{'order'} = $idx;
10923:0): if (ref($domconfig{$action}) eq 'HASH') {
10924:0): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10925:0): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
10926:0): $changes{$itemid} = 1;
10927:0): }
10928:0): }
10929:0): }
10930:0): $idx ++;
10931:0): }
10932:0): }
10933:0): }
10934:0): my %ltitoolshash = (
10935:0): $action => { %confhash }
10936:0): );
10937:0): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
10938:0): $dom);
10939:0): if ($putresult eq 'ok') {
10940:0): my %ltienchash = (
10941:0): $action => { %encconfig }
10942:0): );
10943:0): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
10944:0): if (keys(%changes) > 0) {
10945:0): my $cachetime = 24*60*60;
10946:0): my %ltiall = %confhash;
10947:0): foreach my $id (keys(%ltiall)) {
10948:0): if (ref($encconfig{$id}) eq 'HASH') {
10949:0): foreach my $item ('key','secret') {
10950:0): $ltiall{$id}{$item} = $encconfig{$id}{$item};
10951:0): }
10952:0): }
10953:0): }
10954:0): &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
10955:0): if (ref($lastactref) eq 'HASH') {
10956:0): $lastactref->{'ltitools'} = 1;
10957:0): }
10958:0): $resulttext = &mt('Changes made:').'<ul>';
10959:0): my %bynum;
10960:0): foreach my $itemid (sort(keys(%changes))) {
10961:0): my $position = $confhash{$itemid}{'order'};
10962:0): $bynum{$position} = $itemid;
10963:0): }
10964:0): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
10965:0): my $itemid = $bynum{$pos};
10966:0): if (ref($confhash{$itemid}) ne 'HASH') {
10967:0): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
10968:0): } else {
10969:0): $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
10970:0): if ($confhash{$itemid}{'image'}) {
10971:0): $resulttext .= ' '.
10972:0): '<img src="'.$confhash{$itemid}{'image'}.'"'.
10973:0): ' alt="'.&mt('Tool Provider icon').'" />';
10974:0): }
10975:0): $resulttext .= '</li><ul>';
10976:0): my $position = $pos + 1;
10977:0): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
5(raebur 10978:0): foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1(raebur 10979:0): if ($confhash{$itemid}{$item} ne '') {
10980:0): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
10981:0): }
10982:0): }
10983:0): if ($encconfig{$itemid}{'key'} ne '') {
10984:0): $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
10985:0): }
10986:0): if ($encconfig{$itemid}{'secret'} ne '') {
10987:0): $resulttext .= '<li>'.$lt{'secret'}.': ';
10988:0): my $num = length($encconfig{$itemid}{'secret'});
10989:0): $resulttext .= ('*'x$num).'</li>';
10990:0): }
10991:0): $resulttext .= '<li>'.&mt('Configurable in course:');
5(raebur 10992:0): my @possconfig = ('label','title','target','linktext','explanation','append');
1(raebur 10993:0): my $numconfig = 0;
10994:0): if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
10995:0): foreach my $item (@possconfig) {
10996:0): if ($confhash{$itemid}{'crsconf'}{$item}) {
10997:0): $numconfig ++;
10998:0): $resulttext .= ' "'.$lt{'crs'.$item}.'"';
10999:0): }
11000:0): }
11001:0): }
11002:0): if (!$numconfig) {
11003:0): $resulttext .= &mt('None');
11004:0): }
11005:0): $resulttext .= '</li>';
11006:0): if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11007:0): my $displaylist;
11008:0): if ($confhash{$itemid}{'display'}{'target'}) {
11009:0): $displaylist = &mt('Display target').': '.
11010:0): $confhash{$itemid}{'display'}{'target'}.',';
11011:0): }
11012:0): foreach my $size ('width','height') {
11013:0): if ($confhash{$itemid}{'display'}{$size}) {
11014:0): $displaylist .= (' 'x2).$lt{$size}.': '.
11015:0): $confhash{$itemid}{'display'}{$size}.',';
11016:0): }
11017:0): }
11018:0): if ($displaylist) {
11019:0): $displaylist =~ s/,$//;
11020:0): $resulttext .= '<li>'.$displaylist.'</li>';
11021:0): }
11022:0): foreach my $item ('linktext','explanation') {
11023:0): if ($confhash{$itemid}{'display'}{$item}) {
11024:0): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11025:0): }
11026:0): }
11027:0): }
11028:0): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11029:0): my $fieldlist;
11030:0): foreach my $field (@allfields) {
11031:0): if ($confhash{$itemid}{'fields'}{$field}) {
11032:0): $fieldlist .= (' 'x2).$lt{$field}.',';
11033:0): }
11034:0): }
11035:0): if ($fieldlist) {
11036:0): $fieldlist =~ s/,$//;
5(raebur 11037:0): if ($confhash{$itemid}{'fields'}{'user'}) {
11038:0): if ($confhash{$itemid}{'incdom'}) {
11039:0): $fieldlist .= ' ('.&mt('username:domain').')';
11040:0): } else {
11041:0): $fieldlist .= ' ('.&mt('username').')';
11042:0): }
11043:0): }
1(raebur 11044:0): $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11045:0): }
11046:0): }
11047:0): if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11048:0): my $rolemaps;
11049:0): foreach my $role (@courseroles) {
11050:0): if ($confhash{$itemid}{'roles'}{$role}) {
11051:0): $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11052:0): $confhash{$itemid}{'roles'}{$role}.',';
11053:0): }
11054:0): }
11055:0): if ($rolemaps) {
11056:0): $rolemaps =~ s/,$//;
11057:0): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11058:0): }
11059:0): }
11060:0): if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11061:0): my $customlist;
11062:0): if (keys(%{$confhash{$itemid}{'custom'}})) {
11063:0): foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11064:0): $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11065:0): }
11066:0): }
11067:0): if ($customlist) {
5(raebur 11068:0): $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1(raebur 11069:0): }
11070:0): }
11071:0): $resulttext .= '</ul></li>';
11072:0): }
11073:0): }
11074:0): $resulttext .= '</ul>';
11075:0): } else {
11076:0): $resulttext = &mt('No changes made.');
11077:0): }
11078:0): } else {
11079:0): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11080:0): }
11081:0): if ($errors) {
11082:0): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11083:0): $errors.'</ul>';
11084:0): }
11085:0): return $resulttext;
11086:0): }
11087:0):
11088:0): sub process_ltitools_image {
11089:0): my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11090:0): my $filename = $env{'form.'.$caller.'.filename'};
11091:0): my ($error,$url);
11092:0): my ($width,$height) = (21,21);
11093:0): if ($configuserok eq 'ok') {
11094:0): if ($switchserver) {
11095:0): $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11096:0): $switchserver);
11097:0): } elsif ($author_ok eq 'ok') {
11098:0): my ($result,$imageurl,$madethumb) =
11099:0): &publishlogo($r,'upload',$caller,$dom,$confname,
11100:0): "ltitools/$itemid/icon",$width,$height);
11101:0): if ($result eq 'ok') {
11102:0): if ($madethumb) {
11103:0): my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11104:0): my $imagethumb = "$path/tn-".$imagefile;
11105:0): $url = $imagethumb;
11106:0): } else {
11107:0): $url = $imageurl;
11108:0): }
11109:0): } else {
11110:0): $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11111:0): }
11112:0): } else {
11113: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);
11114:0): }
11115:0): } else {
11116: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);
11117:0): }
11118:0): return ($url,$error);
11119:0): }
11120:0):
11121:0): sub get_ltitools_id {
11122:0): my ($cdom,$title) = @_;
11123:0): # get lock on ltitools db
11124:0): my $lockhash = {
11125:0): lock => $env{'user.name'}.
11126:0): ':'.$env{'user.domain'},
11127:0): };
11128:0): my $tries = 0;
11129:0): my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11130:0): my ($id,$error);
11131:0):
11132:0): while (($gotlock ne 'ok') && ($tries<10)) {
11133:0): $tries ++;
11134:0): sleep (0.1);
11135:0): $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11136:0): }
11137:0): if ($gotlock eq 'ok') {
11138:0): my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11139:0): if ($currids{'lock'}) {
11140:0): delete($currids{'lock'});
11141:0): if (keys(%currids)) {
11142:0): my @curr = sort { $a <=> $b } keys(%currids);
11143:0): if ($curr[-1] =~ /^\d+$/) {
11144:0): $id = 1 + $curr[-1];
11145:0): }
11146:0): } else {
11147:0): $id = 1;
11148:0): }
11149:0): if ($id) {
11150:0): unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11151:0): $error = 'nostore';
11152:0): }
11153:0): } else {
11154:0): $error = 'nonumber';
11155:0): }
11156:0): }
11157:0): my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11158:0): } else {
11159:0): $error = 'nolock';
11160:0): }
11161:0): return ($id,$error);
11162:0): }
11163:0):
1.3 raeburn 11164: sub modify_autoenroll {
1.160.6.24 raeburn 11165: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 11166: my ($resulttext,%changes);
11167: my %currautoenroll;
11168: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
11169: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
11170: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
11171: }
11172: }
11173: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
11174: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 11175: sender => 'Sender for notification messages',
1.160.6.68 raeburn 11176: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
11177: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 11178: my @offon = ('off','on');
1.17 raeburn 11179: my $sender_uname = $env{'form.sender_uname'};
11180: my $sender_domain = $env{'form.sender_domain'};
11181: if ($sender_domain eq '') {
11182: $sender_uname = '';
11183: } elsif ($sender_uname eq '') {
11184: $sender_domain = '';
11185: }
1.129 raeburn 11186: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 11187: my $failsafe = $env{'form.autoenroll_failsafe'};
11188: $failsafe =~ s{^\s+|\s+$}{}g;
11189: if ($failsafe =~ /\D/) {
11190: undef($failsafe);
11191: }
1.1 raeburn 11192: my %autoenrollhash = (
1.129 raeburn 11193: autoenroll => { 'run' => $env{'form.autoenroll_run'},
11194: 'sender_uname' => $sender_uname,
11195: 'sender_domain' => $sender_domain,
11196: 'co-owners' => $coowners,
1.160.6.68 raeburn 11197: 'autofailsafe' => $failsafe,
1.1 raeburn 11198: }
11199: );
1.4 raeburn 11200: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
11201: $dom);
1.1 raeburn 11202: if ($putresult eq 'ok') {
11203: if (exists($currautoenroll{'run'})) {
11204: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
11205: $changes{'run'} = 1;
11206: }
11207: } elsif ($autorun) {
11208: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 11209: $changes{'run'} = 1;
1.1 raeburn 11210: }
11211: }
1.17 raeburn 11212: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 11213: $changes{'sender'} = 1;
11214: }
1.17 raeburn 11215: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 11216: $changes{'sender'} = 1;
11217: }
1.129 raeburn 11218: if ($currautoenroll{'co-owners'} ne '') {
11219: if ($currautoenroll{'co-owners'} ne $coowners) {
11220: $changes{'coowners'} = 1;
11221: }
11222: } elsif ($coowners) {
11223: $changes{'coowners'} = 1;
1.160.6.68 raeburn 11224: }
11225: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
11226: $changes{'autofailsafe'} = 1;
11227: }
1.1 raeburn 11228: if (keys(%changes) > 0) {
11229: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 11230: if ($changes{'run'}) {
1.1 raeburn 11231: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
11232: }
11233: if ($changes{'sender'}) {
1.17 raeburn 11234: if ($sender_uname eq '' || $sender_domain eq '') {
11235: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
11236: } else {
11237: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
11238: }
1.1 raeburn 11239: }
1.129 raeburn 11240: if ($changes{'coowners'}) {
11241: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
11242: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 11243: if (ref($lastactref) eq 'HASH') {
11244: $lastactref->{'domainconfig'} = 1;
11245: }
1.129 raeburn 11246: }
1.160.6.68 raeburn 11247: if ($changes{'autofailsafe'}) {
11248: if ($failsafe ne '') {
1.160.6.82 raeburn 11249: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 11250: } else {
1.160.6.82 raeburn 11251: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 11252: }
11253: &Apache::lonnet::get_domain_defaults($dom,1);
11254: if (ref($lastactref) eq 'HASH') {
11255: $lastactref->{'domdefaults'} = 1;
11256: }
11257: }
1.1 raeburn 11258: $resulttext .= '</ul>';
11259: } else {
11260: $resulttext = &mt('No changes made to auto-enrollment settings');
11261: }
11262: } else {
1.11 albertel 11263: $resulttext = '<span class="LC_error">'.
11264: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11265: }
1.3 raeburn 11266: return $resulttext;
1.1 raeburn 11267: }
11268:
11269: sub modify_autoupdate {
1.3 raeburn 11270: my ($dom,%domconfig) = @_;
1.1 raeburn 11271: my ($resulttext,%currautoupdate,%fields,%changes);
11272: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
11273: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
11274: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
11275: }
11276: }
11277: my @offon = ('off','on');
11278: my %title = &Apache::lonlocal::texthash (
11279: run => 'Auto-update:',
11280: classlists => 'Updates to user information in classlists?'
11281: );
1.44 raeburn 11282: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11283: my %fieldtitles = &Apache::lonlocal::texthash (
11284: id => 'Student/Employee ID',
1.20 raeburn 11285: permanentemail => 'E-mail address',
1.1 raeburn 11286: lastname => 'Last Name',
11287: firstname => 'First Name',
11288: middlename => 'Middle Name',
1.132 raeburn 11289: generation => 'Generation',
1.1 raeburn 11290: );
1.142 raeburn 11291: $othertitle = &mt('All users');
1.1 raeburn 11292: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 11293: $othertitle = &mt('Other users');
1.1 raeburn 11294: }
11295: foreach my $key (keys(%env)) {
11296: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 11297: my ($usertype,$item) = ($1,$2);
11298: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
11299: if ($usertype eq 'default') {
11300: push(@{$fields{$1}},$2);
11301: } elsif (ref($types) eq 'ARRAY') {
11302: if (grep(/^\Q$usertype\E$/,@{$types})) {
11303: push(@{$fields{$1}},$2);
11304: }
11305: }
11306: }
1.1 raeburn 11307: }
11308: }
1.131 raeburn 11309: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
11310: @lockablenames = sort(@lockablenames);
11311: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
11312: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11313: if (@changed) {
11314: $changes{'lockablenames'} = 1;
11315: }
11316: } else {
11317: if (@lockablenames) {
11318: $changes{'lockablenames'} = 1;
11319: }
11320: }
1.1 raeburn 11321: my %updatehash = (
11322: autoupdate => { run => $env{'form.autoupdate_run'},
11323: classlists => $env{'form.classlists'},
11324: fields => {%fields},
1.131 raeburn 11325: lockablenames => \@lockablenames,
1.1 raeburn 11326: }
11327: );
11328: foreach my $key (keys(%currautoupdate)) {
11329: if (($key eq 'run') || ($key eq 'classlists')) {
11330: if (exists($updatehash{autoupdate}{$key})) {
11331: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
11332: $changes{$key} = 1;
11333: }
11334: }
11335: } elsif ($key eq 'fields') {
11336: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 11337: foreach my $item (@{$types},'default') {
1.1 raeburn 11338: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
11339: my $change = 0;
11340: foreach my $type (@{$currautoupdate{$key}{$item}}) {
11341: if (!exists($fields{$item})) {
11342: $change = 1;
1.132 raeburn 11343: last;
1.1 raeburn 11344: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 11345: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 11346: $change = 1;
1.132 raeburn 11347: last;
1.1 raeburn 11348: }
11349: }
11350: }
11351: if ($change) {
11352: push(@{$changes{$key}},$item);
11353: }
1.26 raeburn 11354: }
1.1 raeburn 11355: }
11356: }
1.131 raeburn 11357: } elsif ($key eq 'lockablenames') {
11358: if (ref($currautoupdate{$key}) eq 'ARRAY') {
11359: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11360: if (@changed) {
11361: $changes{'lockablenames'} = 1;
11362: }
11363: } else {
11364: if (@lockablenames) {
11365: $changes{'lockablenames'} = 1;
11366: }
11367: }
11368: }
11369: }
11370: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
11371: if (@lockablenames) {
11372: $changes{'lockablenames'} = 1;
1.1 raeburn 11373: }
11374: }
1.26 raeburn 11375: foreach my $item (@{$types},'default') {
11376: if (defined($fields{$item})) {
11377: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 11378: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
11379: my $change = 0;
11380: if (ref($fields{$item}) eq 'ARRAY') {
11381: foreach my $type (@{$fields{$item}}) {
11382: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
11383: $change = 1;
11384: last;
11385: }
11386: }
11387: }
11388: if ($change) {
11389: push(@{$changes{'fields'}},$item);
11390: }
11391: } else {
1.26 raeburn 11392: push(@{$changes{'fields'}},$item);
11393: }
11394: } else {
11395: push(@{$changes{'fields'}},$item);
1.1 raeburn 11396: }
11397: }
11398: }
11399: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
11400: $dom);
11401: if ($putresult eq 'ok') {
11402: if (keys(%changes) > 0) {
11403: $resulttext = &mt('Changes made:').'<ul>';
11404: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 11405: if ($key eq 'lockablenames') {
11406: $resulttext .= '<li>';
11407: if (@lockablenames) {
11408: $usertypes->{'default'} = $othertitle;
11409: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
11410: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
11411: } else {
11412: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
11413: }
11414: $resulttext .= '</li>';
11415: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 11416: foreach my $item (@{$changes{$key}}) {
11417: my @newvalues;
11418: foreach my $type (@{$fields{$item}}) {
11419: push(@newvalues,$fieldtitles{$type});
11420: }
1.3 raeburn 11421: my $newvaluestr;
11422: if (@newvalues > 0) {
11423: $newvaluestr = join(', ',@newvalues);
11424: } else {
11425: $newvaluestr = &mt('none');
1.6 raeburn 11426: }
1.1 raeburn 11427: if ($item eq 'default') {
1.26 raeburn 11428: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 11429: } else {
1.26 raeburn 11430: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 11431: }
11432: }
11433: } else {
11434: my $newvalue;
11435: if ($key eq 'run') {
11436: $newvalue = $offon[$env{'form.autoupdate_run'}];
11437: } else {
11438: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 11439: }
1.1 raeburn 11440: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
11441: }
11442: }
11443: $resulttext .= '</ul>';
11444: } else {
1.3 raeburn 11445: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 11446: }
11447: } else {
1.11 albertel 11448: $resulttext = '<span class="LC_error">'.
11449: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11450: }
1.3 raeburn 11451: return $resulttext;
1.1 raeburn 11452: }
11453:
1.125 raeburn 11454: sub modify_autocreate {
11455: my ($dom,%domconfig) = @_;
11456: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
11457: if (ref($domconfig{'autocreate'}) eq 'HASH') {
11458: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
11459: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
11460: }
11461: }
11462: my %title= ( xml => 'Auto-creation of courses in XML course description files',
11463: req => 'Auto-creation of validated requests for official courses',
11464: xmldc => 'Identity of course creator of courses from XML files',
11465: );
11466: my @types = ('xml','req');
11467: foreach my $item (@types) {
11468: $newvals{$item} = $env{'form.autocreate_'.$item};
11469: $newvals{$item} =~ s/\D//g;
11470: $newvals{$item} = 0 if ($newvals{$item} eq '');
11471: }
11472: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 11473: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 11474: unless (exists($domcoords{$newvals{'xmldc'}})) {
11475: $newvals{'xmldc'} = '';
11476: }
11477: %autocreatehash = (
11478: autocreate => { xml => $newvals{'xml'},
11479: req => $newvals{'req'},
11480: }
11481: );
11482: if ($newvals{'xmldc'} ne '') {
11483: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
11484: }
11485: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
11486: $dom);
11487: if ($putresult eq 'ok') {
11488: my @items = @types;
11489: if ($newvals{'xml'}) {
11490: push(@items,'xmldc');
11491: }
11492: foreach my $item (@items) {
11493: if (exists($currautocreate{$item})) {
11494: if ($currautocreate{$item} ne $newvals{$item}) {
11495: $changes{$item} = 1;
11496: }
11497: } elsif ($newvals{$item}) {
11498: $changes{$item} = 1;
11499: }
11500: }
11501: if (keys(%changes) > 0) {
11502: my @offon = ('off','on');
11503: $resulttext = &mt('Changes made:').'<ul>';
11504: foreach my $item (@types) {
11505: if ($changes{$item}) {
11506: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 11507: $resulttext .= '<li>'.
11508: &mt("$title{$item} set to [_1]$newtxt [_2]",
11509: '<b>','</b>').
11510: '</li>';
1.125 raeburn 11511: }
11512: }
11513: if ($changes{'xmldc'}) {
11514: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
11515: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 11516: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 11517: }
11518: $resulttext .= '</ul>';
11519: } else {
11520: $resulttext = &mt('No changes made to auto-creation settings');
11521: }
11522: } else {
11523: $resulttext = '<span class="LC_error">'.
11524: &mt('An error occurred: [_1]',$putresult).'</span>';
11525: }
11526: return $resulttext;
11527: }
11528:
1.23 raeburn 11529: sub modify_directorysrch {
1.160.6.81 raeburn 11530: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 11531: my ($resulttext,%changes);
11532: my %currdirsrch;
11533: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
11534: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
11535: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
11536: }
11537: }
1.160.6.72 raeburn 11538: my %title = ( available => 'Institutional directory search available',
11539: localonly => 'Other domains can search institution',
11540: lcavailable => 'LON-CAPA directory search available',
11541: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 11542: searchby => 'Search types',
11543: searchtypes => 'Search latitude');
11544: my @offon = ('off','on');
1.24 raeburn 11545: my @otherdoms = ('Yes','No');
1.23 raeburn 11546:
1.25 raeburn 11547: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 11548: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
11549: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
11550:
1.44 raeburn 11551: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 11552: if (keys(%{$usertypes}) == 0) {
11553: @cansearch = ('default');
11554: } else {
11555: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
11556: foreach my $type (@{$currdirsrch{'cansearch'}}) {
11557: if (!grep(/^\Q$type\E$/,@cansearch)) {
11558: push(@{$changes{'cansearch'}},$type);
11559: }
1.23 raeburn 11560: }
1.26 raeburn 11561: foreach my $type (@cansearch) {
11562: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
11563: push(@{$changes{'cansearch'}},$type);
11564: }
1.23 raeburn 11565: }
1.26 raeburn 11566: } else {
11567: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 11568: }
11569: }
11570:
11571: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
11572: foreach my $by (@{$currdirsrch{'searchby'}}) {
11573: if (!grep(/^\Q$by\E$/,@searchby)) {
11574: push(@{$changes{'searchby'}},$by);
11575: }
11576: }
11577: foreach my $by (@searchby) {
11578: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
11579: push(@{$changes{'searchby'}},$by);
11580: }
11581: }
11582: } else {
11583: push(@{$changes{'searchby'}},@searchby);
11584: }
1.25 raeburn 11585:
11586: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
11587: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
11588: if (!grep(/^\Q$type\E$/,@searchtypes)) {
11589: push(@{$changes{'searchtypes'}},$type);
11590: }
11591: }
11592: foreach my $type (@searchtypes) {
11593: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
11594: push(@{$changes{'searchtypes'}},$type);
11595: }
11596: }
11597: } else {
11598: if (exists($currdirsrch{'searchtypes'})) {
11599: foreach my $type (@searchtypes) {
11600: if ($type ne $currdirsrch{'searchtypes'}) {
11601: push(@{$changes{'searchtypes'}},$type);
11602: }
11603: }
11604: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
11605: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
11606: }
11607: } else {
11608: push(@{$changes{'searchtypes'}},@searchtypes);
11609: }
11610: }
11611:
1.23 raeburn 11612: my %dirsrch_hash = (
11613: directorysrch => { available => $env{'form.dirsrch_available'},
11614: cansearch => \@cansearch,
1.160.6.72 raeburn 11615: localonly => $env{'form.dirsrch_instlocalonly'},
11616: lclocalonly => $env{'form.dirsrch_domlocalonly'},
11617: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 11618: searchby => \@searchby,
1.25 raeburn 11619: searchtypes => \@searchtypes,
1.23 raeburn 11620: }
11621: );
11622: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
11623: $dom);
11624: if ($putresult eq 'ok') {
11625: if (exists($currdirsrch{'available'})) {
11626: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
11627: $changes{'available'} = 1;
11628: }
11629: } else {
11630: if ($env{'form.dirsrch_available'} eq '1') {
11631: $changes{'available'} = 1;
11632: }
11633: }
1.160.6.72 raeburn 11634: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 11635: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
11636: $changes{'lcavailable'} = 1;
11637: }
1.24 raeburn 11638: } else {
1.160.6.72 raeburn 11639: if ($env{'form.dirsrch_lcavailable'} eq '1') {
11640: $changes{'lcavailable'} = 1;
11641: }
11642: }
11643: if (exists($currdirsrch{'localonly'})) {
11644: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 11645: $changes{'localonly'} = 1;
11646: }
1.160.6.72 raeburn 11647: } else {
11648: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
11649: $changes{'localonly'} = 1;
11650: }
11651: }
11652: if (exists($currdirsrch{'lclocalonly'})) {
11653: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
11654: $changes{'lclocalonly'} = 1;
11655: }
11656: } else {
11657: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
11658: $changes{'lclocalonly'} = 1;
11659: }
1.24 raeburn 11660: }
1.23 raeburn 11661: if (keys(%changes) > 0) {
11662: $resulttext = &mt('Changes made:').'<ul>';
11663: if ($changes{'available'}) {
11664: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
11665: }
1.160.6.72 raeburn 11666: if ($changes{'lcavailable'}) {
11667: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
11668: }
1.24 raeburn 11669: if ($changes{'localonly'}) {
1.160.6.72 raeburn 11670: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
11671: }
11672: if ($changes{'lclocalonly'}) {
11673: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 11674: }
1.23 raeburn 11675: if (ref($changes{'cansearch'}) eq 'ARRAY') {
11676: my $chgtext;
1.26 raeburn 11677: if (ref($usertypes) eq 'HASH') {
11678: if (keys(%{$usertypes}) > 0) {
11679: foreach my $type (@{$types}) {
11680: if (grep(/^\Q$type\E$/,@cansearch)) {
11681: $chgtext .= $usertypes->{$type}.'; ';
11682: }
11683: }
11684: if (grep(/^default$/,@cansearch)) {
11685: $chgtext .= $othertitle;
11686: } else {
11687: $chgtext =~ s/\; $//;
11688: }
1.160.6.13 raeburn 11689: $resulttext .=
11690: '<li>'.
11691: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
11692: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
11693: '</li>';
1.23 raeburn 11694: }
11695: }
11696: }
11697: if (ref($changes{'searchby'}) eq 'ARRAY') {
11698: my ($searchtitles,$titleorder) = &sorted_searchtitles();
11699: my $chgtext;
11700: foreach my $type (@{$titleorder}) {
11701: if (grep(/^\Q$type\E$/,@searchby)) {
11702: if (defined($searchtitles->{$type})) {
11703: $chgtext .= $searchtitles->{$type}.'; ';
11704: }
11705: }
11706: }
11707: $chgtext =~ s/\; $//;
11708: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
11709: }
1.25 raeburn 11710: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
11711: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
11712: my $chgtext;
11713: foreach my $type (@{$srchtypeorder}) {
11714: if (grep(/^\Q$type\E$/,@searchtypes)) {
11715: if (defined($srchtypes_desc->{$type})) {
11716: $chgtext .= $srchtypes_desc->{$type}.'; ';
11717: }
11718: }
11719: }
11720: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 11721: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 11722: }
11723: $resulttext .= '</ul>';
1.160.6.81 raeburn 11724: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
11725: if (ref($lastactref) eq 'HASH') {
11726: $lastactref->{'directorysrch'} = 1;
11727: }
1.23 raeburn 11728: } else {
1.160.6.72 raeburn 11729: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 11730: }
11731: } else {
11732: $resulttext = '<span class="LC_error">'.
1.27 raeburn 11733: &mt('An error occurred: [_1]',$putresult).'</span>';
11734: }
11735: return $resulttext;
11736: }
11737:
1.28 raeburn 11738: sub modify_contacts {
1.160.6.24 raeburn 11739: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 11740: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
11741: if (ref($domconfig{'contacts'}) eq 'HASH') {
11742: foreach my $key (keys(%{$domconfig{'contacts'}})) {
11743: $currsetting{$key} = $domconfig{'contacts'}{$key};
11744: }
11745: }
1.160.6.78 raeburn 11746: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 11747: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 11748: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 11749: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.102.2 7(raebur 11750:1): my @toggles = ('reporterrors','reportupdates','reportstatus');
11751:1): my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 11752: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 11753: foreach my $type (@mailings) {
11754: @{$newsetting{$type}} =
11755: &Apache::loncommon::get_env_multiple('form.'.$type);
11756: foreach my $item (@contacts) {
11757: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
11758: $contacts_hash{contacts}{$type}{$item} = 1;
11759: } else {
11760: $contacts_hash{contacts}{$type}{$item} = 0;
11761: }
1.160.6.78 raeburn 11762: }
1.28 raeburn 11763: $others{$type} = $env{'form.'.$type.'_others'};
11764: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 11765: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11766: $bcc{$type} = $env{'form.'.$type.'_bcc'};
11767: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 11768: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
11769: $includestr{$type} = $env{'form.'.$type.'_includestr'};
11770: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
11771: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
11772: }
1.134 raeburn 11773: }
1.28 raeburn 11774: }
11775: foreach my $item (@contacts) {
11776: $to{$item} = $env{'form.'.$item};
11777: $contacts_hash{'contacts'}{$item} = $to{$item};
11778: }
1.160.6.23 raeburn 11779: foreach my $item (@toggles) {
11780: if ($env{'form.'.$item} =~ /^(0|1)$/) {
11781: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
11782: }
11783: }
1.160.6.102.2 7(raebur 11784:1): my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
11785:1): foreach my $item (@lonstatus) {
11786:1): if ($item eq 'excluded') {
11787:1): my (%serverhomes,@excluded);
11788:1): map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
11789:1): my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
11790:1): if (@possexcluded) {
11791:1): foreach my $id (sort(@possexcluded)) {
11792:1): if ($serverhomes{$id}) {
11793:1): push(@excluded,$id);
11794:1): }
11795:1): }
11796:1): }
11797:1): if (@excluded) {
11798:1): $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
11799:1): }
11800:1): } elsif ($item eq 'weights') {
11801:1): foreach my $type ('E','W','N','U') {
11802:1): $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
11803:1): if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
11804:1): unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
11805:1): $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
11806:1): $env{'form.error'.$item.'_'.$type};
11807:1): }
11808:1): }
11809:1): }
11810:1): } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
11811:1): $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
11812:1): if ($env{'form.error'.$item} =~ /^\d+$/) {
11813:1): unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
11814:1): $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
11815:1): }
11816:1): }
11817:1): }
11818:1): }
1.160.6.78 raeburn 11819: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
11820: foreach my $field (@{$fields}) {
11821: if (ref($possoptions->{$field}) eq 'ARRAY') {
11822: my $value = $env{'form.helpform_'.$field};
11823: $value =~ s/^\s+|\s+$//g;
11824: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 11825: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 11826: if ($field eq 'screenshot') {
11827: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
11828: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 11829: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 11830: }
11831: }
11832: }
11833: }
11834: }
11835: }
1.160.6.101 raeburn 11836: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11837: my (@statuses,%usertypeshash,@overrides);
11838: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
11839: @statuses = @{$types};
11840: if (ref($usertypes) eq 'HASH') {
11841: %usertypeshash = %{$usertypes};
11842: }
11843: }
11844: if (@statuses) {
11845: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
11846: foreach my $type (@possoverrides) {
11847: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
11848: push(@overrides,$type);
11849: }
11850: }
11851: if (@overrides) {
11852: foreach my $type (@overrides) {
11853: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
11854: foreach my $item (@contacts) {
11855: if (grep(/^\Q$item\E$/,@standard)) {
11856: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
11857: $newsetting{'override_'.$type}{$item} = 1;
11858: } else {
11859: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
11860: $newsetting{'override_'.$type}{$item} = 0;
11861: }
11862: }
11863: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
11864: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
11865: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
11866: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
11867: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
11868: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
11869: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
11870: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
11871: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
11872: }
11873: }
11874: }
11875: }
1.28 raeburn 11876: if (keys(%currsetting) > 0) {
11877: foreach my $item (@contacts) {
11878: if ($to{$item} ne $currsetting{$item}) {
11879: $changes{$item} = 1;
11880: }
11881: }
11882: foreach my $type (@mailings) {
11883: foreach my $item (@contacts) {
11884: if (ref($currsetting{$type}) eq 'HASH') {
11885: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
11886: push(@{$changes{$type}},$item);
11887: }
11888: } else {
11889: push(@{$changes{$type}},@{$newsetting{$type}});
11890: }
11891: }
11892: if ($others{$type} ne $currsetting{$type}{'others'}) {
11893: push(@{$changes{$type}},'others');
11894: }
1.160.6.78 raeburn 11895: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11896: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
11897: push(@{$changes{$type}},'bcc');
11898: }
1.160.6.78 raeburn 11899: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
11900: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
11901: push(@{$changes{$type}},'include');
11902: }
11903: }
11904: }
11905: if (ref($fields) eq 'ARRAY') {
11906: if (ref($currsetting{'helpform'}) eq 'HASH') {
11907: foreach my $field (@{$fields}) {
11908: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
11909: push(@{$changes{'helpform'}},$field);
11910: }
11911: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11912: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
11913: push(@{$changes{'helpform'}},'maxsize');
11914: }
11915: }
11916: }
11917: } else {
11918: foreach my $field (@{$fields}) {
11919: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
11920: push(@{$changes{'helpform'}},$field);
11921: }
11922: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11923: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
11924: push(@{$changes{'helpform'}},'maxsize');
11925: }
11926: }
11927: }
1.134 raeburn 11928: }
1.28 raeburn 11929: }
1.160.6.101 raeburn 11930: if (@statuses) {
11931: if (ref($currsetting{'overrides'}) eq 'HASH') {
11932: foreach my $key (keys(%{$currsetting{'overrides'}})) {
11933: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
11934: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
11935: foreach my $item (@contacts,'bcc','others','include') {
11936: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
11937: push(@{$changes{'overrides'}},$key);
11938: last;
11939: }
11940: }
11941: } else {
11942: push(@{$changes{'overrides'}},$key);
11943: }
11944: }
11945: }
11946: foreach my $key (@overrides) {
11947: unless (exists($currsetting{'overrides'}{$key})) {
11948: push(@{$changes{'overrides'}},$key);
11949: }
11950: }
11951: } else {
11952: foreach my $key (@overrides) {
11953: push(@{$changes{'overrides'}},$key);
11954: }
11955: }
11956: }
1.160.6.102.2 7(raebur 11957:1): if (ref($currsetting{'lonstatus'}) eq 'HASH') {
11958:1): foreach my $key ('excluded','weights','threshold','sysmail') {
11959:1): if ($key eq 'excluded') {
11960:1): if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
11961:1): (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
11962:1): if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
11963:1): (@{$currsetting{'lonstatus'}{$key}})) {
11964:1): my @diffs =
11965:1): &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
11966:1): $currsetting{'lonstatus'}{$key});
11967:1): if (@diffs) {
11968:1): push(@{$changes{'lonstatus'}},$key);
11969:1): }
11970:1): } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
11971:1): push(@{$changes{'lonstatus'}},$key);
11972:1): }
11973:1): } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
11974:1): (@{$currsetting{'lonstatus'}{$key}})) {
11975:1): push(@{$changes{'lonstatus'}},$key);
11976:1): }
11977:1): } elsif ($key eq 'weights') {
11978:1): if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
11979:1): (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
11980:1): if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
11981:1): foreach my $type ('E','W','N','U') {
11982:1): unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
11983:1): $currsetting{'lonstatus'}{$key}{$type}) {
11984:1): push(@{$changes{'lonstatus'}},$key);
11985:1): last;
11986:1): }
11987:1): }
11988:1): } else {
11989:1): foreach my $type ('E','W','N','U') {
11990:1): if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
11991:1): push(@{$changes{'lonstatus'}},$key);
11992:1): last;
11993:1): }
11994:1): }
11995:1): }
11996:1): } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
11997:1): foreach my $type ('E','W','N','U') {
11998:1): if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
11999:1): push(@{$changes{'lonstatus'}},$key);
12000:1): last;
12001:1): }
12002:1): }
12003:1): }
12004:1): } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
12005:1): if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12006:1): if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12007:1): if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
12008:1): push(@{$changes{'lonstatus'}},$key);
12009:1): }
12010:1): } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
12011:1): push(@{$changes{'lonstatus'}},$key);
12012:1): }
12013:1): } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12014:1): push(@{$changes{'lonstatus'}},$key);
12015:1): }
12016:1): }
12017:1): }
12018:1): } else {
12019:1): if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12020:1): foreach my $key ('excluded','weights','threshold','sysmail') {
12021:1): if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12022:1): push(@{$changes{'lonstatus'}},$key);
12023:1): }
12024:1): }
12025:1): }
12026:1): }
1.28 raeburn 12027: } else {
12028: my %default;
12029: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12030: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12031: $default{'errormail'} = 'adminemail';
12032: $default{'packagesmail'} = 'adminemail';
12033: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 12034: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12035: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12036: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 12037: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 12038: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 12039: foreach my $item (@contacts) {
12040: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 12041: $changes{$item} = 1;
1.160.6.23 raeburn 12042: }
1.28 raeburn 12043: }
12044: foreach my $type (@mailings) {
12045: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12046: push(@{$changes{$type}},@{$newsetting{$type}});
12047: }
12048: if ($others{$type} ne '') {
12049: push(@{$changes{$type}},'others');
1.134 raeburn 12050: }
1.160.6.78 raeburn 12051: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12052: if ($bcc{$type} ne '') {
12053: push(@{$changes{$type}},'bcc');
12054: }
1.160.6.78 raeburn 12055: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12056: push(@{$changes{$type}},'include');
12057: }
12058: }
12059: }
12060: if (ref($fields) eq 'ARRAY') {
12061: foreach my $field (@{$fields}) {
12062: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12063: push(@{$changes{'helpform'}},$field);
12064: }
12065: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12066: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12067: push(@{$changes{'helpform'}},'maxsize');
12068: }
12069: }
1.134 raeburn 12070: }
1.28 raeburn 12071: }
1.160.6.102.2 7(raebur 12072:1): if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12073:1): foreach my $key ('excluded','weights','threshold','sysmail') {
12074:1): if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12075:1): push(@{$changes{'lonstatus'}},$key);
12076:1): }
12077:1): }
12078:1): }
1.28 raeburn 12079: }
1.160.6.23 raeburn 12080: foreach my $item (@toggles) {
12081: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12082: $changes{$item} = 1;
12083: } elsif ((!$env{'form.'.$item}) &&
12084: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12085: $changes{$item} = 1;
12086: }
12087: }
1.28 raeburn 12088: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12089: $dom);
12090: if ($putresult eq 'ok') {
12091: if (keys(%changes) > 0) {
1.160.6.24 raeburn 12092: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12093: if (ref($lastactref) eq 'HASH') {
12094: $lastactref->{'domainconfig'} = 1;
12095: }
1.28 raeburn 12096: my ($titles,$short_titles) = &contact_titles();
12097: $resulttext = &mt('Changes made:').'<ul>';
12098: foreach my $item (@contacts) {
12099: if ($changes{$item}) {
12100: $resulttext .= '<li>'.$titles->{$item}.
12101: &mt(' set to: ').
12102: '<span class="LC_cusr_emph">'.
12103: $to{$item}.'</span></li>';
12104: }
12105: }
12106: foreach my $type (@mailings) {
12107: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 12108: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
12109: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
12110: } else {
12111: $resulttext .= '<li>'.$titles->{$type}.': ';
12112: }
1.28 raeburn 12113: my @text;
12114: foreach my $item (@{$newsetting{$type}}) {
12115: push(@text,$short_titles->{$item});
12116: }
12117: if ($others{$type} ne '') {
12118: push(@text,$others{$type});
12119: }
1.160.6.78 raeburn 12120: if (@text) {
12121: $resulttext .= '<span class="LC_cusr_emph">'.
12122: join(', ',@text).'</span>';
12123: }
12124: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12125: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 12126: my $bcctext;
12127: if (@text) {
12128: $bcctext = ' '.&mt('with Bcc to');
12129: } else {
12130: $bcctext = '(Bcc)';
12131: }
12132: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12133: } elsif (!@text) {
12134: $resulttext .= &mt('No one');
1.134 raeburn 12135: }
1.160.6.78 raeburn 12136: if ($includestr{$type} ne '') {
12137: if ($includeloc{$type} eq 'b') {
12138: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12139: } elsif ($includeloc{$type} eq 's') {
12140: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12141: }
12142: }
12143: } elsif (!@text) {
12144: $resulttext .= &mt('No recipients');
1.134 raeburn 12145: }
12146: $resulttext .= '</li>';
1.28 raeburn 12147: }
12148: }
1.160.6.101 raeburn 12149: if (ref($changes{'overrides'}) eq 'ARRAY') {
12150: my @deletions;
12151: foreach my $type (@{$changes{'overrides'}}) {
12152: if ($usertypeshash{$type}) {
12153: if (grep(/^\Q$type\E/,@overrides)) {
12154: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12155: $usertypeshash{$type}).'<ul><li>';
12156: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12157: my @text;
12158: foreach my $item (@contacts) {
12159: if ($newsetting{'override_'.$type}{$item}) {
12160: push(@text,$short_titles->{$item});
12161: }
12162: }
12163: if ($newsetting{'override_'.$type}{'others'} ne '') {
12164: push(@text,$newsetting{'override_'.$type}{'others'});
12165: }
12166:
12167: if (@text) {
12168: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12169: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12170: }
12171: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12172: my $bcctext;
12173: if (@text) {
12174: $bcctext = ' '.&mt('with Bcc to');
12175: } else {
12176: $bcctext = '(Bcc)';
12177: }
12178: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12179: } elsif (!@text) {
12180: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12181: }
12182: $resulttext .= '</li>';
12183: if ($newsetting{'override_'.$type}{'include'} ne '') {
12184: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12185: if ($loc eq 'b') {
12186: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12187: } elsif ($loc eq 's') {
12188: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12189: }
12190: }
12191: }
12192: $resulttext .= '</li></ul></li>';
12193: } else {
12194: push(@deletions,$usertypeshash{$type});
12195: }
12196: }
12197: }
12198: if (@deletions) {
12199: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12200: join(', ',@deletions)).'</li>';
12201: }
12202: }
1.160.6.23 raeburn 12203: my @offon = ('off','on');
1.160.6.102.2 7(raebur 12204:1): my $corelink = &core_link_msu();
1.160.6.23 raeburn 12205: if ($changes{'reporterrors'}) {
12206: $resulttext .= '<li>'.
12207: &mt('E-mail error reports to [_1] set to "'.
12208: $offon[$env{'form.reporterrors'}].'".',
1.160.6.102.2 7(raebur 12209:1): $corelink).
1.160.6.23 raeburn 12210: '</li>';
12211: }
12212: if ($changes{'reportupdates'}) {
12213: $resulttext .= '<li>'.
12214: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12215: $offon[$env{'form.reportupdates'}].'".',
1.160.6.102.2 7(raebur 12216:1): $corelink).
1.160.6.23 raeburn 12217: '</li>';
12218: }
1.160.6.102.2 7(raebur 12219:1): if ($changes{'reportstatus'}) {
12220:1): $resulttext .= '<li>'.
12221:1): &mt('E-mail status if errors above threshold to [_1] set to "'.
12222:1): $offon[$env{'form.reportstatus'}].'".',
12223:1): $corelink).
12224:1): '</li>';
12225:1): }
12226:1): if (ref($changes{'lonstatus'}) eq 'ARRAY') {
12227:1): $resulttext .= '<li>'.
12228:1): &mt('Nightly status check e-mail settings').':<ul>';
12229:1): my (%defval,%use_def,%shown);
12230:1): $defval{'threshold'} = $lonstatus_defs->{'threshold'};
12231:1): $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
12232:1): $defval{'weights'} =
12233:1): join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
12234:1): $defval{'excluded'} = &mt('None');
12235:1): if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
12236:1): foreach my $item ('threshold','sysmail','weights','excluded') {
12237:1): if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
12238:1): if (($item eq 'threshold') || ($item eq 'sysmail')) {
12239:1): $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
12240:1): } elsif ($item eq 'weights') {
12241:1): if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
12242:1): foreach my $type ('E','W','N','U') {
12243:1): $shown{$item} .= $lonstatus_names->{$type}.'=';
12244:1): if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
12245:1): $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
12246:1): } else {
12247:1): $shown{$item} .= $lonstatus_defs->{$type};
12248:1): }
12249:1): $shown{$item} .= ', ';
12250:1): }
12251:1): $shown{$item} =~ s/, $//;
12252:1): } else {
12253:1): $shown{$item} = $defval{$item};
12254:1): }
12255:1): } elsif ($item eq 'excluded') {
12256:1): if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
12257:1): $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
12258:1): } else {
12259:1): $shown{$item} = $defval{$item};
12260:1): }
12261:1): }
12262:1): } else {
12263:1): $shown{$item} = $defval{$item};
12264:1): }
12265:1): }
12266:1): } else {
12267:1): foreach my $item ('threshold','weights','excluded','sysmail') {
12268:1): $shown{$item} = $defval{$item};
12269:1): }
12270:1): }
12271:1): foreach my $item ('threshold','weights','excluded','sysmail') {
12272:1): $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
12273:1): $shown{$item}).'</li>';
12274:1): }
12275:1): $resulttext .= '</ul></li>';
12276:1): }
1.160.6.78 raeburn 12277: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12278: my (@optional,@required,@unused,$maxsizechg);
12279: foreach my $field (@{$changes{'helpform'}}) {
12280: if ($field eq 'maxsize') {
12281: $maxsizechg = 1;
12282: next;
12283: }
12284: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
12285: push(@optional,$field);
12286: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12287: push(@unused,$field);
12288: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
12289: push(@required,$field);
12290: }
12291: }
12292: if (@optional) {
12293: $resulttext .= '<li>'.
12294: &mt('Help form fields changed to "Optional": [_1].',
12295: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12296: '</li>';
12297: }
12298: if (@required) {
12299: $resulttext .= '<li>'.
12300: &mt('Help form fields changed to "Required": [_1].',
12301: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12302: '</li>';
12303: }
12304: if (@unused) {
12305: $resulttext .= '<li>'.
12306: &mt('Help form fields changed to "Not shown": [_1].',
12307: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12308: '</li>';
12309: }
12310: if ($maxsizechg) {
12311: $resulttext .= '<li>'.
12312: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12313: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12314: '</li>';
12315: }
12316: }
1.28 raeburn 12317: $resulttext .= '</ul>';
12318: } else {
1.160.6.78 raeburn 12319: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 12320: }
12321: } else {
12322: $resulttext = '<span class="LC_error">'.
12323: &mt('An error occurred: [_1].',$putresult).'</span>';
12324: }
12325: return $resulttext;
12326: }
12327:
1.160.6.98 raeburn 12328: sub modify_passwords {
12329: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
12330: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
12331: $updatedefaults,$updateconf);
12332: my $customfn = 'resetpw.html';
12333: if (ref($domconfig{'passwords'}) eq 'HASH') {
12334: %current = %{$domconfig{'passwords'}};
12335: }
12336: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12337: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12338: if (ref($types) eq 'ARRAY') {
12339: @oktypes = @{$types};
12340: }
12341: push(@oktypes,'default');
12342:
12343: my %titles = &Apache::lonlocal::texthash (
12344: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
12345: intauth_check => 'Check bcrypt cost if authenticated',
12346: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
12347: permanent => 'Permanent e-mail address',
12348: critical => 'Critical notification address',
12349: notify => 'Notification address',
12350: min => 'Minimum password length',
12351: max => 'Maximum password length',
12352: chars => 'Required characters',
12353: numsaved => 'Number of previous passwords to save',
12354: reset => 'Resetting Forgotten Password',
12355: intauth => 'Encryption of Stored Passwords (Internal Auth)',
12356: rules => 'Rules for LON-CAPA Passwords',
12357: crsownerchg => 'Course Owner Changing Student Passwords',
12358: username => 'Username',
12359: email => 'E-mail address',
12360: );
12361:
12362: #
12363: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
12364: #
12365: my (%curr_defaults,%save_defaults);
12366: if (ref($domconfig{'defaults'}) eq 'HASH') {
12367: foreach my $key (keys(%{$domconfig{'defaults'}})) {
12368: if ($key =~ /^intauth_(cost|check|switch)$/) {
12369: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
12370: } else {
12371: $save_defaults{$key} = $domconfig{'defaults'}{$key};
12372: }
12373: }
12374: }
12375: my %staticdefaults = (
12376: 'resetlink' => 2,
12377: 'resetcase' => \@oktypes,
12378: 'resetprelink' => 'both',
12379: 'resetemail' => ['critical','notify','permanent'],
12380: 'intauth_cost' => 10,
12381: 'intauth_check' => 0,
12382: 'intauth_switch' => 0,
12383: );
1.160.6.99 raeburn 12384: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 12385: foreach my $type (@oktypes) {
12386: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
12387: }
12388: my $linklife = $env{'form.passwords_link'};
12389: $linklife =~ s/^\s+|\s+$//g;
12390: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
12391: $newvalues{'resetlink'} = $linklife;
12392: if ($current{'resetlink'}) {
12393: if ($current{'resetlink'} ne $linklife) {
12394: $changes{'reset'} = 1;
12395: }
1.160.6.102 raeburn 12396: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12397: if ($staticdefaults{'resetlink'} ne $linklife) {
12398: $changes{'reset'} = 1;
12399: }
12400: }
12401: } elsif ($current{'resetlink'}) {
12402: $changes{'reset'} = 1;
12403: }
12404: my @casesens;
12405: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
12406: foreach my $case (sort(@posscase)) {
12407: if (grep(/^\Q$case\E$/,@oktypes)) {
12408: push(@casesens,$case);
12409: }
12410: }
12411: $newvalues{'resetcase'} = \@casesens;
12412: if (ref($current{'resetcase'}) eq 'ARRAY') {
12413: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
12414: if (@diffs > 0) {
12415: $changes{'reset'} = 1;
12416: }
1.160.6.102 raeburn 12417: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12418: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
12419: if (@diffs > 0) {
12420: $changes{'reset'} = 1;
12421: }
12422: }
12423: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
12424: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
12425: if (exists($current{'resetprelink'})) {
12426: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
12427: $changes{'reset'} = 1;
12428: }
1.160.6.102 raeburn 12429: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12430: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
12431: $changes{'reset'} = 1;
12432: }
12433: }
12434: } elsif ($current{'resetprelink'}) {
12435: $changes{'reset'} = 1;
12436: }
12437: foreach my $type (@oktypes) {
12438: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
12439: my @postlink;
12440: foreach my $item (sort(@possplink)) {
12441: if ($item =~ /^(email|username)$/) {
12442: push(@postlink,$item);
12443: }
12444: }
12445: $newvalues{'resetpostlink'}{$type} = \@postlink;
12446: unless ($changes{'reset'}) {
12447: if (ref($current{'resetpostlink'}) eq 'HASH') {
12448: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
12449: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
12450: if (@diffs > 0) {
12451: $changes{'reset'} = 1;
12452: }
12453: } else {
12454: $changes{'reset'} = 1;
12455: }
1.160.6.102 raeburn 12456: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12457: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
12458: if (@diffs > 0) {
12459: $changes{'reset'} = 1;
12460: }
12461: }
12462: }
12463: }
12464: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
12465: my @resetemail;
12466: foreach my $item (sort(@possemailsrc)) {
12467: if ($item =~ /^(permanent|critical|notify)$/) {
12468: push(@resetemail,$item);
12469: }
12470: }
12471: $newvalues{'resetemail'} = \@resetemail;
12472: unless ($changes{'reset'}) {
12473: if (ref($current{'resetemail'}) eq 'ARRAY') {
12474: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
12475: if (@diffs > 0) {
12476: $changes{'reset'} = 1;
12477: }
1.160.6.102 raeburn 12478: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12479: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
12480: if (@diffs > 0) {
12481: $changes{'reset'} = 1;
12482: }
12483: }
12484: }
12485: if ($env{'form.passwords_stdtext'} == 0) {
12486: $newvalues{'resetremove'} = 1;
12487: unless ($current{'resetremove'}) {
12488: $changes{'reset'} = 1;
12489: }
12490: } elsif ($current{'resetremove'}) {
12491: $changes{'reset'} = 1;
12492: }
12493: if ($env{'form.passwords_customfile.filename'} ne '') {
12494: my $servadm = $r->dir_config('lonAdmEMail');
12495: my $servadm = $r->dir_config('lonAdmEMail');
12496: my ($configuserok,$author_ok,$switchserver) =
12497: &config_check($dom,$confname,$servadm);
12498: my $error;
12499: if ($configuserok eq 'ok') {
12500: if ($switchserver) {
12501: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
12502: } else {
12503: if ($author_ok eq 'ok') {
12504: my ($result,$customurl) =
12505: &publishlogo($r,'upload','passwords_customfile',$dom,
12506: $confname,'customtext/resetpw','','',$customfn);
12507: if ($result eq 'ok') {
12508: $newvalues{'resetcustom'} = $customurl;
12509: $changes{'reset'} = 1;
12510: } else {
12511: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
12512: }
12513: } else {
12514: $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);
12515: }
12516: }
12517: } else {
12518: $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);
12519: }
12520: if ($error) {
12521: &Apache::lonnet::logthis($error);
12522: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12523: }
12524: } elsif ($current{'resetcustom'}) {
12525: if ($env{'form.passwords_custom_del'}) {
12526: $changes{'reset'} = 1;
12527: } else {
12528: $newvalues{'resetcustom'} = $current{'resetcustom'};
12529: }
12530: }
12531: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
12532: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
12533: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
12534: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
12535: $changes{'intauth'} = 1;
12536: }
12537: } else {
12538: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
12539: }
12540: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
12541: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
12542: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
12543: $changes{'intauth'} = 1;
12544: }
12545: } else {
12546: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12547: }
12548: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
12549: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
12550: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
12551: $changes{'intauth'} = 1;
12552: }
12553: } else {
12554: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12555: }
12556: foreach my $item ('cost','check','switch') {
12557: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
12558: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
12559: $updatedefaults = 1;
12560: }
12561: }
12562: foreach my $rule ('min','max','numsaved') {
12563: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.160.6.99 raeburn 12564: my $ruleok;
12565: if ($rule eq 'min') {
12566: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
12567: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
12568: $ruleok = 1;
12569: }
12570: }
12571: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
12572: ($env{'form.passwords_'.$rule} ne '0')) {
12573: $ruleok = 1;
12574: }
12575: if ($ruleok) {
1.160.6.98 raeburn 12576: $newvalues{$rule} = $env{'form.passwords_'.$rule};
12577: if (exists($current{$rule})) {
12578: if ($newvalues{$rule} ne $current{$rule}) {
12579: $changes{'rules'} = 1;
12580: }
12581: } elsif ($rule eq 'min') {
12582: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
12583: $changes{'rules'} = 1;
12584: }
1.160.6.102.2 3(raebur 12585:0): } else {
12586:0): $changes{'rules'} = 1;
1.160.6.98 raeburn 12587: }
12588: } elsif (exists($current{$rule})) {
12589: $changes{'rules'} = 1;
12590: }
12591: }
12592: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
12593: my @chars;
12594: foreach my $item (sort(@posschars)) {
12595: if ($item =~ /^(uc|lc|num|spec)$/) {
12596: push(@chars,$item);
12597: }
12598: }
12599: $newvalues{'chars'} = \@chars;
12600: unless ($changes{'rules'}) {
12601: if (ref($current{'chars'}) eq 'ARRAY') {
12602: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
12603: if (@diffs > 0) {
12604: $changes{'rules'} = 1;
12605: }
12606: } else {
12607: if (@chars > 0) {
12608: $changes{'rules'} = 1;
12609: }
12610: }
12611: }
12612: my %crsownerchg = (
12613: by => [],
12614: for => [],
12615: );
12616: foreach my $item ('by','for') {
12617: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
12618: foreach my $type (sort(@posstypes)) {
12619: if (grep(/^\Q$type\E$/,@oktypes)) {
12620: push(@{$crsownerchg{$item}},$type);
12621: }
12622: }
12623: }
12624: $newvalues{'crsownerchg'} = \%crsownerchg;
12625: if (ref($current{'crsownerchg'}) eq 'HASH') {
12626: foreach my $item ('by','for') {
12627: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
12628: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
12629: if (@diffs > 0) {
12630: $changes{'crsownerchg'} = 1;
12631: last;
12632: }
12633: }
12634: }
1.160.6.102 raeburn 12635: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 12636: foreach my $item ('by','for') {
12637: if (@{$crsownerchg{$item}} > 0) {
12638: $changes{'crsownerchg'} = 1;
12639: last;
12640: }
12641: }
12642: }
12643:
12644: my %confighash = (
12645: defaults => \%save_defaults,
12646: passwords => \%newvalues,
12647: );
12648: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
12649:
12650: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
12651: if ($putresult eq 'ok') {
12652: if (keys(%changes) > 0) {
12653: $resulttext = &mt('Changes made: ').'<ul>';
12654: foreach my $key ('reset','intauth','rules','crsownerchg') {
12655: if ($changes{$key}) {
12656: unless ($key eq 'intauth') {
12657: $updateconf = 1;
12658: }
12659: $resulttext .= '<li>'.$titles{$key}.':<ul>';
12660: if ($key eq 'reset') {
12661: if ($confighash{'passwords'}{'captcha'} eq 'original') {
12662: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
12663: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
12664: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.102.2 3(raebur 12665:0): &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
12666:0): if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
12667:0): $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
12668:0): &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
12669:0): }
1.160.6.98 raeburn 12670: } else {
12671: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
12672: }
12673: if ($confighash{'passwords'}{'resetlink'}) {
12674: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
12675: } else {
12676: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
12677: &mt('Will default to 2 hours').'</li>';
12678: }
12679: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
12680: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
12681: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
12682: } else {
12683: my $casesens;
12684: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
12685: if ($type eq 'default') {
12686: $casesens .= $othertitle.', ';
12687: } elsif ($usertypes->{$type} ne '') {
12688: $casesens .= $usertypes->{$type}.', ';
12689: }
12690: }
12691: $casesens =~ s/\Q, \E$//;
12692: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
12693: }
12694: } else {
12695: $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>';
12696: }
12697: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
12698: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
12699: } else {
12700: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
12701: }
12702: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
12703: my $output;
12704: if (ref($types) eq 'ARRAY') {
12705: foreach my $type (@{$types}) {
12706: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
12707: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
12708: $output .= $usertypes->{$type}.' -- '.&mt('none');
12709: } else {
12710: $output .= $usertypes->{$type}.' -- '.
12711: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
12712: }
12713: }
12714: }
12715: }
12716: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
12717: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
12718: $output .= $othertitle.' -- '.&mt('none');
12719: } else {
12720: $output .= $othertitle.' -- '.
12721: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
12722: }
12723: }
12724: if ($output) {
12725: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
12726: } else {
12727: $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>';
12728: }
12729: } else {
12730: $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>';
12731: }
12732: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
12733: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
12734: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
12735: } else {
12736: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
12737: }
12738: } else {
12739: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
12740: }
12741: if ($confighash{'passwords'}{'resetremove'}) {
12742: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
12743: } else {
12744: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
12745: }
12746: if ($confighash{'passwords'}{'resetcustom'}) {
12747: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.102.2 3(raebur 12748:0): &mt('custom text'),600,500,undef,undef,
12749:0): undef,undef,'background-color:#ffffff');
12750:0): $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 12751: } else {
12752: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
12753: }
12754: } elsif ($key eq 'intauth') {
12755: foreach my $item ('cost','switch','check') {
12756: my $value = $save_defaults{$key.'_'.$item};
12757: if ($item eq 'switch') {
12758: my %optiondesc = &Apache::lonlocal::texthash (
12759: 0 => 'No',
12760: 1 => 'Yes',
12761: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12762: );
12763: if ($value =~ /^(0|1|2)$/) {
12764: $value = $optiondesc{$value};
12765: } else {
12766: $value = &mt('none -- defaults to No');
12767: }
12768: } elsif ($item eq 'check') {
12769: my %optiondesc = &Apache::lonlocal::texthash (
12770: 0 => 'No',
12771: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12772: 2 => 'Yes, disallow login if stored cost is less than domain default',
12773: );
12774: if ($value =~ /^(0|1|2)$/) {
12775: $value = $optiondesc{$value};
12776: } else {
12777: $value = &mt('none -- defaults to No');
12778: }
12779: }
12780: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
12781: }
12782: } elsif ($key eq 'rules') {
12783: foreach my $rule ('min','max','numsaved') {
12784: if ($confighash{'passwords'}{$rule} eq '') {
12785: if ($rule eq 'min') {
12786: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 12787: ' '.&mt('Default of [_1] will be used',
12788: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 12789: } else {
12790: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
12791: }
12792: } else {
12793: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
12794: }
12795: }
1.160.6.102.2 3(raebur 12796:0): if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
12797:0): if (@{$confighash{'passwords'}{'chars'}} > 0) {
12798:0): my %rulenames = &Apache::lonlocal::texthash(
12799:0): uc => 'At least one upper case letter',
12800:0): lc => 'At least one lower case letter',
12801:0): num => 'At least one number',
12802:0): spec => 'At least one non-alphanumeric',
12803:0): );
12804:0): my $needed = '<ul><li>'.
12805:0): join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
12806:0): '</li></ul>';
12807:0): $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
12808:0): } else {
12809:0): $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
12810:0): }
12811:0): } else {
12812:0): $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
12813:0): }
1.160.6.98 raeburn 12814: } elsif ($key eq 'crsownerchg') {
12815: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
12816: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
12817: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
12818: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
12819: } else {
12820: my %crsownerstr;
12821: foreach my $item ('by','for') {
12822: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
12823: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
12824: if ($type eq 'default') {
12825: $crsownerstr{$item} .= $othertitle.', ';
12826: } elsif ($usertypes->{$type} ne '') {
12827: $crsownerstr{$item} .= $usertypes->{$type}.', ';
12828: }
12829: }
12830: $crsownerstr{$item} =~ s/\Q, \E$//;
12831: }
12832: }
12833: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
12834: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
12835: }
12836: } else {
12837: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
12838: }
12839: }
12840: $resulttext .= '</ul></li>';
12841: }
12842: }
12843: $resulttext .= '</ul>';
12844: } else {
12845: $resulttext = &mt('No changes made to password settings');
12846: }
12847: my $cachetime = 24*60*60;
12848: if ($updatedefaults) {
12849: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12850: if (ref($lastactref) eq 'HASH') {
12851: $lastactref->{'domdefaults'} = 1;
12852: }
12853: }
12854: if ($updateconf) {
12855: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
12856: if (ref($lastactref) eq 'HASH') {
12857: $lastactref->{'passwdconf'} = 1;
12858: }
12859: }
12860: } else {
12861: $resulttext = '<span class="LC_error">'.
12862: &mt('An error occurred: [_1]',$putresult).'</span>';
12863: }
12864: if ($errors) {
12865: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
12866: $errors.'</ul></p>';
12867: }
12868: return $resulttext;
12869: }
12870:
1.28 raeburn 12871: sub modify_usercreation {
1.27 raeburn 12872: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 12873: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 12874: my $warningmsg;
1.27 raeburn 12875: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12876: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 12877: if ($key eq 'cancreate') {
12878: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
12879: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 12880: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 12881: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 12882: } else {
12883: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 12884: }
1.50 raeburn 12885: }
1.43 raeburn 12886: }
1.160.6.34 raeburn 12887: } elsif ($key eq 'email_rule') {
12888: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
12889: } else {
12890: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 12891: }
12892: }
1.34 raeburn 12893: }
1.160.6.34 raeburn 12894: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
12895: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
12896: my @contexts = ('author','course','requestcrs');
12897: foreach my $item(@contexts) {
12898: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 12899: }
1.34 raeburn 12900: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12901: foreach my $item (@contexts) {
1.160.6.34 raeburn 12902: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
12903: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 12904: }
1.27 raeburn 12905: }
1.34 raeburn 12906: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
12907: foreach my $item (@contexts) {
1.43 raeburn 12908: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 12909: if ($cancreate{$item} ne 'any') {
12910: push(@{$changes{'cancreate'}},$item);
12911: }
12912: } else {
12913: if ($cancreate{$item} ne 'none') {
12914: push(@{$changes{'cancreate'}},$item);
12915: }
1.27 raeburn 12916: }
12917: }
12918: } else {
1.43 raeburn 12919: foreach my $item (@contexts) {
1.34 raeburn 12920: push(@{$changes{'cancreate'}},$item);
12921: }
1.27 raeburn 12922: }
1.34 raeburn 12923:
1.27 raeburn 12924: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
12925: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
12926: if (!grep(/^\Q$type\E$/,@username_rule)) {
12927: push(@{$changes{'username_rule'}},$type);
12928: }
12929: }
12930: foreach my $type (@username_rule) {
12931: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
12932: push(@{$changes{'username_rule'}},$type);
12933: }
12934: }
12935: } else {
12936: push(@{$changes{'username_rule'}},@username_rule);
12937: }
12938:
1.32 raeburn 12939: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
12940: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
12941: if (!grep(/^\Q$type\E$/,@id_rule)) {
12942: push(@{$changes{'id_rule'}},$type);
12943: }
12944: }
12945: foreach my $type (@id_rule) {
12946: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
12947: push(@{$changes{'id_rule'}},$type);
12948: }
12949: }
12950: } else {
12951: push(@{$changes{'id_rule'}},@id_rule);
12952: }
12953:
1.43 raeburn 12954: my @authen_contexts = ('author','course','domain');
1.28 raeburn 12955: my @authtypes = ('int','krb4','krb5','loc');
12956: my %authhash;
1.43 raeburn 12957: foreach my $item (@authen_contexts) {
1.28 raeburn 12958: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
12959: foreach my $auth (@authtypes) {
12960: if (grep(/^\Q$auth\E$/,@authallowed)) {
12961: $authhash{$item}{$auth} = 1;
12962: } else {
12963: $authhash{$item}{$auth} = 0;
12964: }
12965: }
12966: }
12967: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 12968: foreach my $item (@authen_contexts) {
1.28 raeburn 12969: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
12970: foreach my $auth (@authtypes) {
12971: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
12972: push(@{$changes{'authtypes'}},$item);
12973: last;
12974: }
12975: }
12976: }
12977: }
12978: } else {
1.43 raeburn 12979: foreach my $item (@authen_contexts) {
1.28 raeburn 12980: push(@{$changes{'authtypes'}},$item);
12981: }
12982: }
12983:
1.160.6.34 raeburn 12984: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
12985: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
12986: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
12987: $save_usercreate{'id_rule'} = \@id_rule;
12988: $save_usercreate{'username_rule'} = \@username_rule,
12989: $save_usercreate{'authtypes'} = \%authhash;
12990:
1.27 raeburn 12991: my %usercreation_hash = (
1.160.6.34 raeburn 12992: usercreation => \%save_usercreate,
12993: );
1.27 raeburn 12994:
12995: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
12996: $dom);
1.50 raeburn 12997:
1.160.6.34 raeburn 12998: if ($putresult eq 'ok') {
12999: if (keys(%changes) > 0) {
13000: $resulttext = &mt('Changes made:').'<ul>';
13001: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13002: my %lt = &usercreation_types();
13003: foreach my $type (@{$changes{'cancreate'}}) {
13004: my $chgtext = $lt{$type}.', ';
13005: if ($cancreate{$type} eq 'none') {
13006: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13007: } elsif ($cancreate{$type} eq 'any') {
13008: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13009: } elsif ($cancreate{$type} eq 'official') {
13010: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13011: } elsif ($cancreate{$type} eq 'unofficial') {
13012: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13013: }
13014: $resulttext .= '<li>'.$chgtext.'</li>';
13015: }
13016: }
13017: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13018: my ($rules,$ruleorder) =
13019: &Apache::lonnet::inst_userrules($dom,'username');
13020: my $chgtext = '<ul>';
13021: foreach my $type (@username_rule) {
13022: if (ref($rules->{$type}) eq 'HASH') {
13023: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13024: }
13025: }
13026: $chgtext .= '</ul>';
13027: if (@username_rule > 0) {
13028: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13029: } else {
13030: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13031: }
13032: }
13033: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13034: my ($idrules,$idruleorder) =
13035: &Apache::lonnet::inst_userrules($dom,'id');
13036: my $chgtext = '<ul>';
13037: foreach my $type (@id_rule) {
13038: if (ref($idrules->{$type}) eq 'HASH') {
13039: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13040: }
13041: }
13042: $chgtext .= '</ul>';
13043: if (@id_rule > 0) {
13044: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13045: } else {
13046: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13047: }
13048: }
13049: my %authname = &authtype_names();
13050: my %context_title = &context_names();
13051: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13052: my $chgtext = '<ul>';
13053: foreach my $type (@{$changes{'authtypes'}}) {
13054: my @allowed;
13055: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13056: foreach my $auth (@authtypes) {
13057: if ($authhash{$type}{$auth}) {
13058: push(@allowed,$authname{$auth});
13059: }
13060: }
13061: if (@allowed > 0) {
13062: $chgtext .= join(', ',@allowed).'</li>';
13063: } else {
13064: $chgtext .= &mt('none').'</li>';
13065: }
13066: }
13067: $chgtext .= '</ul>';
13068: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13069: $resulttext .= '</li>';
13070: }
13071: $resulttext .= '</ul>';
13072: } else {
13073: $resulttext = &mt('No changes made to user creation settings');
13074: }
13075: } else {
13076: $resulttext = '<span class="LC_error">'.
13077: &mt('An error occurred: [_1]',$putresult).'</span>';
13078: }
13079: if ($warningmsg ne '') {
13080: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13081: }
13082: return $resulttext;
13083: }
13084:
13085: sub modify_selfcreation {
1.160.6.93 raeburn 13086: my ($dom,$lastactref,%domconfig) = @_;
13087: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13088: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13089: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13090: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13091: if (ref($typesref) eq 'ARRAY') {
13092: @types = @{$typesref};
13093: }
13094: if (ref($usertypesref) eq 'HASH') {
13095: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 13096: }
1.160.6.93 raeburn 13097: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 13098: #
13099: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13100: #
13101: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13102: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13103: if ($key eq 'cancreate') {
13104: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13105: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13106: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 13107: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13108: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13109: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13110: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
13111: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 13112: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13113: } else {
13114: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13115: }
13116: }
13117: }
13118: } elsif ($key eq 'email_rule') {
13119: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13120: } else {
13121: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13122: }
13123: }
13124: }
13125: #
13126: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13127: #
13128: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13129: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13130: if ($key eq 'selfcreate') {
13131: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13132: } else {
13133: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13134: }
13135: }
13136: }
1.160.6.93 raeburn 13137: #
13138: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13139: #
13140: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13141: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13142: if ($key eq 'inststatusguest') {
13143: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13144: } else {
13145: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13146: }
13147: }
13148: }
1.160.6.34 raeburn 13149:
13150: my @contexts = ('selfcreate');
13151: @{$cancreate{'selfcreate'}} = ();
13152: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 13153: if (@types) {
13154: @{$cancreate{'statustocreate'}} = ();
13155: }
1.160.6.40 raeburn 13156: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 13157: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 13158: %{$cancreate{'emailverified'}} = ();
13159: %{$cancreate{'emailoptions'}} = ();
13160: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13161: my %selfcreatetypes = (
13162: sso => 'users authenticated by institutional single sign on',
13163: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 13164: email => 'users verified by e-mail',
1.50 raeburn 13165: );
1.160.6.34 raeburn 13166: #
13167: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13168: # is permitted.
13169: #
1.160.6.40 raeburn 13170:
1.160.6.93 raeburn 13171: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 13172:
1.160.6.93 raeburn 13173: my (@statuses,%email_rule);
1.160.6.35 raeburn 13174: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 13175: if ($item eq 'email') {
1.160.6.40 raeburn 13176: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 13177: if (@types) {
13178: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13179: foreach my $status (@poss_statuses) {
13180: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13181: push(@statuses,$status);
13182: }
13183: }
13184: $save_inststatus{'inststatusguest'} = \@statuses;
13185: } else {
13186: push(@statuses,'default');
13187: }
13188: if (@statuses) {
13189: my %curr_rule;
13190: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13191: foreach my $type (@statuses) {
13192: $curr_rule{$type} = $curr_usercreation{'email_rule'};
13193: }
13194: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13195: foreach my $type (@statuses) {
13196: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13197: }
13198: }
13199: push(@{$cancreate{'selfcreate'}},'email');
13200: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13201: my %curremaildom;
13202: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13203: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13204: }
13205: foreach my $type (@statuses) {
13206: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13207: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13208: }
13209: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13210: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13211: }
13212: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13213: #
13214: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13215: #
13216: my $chosen = $1;
13217: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13218: my $emaildom;
13219: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13220: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13221: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13222: if (ref($curremaildom{$type}) eq 'HASH') {
13223: if (exists($curremaildom{$type}{$chosen})) {
13224: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13225: push(@{$changes{'cancreate'}},'emaildomain');
13226: }
13227: } elsif ($emaildom ne '') {
13228: push(@{$changes{'cancreate'}},'emaildomain');
13229: }
13230: } elsif ($emaildom ne '') {
13231: push(@{$changes{'cancreate'}},'emaildomain');
13232: }
13233: }
13234: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13235: } elsif ($chosen eq 'custom') {
13236: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13237: $email_rule{$type} = [];
13238: if (ref($emailrules) eq 'HASH') {
13239: foreach my $rule (@possemail_rules) {
13240: if (exists($emailrules->{$rule})) {
13241: push(@{$email_rule{$type}},$rule);
13242: }
13243: }
13244: }
13245: if (@{$email_rule{$type}}) {
13246: $cancreate{'emailoptions'}{$type} = 'custom';
13247: if (ref($curr_rule{$type}) eq 'ARRAY') {
13248: if (@{$curr_rule{$type}} > 0) {
13249: foreach my $rule (@{$curr_rule{$type}}) {
13250: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13251: push(@{$changes{'email_rule'}},$type);
13252: }
13253: }
13254: }
13255: foreach my $type (@{$email_rule{$type}}) {
13256: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13257: push(@{$changes{'email_rule'}},$type);
13258: }
13259: }
13260: } else {
13261: push(@{$changes{'email_rule'}},$type);
13262: }
13263: }
13264: } else {
13265: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13266: }
13267: }
13268: }
13269: if (@types) {
13270: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13271: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13272: if (@changed) {
13273: push(@{$changes{'inststatus'}},'inststatusguest');
13274: }
13275: } else {
13276: push(@{$changes{'inststatus'}},'inststatusguest');
13277: }
13278: }
13279: } else {
13280: delete($env{'form.cancreate_email'});
13281: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13282: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13283: push(@{$changes{'inststatus'}},'inststatusguest');
13284: }
13285: }
13286: }
13287: } else {
13288: $save_inststatus{'inststatusguest'} = [];
13289: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13290: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13291: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 13292: }
13293: }
1.160.6.34 raeburn 13294: }
13295: } else {
13296: if ($env{'form.cancreate_'.$item}) {
13297: push(@{$cancreate{'selfcreate'}},$item);
13298: }
13299: }
13300: }
1.160.6.93 raeburn 13301: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 13302: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13303: #
1.160.6.35 raeburn 13304: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13305: # 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 13306: #
1.160.6.40 raeburn 13307:
1.160.6.48 raeburn 13308: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 13309: push(@contexts,'emailusername');
1.160.6.93 raeburn 13310: if (@statuses) {
13311: foreach my $type (@statuses) {
1.160.6.35 raeburn 13312: if (ref($infofields) eq 'ARRAY') {
13313: foreach my $field (@{$infofields}) {
13314: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13315: $cancreate{'emailusername'}{$type}{$field} = $1;
13316: }
13317: }
1.160.6.34 raeburn 13318: }
13319: }
13320: }
13321: #
13322: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 13323: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 13324: #
13325:
13326: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13327: @approvalnotify = sort(@approvalnotify);
13328: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13329: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13330: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13331: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13332: push(@{$changes{'cancreate'}},'notify');
13333: }
13334: } else {
13335: if ($cancreate{'notify'}{'approval'}) {
13336: push(@{$changes{'cancreate'}},'notify');
13337: }
13338: }
13339: } elsif ($cancreate{'notify'}{'approval'}) {
13340: push(@{$changes{'cancreate'}},'notify');
13341: }
13342:
13343: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13344: }
13345: #
1.160.6.40 raeburn 13346: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 13347: # institutional log-in.
13348: #
13349: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13350: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13351: ($domdefaults{'auth_def'} eq 'localauth'))) {
13352: $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.').' '.
13353: &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.');
13354: }
13355: }
13356: my @fields = ('lastname','firstname','middlename','generation',
13357: 'permanentemail','id');
1.160.6.44 raeburn 13358: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 13359: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13360: #
13361: # Where usernames may created for institutional log-in and/or institutional single sign on:
13362: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13363: # may self-create accounts
13364: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13365: # which the user may supply, if institutional data is unavailable.
13366: #
13367: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 13368: if (@types) {
13369: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13370: push(@contexts,'statustocreate');
13371: foreach my $type (@types) {
1.160.6.34 raeburn 13372: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13373: foreach my $field (@fields) {
13374: if (grep(/^\Q$field\E$/,@modifiable)) {
13375: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13376: } else {
13377: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13378: }
13379: }
13380: }
13381: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 13382: foreach my $type (@types) {
1.160.6.34 raeburn 13383: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13384: foreach my $field (@fields) {
13385: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13386: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13387: push(@{$changes{'selfcreate'}},$type);
13388: last;
13389: }
13390: }
13391: }
13392: }
13393: } else {
1.160.6.93 raeburn 13394: foreach my $type (@types) {
1.160.6.34 raeburn 13395: push(@{$changes{'selfcreate'}},$type);
13396: }
13397: }
13398: }
1.160.6.44 raeburn 13399: foreach my $field (@shibfields) {
13400: if ($env{'form.shibenv_'.$field} ne '') {
13401: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13402: }
13403: }
13404: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13405: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13406: foreach my $field (@shibfields) {
13407: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13408: push(@{$changes{'cancreate'}},'shibenv');
13409: }
13410: }
13411: } else {
13412: foreach my $field (@shibfields) {
13413: if ($env{'form.shibenv_'.$field}) {
13414: push(@{$changes{'cancreate'}},'shibenv');
13415: last;
13416: }
13417: }
13418: }
13419: }
1.160.6.34 raeburn 13420: }
13421: foreach my $item (@contexts) {
13422: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13423: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13424: if (ref($cancreate{$item}) eq 'ARRAY') {
13425: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13426: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13427: push(@{$changes{'cancreate'}},$item);
13428: }
13429: }
13430: }
13431: }
13432: if (ref($cancreate{$item}) eq 'ARRAY') {
13433: foreach my $type (@{$cancreate{$item}}) {
13434: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13435: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13436: push(@{$changes{'cancreate'}},$item);
13437: }
13438: }
13439: }
13440: }
13441: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13442: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 13443: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13444: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13445: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13446: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13447: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13448: push(@{$changes{'cancreate'}},$item);
13449: }
13450: }
13451: }
1.160.6.93 raeburn 13452: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13453: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13454: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13455: push(@{$changes{'cancreate'}},$item);
13456: }
1.160.6.34 raeburn 13457: }
13458: }
13459: }
1.160.6.93 raeburn 13460: foreach my $type (keys(%{$cancreate{$item}})) {
13461: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13462: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13463: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13464: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13465: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13466: push(@{$changes{'cancreate'}},$item);
13467: }
13468: }
13469: } else {
13470: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13471: push(@{$changes{'cancreate'}},$item);
13472: }
13473: }
13474: }
1.160.6.93 raeburn 13475: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13476: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13477: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13478: push(@{$changes{'cancreate'}},$item);
13479: }
1.160.6.34 raeburn 13480: }
13481: }
13482: }
13483: }
13484: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13485: if (ref($cancreate{$item}) eq 'ARRAY') {
13486: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13487: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13488: push(@{$changes{'cancreate'}},$item);
13489: }
13490: }
1.160.6.93 raeburn 13491: }
13492: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13493: if (ref($cancreate{$item}) eq 'HASH') {
13494: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13495: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 13496: }
13497: }
13498: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 13499: if (ref($cancreate{$item}) eq 'HASH') {
13500: foreach my $type (keys(%{$cancreate{$item}})) {
13501: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13502: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13503: if ($cancreate{$item}{$type}{$field}) {
13504: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13505: push(@{$changes{'cancreate'}},$item);
13506: }
13507: last;
13508: }
13509: }
13510: }
13511: }
1.160.6.34 raeburn 13512: }
13513: }
13514: }
13515: #
13516: # Populate %save_usercreate hash with updates to self-creation configuration.
13517: #
13518: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13519: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 13520: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 13521: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13522: if (ref($cancreate{'notify'}) eq 'HASH') {
13523: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13524: }
1.160.6.40 raeburn 13525: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13526: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13527: }
1.160.6.93 raeburn 13528: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13529: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13530: }
13531: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13532: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13533: }
13534: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13535: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13536: }
1.160.6.34 raeburn 13537: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13538: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13539: }
1.160.6.44 raeburn 13540: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13541: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13542: }
1.160.6.34 raeburn 13543: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 13544: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 13545:
13546: my %userconfig_hash = (
13547: usercreation => \%save_usercreate,
13548: usermodification => \%save_usermodify,
1.160.6.93 raeburn 13549: inststatus => \%save_inststatus,
1.160.6.34 raeburn 13550: );
1.160.6.93 raeburn 13551:
1.160.6.34 raeburn 13552: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13553: $dom);
13554: #
1.160.6.93 raeburn 13555: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 13556: #
1.27 raeburn 13557: if ($putresult eq 'ok') {
13558: if (keys(%changes) > 0) {
13559: $resulttext = &mt('Changes made:').'<ul>';
13560: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 13561: my %lt = &selfcreation_types();
1.34 raeburn 13562: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 13563: my $chgtext = '';
1.45 raeburn 13564: if ($type eq 'selfcreate') {
1.50 raeburn 13565: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 13566: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13567: } else {
1.160.6.34 raeburn 13568: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13569: '<ul>';
1.50 raeburn 13570: foreach my $case (@{$cancreate{$type}}) {
13571: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13572: }
13573: $chgtext .= '</ul>';
1.100 raeburn 13574: if (ref($cancreate{$type}) eq 'ARRAY') {
13575: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13576: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13577: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 13578: $chgtext .= '<span class="LC_warning">'.
13579: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13580: '</span><br />';
1.100 raeburn 13581: }
13582: }
13583: }
1.160.6.93 raeburn 13584: if (grep(/^email$/,@{$cancreate{$type}})) {
13585: if (!@statuses) {
13586: $chgtext .= '<span class="LC_warning">'.
13587: &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.").
13588: '</span><br />';
13589:
13590: }
13591: }
1.100 raeburn 13592: }
1.43 raeburn 13593: }
1.160.6.44 raeburn 13594: } elsif ($type eq 'shibenv') {
13595: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 13596: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 13597: } else {
13598: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13599: '<ul>';
13600: foreach my $field (@shibfields) {
13601: next if ($cancreate{$type}{$field} eq '');
13602: if ($field eq 'inststatus') {
13603: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13604: } else {
13605: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13606: }
13607: }
13608: $chgtext .= '</ul>';
1.160.6.93 raeburn 13609: }
1.93 raeburn 13610: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13611: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13612: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13613: if (@{$cancreate{'selfcreate'}} > 0) {
13614: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13615: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13616: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 13617: $chgtext .= '<br />'.
13618: '<span class="LC_warning">'.
13619: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13620: '</span>';
13621: }
1.160.6.93 raeburn 13622: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13623: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13624: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13625: } else {
13626: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13627: }
13628: $chgtext .= '<ul>';
13629: foreach my $case (@{$cancreate{$type}}) {
13630: if ($case eq 'default') {
13631: $chgtext .= '<li>'.$othertitle.'</li>';
13632: } else {
1.160.6.93 raeburn 13633: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13634: }
13635: }
1.100 raeburn 13636: $chgtext .= '</ul>';
13637: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 13638: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 13639: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13640: '</span>';
1.100 raeburn 13641: }
13642: }
13643: } else {
13644: if (@{$cancreate{$type}} == 0) {
13645: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13646: } else {
13647: $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 13648: }
13649: }
1.160.6.93 raeburn 13650: $chgtext .= '<br />';
1.93 raeburn 13651: }
1.160.6.40 raeburn 13652: } elsif ($type eq 'selfcreateprocessing') {
13653: my %choices = &Apache::lonlocal::texthash (
13654: automatic => 'Automatic approval',
13655: approval => 'Queued for approval',
13656: );
1.160.6.93 raeburn 13657: if (@types) {
13658: if (@statuses) {
13659: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
13660: '<ul>';
13661: foreach my $status (@statuses) {
13662: if ($status eq 'default') {
13663: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
13664: } else {
13665: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
13666: }
13667: }
13668: $chgtext .= '</ul>';
13669: }
13670: } else {
13671: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13672: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13673: }
13674: } elsif ($type eq 'emailverified') {
13675: my %options = &Apache::lonlocal::texthash (
13676: all => 'Same as e-mail',
13677: first => 'Omit @domain',
13678: free => 'Free to choose',
13679: );
13680: if (@types) {
13681: if (@statuses) {
13682: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13683: '<ul>';
13684: foreach my $status (@statuses) {
13685: if ($status eq 'default') {
13686: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
13687: } else {
13688: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
13689: }
13690: }
13691: $chgtext .= '</ul>';
13692: }
1.160.6.40 raeburn 13693: } else {
1.160.6.93 raeburn 13694: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
13695: $options{$cancreate{'emailverified'}{'default'}});
13696: }
13697: } elsif ($type eq 'emailoptions') {
13698: my %options = &Apache::lonlocal::texthash (
13699: any => 'Any e-mail',
13700: inst => 'Institutional only',
13701: noninst => 'Non-institutional only',
13702: custom => 'Custom restrictions',
13703: );
13704: if (@types) {
13705: if (@statuses) {
13706: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13707: '<ul>';
13708: foreach my $status (@statuses) {
13709: if ($type eq 'default') {
13710: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13711: } else {
13712: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13713: }
13714: }
13715: $chgtext .= '</ul>';
13716: }
13717: } else {
13718: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13719: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13720: } else {
13721: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13722: $options{$cancreate{'emailoptions'}{'default'}});
13723: }
13724: }
13725: } elsif ($type eq 'emaildomain') {
13726: my $output;
13727: if (@statuses) {
13728: foreach my $type (@statuses) {
13729: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13730: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13731: if ($type eq 'default') {
13732: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13733: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13734: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13735: } else {
13736: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13737: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13738: }
13739: } else {
13740: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13741: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13742: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13743: } else {
13744: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13745: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13746: }
13747: }
13748: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13749: if ($type eq 'default') {
13750: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13751: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13752: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13753: } else {
13754: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13755: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13756: }
13757: } else {
13758: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13759: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13760: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13761: } else {
13762: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13763: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13764: }
13765: }
13766: }
13767: }
13768: }
13769: }
13770: if ($output ne '') {
13771: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
13772: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 13773: }
1.160.6.5 raeburn 13774: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 13775: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 13776: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
13777: } else {
13778: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 13779: if ($captchas{$savecaptcha{$type}}) {
13780: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 13781: } else {
13782: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
13783: }
13784: }
13785: } elsif ($type eq 'recaptchakeys') {
13786: my ($privkey,$pubkey);
1.160.6.34 raeburn 13787: if (ref($savecaptcha{$type}) eq 'HASH') {
13788: $pubkey = $savecaptcha{$type}{'public'};
13789: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 13790: }
13791: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
13792: if (!$pubkey) {
13793: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
13794: } else {
13795: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13796: }
13797: if (!$privkey) {
13798: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
13799: } else {
13800: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
13801: }
13802: $chgtext .= '</ul>';
1.160.6.69 raeburn 13803: } elsif ($type eq 'recaptchaversion') {
13804: if ($savecaptcha{'captcha'} eq 'recaptcha') {
13805: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
13806: }
1.160.6.34 raeburn 13807: } elsif ($type eq 'emailusername') {
13808: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 13809: if (@statuses) {
13810: foreach my $type (@statuses) {
1.160.6.35 raeburn 13811: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
13812: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 13813: $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 13814: '<ul>';
13815: foreach my $field (@{$infofields}) {
13816: if ($cancreate{'emailusername'}{$type}{$field}) {
13817: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
13818: }
13819: }
1.160.6.50 raeburn 13820: $chgtext .= '</ul>';
13821: } else {
1.160.6.93 raeburn 13822: $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 13823: }
13824: } else {
1.160.6.93 raeburn 13825: $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 13826: }
13827: }
13828: }
13829: }
13830: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 13831: my $numapprove = 0;
1.160.6.34 raeburn 13832: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13833: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
13834: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 13835: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
13836: $numapprove ++;
1.160.6.34 raeburn 13837: }
13838: }
1.43 raeburn 13839: }
1.160.6.93 raeburn 13840: unless ($numapprove) {
13841: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
13842: }
1.34 raeburn 13843: }
1.160.6.34 raeburn 13844: if ($chgtext) {
13845: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 13846: }
13847: }
13848: }
1.160.6.93 raeburn 13849: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 13850: my ($emailrules,$emailruleorder) =
13851: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 13852: foreach my $type (@{$changes{'email_rule'}}) {
13853: if (ref($email_rule{$type}) eq 'ARRAY') {
13854: my $chgtext = '<ul>';
13855: foreach my $rule (@{$email_rule{$type}}) {
13856: if (ref($emailrules->{$rule}) eq 'HASH') {
13857: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
13858: }
13859: }
13860: $chgtext .= '</ul>';
13861: my $typename;
13862: if (@types) {
13863: if ($type eq 'default') {
13864: $typename = $othertitle;
13865: } else {
13866: $typename = $usertypes{$type};
13867: }
13868: $chgtext .= &mt('(Affiliation: [_1])',$typename);
13869: }
13870: if (@{$email_rule{$type}} > 0) {
13871: $resulttext .= '<li>'.
13872: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
13873: $usertypes{$type}).
13874: $chgtext.
13875: '</li>';
13876: } else {
13877: $resulttext .= '<li>'.
13878: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
13879: '</li>'.
13880: &mt('(Affiliation: [_1])',$typename);
13881: }
1.43 raeburn 13882: }
13883: }
1.160.6.93 raeburn 13884: }
13885: if (ref($changes{'inststatus'}) eq 'ARRAY') {
13886: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
13887: if (@{$save_inststatus{'inststatusguest'}} > 0) {
13888: my $chgtext = '<ul>';
13889: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
13890: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
13891: }
13892: $chgtext .= '</ul>';
13893: $resulttext .= '<li>'.
13894: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
13895: $chgtext.
13896: '</li>';
13897: } else {
13898: $resulttext .= '<li>'.
13899: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
13900: '</li>';
13901: }
1.43 raeburn 13902: }
13903: }
1.160.6.34 raeburn 13904: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
13905: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
13906: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13907: foreach my $type (@{$changes{'selfcreate'}}) {
13908: my $typename = $type;
1.160.6.93 raeburn 13909: if (keys(%usertypes) > 0) {
13910: if ($usertypes{$type} ne '') {
13911: $typename = $usertypes{$type};
1.28 raeburn 13912: }
13913: }
1.160.6.34 raeburn 13914: my @modifiable;
13915: $resulttext .= '<li>'.
13916: &mt('Self-creation of account by users with status: [_1]',
13917: '<span class="LC_cusr_emph">'.$typename.'</span>').
13918: ' - '.&mt('modifiable fields (if institutional data blank): ');
13919: foreach my $field (@fields) {
13920: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
13921: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
13922: }
13923: }
13924: if (@modifiable > 0) {
13925: $resulttext .= join(', ',@modifiable);
1.43 raeburn 13926: } else {
1.160.6.34 raeburn 13927: $resulttext .= &mt('none');
1.43 raeburn 13928: }
1.160.6.34 raeburn 13929: $resulttext .= '</li>';
1.28 raeburn 13930: }
1.160.6.34 raeburn 13931: $resulttext .= '</ul></li>';
1.28 raeburn 13932: }
1.27 raeburn 13933: $resulttext .= '</ul>';
1.160.6.93 raeburn 13934: my $cachetime = 24*60*60;
13935: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
13936: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13937: if (ref($lastactref) eq 'HASH') {
13938: $lastactref->{'domdefaults'} = 1;
13939: }
1.27 raeburn 13940: } else {
1.160.6.34 raeburn 13941: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 13942: }
13943: } else {
13944: $resulttext = '<span class="LC_error">'.
1.23 raeburn 13945: &mt('An error occurred: [_1]',$putresult).'</span>';
13946: }
1.43 raeburn 13947: if ($warningmsg ne '') {
13948: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13949: }
1.23 raeburn 13950: return $resulttext;
13951: }
13952:
1.160.6.5 raeburn 13953: sub process_captcha {
1.160.6.102.2 3(raebur 13954:0): my ($container,$changes,$newsettings,$currsettings) = @_;
13955:0): return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 13956: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
13957: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
13958: $newsettings->{'captcha'} = 'original';
13959: }
1.160.6.102.2 3(raebur 13960:0): my %current;
13961:0): if (ref($currsettings) eq 'HASH') {
13962:0): %current = %{$currsettings};
13963:0): }
13964:0): if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 13965: if ($container eq 'cancreate') {
13966: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13967: push(@{$changes->{'cancreate'}},'captcha');
13968: } elsif (!defined($changes->{'cancreate'})) {
13969: $changes->{'cancreate'} = ['captcha'];
13970: }
1.160.6.102 raeburn 13971: } elsif ($container eq 'passwords') {
13972: $changes->{'reset'} = 1;
1.160.6.5 raeburn 13973: } else {
13974: $changes->{'captcha'} = 1;
13975: }
13976: }
1.160.6.69 raeburn 13977: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 13978: if ($newsettings->{'captcha'} eq 'recaptcha') {
13979: $newpub = $env{'form.'.$container.'_recaptchapub'};
13980: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 13981: $newpub =~ s/[^\w\-]//g;
13982: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 13983: $newsettings->{'recaptchakeys'} = {
13984: public => $newpub,
13985: private => $newpriv,
13986: };
1.160.6.69 raeburn 13987: $newversion = $env{'form.'.$container.'_recaptchaversion'};
13988: $newversion =~ s/\D//g;
13989: if ($newversion ne '2') {
13990: $newversion = 1;
13991: }
13992: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 13993: }
1.160.6.102.2 3(raebur 13994:0): if (ref($current{'recaptchakeys'}) eq 'HASH') {
13995:0): $currpub = $current{'recaptchakeys'}{'public'};
13996:0): $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 13997: unless ($newsettings->{'captcha'} eq 'recaptcha') {
13998: $newsettings->{'recaptchakeys'} = {
13999: public => '',
14000: private => '',
14001: }
14002: }
1.160.6.5 raeburn 14003: }
1.160.6.102.2 3(raebur 14004:0): if ($current{'captcha'} eq 'recaptcha') {
14005:0): $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 14006: if ($currversion ne '2') {
14007: $currversion = 1;
14008: }
14009: }
14010: if ($currversion ne $newversion) {
14011: if ($container eq 'cancreate') {
14012: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14013: push(@{$changes->{'cancreate'}},'recaptchaversion');
14014: } elsif (!defined($changes->{'cancreate'})) {
14015: $changes->{'cancreate'} = ['recaptchaversion'];
14016: }
1.160.6.102 raeburn 14017: } elsif ($container eq 'passwords') {
14018: $changes->{'reset'} = 1;
1.160.6.69 raeburn 14019: } else {
14020: $changes->{'recaptchaversion'} = 1;
14021: }
14022: }
1.160.6.5 raeburn 14023: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
14024: if ($container eq 'cancreate') {
14025: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14026: push(@{$changes->{'cancreate'}},'recaptchakeys');
14027: } elsif (!defined($changes->{'cancreate'})) {
14028: $changes->{'cancreate'} = ['recaptchakeys'];
14029: }
1.160.6.102 raeburn 14030: } elsif ($container eq 'passwords') {
14031: $changes->{'reset'} = 1;
1.160.6.5 raeburn 14032: } else {
14033: $changes->{'recaptchakeys'} = 1;
14034: }
14035: }
14036: return;
14037: }
14038:
1.33 raeburn 14039: sub modify_usermodification {
14040: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 14041: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14042: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14043: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 14044: if ($key eq 'selfcreate') {
14045: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14046: } else {
14047: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14048: }
1.33 raeburn 14049: }
14050: }
1.160.6.34 raeburn 14051: my @contexts = ('author','course');
1.33 raeburn 14052: my %context_title = (
14053: author => 'In author context',
14054: course => 'In course context',
14055: );
14056: my @fields = ('lastname','firstname','middlename','generation',
14057: 'permanentemail','id');
14058: my %roles = (
14059: author => ['ca','aa'],
14060: course => ['st','ep','ta','in','cr'],
14061: );
14062: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14063: foreach my $context (@contexts) {
14064: foreach my $role (@{$roles{$context}}) {
14065: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14066: foreach my $item (@fields) {
14067: if (grep(/^\Q$item\E$/,@modifiable)) {
14068: $modifyhash{$context}{$role}{$item} = 1;
14069: } else {
14070: $modifyhash{$context}{$role}{$item} = 0;
14071: }
14072: }
14073: }
14074: if (ref($curr_usermodification{$context}) eq 'HASH') {
14075: foreach my $role (@{$roles{$context}}) {
14076: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14077: foreach my $field (@fields) {
14078: if ($modifyhash{$context}{$role}{$field} ne
14079: $curr_usermodification{$context}{$role}{$field}) {
14080: push(@{$changes{$context}},$role);
14081: last;
14082: }
14083: }
14084: }
14085: }
14086: } else {
14087: foreach my $context (@contexts) {
14088: foreach my $role (@{$roles{$context}}) {
14089: push(@{$changes{$context}},$role);
14090: }
14091: }
14092: }
14093: }
14094: my %usermodification_hash = (
14095: usermodification => \%modifyhash,
14096: );
14097: my $putresult = &Apache::lonnet::put_dom('configuration',
14098: \%usermodification_hash,$dom);
14099: if ($putresult eq 'ok') {
14100: if (keys(%changes) > 0) {
14101: $resulttext = &mt('Changes made: ').'<ul>';
14102: foreach my $context (@contexts) {
14103: if (ref($changes{$context}) eq 'ARRAY') {
14104: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14105: if (ref($changes{$context}) eq 'ARRAY') {
14106: foreach my $role (@{$changes{$context}}) {
14107: my $rolename;
1.160.6.34 raeburn 14108: if ($role eq 'cr') {
14109: $rolename = &mt('Custom');
1.33 raeburn 14110: } else {
1.160.6.34 raeburn 14111: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14112: }
14113: my @modifiable;
1.160.6.34 raeburn 14114: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14115: foreach my $field (@fields) {
14116: if ($modifyhash{$context}{$role}{$field}) {
14117: push(@modifiable,$fieldtitles{$field});
14118: }
14119: }
14120: if (@modifiable > 0) {
14121: $resulttext .= join(', ',@modifiable);
14122: } else {
14123: $resulttext .= &mt('none');
14124: }
14125: $resulttext .= '</li>';
14126: }
14127: $resulttext .= '</ul></li>';
14128: }
14129: }
14130: }
14131: $resulttext .= '</ul>';
14132: } else {
14133: $resulttext = &mt('No changes made to user modification settings');
14134: }
14135: } else {
14136: $resulttext = '<span class="LC_error">'.
14137: &mt('An error occurred: [_1]',$putresult).'</span>';
14138: }
14139: return $resulttext;
14140: }
14141:
1.43 raeburn 14142: sub modify_defaults {
1.160.6.27 raeburn 14143: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14144: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 14145: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 14146: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 14147: 'portal_def');
1.43 raeburn 14148: my @authtypes = ('internal','krb4','krb5','localauth');
14149: foreach my $item (@items) {
14150: $newvalues{$item} = $env{'form.'.$item};
14151: if ($item eq 'auth_def') {
14152: if ($newvalues{$item} ne '') {
14153: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14154: push(@errors,$item);
14155: }
14156: }
14157: } elsif ($item eq 'lang_def') {
14158: if ($newvalues{$item} ne '') {
14159: if ($newvalues{$item} =~ /^(\w+)/) {
14160: my $langcode = $1;
1.103 raeburn 14161: if ($langcode ne 'x_chef') {
14162: if (code2language($langcode) eq '') {
14163: push(@errors,$item);
14164: }
1.43 raeburn 14165: }
14166: } else {
14167: push(@errors,$item);
14168: }
14169: }
1.54 raeburn 14170: } elsif ($item eq 'timezone_def') {
14171: if ($newvalues{$item} ne '') {
1.62 raeburn 14172: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14173: push(@errors,$item);
14174: }
14175: }
1.68 raeburn 14176: } elsif ($item eq 'datelocale_def') {
14177: if ($newvalues{$item} ne '') {
14178: my @datelocale_ids = DateTime::Locale->ids();
14179: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14180: push(@errors,$item);
14181: }
14182: }
1.141 raeburn 14183: } elsif ($item eq 'portal_def') {
14184: if ($newvalues{$item} ne '') {
14185: 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])\/?$/) {
14186: push(@errors,$item);
14187: }
14188: }
1.43 raeburn 14189: }
14190: if (grep(/^\Q$item\E$/,@errors)) {
14191: $newvalues{$item} = $domdefaults{$item};
14192: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14193: $changes{$item} = 1;
14194: }
1.72 raeburn 14195: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14196: }
1.160.6.98 raeburn 14197: my %staticdefaults = (
14198: 'intauth_cost' => 10,
14199: 'intauth_check' => 0,
14200: 'intauth_switch' => 0,
14201: );
14202: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
14203: if (exists($domdefaults{$item})) {
14204: $newvalues{$item} = $domdefaults{$item};
14205: } else {
14206: $newvalues{$item} = $staticdefaults{$item};
14207: }
14208: }
1.43 raeburn 14209: my %defaults_hash = (
1.72 raeburn 14210: defaults => \%newvalues,
14211: );
1.43 raeburn 14212: my $title = &defaults_titles();
1.160.6.40 raeburn 14213:
14214: my $currinststatus;
14215: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14216: $currinststatus = $domconfig{'inststatus'};
14217: } else {
14218: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14219: $currinststatus = {
14220: inststatustypes => $usertypes,
14221: inststatusorder => $types,
14222: inststatusguest => [],
14223: };
14224: }
14225: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14226: my @allpos;
14227: my %alltypes;
1.160.6.93 raeburn 14228: my @inststatusguest;
14229: if (ref($currinststatus) eq 'HASH') {
14230: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14231: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14232: unless (grep(/^\Q$type\E$/,@todelete)) {
14233: push(@inststatusguest,$type);
14234: }
14235: }
14236: }
14237: }
14238: my ($currtitles,$currorder);
1.160.6.40 raeburn 14239: if (ref($currinststatus) eq 'HASH') {
14240: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14241: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14242: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14243: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14244: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14245: }
14246: }
14247: unless (grep(/^\Q$type\E$/,@todelete)) {
14248: my $position = $env{'form.inststatus_pos_'.$type};
14249: $position =~ s/\D+//g;
14250: $allpos[$position] = $type;
14251: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14252: $alltypes{$type} =~ s/`//g;
14253: }
14254: }
14255: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14256: $currtitles =~ s/,$//;
14257: }
14258: }
14259: if ($env{'form.addinststatus'}) {
14260: my $newtype = $env{'form.addinststatus'};
14261: $newtype =~ s/\W//g;
14262: unless (exists($alltypes{$newtype})) {
14263: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14264: $alltypes{$newtype} =~ s/`//g;
14265: my $position = $env{'form.addinststatus_pos'};
14266: $position =~ s/\D+//g;
14267: if ($position ne '') {
14268: $allpos[$position] = $newtype;
14269: }
14270: }
14271: }
1.160.6.93 raeburn 14272: my @orderedstatus;
1.160.6.40 raeburn 14273: foreach my $type (@allpos) {
14274: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14275: push(@orderedstatus,$type);
14276: }
14277: }
14278: foreach my $type (keys(%alltypes)) {
14279: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14280: delete($alltypes{$type});
14281: }
14282: }
14283: $defaults_hash{'inststatus'} = {
14284: inststatustypes => \%alltypes,
14285: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 14286: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 14287: };
14288: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14289: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14290: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14291: }
14292: }
14293: if ($currorder ne join(',',@orderedstatus)) {
14294: $changes{'inststatus'}{'inststatusorder'} = 1;
14295: }
14296: my $newtitles;
14297: foreach my $item (@orderedstatus) {
14298: $newtitles .= $alltypes{$item}.',';
14299: }
14300: $newtitles =~ s/,$//;
14301: if ($currtitles ne $newtitles) {
14302: $changes{'inststatus'}{'inststatustypes'} = 1;
14303: }
1.43 raeburn 14304: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14305: $dom);
14306: if ($putresult eq 'ok') {
14307: if (keys(%changes) > 0) {
14308: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 14309: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14310: 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";
14311: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 14312: if ($item eq 'inststatus') {
14313: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 14314: if (@orderedstatus) {
1.160.6.40 raeburn 14315: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14316: foreach my $type (@orderedstatus) {
14317: $resulttext .= $alltypes{$type}.', ';
14318: }
14319: $resulttext =~ s/, $//;
14320: $resulttext .= '</li>';
1.160.6.93 raeburn 14321: } else {
14322: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 14323: }
14324: }
14325: } else {
14326: my $value = $env{'form.'.$item};
14327: if ($value eq '') {
14328: $value = &mt('none');
14329: } elsif ($item eq 'auth_def') {
14330: my %authnames = &authtype_names();
14331: my %shortauth = (
14332: internal => 'int',
14333: krb4 => 'krb4',
14334: krb5 => 'krb5',
14335: localauth => 'loc',
14336: );
14337: $value = $authnames{$shortauth{$value}};
14338: }
14339: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14340: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14341: }
14342: }
14343: $resulttext .= '</ul>';
14344: $mailmsgtext .= "\n";
14345: my $cachetime = 24*60*60;
1.72 raeburn 14346: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 14347: if (ref($lastactref) eq 'HASH') {
14348: $lastactref->{'domdefaults'} = 1;
14349: }
1.68 raeburn 14350: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 14351: my $notify = 1;
14352: if (ref($domconfig{'contacts'}) eq 'HASH') {
14353: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14354: $notify = 0;
14355: }
14356: }
14357: if ($notify) {
14358: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14359: "LON-CAPA Domain Settings Change - $dom",
14360: $mailmsgtext);
14361: }
1.54 raeburn 14362: }
1.43 raeburn 14363: } else {
1.54 raeburn 14364: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14365: }
14366: } else {
14367: $resulttext = '<span class="LC_error">'.
14368: &mt('An error occurred: [_1]',$putresult).'</span>';
14369: }
14370: if (@errors > 0) {
14371: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14372: foreach my $item (@errors) {
14373: $resulttext .= ' "'.$title->{$item}.'",';
14374: }
14375: $resulttext =~ s/,$//;
14376: }
14377: return $resulttext;
14378: }
14379:
1.46 raeburn 14380: sub modify_scantron {
1.160.6.24 raeburn 14381: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14382: my ($resulttext,%confhash,%changes,$errors);
14383: my $custom = 'custom.tab';
14384: my $default = 'default.tab';
14385: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 14386: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 14387: &config_check($dom,$confname,$servadm);
14388: if ($env{'form.scantronformat.filename'} ne '') {
14389: my $error;
14390: if ($configuserok eq 'ok') {
14391: if ($switchserver) {
1.130 raeburn 14392: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14393: } else {
14394: if ($author_ok eq 'ok') {
14395: my ($result,$scantronurl) =
14396: &publishlogo($r,'upload','scantronformat',$dom,
14397: $confname,'scantron','','',$custom);
14398: if ($result eq 'ok') {
14399: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14400: $changes{'scantronformat'} = 1;
1.46 raeburn 14401: } else {
14402: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14403: }
14404: } else {
14405: $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);
14406: }
14407: }
14408: } else {
14409: $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);
14410: }
14411: if ($error) {
14412: &Apache::lonnet::logthis($error);
14413: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14414: }
14415: }
1.48 raeburn 14416: if (ref($domconfig{'scantron'}) eq 'HASH') {
14417: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14418: if ($env{'form.scantronformat_del'}) {
14419: $confhash{'scantron'}{'scantronformat'} = '';
14420: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 14421: } else {
14422: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
14423: }
14424: }
14425: }
14426: my @options = ('hdr','pad','rem');
14427: my @fields = &scantroncsv_fields();
14428: my %titles = &scantronconfig_titles();
14429: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
14430: my ($newdat,$currdat,%newcol,%currcol);
14431: if (grep(/^dat$/,@formats)) {
14432: $confhash{'scantron'}{config}{dat} = 1;
14433: $newdat = 1;
14434: } else {
14435: $newdat = 0;
14436: }
14437: if (grep(/^csv$/,@formats)) {
14438: my %bynum;
14439: foreach my $field (@fields) {
14440: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
14441: my $posscol = $1;
14442: if (($posscol < 20) && (!$bynum{$posscol})) {
14443: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
14444: $bynum{$posscol} = $field;
14445: $newcol{$field} = $posscol;
14446: }
14447: }
14448: }
14449: if (keys(%newcol)) {
14450: foreach my $option (@options) {
14451: if ($env{'form.scantroncsv_'.$option}) {
14452: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
14453: }
14454: }
14455: }
14456: }
14457: $currdat = 1;
14458: if (ref($domconfig{'scantron'}) eq 'HASH') {
14459: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
14460: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
14461: $currdat = 0;
14462: }
14463: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14464: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14465: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
14466: }
14467: }
14468: }
14469: }
14470: if ($currdat != $newdat) {
14471: $changes{'config'} = 1;
14472: } else {
14473: foreach my $field (@fields) {
14474: if ($currcol{$field} ne '') {
14475: if ($currcol{$field} ne $newcol{$field}) {
14476: $changes{'config'} = 1;
14477: last;
14478: }
14479: } elsif ($newcol{$field} ne '') {
14480: $changes{'config'} = 1;
14481: last;
1.46 raeburn 14482: }
14483: }
14484: }
14485: if (keys(%confhash) > 0) {
14486: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14487: $dom);
14488: if ($putresult eq 'ok') {
14489: if (keys(%changes) > 0) {
1.48 raeburn 14490: if (ref($confhash{'scantron'}) eq 'HASH') {
14491: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 14492: if ($changes{'scantronformat'}) {
14493: if ($confhash{'scantron'}{'scantronformat'} eq '') {
14494: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
14495: } else {
14496: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
14497: }
14498: }
14499: if ($changes{'config'}) {
14500: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
14501: if ($confhash{'scantron'}{'config'}{'dat'}) {
14502: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
14503: }
14504: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14505: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14506: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
14507: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
14508: foreach my $field (@fields) {
14509: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
14510: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
14511: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
14512: }
14513: }
14514: $resulttext .= '</ul></li>';
14515: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
14516: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
14517: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
14518: foreach my $option (@options) {
14519: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
14520: $resulttext .= '<li>'.$titles{$option}.'</li>';
14521: }
14522: }
14523: $resulttext .= '</ul></li>';
14524: }
14525: }
14526: }
14527: }
14528: }
14529: } else {
14530: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
14531: }
1.46 raeburn 14532: }
1.48 raeburn 14533: $resulttext .= '</ul>';
14534: } else {
1.130 raeburn 14535: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14536: }
14537: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14538: if (ref($lastactref) eq 'HASH') {
14539: $lastactref->{'domainconfig'} = 1;
14540: }
1.46 raeburn 14541: } else {
1.160.6.97 raeburn 14542: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 14543: }
14544: } else {
14545: $resulttext = '<span class="LC_error">'.
14546: &mt('An error occurred: [_1]',$putresult).'</span>';
14547: }
14548: } else {
1.160.6.97 raeburn 14549: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 14550: }
14551: if ($errors) {
14552: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14553: $errors.'</ul>';
14554: }
14555: return $resulttext;
14556: }
14557:
1.48 raeburn 14558: sub modify_coursecategories {
1.160.6.43 raeburn 14559: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14560: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14561: $cathash);
1.48 raeburn 14562: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 14563: my @catitems = ('unauth','auth');
14564: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14565: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14566: $cathash = $domconfig{'coursecategories'}{'cats'};
14567: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14568: $changes{'togglecats'} = 1;
14569: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14570: }
14571: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14572: $changes{'categorize'} = 1;
14573: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14574: }
1.120 raeburn 14575: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14576: $changes{'togglecatscomm'} = 1;
14577: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14578: }
14579: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14580: $changes{'categorizecomm'} = 1;
14581: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
14582: }
1.160.6.42 raeburn 14583: foreach my $item (@catitems) {
14584: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14585: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14586: $changes{$item} = 1;
14587: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14588: }
14589: }
14590: }
1.57 raeburn 14591: } else {
14592: $changes{'togglecats'} = 1;
14593: $changes{'categorize'} = 1;
1.124 raeburn 14594: $changes{'togglecatscomm'} = 1;
14595: $changes{'categorizecomm'} = 1;
1.87 raeburn 14596: $domconfig{'coursecategories'} = {
14597: togglecats => $env{'form.togglecats'},
14598: categorize => $env{'form.categorize'},
1.124 raeburn 14599: togglecatscomm => $env{'form.togglecatscomm'},
14600: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 14601: };
1.160.6.42 raeburn 14602: foreach my $item (@catitems) {
14603: if ($env{'form.coursecat_'.$item} ne 'std') {
14604: $changes{$item} = 1;
14605: }
14606: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14607: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14608: }
14609: }
1.57 raeburn 14610: }
14611: if (ref($cathash) eq 'HASH') {
14612: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14613: push (@deletecategory,'instcode::0');
14614: }
1.120 raeburn 14615: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14616: push(@deletecategory,'communities::0');
14617: }
1.48 raeburn 14618: }
1.57 raeburn 14619: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14620: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14621: if (@deletecategory > 0) {
14622: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14623: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14624: foreach my $item (@deletecategory) {
1.57 raeburn 14625: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14626: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14627: $deletions{$item} = 1;
1.57 raeburn 14628: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14629: }
14630: }
14631: }
1.57 raeburn 14632: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14633: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14634: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14635: $reorderings{$item} = 1;
1.57 raeburn 14636: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14637: }
14638: if ($env{'form.addcategory_name_'.$item} ne '') {
14639: my $newcat = $env{'form.addcategory_name_'.$item};
14640: my $newdepth = $depth+1;
14641: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14642: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14643: $adds{$newitem} = 1;
14644: }
14645: if ($env{'form.subcat_'.$item} ne '') {
14646: my $newcat = $env{'form.subcat_'.$item};
14647: my $newdepth = $depth+1;
14648: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14649: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14650: $adds{$newitem} = 1;
14651: }
14652: }
14653: }
14654: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14655: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14656: my $newitem = 'instcode::0';
1.57 raeburn 14657: if ($cathash->{$newitem} eq '') {
14658: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14659: $adds{$newitem} = 1;
14660: }
14661: } else {
14662: my $newitem = 'instcode::0';
1.57 raeburn 14663: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14664: $adds{$newitem} = 1;
14665: }
14666: }
1.120 raeburn 14667: if ($env{'form.communities'} eq '1') {
14668: if (ref($cathash) eq 'HASH') {
14669: my $newitem = 'communities::0';
14670: if ($cathash->{$newitem} eq '') {
14671: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14672: $adds{$newitem} = 1;
14673: }
14674: } else {
14675: my $newitem = 'communities::0';
14676: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14677: $adds{$newitem} = 1;
14678: }
14679: }
1.48 raeburn 14680: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14681: if (($env{'form.addcategory_name'} ne 'instcode') &&
14682: ($env{'form.addcategory_name'} ne 'communities')) {
14683: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14684: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14685: $adds{$newitem} = 1;
14686: }
1.48 raeburn 14687: }
1.57 raeburn 14688: my $putresult;
1.48 raeburn 14689: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14690: if (keys(%deletions) > 0) {
14691: foreach my $key (keys(%deletions)) {
14692: if ($predelallitems{$key} ne '') {
14693: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14694: }
14695: }
14696: }
14697: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14698: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14699: if (ref($chkcats[0]) eq 'ARRAY') {
14700: my $depth = 0;
14701: my $chg = 0;
14702: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14703: my $name = $chkcats[0][$i];
14704: my $item;
14705: if ($name eq '') {
14706: $chg ++;
14707: } else {
14708: $item = &escape($name).'::0';
14709: if ($chg) {
1.57 raeburn 14710: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14711: }
14712: $depth ++;
1.57 raeburn 14713: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14714: $depth --;
14715: }
14716: }
14717: }
1.57 raeburn 14718: }
14719: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14720: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14721: if ($putresult eq 'ok') {
1.57 raeburn 14722: my %title = (
1.120 raeburn 14723: togglecats => 'Show/Hide a course in catalog',
14724: categorize => 'Assign a category to a course',
14725: togglecatscomm => 'Show/Hide a community in catalog',
14726: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14727: );
14728: my %level = (
1.120 raeburn 14729: dom => 'set in Domain ("Modify Course/Community")',
14730: crs => 'set in Course ("Course Configuration")',
14731: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 14732: none => 'No catalog',
14733: std => 'Standard catalog',
14734: domonly => 'Domain-only catalog',
14735: codesrch => 'Code search form',
1.57 raeburn 14736: );
1.48 raeburn 14737: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14738: if ($changes{'togglecats'}) {
14739: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14740: }
14741: if ($changes{'categorize'}) {
14742: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14743: }
1.120 raeburn 14744: if ($changes{'togglecatscomm'}) {
14745: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14746: }
14747: if ($changes{'categorizecomm'}) {
14748: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14749: }
1.160.6.42 raeburn 14750: if ($changes{'unauth'}) {
14751: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14752: }
14753: if ($changes{'auth'}) {
14754: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14755: }
1.57 raeburn 14756: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14757: my $cathash;
14758: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14759: $cathash = $domconfig{'coursecategories'}{'cats'};
14760: } else {
14761: $cathash = {};
14762: }
14763: my (@cats,@trails,%allitems);
14764: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
14765: if (keys(%deletions) > 0) {
14766: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
14767: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
14768: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
14769: }
14770: $resulttext .= '</ul></li>';
14771: }
14772: if (keys(%reorderings) > 0) {
14773: my %sort_by_trail;
14774: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
14775: foreach my $key (keys(%reorderings)) {
14776: if ($allitems{$key} ne '') {
14777: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14778: }
1.48 raeburn 14779: }
1.57 raeburn 14780: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14781: $resulttext .= '<li>'.$trails[$trail].'</li>';
14782: }
14783: $resulttext .= '</ul></li>';
1.48 raeburn 14784: }
1.57 raeburn 14785: if (keys(%adds) > 0) {
14786: my %sort_by_trail;
14787: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
14788: foreach my $key (keys(%adds)) {
14789: if ($allitems{$key} ne '') {
14790: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14791: }
14792: }
14793: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14794: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 14795: }
1.57 raeburn 14796: $resulttext .= '</ul></li>';
1.48 raeburn 14797: }
1.160.6.92 raeburn 14798: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
14799: if (ref($lastactref) eq 'HASH') {
14800: $lastactref->{'cats'} = 1;
14801: }
1.48 raeburn 14802: }
14803: $resulttext .= '</ul>';
1.160.6.43 raeburn 14804: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 14805: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14806: if ($changes{'auth'}) {
14807: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
14808: }
14809: if ($changes{'unauth'}) {
14810: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
14811: }
14812: my $cachetime = 24*60*60;
14813: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 14814: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 14815: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 14816: }
14817: }
1.48 raeburn 14818: } else {
14819: $resulttext = '<span class="LC_error">'.
1.57 raeburn 14820: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 14821: }
14822: } else {
1.120 raeburn 14823: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 14824: }
14825: return $resulttext;
14826: }
14827:
1.69 raeburn 14828: sub modify_serverstatuses {
14829: my ($dom,%domconfig) = @_;
14830: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
14831: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
14832: %currserverstatus = %{$domconfig{'serverstatuses'}};
14833: }
14834: my @pages = &serverstatus_pages();
14835: foreach my $type (@pages) {
14836: $newserverstatus{$type}{'namedusers'} = '';
14837: $newserverstatus{$type}{'machines'} = '';
14838: if (defined($env{'form.'.$type.'_namedusers'})) {
14839: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
14840: my @okusers;
14841: foreach my $user (@users) {
14842: my ($uname,$udom) = split(/:/,$user);
14843: if (($udom =~ /^$match_domain$/) &&
14844: (&Apache::lonnet::domain($udom)) &&
14845: ($uname =~ /^$match_username$/)) {
14846: if (!grep(/^\Q$user\E/,@okusers)) {
14847: push(@okusers,$user);
14848: }
14849: }
14850: }
14851: if (@okusers > 0) {
14852: @okusers = sort(@okusers);
14853: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
14854: }
14855: }
14856: if (defined($env{'form.'.$type.'_machines'})) {
14857: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
14858: my @okmachines;
14859: foreach my $ip (@machines) {
14860: my @parts = split(/\./,$ip);
14861: next if (@parts < 4);
14862: my $badip = 0;
14863: for (my $i=0; $i<4; $i++) {
14864: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
14865: $badip = 1;
14866: last;
14867: }
14868: }
14869: if (!$badip) {
14870: push(@okmachines,$ip);
14871: }
14872: }
14873: @okmachines = sort(@okmachines);
14874: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
14875: }
14876: }
14877: my %serverstatushash = (
14878: serverstatuses => \%newserverstatus,
14879: );
14880: foreach my $type (@pages) {
1.83 raeburn 14881: foreach my $setting ('namedusers','machines') {
1.84 raeburn 14882: my (@current,@new);
1.83 raeburn 14883: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 14884: if ($currserverstatus{$type}{$setting} ne '') {
14885: @current = split(/,/,$currserverstatus{$type}{$setting});
14886: }
14887: }
14888: if ($newserverstatus{$type}{$setting} ne '') {
14889: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 14890: }
14891: if (@current > 0) {
14892: if (@new > 0) {
14893: foreach my $item (@current) {
14894: if (!grep(/^\Q$item\E$/,@new)) {
14895: $changes{$type}{$setting} = 1;
1.82 raeburn 14896: last;
14897: }
14898: }
1.84 raeburn 14899: foreach my $item (@new) {
14900: if (!grep(/^\Q$item\E$/,@current)) {
14901: $changes{$type}{$setting} = 1;
14902: last;
1.82 raeburn 14903: }
14904: }
14905: } else {
1.83 raeburn 14906: $changes{$type}{$setting} = 1;
1.69 raeburn 14907: }
1.83 raeburn 14908: } elsif (@new > 0) {
14909: $changes{$type}{$setting} = 1;
1.69 raeburn 14910: }
14911: }
14912: }
14913: if (keys(%changes) > 0) {
1.81 raeburn 14914: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 14915: my $putresult = &Apache::lonnet::put_dom('configuration',
14916: \%serverstatushash,$dom);
14917: if ($putresult eq 'ok') {
14918: $resulttext .= &mt('Changes made:').'<ul>';
14919: foreach my $type (@pages) {
1.84 raeburn 14920: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 14921: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 14922: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 14923: if ($newserverstatus{$type}{'namedusers'} eq '') {
14924: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
14925: } else {
14926: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
14927: }
1.84 raeburn 14928: }
14929: if ($changes{$type}{'machines'}) {
1.69 raeburn 14930: if ($newserverstatus{$type}{'machines'} eq '') {
14931: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
14932: } else {
14933: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
14934: }
14935:
14936: }
14937: $resulttext .= '</ul></li>';
14938: }
14939: }
14940: $resulttext .= '</ul>';
14941: } else {
14942: $resulttext = '<span class="LC_error">'.
14943: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
14944:
14945: }
14946: } else {
14947: $resulttext = &mt('No changes made to access to server status pages');
14948: }
14949: return $resulttext;
14950: }
14951:
1.118 jms 14952: sub modify_helpsettings {
1.160.6.77 raeburn 14953: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 14954: my ($resulttext,$errors,%changes,%helphash);
14955: my %defaultchecked = ('submitbugs' => 'on');
14956: my @offon = ('off','on');
1.118 jms 14957: my @toggles = ('submitbugs');
1.160.6.77 raeburn 14958: my %current = ('submitbugs' => '',
14959: 'adhoc' => {},
14960: );
1.118 jms 14961: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 14962: %current = %{$domconfig{'helpsettings'}};
14963: }
1.160.6.77 raeburn 14964: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 14965: foreach my $item (@toggles) {
14966: if ($defaultchecked{$item} eq 'on') {
14967: if ($current{$item} eq '') {
14968: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 14969: $changes{$item} = 1;
14970: }
1.160.6.73 raeburn 14971: } elsif ($current{$item} ne $env{'form.'.$item}) {
14972: $changes{$item} = 1;
14973: }
14974: } elsif ($defaultchecked{$item} eq 'off') {
14975: if ($current{$item} eq '') {
14976: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 14977: $changes{$item} = 1;
14978: }
1.160.6.73 raeburn 14979: } elsif ($current{$item} ne $env{'form.'.$item}) {
14980: $changes{$item} = 1;
14981: }
14982: }
14983: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
14984: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
14985: }
14986: }
1.160.6.77 raeburn 14987: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 14988: my $confname = $dom.'-domainconfig';
14989: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 14990: my (@allpos,%newsettings,%changedprivs,$newrole);
14991: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 14992: my @accesstypes = ('all','dh','da','none','status','inc','exc');
14993: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 14994: my %lt = &Apache::lonlocal::texthash(
14995: s => 'system',
14996: d => 'domain',
14997: order => 'Display order',
14998: access => 'Role usage',
1.160.6.79 raeburn 14999: all => 'All with domain helpdesk or helpdesk assistant role',
15000: dh => 'All with domain helpdesk role',
15001: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 15002: none => 'None',
15003: status => 'Determined based on institutional status',
15004: inc => 'Include all, but exclude specific personnel',
15005: exc => 'Exclude all, but include specific personnel',
15006: );
15007: for (my $num=0; $num<=$maxnum; $num++) {
15008: my ($prefix,$identifier,$rolename,%curr);
15009: if ($num == $maxnum) {
15010: next unless ($env{'form.newcusthelp'} == $maxnum);
15011: $identifier = 'custhelp'.$num;
15012: $prefix = 'helproles_'.$num;
15013: $rolename = $env{'form.custhelpname'.$num};
15014: $rolename=~s/[^A-Za-z0-9]//gs;
15015: next if ($rolename eq '');
15016: next if (exists($existing{'rolesdef_'.$rolename}));
15017: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15018: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15019: $newprivs{'c'},$confname,$dom);
15020: if ($result ne 'ok') {
15021: $errors .= '<li><span class="LC_error">'.
15022: &mt('An error occurred storing the new custom role: [_1]',
15023: $result).'</span></li>';
15024: next;
15025: } else {
15026: $changedprivs{$rolename} = \%newprivs;
15027: $newrole = $rolename;
15028: }
15029: } else {
15030: $prefix = 'helproles_'.$num;
15031: $rolename = $env{'form.'.$prefix};
15032: next if ($rolename eq '');
15033: next unless (exists($existing{'rolesdef_'.$rolename}));
15034: $identifier = 'custhelp'.$num;
15035: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15036: my %currprivs;
15037: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
15038: split(/\_/,$existing{'rolesdef_'.$rolename});
15039: foreach my $level ('c','d','s') {
15040: if ($newprivs{$level} ne $currprivs{$level}) {
15041: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15042: $newprivs{'c'},$confname,$dom);
15043: if ($result ne 'ok') {
15044: $errors .= '<li><span class="LC_error">'.
15045: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15046: $rolename,$result).'</span></li>';
15047: } else {
15048: $changedprivs{$rolename} = \%newprivs;
15049: }
15050: last;
15051: }
15052: }
15053: if (ref($current{'adhoc'}) eq 'HASH') {
15054: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15055: %curr = %{$current{'adhoc'}{$rolename}};
15056: }
15057: }
15058: }
15059: my $newpos = $env{'form.'.$prefix.'_pos'};
15060: $newpos =~ s/\D+//g;
15061: $allpos[$newpos] = $rolename;
15062: my $newdesc = $env{'form.'.$prefix.'_desc'};
15063: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15064: if ($curr{'desc'}) {
15065: if ($curr{'desc'} ne $newdesc) {
15066: $changes{'customrole'}{$rolename}{'desc'} = 1;
15067: $newsettings{$rolename}{'desc'} = $newdesc;
15068: }
15069: } elsif ($newdesc ne '') {
15070: $changes{'customrole'}{$rolename}{'desc'} = 1;
15071: $newsettings{$rolename}{'desc'} = $newdesc;
15072: }
15073: my $access = $env{'form.'.$prefix.'_access'};
15074: if (grep(/^\Q$access\E$/,@accesstypes)) {
15075: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15076: if ($access eq 'status') {
15077: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15078: if (scalar(@statuses) == 0) {
15079: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
15080: } else {
15081: my (@shownstatus,$numtypes);
15082: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15083: if (ref($types) eq 'ARRAY') {
15084: $numtypes = scalar(@{$types});
15085: foreach my $type (sort(@statuses)) {
15086: if ($type eq 'default') {
15087: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15088: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15089: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15090: push(@shownstatus,$usertypes->{$type});
15091: }
1.160.6.73 raeburn 15092: }
15093: }
1.160.6.77 raeburn 15094: if (grep(/^default$/,@statuses)) {
15095: push(@shownstatus,$othertitle);
15096: }
15097: if (scalar(@shownstatus) == 1+$numtypes) {
15098: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15099: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15100: } else {
15101: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15102: if (ref($curr{'status'}) eq 'ARRAY') {
15103: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15104: if (@diffs) {
15105: $changes{'customrole'}{$rolename}{$access} = 1;
15106: }
15107: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15108: $changes{'customrole'}{$rolename}{$access} = 1;
15109: }
15110: }
15111: }
15112: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15113: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15114: my @newspecstaff;
15115: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15116: foreach my $person (sort(@personnel)) {
15117: if ($domhelpdesk{$person}) {
15118: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15119: }
15120: }
15121: if (ref($curr{$access}) eq 'ARRAY') {
15122: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15123: if (@diffs) {
15124: $changes{'customrole'}{$rolename}{$access} = 1;
15125: }
15126: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15127: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 15128: }
1.160.6.77 raeburn 15129: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15130: my ($uname,$udom) = split(/:/,$person);
15131: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15132: }
15133: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 15134: }
1.160.6.77 raeburn 15135: } else {
15136: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15137: }
15138: unless ($curr{'access'} eq $access) {
15139: $changes{'customrole'}{$rolename}{'access'} = 1;
15140: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 15141: }
15142: }
1.160.6.77 raeburn 15143: if (@allpos > 0) {
15144: my $idx = 0;
15145: foreach my $rolename (@allpos) {
15146: if ($rolename ne '') {
15147: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15148: if (ref($current{'adhoc'}) eq 'HASH') {
15149: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15150: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15151: $changes{'customrole'}{$rolename}{'order'} = 1;
15152: $newsettings{$rolename}{'order'} = $idx+1;
15153: }
15154: }
1.160.6.73 raeburn 15155: }
1.160.6.77 raeburn 15156: $idx ++;
1.122 jms 15157: }
15158: }
1.118 jms 15159: }
1.123 jms 15160: my $putresult;
15161: if (keys(%changes) > 0) {
1.160.6.5 raeburn 15162: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
15163: if ($putresult eq 'ok') {
1.160.6.77 raeburn 15164: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15165: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15166: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15167: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15168: }
15169: }
15170: my $cachetime = 24*60*60;
15171: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15172: if (ref($lastactref) eq 'HASH') {
15173: $lastactref->{'domdefaults'} = 1;
15174: }
15175: } else {
15176: $errors .= '<li><span class="LC_error">'.
15177: &mt('An error occurred storing the settings: [_1]',
15178: $putresult).'</span></li>';
15179: }
15180: }
15181: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15182: $resulttext = &mt('Changes made:').'<ul>';
15183: my (%shownprivs,@levelorder);
15184: @levelorder = ('c','d','s');
15185: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 15186: foreach my $item (sort(keys(%changes))) {
15187: if ($item eq 'submitbugs') {
15188: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15189: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15190: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 15191: } elsif ($item eq 'customrole') {
15192: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 15193: my @keyorder = ('order','desc','access','status','exc','inc');
15194: my %keytext = &Apache::lonlocal::texthash(
15195: order => 'Order',
15196: desc => 'Role description',
15197: access => 'Role usage',
1.160.6.83 raeburn 15198: status => 'Allowed institutional types',
1.160.6.77 raeburn 15199: exc => 'Allowed personnel',
15200: inc => 'Disallowed personnel',
15201: );
1.160.6.73 raeburn 15202: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 15203: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15204: if ($role eq $newrole) {
15205: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15206: $role).'<ul>';
15207: } else {
15208: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15209: $role).'<ul>';
15210: }
15211: foreach my $key (@keyorder) {
15212: if ($changes{'customrole'}{$role}{$key}) {
15213: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15214: $keytext{$key},$newsettings{$role}{$key}).
15215: '</li>';
15216: }
15217: }
15218: if (ref($changedprivs{$role}) eq 'HASH') {
15219: $shownprivs{$role} = 1;
15220: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15221: foreach my $level (@levelorder) {
15222: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15223: next if ($item eq '');
15224: my ($priv) = split(/\&/,$item,2);
15225: if (&Apache::lonnet::plaintext($priv)) {
15226: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15227: unless ($level eq 'c') {
15228: $resulttext .= ' ('.$lt{$level}.')';
15229: }
15230: $resulttext .= '</li>';
15231: }
15232: }
15233: }
15234: $resulttext .= '</ul>';
15235: }
15236: $resulttext .= '</ul></li>';
15237: }
1.160.6.73 raeburn 15238: }
15239: }
1.160.6.5 raeburn 15240: }
15241: }
15242: }
1.160.6.77 raeburn 15243: if (keys(%changedprivs)) {
15244: foreach my $role (sort(keys(%changedprivs))) {
15245: unless ($shownprivs{$role}) {
15246: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15247: $role).'<ul>'.
15248: '<li>'.&mt('Privileges set to :').'<ul>';
15249: foreach my $level (@levelorder) {
15250: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15251: next if ($item eq '');
15252: my ($priv) = split(/\&/,$item,2);
15253: if (&Apache::lonnet::plaintext($priv)) {
15254: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15255: unless ($level eq 'c') {
15256: $resulttext .= ' ('.$lt{$level}.')';
15257: }
15258: $resulttext .= '</li>';
15259: }
15260: }
15261: }
15262: $resulttext .= '</ul></li></ul></li>';
15263: }
15264: }
15265: }
15266: $resulttext .= '</ul>';
15267: } else {
15268: $resulttext = &mt('No changes made to help settings');
1.118 jms 15269: }
15270: if ($errors) {
1.160.6.5 raeburn 15271: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 15272: $errors.'</ul>';
1.118 jms 15273: }
15274: return $resulttext;
15275: }
15276:
1.121 raeburn 15277: sub modify_coursedefaults {
1.160.6.27 raeburn 15278: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15279: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 15280: my %defaultchecked = (
15281: 'uselcmath' => 'on',
15282: 'usejsme' => 'on'
15283: );
15284: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 15285: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 15286: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
15287: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 15288: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 15289: my %staticdefaults = (
15290: anonsurvey_threshold => 10,
15291: uploadquota => 500,
1.160.6.57 raeburn 15292: postsubmit => 60,
1.160.6.70 raeburn 15293: mysqltables => 172800,
1.160.6.21 raeburn 15294: );
1.160.6.90 raeburn 15295: my %texoptions = (
15296: MathJax => 'MathJax',
15297: mimetex => &mt('Convert to Images'),
15298: tth => &mt('TeX to HTML'),
15299: );
1.121 raeburn 15300: $defaultshash{'coursedefaults'} = {};
15301:
15302: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15303: if ($domconfig{'coursedefaults'} eq '') {
15304: $domconfig{'coursedefaults'} = {};
15305: }
15306: }
15307:
15308: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15309: foreach my $item (@toggles) {
15310: if ($defaultchecked{$item} eq 'on') {
15311: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15312: ($env{'form.'.$item} eq '0')) {
15313: $changes{$item} = 1;
1.160.6.16 raeburn 15314: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15315: $changes{$item} = 1;
15316: }
15317: } elsif ($defaultchecked{$item} eq 'off') {
15318: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15319: ($env{'form.'.$item} eq '1')) {
15320: $changes{$item} = 1;
15321: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15322: $changes{$item} = 1;
15323: }
15324: }
15325: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15326: }
1.160.6.21 raeburn 15327: foreach my $item (@numbers) {
15328: my ($currdef,$newdef);
1.160.6.26 raeburn 15329: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 15330: if ($item eq 'anonsurvey_threshold') {
15331: $currdef = $domconfig{'coursedefaults'}{$item};
15332: $newdef =~ s/\D//g;
15333: if ($newdef eq '' || $newdef < 1) {
15334: $newdef = 1;
15335: }
15336: $defaultshash{'coursedefaults'}{$item} = $newdef;
15337: } else {
1.160.6.70 raeburn 15338: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15339: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15340: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 15341: }
15342: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 15343: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 15344: }
15345: if ($currdef ne $newdef) {
15346: if ($item eq 'anonsurvey_threshold') {
15347: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15348: $changes{$item} = 1;
15349: }
1.160.6.70 raeburn 15350: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
15351: my $setting = $1;
15352: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15353: $changes{$setting} = 1;
1.160.6.21 raeburn 15354: }
15355: }
1.139 raeburn 15356: }
15357: }
1.160.6.90 raeburn 15358: my $texengine;
15359: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15360: $texengine = $env{'form.texengine'};
15361: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
15362: if ($currdef eq '') {
15363: unless ($texengine eq $Apache::lonnet::deftex) {
15364: $changes{'texengine'} = 1;
15365: }
15366: } elsif ($currdef ne $texengine) {
15367: $changes{'texengine'} = 1;
15368: }
15369: }
15370: if ($texengine ne '') {
15371: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15372: }
1.160.6.64 raeburn 15373: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15374: my @currclonecode;
15375: if (ref($currclone) eq 'HASH') {
15376: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15377: @currclonecode = @{$currclone->{'instcode'}};
15378: }
15379: }
15380: my $newclone;
15381: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
15382: $newclone = $env{'form.canclone'};
15383: }
15384: if ($newclone eq 'instcode') {
15385: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15386: my (%codedefaults,@code_order,@clonecode);
15387: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15388: \@code_order);
15389: foreach my $item (@code_order) {
15390: if (grep(/^\Q$item\E$/,@newcodes)) {
15391: push(@clonecode,$item);
15392: }
15393: }
15394: if (@clonecode) {
15395: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15396: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15397: if (@diffs) {
15398: $changes{'canclone'} = 1;
15399: }
15400: } else {
15401: $newclone eq '';
15402: }
15403: } elsif ($newclone ne '') {
15404: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15405: }
15406: if ($newclone ne $currclone) {
15407: $changes{'canclone'} = 1;
15408: }
1.160.6.57 raeburn 15409: my %credits;
15410: foreach my $type (@types) {
15411: unless ($type eq 'community') {
15412: $credits{$type} = $env{'form.'.$type.'_credits'};
15413: $credits{$type} =~ s/[^\d.]+//g;
15414: }
15415: }
15416: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15417: ($env{'form.coursecredits'} eq '1')) {
15418: $changes{'coursecredits'} = 1;
15419: foreach my $type (keys(%credits)) {
15420: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15421: }
15422: } else {
15423: if ($env{'form.coursecredits'} eq '1') {
15424: foreach my $type (@types) {
15425: unless ($type eq 'community') {
15426: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
15427: $changes{'coursecredits'} = 1;
15428: }
15429: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15430: }
15431: }
15432: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15433: foreach my $type (@types) {
15434: unless ($type eq 'community') {
15435: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15436: $changes{'coursecredits'} = 1;
15437: last;
15438: }
15439: }
15440: }
15441: }
15442: }
15443: if ($env{'form.postsubmit'} eq '1') {
15444: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15445: my %currtimeout;
15446: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15447: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15448: $changes{'postsubmit'} = 1;
15449: }
15450: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15451: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15452: }
15453: } else {
15454: $changes{'postsubmit'} = 1;
15455: }
15456: foreach my $type (@types) {
15457: my $timeout = $env{'form.'.$type.'_timeout'};
15458: $timeout =~ s/\D//g;
15459: if ($timeout == $staticdefaults{'postsubmit'}) {
15460: $timeout = '';
15461: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15462: $timeout = '0';
15463: }
15464: unless ($timeout eq '') {
15465: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15466: }
15467: if (exists($currtimeout{$type})) {
15468: if ($timeout ne $currtimeout{$type}) {
15469: $changes{'postsubmit'} = 1;
15470: }
15471: } elsif ($timeout ne '') {
15472: $changes{'postsubmit'} = 1;
15473: }
15474: }
15475: } else {
15476: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15477: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15478: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15479: $changes{'postsubmit'} = 1;
15480: }
15481: } else {
15482: $changes{'postsubmit'} = 1;
15483: }
1.160.6.16 raeburn 15484: }
1.121 raeburn 15485: }
15486: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15487: $dom);
15488: if ($putresult eq 'ok') {
15489: if (keys(%changes) > 0) {
1.160.6.27 raeburn 15490: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 15491: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 15492: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.90 raeburn 15493: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15494: foreach my $item ('uselcmath','usejsme','texengine') {
1.160.6.57 raeburn 15495: if ($changes{$item}) {
15496: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15497: }
1.160.6.16 raeburn 15498: }
15499: if ($changes{'coursecredits'}) {
15500: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 15501: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15502: $domdefaults{$type.'credits'} =
15503: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15504: }
15505: }
15506: }
15507: if ($changes{'postsubmit'}) {
15508: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15509: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15510: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15511: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15512: $domdefaults{$type.'postsubtimeout'} =
15513: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15514: }
15515: }
1.160.6.16 raeburn 15516: }
15517: }
1.160.6.21 raeburn 15518: if ($changes{'uploadquota'}) {
15519: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15520: foreach my $type (@types) {
15521: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15522: }
15523: }
15524: }
1.160.6.64 raeburn 15525: if ($changes{'canclone'}) {
15526: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15527: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15528: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15529: if (@clonecodes) {
15530: $domdefaults{'canclone'} = join('+',@clonecodes);
15531: }
15532: }
15533: } else {
15534: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15535: }
15536: }
1.121 raeburn 15537: my $cachetime = 24*60*60;
15538: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 15539: if (ref($lastactref) eq 'HASH') {
15540: $lastactref->{'domdefaults'} = 1;
15541: }
1.121 raeburn 15542: }
15543: $resulttext = &mt('Changes made:').'<ul>';
15544: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 15545: if ($item eq 'uselcmath') {
1.121 raeburn 15546: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 15547: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 15548: } else {
1.160.6.57 raeburn 15549: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15550: }
15551: } elsif ($item eq 'usejsme') {
15552: if ($env{'form.'.$item} eq '1') {
15553: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15554: } else {
15555: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 15556: }
1.160.6.90 raeburn 15557: } elsif ($item eq 'texengine') {
15558: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15559: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15560: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15561: }
1.139 raeburn 15562: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 15563: $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 15564: } elsif ($item eq 'uploadquota') {
15565: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15566: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15567: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15568: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 15569: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
15570:
1.160.6.21 raeburn 15571: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15572: '</ul>'.
15573: '</li>';
15574: } else {
15575: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15576: }
1.160.6.70 raeburn 15577: } elsif ($item eq 'mysqltables') {
15578: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15579: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15580: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15581: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15582: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15583: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15584: '</ul>'.
15585: '</li>';
15586: } else {
15587: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15588: }
1.160.6.57 raeburn 15589: } elsif ($item eq 'postsubmit') {
15590: if ($domdefaults{'postsubmit'} eq 'off') {
15591: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15592: } else {
15593: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
15594: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15595: $resulttext .= &mt('durations:').'<ul>';
15596: foreach my $type (@types) {
15597: $resulttext .= '<li>';
15598: my $timeout;
15599: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15600: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15601: }
15602: my $display;
15603: if ($timeout eq '0') {
15604: $display = &mt('unlimited');
15605: } elsif ($timeout eq '') {
15606: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15607: } else {
15608: $display = &mt('[quant,_1,second]',$timeout);
15609: }
15610: if ($type eq 'community') {
15611: $resulttext .= &mt('Communities');
15612: } elsif ($type eq 'official') {
15613: $resulttext .= &mt('Official courses');
15614: } elsif ($type eq 'unofficial') {
15615: $resulttext .= &mt('Unofficial courses');
15616: } elsif ($type eq 'textbook') {
15617: $resulttext .= &mt('Textbook courses');
15618: }
15619: $resulttext .= ' -- '.$display.'</li>';
15620: }
15621: $resulttext .= '</ul>';
15622: }
15623: $resulttext .= '</li>';
15624: }
1.160.6.16 raeburn 15625: } elsif ($item eq 'coursecredits') {
15626: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15627: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 15628: ($domdefaults{'unofficialcredits'} eq '') &&
15629: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 15630: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15631: } else {
15632: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15633: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15634: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 15635: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 15636: '</ul>'.
15637: '</li>';
15638: }
15639: } else {
15640: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15641: }
1.160.6.64 raeburn 15642: } elsif ($item eq 'canclone') {
15643: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15644: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15645: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15646: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15647: }
15648: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15649: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15650: } else {
15651: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
15652: }
1.140 raeburn 15653: }
1.121 raeburn 15654: }
15655: $resulttext .= '</ul>';
15656: } else {
15657: $resulttext = &mt('No changes made to course defaults');
15658: }
15659: } else {
15660: $resulttext = '<span class="LC_error">'.
15661: &mt('An error occurred: [_1]',$putresult).'</span>';
15662: }
15663: return $resulttext;
15664: }
15665:
1.160.6.37 raeburn 15666: sub modify_selfenrollment {
15667: my ($dom,$lastactref,%domconfig) = @_;
15668: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
15669: my @types = ('official','unofficial','community','textbook');
15670: my %titles = &tool_titles();
15671: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15672: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
15673: $ordered{'default'} = ['types','registered','approval','limit'];
15674:
15675: my (%roles,%shown,%toplevel);
15676: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15677:
15678: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15679: if ($domconfig{'selfenrollment'} eq '') {
15680: $domconfig{'selfenrollment'} = {};
15681: }
15682: }
15683: %toplevel = (
15684: admin => 'Configuration Rights',
15685: default => 'Default settings',
15686: validation => 'Validation of self-enrollment requests',
15687: );
15688: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
15689:
15690: if (ref($ordered{'admin'}) eq 'ARRAY') {
15691: foreach my $item (@{$ordered{'admin'}}) {
15692: foreach my $type (@types) {
15693: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15694: $selfenrollhash{'admin'}{$type}{$item} = 1;
15695: } else {
15696: $selfenrollhash{'admin'}{$type}{$item} = 0;
15697: }
15698: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15699: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15700: if ($selfenrollhash{'admin'}{$type}{$item} ne
15701: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15702: push(@{$changes{'admin'}{$type}},$item);
15703: }
15704: } else {
15705: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15706: push(@{$changes{'admin'}{$type}},$item);
15707: }
15708: }
15709: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15710: push(@{$changes{'admin'}{$type}},$item);
15711: }
15712: }
15713: }
15714: }
15715:
15716: foreach my $item (@{$ordered{'default'}}) {
15717: foreach my $type (@types) {
15718: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15719: if ($item eq 'types') {
15720: unless (($value eq 'all') || ($value eq 'dom')) {
15721: $value = '';
15722: }
15723: } elsif ($item eq 'registered') {
15724: unless ($value eq '1') {
15725: $value = 0;
15726: }
15727: } elsif ($item eq 'approval') {
15728: unless ($value =~ /^[012]$/) {
15729: $value = 0;
15730: }
15731: } else {
15732: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15733: $value = 'none';
15734: }
15735: }
15736: $selfenrollhash{'default'}{$type}{$item} = $value;
15737: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15738: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15739: if ($selfenrollhash{'default'}{$type}{$item} ne
15740: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15741: push(@{$changes{'default'}{$type}},$item);
15742: }
15743: } else {
15744: push(@{$changes{'default'}{$type}},$item);
15745: }
15746: } else {
15747: push(@{$changes{'default'}{$type}},$item);
15748: }
15749: if ($item eq 'limit') {
15750: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15751: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15752: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15753: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15754: }
15755: } else {
15756: $selfenrollhash{'default'}{$type}{'cap'} = '';
15757: }
15758: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15759: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15760: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15761: push(@{$changes{'default'}{$type}},'cap');
15762: }
15763: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
15764: push(@{$changes{'default'}{$type}},'cap');
15765: }
15766: }
15767: }
15768: }
15769:
15770: foreach my $item (@{$itemsref}) {
15771: if ($item eq 'fields') {
15772: my @changed;
15773: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
15774: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
15775: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
15776: }
15777: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15778: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
15779: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
15780: $domconfig{'selfenrollment'}{'validation'}{$item});
15781: } else {
15782: @changed = @{$selfenrollhash{'validation'}{$item}};
15783: }
15784: } else {
15785: @changed = @{$selfenrollhash{'validation'}{$item}};
15786: }
15787: if (@changed) {
15788: if ($selfenrollhash{'validation'}{$item}) {
15789: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
15790: } else {
15791: $changes{'validation'}{$item} = &mt('None');
15792: }
15793: }
15794: } else {
15795: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
15796: if ($item eq 'markup') {
15797: if ($env{'form.selfenroll_validation_'.$item}) {
15798: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
15799: }
15800: }
15801: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15802: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
15803: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
15804: }
15805: }
15806: }
15807: }
15808:
15809: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
15810: $dom);
15811: if ($putresult eq 'ok') {
15812: if (keys(%changes) > 0) {
15813: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15814: $resulttext = &mt('Changes made:').'<ul>';
15815: foreach my $key ('admin','default','validation') {
15816: if (ref($changes{$key}) eq 'HASH') {
15817: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
15818: if ($key eq 'validation') {
15819: foreach my $item (@{$itemsref}) {
15820: if (exists($changes{$key}{$item})) {
15821: if ($item eq 'markup') {
15822: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15823: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
15824: } else {
15825: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15826: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
15827: }
15828: }
15829: }
15830: } else {
15831: foreach my $type (@types) {
15832: if ($type eq 'community') {
15833: $roles{'1'} = &mt('Community personnel');
15834: } else {
15835: $roles{'1'} = &mt('Course personnel');
15836: }
15837: if (ref($changes{$key}{$type}) eq 'ARRAY') {
15838: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15839: if ($key eq 'admin') {
15840: my @mgrdc = ();
15841: if (ref($ordered{$key}) eq 'ARRAY') {
15842: foreach my $item (@{$ordered{'admin'}}) {
15843: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15844: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
15845: push(@mgrdc,$item);
15846: }
15847: }
15848: }
15849: if (@mgrdc) {
15850: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
15851: } else {
15852: delete($domdefaults{$type.'selfenrolladmdc'});
15853: }
15854: }
15855: } else {
15856: if (ref($ordered{$key}) eq 'ARRAY') {
15857: foreach my $item (@{$ordered{$key}}) {
15858: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15859: $domdefaults{$type.'selfenroll'.$item} =
15860: $selfenrollhash{$key}{$type}{$item};
15861: }
15862: }
15863: }
15864: }
15865: }
15866: $resulttext .= '<li>'.$titles{$type}.'<ul>';
15867: foreach my $item (@{$ordered{$key}}) {
15868: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15869: $resulttext .= '<li>';
15870: if ($key eq 'admin') {
15871: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
15872: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
15873: } else {
15874: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
15875: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
15876: }
15877: $resulttext .= '</li>';
15878: }
15879: }
15880: $resulttext .= '</ul></li>';
15881: }
15882: }
15883: $resulttext .= '</ul></li>';
15884: }
15885: }
1.160.6.93 raeburn 15886: }
15887: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
15888: my $cachetime = 24*60*60;
15889: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15890: if (ref($lastactref) eq 'HASH') {
15891: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 15892: }
15893: }
15894: $resulttext .= '</ul>';
15895: } else {
15896: $resulttext = &mt('No changes made to self-enrollment settings');
15897: }
15898: } else {
15899: $resulttext = '<span class="LC_error">'.
15900: &mt('An error occurred: [_1]',$putresult).'</span>';
15901: }
15902: return $resulttext;
15903: }
15904:
1.137 raeburn 15905: sub modify_usersessions {
1.160.6.27 raeburn 15906: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 15907: my @hostingtypes = ('version','excludedomain','includedomain');
15908: my @offloadtypes = ('primary','default');
15909: my %types = (
15910: remote => \@hostingtypes,
15911: hosted => \@hostingtypes,
15912: spares => \@offloadtypes,
15913: );
15914: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 15915: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 15916: my (%by_ip,%by_location,@intdoms);
15917: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
15918: my @locations = sort(keys(%by_location));
1.137 raeburn 15919: my (%defaultshash,%changes);
15920: foreach my $prefix (@prefixes) {
15921: $defaultshash{'usersessions'}{$prefix} = {};
15922: }
1.160.6.27 raeburn 15923: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 15924: my $resulttext;
1.138 raeburn 15925: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 15926: foreach my $prefix (@prefixes) {
1.145 raeburn 15927: next if ($prefix eq 'spares');
15928: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 15929: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
15930: if ($type eq 'version') {
15931: my $value = $env{'form.'.$prefix.'_'.$type};
15932: my $okvalue;
15933: if ($value ne '') {
15934: if (grep(/^\Q$value\E$/,@lcversions)) {
15935: $okvalue = $value;
15936: }
15937: }
15938: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15939: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15940: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
15941: if ($inuse == 0) {
15942: $changes{$prefix}{$type} = 1;
15943: } else {
15944: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
15945: $changes{$prefix}{$type} = 1;
15946: }
15947: if ($okvalue ne '') {
15948: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
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: if (($inuse == 1) && ($okvalue ne '')) {
15965: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15966: $changes{$prefix}{$type} = 1;
15967: }
15968: }
15969: } else {
15970: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
15971: my @okvals;
15972: foreach my $val (@vals) {
1.138 raeburn 15973: if ($val =~ /:/) {
15974: my @items = split(/:/,$val);
15975: foreach my $item (@items) {
15976: if (ref($by_location{$item}) eq 'ARRAY') {
15977: push(@okvals,$item);
15978: }
15979: }
15980: } else {
15981: if (ref($by_location{$val}) eq 'ARRAY') {
15982: push(@okvals,$val);
15983: }
1.137 raeburn 15984: }
15985: }
15986: @okvals = sort(@okvals);
15987: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15988: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15989: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
15990: if ($inuse == 0) {
15991: $changes{$prefix}{$type} = 1;
15992: } else {
15993: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15994: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
15995: if (@changed > 0) {
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: } else {
16012: if ($inuse == 1) {
16013: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16014: $changes{$prefix}{$type} = 1;
16015: }
16016: }
16017: }
16018: }
16019: }
1.145 raeburn 16020:
16021: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16022: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16023: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16024: my $savespares;
16025:
16026: foreach my $lonhost (sort(keys(%servers))) {
16027: my $serverhomeID =
16028: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16029: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16030: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16031: my %spareschg;
16032: foreach my $type (@{$types{'spares'}}) {
16033: my @okspares;
16034: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16035: foreach my $server (@checked) {
1.152 raeburn 16036: if (&Apache::lonnet::hostname($server) ne '') {
16037: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16038: unless (grep(/^\Q$server\E$/,@okspares)) {
16039: push(@okspares,$server);
16040: }
1.145 raeburn 16041: }
16042: }
16043: }
16044: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16045: my $newspare;
1.152 raeburn 16046: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16047: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16048: $newspare = $new;
16049: }
16050: }
1.152 raeburn 16051: my @spares;
16052: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16053: @spares = sort(@okspares,$newspare);
16054: } else {
16055: @spares = sort(@okspares);
16056: }
16057: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16058: if (ref($spareid{$lonhost}) eq 'HASH') {
16059: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16060: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16061: if (@diffs > 0) {
16062: $spareschg{$type} = 1;
16063: }
16064: }
16065: }
16066: }
16067: if (keys(%spareschg) > 0) {
16068: $changes{'spares'}{$lonhost} = \%spareschg;
16069: }
16070: }
1.160.6.61 raeburn 16071: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.102.2 4(raebur 16072:0): $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 16073: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16074: my @okoffload;
16075: if (@offloadnow) {
16076: foreach my $server (@offloadnow) {
16077: if (&Apache::lonnet::hostname($server) ne '') {
16078: unless (grep(/^\Q$server\E$/,@okoffload)) {
16079: push(@okoffload,$server);
16080: }
16081: }
16082: }
16083: if (@okoffload) {
16084: foreach my $lonhost (@okoffload) {
16085: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16086: }
16087: }
16088: }
1.160.6.102.2 4(raebur 16089:0): my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
16090:0): my @okoffloadoth;
16091:0): if (@offloadoth) {
16092:0): foreach my $server (@offloadoth) {
16093:0): if (&Apache::lonnet::hostname($server) ne '') {
16094:0): unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
16095:0): push(@okoffloadoth,$server);
16096:0): }
16097:0): }
16098:0): }
16099:0): if (@okoffloadoth) {
16100:0): foreach my $lonhost (@okoffloadoth) {
16101:0): $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
16102:0): }
16103:0): }
16104:0): }
1.145 raeburn 16105: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16106: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16107: if (ref($changes{'spares'}) eq 'HASH') {
16108: if (keys(%{$changes{'spares'}}) > 0) {
16109: $savespares = 1;
16110: }
16111: }
16112: } else {
16113: $savespares = 1;
16114: }
1.160.6.102.2 4(raebur 16115:0): foreach my $offload ('offloadnow','offloadoth') {
16116:0): if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
16117:0): foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
16118:0): unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
16119:0): $changes{$offload} = 1;
1.160.6.61 raeburn 16120: last;
16121: }
16122: }
1.160.6.102.2 4(raebur 16123:0): unless ($changes{$offload}) {
16124:0): foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
16125:0): unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
16126:0): $changes{$offload} = 1;
16127:0): last;
16128:0): }
16129:0): }
16130:0): }
16131:0): } else {
16132:0): if (($offload eq 'offloadnow') && (@okoffload)) {
16133:0): $changes{'offloadnow'} = 1;
16134:0): }
16135:0): if (($offload eq 'offloadoth') && (@okoffloadoth)) {
16136:0): $changes{'offloadoth'} = 1;
16137:0): }
1.160.6.61 raeburn 16138: }
1.160.6.102.2 4(raebur 16139:0): }
16140:0): } else {
16141:0): if (@okoffload) {
1.160.6.61 raeburn 16142: $changes{'offloadnow'} = 1;
16143: }
1.160.6.102.2 4(raebur 16144:0): if (@okoffloadoth) {
16145:0): $changes{'offloadoth'} = 1;
16146:0): }
1.145 raeburn 16147: }
1.147 raeburn 16148: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16149: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16150: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16151: $dom);
16152: if ($putresult eq 'ok') {
16153: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16154: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16155: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16156: }
16157: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16158: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16159: }
1.160.6.61 raeburn 16160: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16161: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16162: }
1.160.6.102.2 4(raebur 16163:0): if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
16164:0): $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
16165:0): }
1.137 raeburn 16166: }
16167: my $cachetime = 24*60*60;
16168: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 16169: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 16170: if (ref($lastactref) eq 'HASH') {
16171: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 16172: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 16173: }
1.147 raeburn 16174: if (keys(%changes) > 0) {
16175: my %lt = &usersession_titles();
16176: $resulttext = &mt('Changes made:').'<ul>';
16177: foreach my $prefix (@prefixes) {
16178: if (ref($changes{$prefix}) eq 'HASH') {
16179: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16180: if ($prefix eq 'spares') {
16181: if (ref($changes{$prefix}) eq 'HASH') {
16182: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16183: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16184: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 16185: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16186: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16187: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16188: foreach my $type (@{$types{$prefix}}) {
16189: if ($changes{$prefix}{$lonhost}{$type}) {
16190: my $offloadto = &mt('None');
16191: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16192: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16193: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16194: }
1.145 raeburn 16195: }
1.147 raeburn 16196: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16197: }
1.137 raeburn 16198: }
16199: }
1.147 raeburn 16200: $resulttext .= '</li>';
1.137 raeburn 16201: }
16202: }
1.147 raeburn 16203: } else {
16204: foreach my $type (@{$types{$prefix}}) {
16205: if (defined($changes{$prefix}{$type})) {
16206: my $newvalue;
16207: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16208: if (ref($defaultshash{'usersessions'}{$prefix})) {
16209: if ($type eq 'version') {
16210: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
16211: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16212: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16213: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16214: }
1.145 raeburn 16215: }
16216: }
16217: }
1.147 raeburn 16218: if ($newvalue eq '') {
16219: if ($type eq 'version') {
16220: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
16221: } else {
16222: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16223: }
1.145 raeburn 16224: } else {
1.147 raeburn 16225: if ($type eq 'version') {
16226: $newvalue .= ' '.&mt('(or later)');
16227: }
16228: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 16229: }
1.137 raeburn 16230: }
16231: }
16232: }
1.147 raeburn 16233: $resulttext .= '</ul>';
1.137 raeburn 16234: }
16235: }
1.160.6.61 raeburn 16236: if ($changes{'offloadnow'}) {
16237: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16238: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.102.2 4(raebur 16239:0): $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 16240: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
16241: $resulttext .= '<li>'.$lonhost.'</li>';
16242: }
16243: $resulttext .= '</ul>';
16244: } else {
1.160.6.102.2 4(raebur 16245:0): $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
16246:0): }
16247:0): } else {
16248:0): $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
16249:0): }
16250:0): }
16251:0): if ($changes{'offloadoth'}) {
16252:0): if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
16253:0): if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
16254:0): $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
16255:0): foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
16256:0): $resulttext .= '<li>'.$lonhost.'</li>';
16257:0): }
16258:0): $resulttext .= '</ul>';
16259:0): } else {
16260:0): $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 16261: }
16262: } else {
1.160.6.102.2 4(raebur 16263:0): $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 16264: }
16265: }
1.147 raeburn 16266: $resulttext .= '</ul>';
16267: } else {
16268: $resulttext = $nochgmsg;
1.137 raeburn 16269: }
16270: } else {
16271: $resulttext = '<span class="LC_error">'.
16272: &mt('An error occurred: [_1]',$putresult).'</span>';
16273: }
16274: } else {
1.147 raeburn 16275: $resulttext = $nochgmsg;
1.137 raeburn 16276: }
16277: return $resulttext;
16278: }
16279:
1.150 raeburn 16280: sub modify_loadbalancing {
16281: my ($dom,%domconfig) = @_;
16282: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16283: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16284: my ($othertitle,$usertypes,$types) =
16285: &Apache::loncommon::sorted_inst_types($dom);
16286: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 16287: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 16288: my @sparestypes = ('primary','default');
16289: my %typetitles = &sparestype_titles();
16290: my $resulttext;
1.160.6.94 raeburn 16291: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 16292: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16293: %existing = %{$domconfig{'loadbalancing'}};
16294: }
16295: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 16296: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 16297: my ($saveloadbalancing,%defaultshash,%changes);
16298: my ($alltypes,$othertypes,$titles) =
16299: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16300: my %ruletitles = &offloadtype_text();
16301: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16302: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16303: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16304: if ($balancer eq '') {
16305: next;
16306: }
16307: if (!exists($servers{$balancer})) {
16308: if (exists($currbalancer{$balancer})) {
16309: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 16310: }
1.160.6.7 raeburn 16311: next;
16312: }
16313: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16314: push(@{$changes{'delete'}},$balancer);
16315: next;
16316: }
16317: if (!exists($currbalancer{$balancer})) {
16318: push(@{$changes{'add'}},$balancer);
16319: }
16320: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16321: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16322: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16323: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16324: $saveloadbalancing = 1;
16325: }
16326: foreach my $sparetype (@sparestypes) {
16327: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16328: my @offloadto;
16329: foreach my $target (@targets) {
16330: if (($servers{$target}) && ($target ne $balancer)) {
16331: if ($sparetype eq 'default') {
16332: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16333: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 16334: }
16335: }
1.160.6.7 raeburn 16336: unless(grep(/^\Q$target\E$/,@offloadto)) {
16337: push(@offloadto,$target);
16338: }
1.150 raeburn 16339: }
16340: }
1.160.6.76 raeburn 16341: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16342: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16343: push(@offloadto,$balancer);
16344: }
16345: }
16346: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 16347: }
1.160.6.94 raeburn 16348: if ($env{'form.loadbalancing_cookie_'.$i}) {
16349: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
16350: if (exists($currbalancer{$balancer})) {
16351: unless ($currcookies{$balancer}) {
16352: $changes{'curr'}{$balancer}{'cookie'} = 1;
16353: }
16354: }
16355: } elsif (exists($currbalancer{$balancer})) {
16356: if ($currcookies{$balancer}) {
16357: $changes{'curr'}{$balancer}{'cookie'} = 1;
16358: }
16359: }
1.160.6.7 raeburn 16360: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 16361: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 16362: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16363: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 16364: if (@targetdiffs > 0) {
1.160.6.7 raeburn 16365: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16366: }
1.160.6.7 raeburn 16367: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16368: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16369: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16370: }
16371: }
16372: }
16373: } else {
1.160.6.7 raeburn 16374: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
16375: foreach my $sparetype (@sparestypes) {
16376: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16377: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16378: $changes{'curr'}{$balancer}{'targets'} = 1;
16379: }
1.150 raeburn 16380: }
16381: }
1.160.6.7 raeburn 16382: }
1.150 raeburn 16383: }
16384: my $ishomedom;
1.160.6.7 raeburn 16385: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16386: $ishomedom = 1;
1.150 raeburn 16387: }
16388: if (ref($alltypes) eq 'ARRAY') {
16389: foreach my $type (@{$alltypes}) {
16390: my $rule;
1.160.6.7 raeburn 16391: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 16392: (!$ishomedom)) {
1.160.6.7 raeburn 16393: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16394: }
16395: if ($rule eq 'specific') {
1.160.6.55 raeburn 16396: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
16397: if (exists($servers{$specifiedhost})) {
16398: $rule = $specifiedhost;
16399: }
1.150 raeburn 16400: }
1.160.6.7 raeburn 16401: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16402: if (ref($currrules{$balancer}) eq 'HASH') {
16403: if ($rule ne $currrules{$balancer}{$type}) {
16404: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16405: }
16406: } elsif ($rule ne '') {
1.160.6.7 raeburn 16407: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16408: }
16409: }
16410: }
1.160.6.7 raeburn 16411: }
16412: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
16413: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
16414: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
16415: $defaultshash{'loadbalancing'} = {};
16416: }
16417: my $putresult = &Apache::lonnet::put_dom('configuration',
16418: \%defaultshash,$dom);
16419: if ($putresult eq 'ok') {
16420: if (keys(%changes) > 0) {
1.160.6.54 raeburn 16421: my %toupdate;
1.160.6.7 raeburn 16422: if (ref($changes{'delete'}) eq 'ARRAY') {
16423: foreach my $balancer (sort(@{$changes{'delete'}})) {
16424: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 16425: $toupdate{$balancer} = 1;
1.150 raeburn 16426: }
1.160.6.7 raeburn 16427: }
16428: if (ref($changes{'add'}) eq 'ARRAY') {
16429: foreach my $balancer (sort(@{$changes{'add'}})) {
16430: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 16431: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 16432: }
16433: }
16434: if (ref($changes{'curr'}) eq 'HASH') {
16435: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 16436: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 16437: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
16438: if ($changes{'curr'}{$balancer}{'targets'}) {
16439: my %offloadstr;
16440: foreach my $sparetype (@sparestypes) {
16441: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16442: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16443: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16444: }
16445: }
1.150 raeburn 16446: }
1.160.6.7 raeburn 16447: if (keys(%offloadstr) == 0) {
16448: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 16449: } else {
1.160.6.7 raeburn 16450: my $showoffload;
16451: foreach my $sparetype (@sparestypes) {
16452: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
16453: if (defined($offloadstr{$sparetype})) {
16454: $showoffload .= $offloadstr{$sparetype};
16455: } else {
16456: $showoffload .= &mt('None');
16457: }
16458: $showoffload .= (' 'x3);
16459: }
16460: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 16461: }
16462: }
16463: }
1.160.6.7 raeburn 16464: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
16465: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
16466: foreach my $type (@{$alltypes}) {
16467: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
16468: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16469: my $balancetext;
16470: if ($rule eq '') {
16471: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 16472: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 16473: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
16474: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 16475: foreach my $sparetype (@sparestypes) {
16476: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16477: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16478: }
16479: }
1.160.6.55 raeburn 16480: foreach my $item (@{$alltypes}) {
16481: next if ($item =~ /^_LC_ipchange/);
16482: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
16483: if ($hasrule eq 'homeserver') {
16484: map { $toupdate{$_} = 1; } (keys(%libraryservers));
16485: } else {
16486: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
16487: if ($servers{$hasrule}) {
16488: $toupdate{$hasrule} = 1;
16489: }
16490: }
16491: }
16492: }
16493: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
16494: $balancetext = $ruletitles{$rule};
16495: } else {
16496: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16497: $balancetext = $ruletitles{'particular'}.' '.$receiver;
16498: if ($receiver) {
16499: $toupdate{$receiver};
16500: }
16501: }
16502: } else {
16503: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 16504: }
1.160.6.7 raeburn 16505: } else {
16506: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
16507: }
1.160.6.26 raeburn 16508: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 16509: }
16510: }
16511: }
16512: }
1.160.6.94 raeburn 16513: if ($changes{'curr'}{$balancer}{'cookie'}) {
16514: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
16515: $balancer).'</li>';
16516: }
1.160.6.102.2 6(raebur 16517:1): }
16518:1): }
16519:1): if (keys(%toupdate)) {
16520:1): my %thismachine;
16521:1): my $updatedhere;
16522:1): my $cachetime = 60*60*24;
16523:1): map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
16524:1): foreach my $lonhost (keys(%toupdate)) {
16525:1): if ($thismachine{$lonhost}) {
16526:1): unless ($updatedhere) {
16527:1): &Apache::lonnet::do_cache_new('loadbalancing',$dom,
16528:1): $defaultshash{'loadbalancing'},
16529:1): $cachetime);
16530:1): $updatedhere = 1;
1.160.6.54 raeburn 16531: }
1.160.6.102.2 6(raebur 16532:1): } else {
16533:1): my $cachekey = &escape('loadbalancing').':'.&escape($dom);
16534:1): &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 16535: }
1.150 raeburn 16536: }
1.160.6.7 raeburn 16537: }
16538: if ($resulttext ne '') {
16539: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 16540: } else {
16541: $resulttext = $nochgmsg;
16542: }
16543: } else {
1.160.6.7 raeburn 16544: $resulttext = $nochgmsg;
1.150 raeburn 16545: }
16546: } else {
1.160.6.7 raeburn 16547: $resulttext = '<span class="LC_error">'.
16548: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 16549: }
16550: } else {
1.160.6.7 raeburn 16551: $resulttext = $nochgmsg;
1.150 raeburn 16552: }
16553: return $resulttext;
16554: }
16555:
1.48 raeburn 16556: sub recurse_check {
16557: my ($chkcats,$categories,$depth,$name) = @_;
16558: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
16559: my $chg = 0;
16560: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
16561: my $category = $chkcats->[$depth]{$name}[$j];
16562: my $item;
16563: if ($category eq '') {
16564: $chg ++;
16565: } else {
16566: my $deeper = $depth + 1;
16567: $item = &escape($category).':'.&escape($name).':'.$depth;
16568: if ($chg) {
16569: $categories->{$item} -= $chg;
16570: }
16571: &recurse_check($chkcats,$categories,$deeper,$category);
16572: $deeper --;
16573: }
16574: }
16575: }
16576: return;
16577: }
16578:
16579: sub recurse_cat_deletes {
16580: my ($item,$coursecategories,$deletions) = @_;
16581: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16582: my $subdepth = $depth + 1;
16583: if (ref($coursecategories) eq 'HASH') {
16584: foreach my $subitem (keys(%{$coursecategories})) {
16585: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
16586: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
16587: delete($coursecategories->{$subitem});
16588: $deletions->{$subitem} = 1;
16589: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 16590: }
1.48 raeburn 16591: }
16592: }
16593: return;
16594: }
16595:
1.125 raeburn 16596: sub active_dc_picker {
1.160.6.16 raeburn 16597: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 16598: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 16599: my @domcoord = keys(%domcoords);
16600: if (keys(%currhash)) {
16601: foreach my $dc (keys(%currhash)) {
16602: unless (exists($domcoords{$dc})) {
16603: push(@domcoord,$dc);
16604: }
16605: }
16606: }
16607: @domcoord = sort(@domcoord);
16608: my $numdcs = scalar(@domcoord);
16609: my $rows = 0;
16610: my $table;
1.125 raeburn 16611: if ($numdcs > 1) {
1.160.6.16 raeburn 16612: $table = '<table>';
16613: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 16614: my $rem = $i%($numinrow);
16615: if ($rem == 0) {
16616: if ($i > 0) {
1.160.6.16 raeburn 16617: $table .= '</tr>';
1.125 raeburn 16618: }
1.160.6.16 raeburn 16619: $table .= '<tr>';
16620: $rows ++;
1.125 raeburn 16621: }
1.160.6.16 raeburn 16622: my $check = '';
16623: if ($inputtype eq 'radio') {
16624: if (keys(%currhash) == 0) {
16625: if (!$i) {
16626: $check = ' checked="checked"';
16627: }
16628: } elsif (exists($currhash{$domcoord[$i]})) {
16629: $check = ' checked="checked"';
16630: }
16631: } else {
16632: if (exists($currhash{$domcoord[$i]})) {
16633: $check = ' checked="checked"';
1.125 raeburn 16634: }
16635: }
1.160.6.16 raeburn 16636: if ($i == @domcoord - 1) {
1.125 raeburn 16637: my $colsleft = $numinrow - $rem;
16638: if ($colsleft > 1) {
1.160.6.16 raeburn 16639: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 16640: } else {
1.160.6.16 raeburn 16641: $table .= '<td class="LC_left_item">';
1.125 raeburn 16642: }
16643: } else {
1.160.6.16 raeburn 16644: $table .= '<td class="LC_left_item">';
16645: }
16646: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
16647: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
16648: $table .= '<span class="LC_nobreak"><label>'.
16649: '<input type="'.$inputtype.'" name="'.$name.'"'.
16650: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
16651: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 16652: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 16653: }
1.160.6.33 raeburn 16654: $table .= '</label></span></td>';
1.125 raeburn 16655: }
1.160.6.16 raeburn 16656: $table .= '</tr></table>';
16657: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 16658: my ($dcname,$dcdom) = split(':',$domcoord[0]);
16659: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 16660: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 16661: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 16662: if ($user ne $dcname.':'.$dcdom) {
16663: $table .= ' ('.$dcname.':'.$dcdom.')';
16664: }
1.160.6.16 raeburn 16665: } else {
16666: my $check;
16667: if (exists($currhash{$domcoord[0]})) {
16668: $check = ' checked="checked"';
16669: }
1.160.6.50 raeburn 16670: $table = '<span class="LC_nobreak"><label>'.
16671: '<input type="checkbox" name="'.$name.'" '.
16672: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 16673: if ($user ne $dcname.':'.$dcdom) {
16674: $table .= ' ('.$dcname.':'.$dcdom.')';
16675: }
16676: $table .= '</label></span>';
1.160.6.16 raeburn 16677: $rows ++;
16678: }
1.125 raeburn 16679: }
1.160.6.16 raeburn 16680: return ($numdcs,$table,$rows);
1.125 raeburn 16681: }
16682:
1.137 raeburn 16683: sub usersession_titles {
16684: return &Apache::lonlocal::texthash(
16685: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
16686: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 16687: spares => 'Servers offloaded to, when busy',
1.137 raeburn 16688: version => 'LON-CAPA version requirement',
1.138 raeburn 16689: excludedomain => 'Allow all, but exclude specific domains',
16690: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 16691: primary => 'Primary (checked first)',
1.154 raeburn 16692: default => 'Default',
1.137 raeburn 16693: );
16694: }
16695:
1.152 raeburn 16696: sub id_for_thisdom {
16697: my (%servers) = @_;
16698: my %altids;
16699: foreach my $server (keys(%servers)) {
16700: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
16701: if ($serverhome ne $server) {
16702: $altids{$serverhome} = $server;
16703: }
16704: }
16705: return %altids;
16706: }
16707:
1.150 raeburn 16708: sub count_servers {
16709: my ($currbalancer,%servers) = @_;
16710: my (@spares,$numspares);
16711: foreach my $lonhost (sort(keys(%servers))) {
16712: next if ($currbalancer eq $lonhost);
16713: push(@spares,$lonhost);
16714: }
16715: if ($currbalancer) {
16716: $numspares = scalar(@spares);
16717: } else {
16718: $numspares = scalar(@spares) - 1;
16719: }
16720: return ($numspares,@spares);
16721: }
16722:
16723: sub lonbalance_targets_js {
1.160.6.7 raeburn 16724: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 16725: my $select = &mt('Select');
16726: my ($alltargets,$allishome,$allinsttypes,@alltypes);
16727: if (ref($servers) eq 'HASH') {
16728: $alltargets = join("','",sort(keys(%{$servers})));
16729: my @homedoms;
16730: foreach my $server (sort(keys(%{$servers}))) {
16731: if (&Apache::lonnet::host_domain($server) eq $dom) {
16732: push(@homedoms,'1');
16733: } else {
16734: push(@homedoms,'0');
16735: }
16736: }
16737: $allishome = join("','",@homedoms);
16738: }
16739: if (ref($types) eq 'ARRAY') {
16740: if (@{$types} > 0) {
16741: @alltypes = @{$types};
16742: }
16743: }
16744: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
16745: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 16746: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 16747: if (ref($settings) eq 'HASH') {
16748: %existing = %{$settings};
16749: }
16750: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 16751: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 16752: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 16753: return <<"END";
16754:
16755: <script type="text/javascript">
16756: // <![CDATA[
16757:
1.160.6.7 raeburn 16758: currBalancers = new Array('$balancers');
16759:
16760: function toggleTargets(balnum) {
16761: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
16762: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
16763: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
16764: var prevbalancer = prevhostitem.value;
16765: var baltotal = document.getElementById('loadbalancing_total').value;
16766: prevhostitem.value = balancer;
16767: if (prevbalancer != '') {
16768: var prevIdx = currBalancers.indexOf(prevbalancer);
16769: if (prevIdx != -1) {
16770: currBalancers.splice(prevIdx,1);
16771: }
16772: }
1.150 raeburn 16773: if (balancer == '') {
1.160.6.7 raeburn 16774: hideSpares(balnum);
1.150 raeburn 16775: } else {
1.160.6.7 raeburn 16776: var currIdx = currBalancers.indexOf(balancer);
16777: if (currIdx == -1) {
16778: currBalancers.push(balancer);
16779: }
1.150 raeburn 16780: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 16781: var ishomedom = homedoms[lonhostitem.selectedIndex];
16782: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 16783: }
1.160.6.7 raeburn 16784: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 16785: return;
16786: }
16787:
1.160.6.7 raeburn 16788: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 16789: var alltargets = new Array('$alltargets');
16790: var insttypes = new Array('$allinsttypes');
1.151 raeburn 16791: var offloadtypes = new Array('primary','default');
16792:
1.160.6.7 raeburn 16793: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
16794: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 16795:
1.151 raeburn 16796: for (var i=0; i<offloadtypes.length; i++) {
16797: var count = 0;
16798: for (var j=0; j<alltargets.length; j++) {
16799: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 16800: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
16801: item.value = alltargets[j];
16802: item.style.textAlign='left';
16803: item.style.textFace='normal';
16804: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
16805: if (currBalancers.indexOf(alltargets[j]) == -1) {
16806: item.disabled = '';
16807: } else {
16808: item.disabled = 'disabled';
16809: item.checked = false;
16810: }
1.151 raeburn 16811: count ++;
16812: }
1.150 raeburn 16813: }
16814: }
1.151 raeburn 16815: for (var k=0; k<insttypes.length; k++) {
16816: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 16817: if (ishomedom == 1) {
1.160.6.7 raeburn 16818: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
16819: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 16820: } else {
1.160.6.7 raeburn 16821: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
16822: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 16823: }
16824: } else {
1.160.6.7 raeburn 16825: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
16826: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 16827: }
1.151 raeburn 16828: if ((insttypes[k] != '_LC_external') &&
16829: ((insttypes[k] != '_LC_internetdom') ||
16830: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 16831: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
16832: item.options.length = 0;
16833: item.options[0] = new Option("","",true,true);
16834: var idx = 0;
1.151 raeburn 16835: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 16836: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
16837: idx ++;
16838: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 16839: }
16840: }
16841: }
16842: }
16843: return;
16844: }
16845:
1.160.6.7 raeburn 16846: function hideSpares(balnum) {
1.150 raeburn 16847: var alltargets = new Array('$alltargets');
16848: var insttypes = new Array('$allinsttypes');
16849: var offloadtypes = new Array('primary','default');
16850:
1.160.6.7 raeburn 16851: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
16852: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 16853:
16854: var total = alltargets.length - 1;
16855: for (var i=0; i<offloadtypes; i++) {
16856: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 16857: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
16858: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
16859: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 16860: }
1.150 raeburn 16861: }
16862: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 16863: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
16864: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 16865: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 16866: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
16867: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 16868: }
16869: }
16870: return;
16871: }
16872:
1.160.6.7 raeburn 16873: function checkOffloads(item,balnum,type) {
1.150 raeburn 16874: var alltargets = new Array('$alltargets');
16875: var offloadtypes = new Array('primary','default');
16876: if (item.checked) {
16877: var total = alltargets.length - 1;
16878: var other;
16879: if (type == offloadtypes[0]) {
1.151 raeburn 16880: other = offloadtypes[1];
1.150 raeburn 16881: } else {
1.151 raeburn 16882: other = offloadtypes[0];
1.150 raeburn 16883: }
16884: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 16885: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 16886: if (server == item.value) {
1.160.6.7 raeburn 16887: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
16888: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 16889: }
16890: }
16891: }
16892: }
16893: return;
16894: }
16895:
1.160.6.7 raeburn 16896: function singleServerToggle(balnum,type) {
16897: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 16898: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 16899: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
16900: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 16901:
16902: } else {
1.160.6.7 raeburn 16903: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
16904: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 16905: }
16906: return;
16907: }
16908:
1.160.6.7 raeburn 16909: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 16910: if (type == '_LC_external') {
1.160.6.26 raeburn 16911: return;
1.150 raeburn 16912: }
1.160.6.7 raeburn 16913: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 16914: for (var i=0; i<typesRules.length; i++) {
16915: if (formname.elements[typesRules[i]].checked) {
16916: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 16917: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
16918: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 16919: } else {
1.160.6.7 raeburn 16920: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
16921: }
16922: }
16923: }
16924: return;
16925: }
16926:
16927: function balancerDeleteChange(balnum) {
16928: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
16929: var baltotal = document.getElementById('loadbalancing_total').value;
16930: var addtarget;
16931: var removetarget;
16932: var action = 'delete';
16933: if (document.getElementById('loadbalancing_delete_'+balnum)) {
16934: var lonhost = hostitem.value;
16935: var currIdx = currBalancers.indexOf(lonhost);
16936: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
16937: if (currIdx != -1) {
16938: currBalancers.splice(currIdx,1);
16939: }
16940: addtarget = lonhost;
16941: } else {
16942: if (currIdx == -1) {
16943: currBalancers.push(lonhost);
16944: }
16945: removetarget = lonhost;
16946: action = 'undelete';
16947: }
16948: balancerChange(balnum,baltotal,action,addtarget,removetarget);
16949: }
16950: return;
16951: }
16952:
16953: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
16954: if (baltotal > 1) {
16955: var offloadtypes = new Array('primary','default');
16956: var alltargets = new Array('$alltargets');
16957: var insttypes = new Array('$allinsttypes');
16958: for (var i=0; i<baltotal; i++) {
16959: if (i != balnum) {
16960: for (var j=0; j<offloadtypes.length; j++) {
16961: var total = alltargets.length - 1;
16962: for (var k=0; k<total; k++) {
16963: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
16964: var server = serveritem.value;
16965: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16966: if (server == addtarget) {
16967: serveritem.disabled = '';
16968: }
16969: }
16970: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16971: if (server == removetarget) {
16972: serveritem.disabled = 'disabled';
16973: serveritem.checked = false;
16974: }
16975: }
16976: }
16977: }
16978: for (var j=0; j<insttypes.length; j++) {
16979: if (insttypes[j] != '_LC_external') {
16980: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
16981: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
16982: var currSel = singleserver.selectedIndex;
16983: var currVal = singleserver.options[currSel].value;
16984: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16985: var numoptions = singleserver.options.length;
16986: var needsnew = 1;
16987: for (var k=0; k<numoptions; k++) {
16988: if (singleserver.options[k] == addtarget) {
16989: needsnew = 0;
16990: break;
16991: }
16992: }
16993: if (needsnew == 1) {
16994: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
16995: }
16996: }
16997: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16998: singleserver.options.length = 0;
16999: if ((currVal) && (currVal != removetarget)) {
17000: singleserver.options[0] = new Option("","",false,false);
17001: } else {
17002: singleserver.options[0] = new Option("","",true,true);
17003: }
17004: var idx = 0;
17005: for (var m=0; m<alltargets.length; m++) {
17006: if (currBalancers.indexOf(alltargets[m]) == -1) {
17007: idx ++;
17008: if (currVal == alltargets[m]) {
17009: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17010: } else {
17011: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17012: }
17013: }
17014: }
17015: }
17016: }
17017: }
17018: }
1.150 raeburn 17019: }
17020: }
17021: }
17022: return;
17023: }
17024:
1.152 raeburn 17025: // ]]>
17026: </script>
17027:
17028: END
17029: }
17030:
17031: sub new_spares_js {
17032: my @sparestypes = ('primary','default');
17033: my $types = join("','",@sparestypes);
17034: my $select = &mt('Select');
17035: return <<"END";
17036:
17037: <script type="text/javascript">
17038: // <![CDATA[
17039:
17040: function updateNewSpares(formname,lonhost) {
17041: var types = new Array('$types');
17042: var include = new Array();
17043: var exclude = new Array();
17044: for (var i=0; i<types.length; i++) {
17045: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17046: for (var j=0; j<spareboxes.length; j++) {
17047: if (formname.elements[spareboxes[j]].checked) {
17048: exclude.push(formname.elements[spareboxes[j]].value);
17049: } else {
17050: include.push(formname.elements[spareboxes[j]].value);
17051: }
17052: }
17053: }
17054: for (var i=0; i<types.length; i++) {
17055: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17056: var selIdx = newSpare.selectedIndex;
17057: var currnew = newSpare.options[selIdx].value;
17058: var okSpares = new Array();
17059: for (var j=0; j<newSpare.options.length; j++) {
17060: var possible = newSpare.options[j].value;
17061: if (possible != '') {
17062: if (exclude.indexOf(possible) == -1) {
17063: okSpares.push(possible);
17064: } else {
17065: if (currnew == possible) {
17066: selIdx = 0;
17067: }
17068: }
17069: }
17070: }
17071: for (var k=0; k<include.length; k++) {
17072: if (okSpares.indexOf(include[k]) == -1) {
17073: okSpares.push(include[k]);
17074: }
17075: }
17076: okSpares.sort();
17077: newSpare.options.length = 0;
17078: if (selIdx == 0) {
17079: newSpare.options[0] = new Option("$select","",true,true);
17080: } else {
17081: newSpare.options[0] = new Option("$select","",false,false);
17082: }
17083: for (var m=0; m<okSpares.length; m++) {
17084: var idx = m+1;
17085: var selThis = 0;
17086: if (selIdx != 0) {
17087: if (okSpares[m] == currnew) {
17088: selThis = 1;
17089: }
17090: }
17091: if (selThis == 1) {
17092: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17093: } else {
17094: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17095: }
17096: }
17097: }
17098: return;
17099: }
17100:
17101: function checkNewSpares(lonhost,type) {
17102: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17103: var chosen = newSpare.options[newSpare.selectedIndex].value;
17104: if (chosen != '') {
17105: var othertype;
17106: var othernewSpare;
17107: if (type == 'primary') {
17108: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17109: }
17110: if (type == 'default') {
17111: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17112: }
17113: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17114: othernewSpare.selectedIndex = 0;
17115: }
17116: }
17117: return;
17118: }
17119:
17120: // ]]>
17121: </script>
17122:
17123: END
17124:
17125: }
17126:
17127: sub common_domprefs_js {
17128: return <<"END";
17129:
17130: <script type="text/javascript">
17131: // <![CDATA[
17132:
1.150 raeburn 17133: function getIndicesByName(formname,item) {
1.152 raeburn 17134: var group = new Array();
1.150 raeburn 17135: for (var i=0;i<formname.elements.length;i++) {
17136: if (formname.elements[i].name == item) {
1.152 raeburn 17137: group.push(formname.elements[i].id);
1.150 raeburn 17138: }
17139: }
1.152 raeburn 17140: return group;
1.150 raeburn 17141: }
17142:
17143: // ]]>
17144: </script>
17145:
17146: END
1.152 raeburn 17147:
1.150 raeburn 17148: }
17149:
1.160.6.5 raeburn 17150: sub recaptcha_js {
17151: my %lt = &captcha_phrases();
17152: return <<"END";
17153:
17154: <script type="text/javascript">
17155: // <![CDATA[
17156:
17157: function updateCaptcha(caller,context) {
17158: var privitem;
17159: var pubitem;
17160: var privtext;
17161: var pubtext;
1.160.6.69 raeburn 17162: var versionitem;
17163: var versiontext;
1.160.6.5 raeburn 17164: if (document.getElementById(context+'_recaptchapub')) {
17165: pubitem = document.getElementById(context+'_recaptchapub');
17166: } else {
17167: return;
17168: }
17169: if (document.getElementById(context+'_recaptchapriv')) {
17170: privitem = document.getElementById(context+'_recaptchapriv');
17171: } else {
17172: return;
17173: }
17174: if (document.getElementById(context+'_recaptchapubtxt')) {
17175: pubtext = document.getElementById(context+'_recaptchapubtxt');
17176: } else {
17177: return;
17178: }
17179: if (document.getElementById(context+'_recaptchaprivtxt')) {
17180: privtext = document.getElementById(context+'_recaptchaprivtxt');
17181: } else {
17182: return;
17183: }
1.160.6.69 raeburn 17184: if (document.getElementById(context+'_recaptchaversion')) {
17185: versionitem = document.getElementById(context+'_recaptchaversion');
17186: } else {
17187: return;
17188: }
17189: if (document.getElementById(context+'_recaptchavertxt')) {
17190: versiontext = document.getElementById(context+'_recaptchavertxt');
17191: } else {
17192: return;
17193: }
1.160.6.5 raeburn 17194: if (caller.checked) {
17195: if (caller.value == 'recaptcha') {
17196: pubitem.type = 'text';
17197: privitem.type = 'text';
17198: pubitem.size = '40';
17199: privitem.size = '40';
17200: pubtext.innerHTML = "$lt{'pub'}";
17201: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 17202: versionitem.type = 'text';
17203: versionitem.size = '3';
17204: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 17205: } else {
17206: pubitem.type = 'hidden';
17207: privitem.type = 'hidden';
1.160.6.69 raeburn 17208: versionitem.type = 'hidden';
1.160.6.5 raeburn 17209: pubtext.innerHTML = '';
17210: privtext.innerHTML = '';
1.160.6.69 raeburn 17211: versiontext.innerHTML = '';
1.160.6.5 raeburn 17212: }
17213: }
17214: return;
17215: }
17216:
17217: // ]]>
17218: </script>
17219:
17220: END
17221:
17222: }
17223:
1.160.6.40 raeburn 17224: sub toggle_display_js {
1.160.6.16 raeburn 17225: return <<"END";
17226:
17227: <script type="text/javascript">
17228: // <![CDATA[
17229:
1.160.6.40 raeburn 17230: function toggleDisplay(domForm,caller) {
17231: if (document.getElementById(caller)) {
17232: var divitem = document.getElementById(caller);
17233: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 17234: var checkval = 1;
17235: var dispval = 'block';
1.160.6.93 raeburn 17236: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 17237: if (caller == 'emailoptions') {
17238: optionsElement = domForm.cancreate_email;
17239: }
1.160.6.57 raeburn 17240: if (caller == 'studentsubmission') {
17241: optionsElement = domForm.postsubmit;
17242: }
1.160.6.64 raeburn 17243: if (caller == 'cloneinstcode') {
17244: optionsElement = domForm.canclone;
17245: checkval = 'instcode';
17246: }
1.160.6.93 raeburn 17247: if (selfcreateRegExp.test(caller)) {
17248: optionsElement = domForm.elements[caller];
17249: checkval = 'other';
17250: dispval = 'inline'
17251: }
1.160.6.40 raeburn 17252: if (optionsElement.length) {
1.160.6.16 raeburn 17253: var currval;
1.160.6.40 raeburn 17254: for (var i=0; i<optionsElement.length; i++) {
17255: if (optionsElement[i].checked) {
17256: currval = optionsElement[i].value;
1.160.6.16 raeburn 17257: }
17258: }
1.160.6.64 raeburn 17259: if (currval == checkval) {
17260: divitem.style.display = dispval;
1.160.6.16 raeburn 17261: } else {
1.160.6.40 raeburn 17262: divitem.style.display = 'none';
1.160.6.16 raeburn 17263: }
17264: }
17265: }
17266: return;
17267: }
17268:
17269: // ]]>
17270: </script>
17271:
17272: END
17273:
17274: }
17275:
1.160.6.5 raeburn 17276: sub captcha_phrases {
17277: return &Apache::lonlocal::texthash (
17278: priv => 'Private key',
17279: pub => 'Public key',
17280: original => 'original (CAPTCHA)',
17281: recaptcha => 'successor (ReCAPTCHA)',
17282: notused => 'unused',
1.160.6.69 raeburn 17283: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 17284: );
17285: }
17286:
1.160.6.24 raeburn 17287: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 17288: my ($dom,$cachekeys) = @_;
17289: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 17290: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17291: my %thismachine;
17292: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.98 raeburn 17293: my @posscached = ('domainconfig','domdefaults','usersessions',
1.160.6.102.2 1(raebur 17294:0): 'ltitools','directorysrch','passwdconf','cats');
1.160.6.61 raeburn 17295: if (keys(%servers)) {
1.160.6.24 raeburn 17296: foreach my $server (keys(%servers)) {
17297: next if ($thismachine{$server});
1.160.6.27 raeburn 17298: my @cached;
17299: foreach my $name (@posscached) {
17300: if ($cachekeys->{$name}) {
17301: push(@cached,&escape($name).':'.&escape($dom));
17302: }
17303: }
17304: if (@cached) {
17305: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17306: }
1.160.6.24 raeburn 17307: }
17308: }
17309: return;
17310: }
17311:
1.3 raeburn 17312: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>