Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.84.2.8
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.84.2. (raeburn 4:): # $Id: domainprefs.pm,v 1.160.6.84.2.7 2017/11/01 03:00:31 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: ###############################################################
1.160.6.84.2. (raeburn 30:): ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.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.84.2. (raeburn 219:): 'requestauthor','selfenrollment','inststatus',
220:): 'ltitools'],$dom);
221:): if (ref($domconfig{'ltitools'}) eq 'HASH') {
222:): my %encconfig =
223:): &Apache::lonnet::get_dom('encconfig',['ltitools'],$dom);
224:): if (ref($encconfig{'ltitools'}) eq 'HASH') {
225:): foreach my $id (keys(%{$domconfig{'ltitools'}})) {
226:): if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
227:): foreach my $item ('key','secret') {
228:): $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
229:): }
230:): }
231:): }
232:): }
233:): }
1.43 raeburn 234: my @prefs_order = ('rolecolors','login','defaults','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.84.2. (raeburn 239:): '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'},
1.160.6.80 raeburn 279: {col1 => 'Internal Authentication',
280: col2 => 'Value'},
1.160.6.40 raeburn 281: {col1 => 'Institutional user types',
282: col2 => 'Assignable to e-mail usernames'}],
1.160.6.37 raeburn 283: print => \&print_defaults,
284: modify => \&modify_defaults,
1.43 raeburn 285: },
1.30 raeburn 286: 'quotas' =>
1.160.6.20 raeburn 287: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 288: help => 'Domain_Configuration_Quotas',
1.77 raeburn 289: header => [{col1 => 'User affiliation',
1.72 raeburn 290: col2 => 'Available tools',
1.160.6.28 raeburn 291: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 292: print => \&print_quotas,
293: modify => \&modify_quotas,
1.30 raeburn 294: },
295: 'autoenroll' =>
296: { text => 'Auto-enrollment settings',
1.67 raeburn 297: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 298: header => [{col1 => 'Configuration setting',
299: col2 => 'Value(s)'}],
1.160.6.37 raeburn 300: print => \&print_autoenroll,
301: modify => \&modify_autoenroll,
1.30 raeburn 302: },
303: 'autoupdate' =>
304: { text => 'Auto-update settings',
1.67 raeburn 305: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 306: header => [{col1 => 'Setting',
307: col2 => 'Value',},
1.131 raeburn 308: {col1 => 'Setting',
309: col2 => 'Affiliation'},
1.43 raeburn 310: {col1 => 'User population',
1.160.6.35 raeburn 311: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 312: print => \&print_autoupdate,
313: modify => \&modify_autoupdate,
1.30 raeburn 314: },
1.125 raeburn 315: 'autocreate' =>
316: { text => 'Auto-course creation settings',
317: help => 'Domain_Configuration_Auto_Creation',
318: header => [{col1 => 'Configuration Setting',
319: col2 => 'Value',}],
1.160.6.37 raeburn 320: print => \&print_autocreate,
321: modify => \&modify_autocreate,
1.125 raeburn 322: },
1.30 raeburn 323: 'directorysrch' =>
1.160.6.72 raeburn 324: { text => 'Directory searches',
1.67 raeburn 325: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 326: header => [{col1 => 'Institutional Directory Setting',
327: col2 => 'Value',},
328: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 329: col2 => 'Value',}],
1.160.6.37 raeburn 330: print => \&print_directorysrch,
331: modify => \&modify_directorysrch,
1.30 raeburn 332: },
333: 'contacts' =>
1.160.6.78 raeburn 334: { text => 'E-mail addresses and helpform',
1.67 raeburn 335: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 336: header => [{col1 => 'Default e-mail addresses',
337: col2 => 'Value',},
338: {col1 => 'Recipient(s) for notifications',
339: col2 => 'Value',},
340: {col1 => 'Ask helpdesk form settings',
341: col2 => 'Value',},],
1.160.6.37 raeburn 342: print => \&print_contacts,
343: modify => \&modify_contacts,
1.30 raeburn 344: },
345: 'usercreation' =>
346: { text => 'User creation',
1.67 raeburn 347: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 348: header => [{col1 => 'Format rule type',
349: col2 => 'Format rules in force'},
1.34 raeburn 350: {col1 => 'User account creation',
351: col2 => 'Usernames which may be created',},
1.30 raeburn 352: {col1 => 'Context',
1.43 raeburn 353: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 354: print => \&print_usercreation,
355: modify => \&modify_usercreation,
1.30 raeburn 356: },
1.160.6.34 raeburn 357: 'selfcreation' =>
358: { text => 'Users self-creating accounts',
359: help => 'Domain_Configuration_Self_Creation',
360: header => [{col1 => 'Self-creation with institutional username',
361: col2 => 'Enabled?'},
362: {col1 => 'Institutional user type (login/SSO self-creation)',
363: col2 => 'Information user can enter'},
364: {col1 => 'Self-creation with e-mail as username',
365: col2 => 'Settings'}],
1.160.6.37 raeburn 366: print => \&print_selfcreation,
367: modify => \&modify_selfcreation,
1.160.6.34 raeburn 368: },
1.69 raeburn 369: 'usermodification' =>
1.33 raeburn 370: { text => 'User modification',
1.67 raeburn 371: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 372: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 373: col2 => 'User information updatable in author context'},
1.33 raeburn 374: {col1 => 'Target user has role',
1.160.6.35 raeburn 375: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 376: print => \&print_usermodification,
377: modify => \&modify_usermodification,
1.33 raeburn 378: },
1.69 raeburn 379: 'scantron' =>
1.95 www 380: { text => 'Bubblesheet format file',
1.67 raeburn 381: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 382: header => [ {col1 => 'Item',
383: col2 => '',
384: }],
1.160.6.37 raeburn 385: print => \&print_scantron,
386: modify => \&modify_scantron,
1.46 raeburn 387: },
1.86 raeburn 388: 'requestcourses' =>
389: {text => 'Request creation of courses',
390: help => 'Domain_Configuration_Request_Courses',
391: header => [{col1 => 'User affiliation',
1.102 raeburn 392: col2 => 'Availability/Processing of requests',},
393: {col1 => 'Setting',
1.160.6.30 raeburn 394: col2 => 'Value'},
395: {col1 => 'Available textbooks',
1.160.6.39 raeburn 396: col2 => ''},
1.160.6.46 raeburn 397: {col1 => 'Available templates',
398: col2 => ''},
1.160.6.39 raeburn 399: {col1 => 'Validation (not official courses)',
400: col2 => 'Value'},],
1.160.6.37 raeburn 401: print => \&print_quotas,
402: modify => \&modify_quotas,
1.86 raeburn 403: },
1.160.6.5 raeburn 404: 'requestauthor' =>
1.160.6.34 raeburn 405: {text => 'Request Authoring Space',
1.160.6.5 raeburn 406: help => 'Domain_Configuration_Request_Author',
407: header => [{col1 => 'User affiliation',
408: col2 => 'Availability/Processing of requests',},
409: {col1 => 'Setting',
410: col2 => 'Value'}],
1.160.6.37 raeburn 411: print => \&print_quotas,
412: modify => \&modify_quotas,
1.160.6.5 raeburn 413: },
1.69 raeburn 414: 'coursecategories' =>
1.120 raeburn 415: { text => 'Cataloging of courses/communities',
1.67 raeburn 416: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 417: header => [{col1 => 'Catalog type/availability',
418: col2 => '',},
419: {col1 => 'Category settings for standard catalog',
1.57 raeburn 420: col2 => '',},
421: {col1 => 'Categories',
422: col2 => '',
423: }],
1.160.6.37 raeburn 424: print => \&print_coursecategories,
425: modify => \&modify_coursecategories,
1.69 raeburn 426: },
427: 'serverstatuses' =>
1.77 raeburn 428: {text => 'Access to server status pages',
1.69 raeburn 429: help => 'Domain_Configuration_Server_Status',
430: header => [{col1 => 'Status Page',
431: col2 => 'Other named users',
432: col3 => 'Specific IPs',
433: }],
1.160.6.37 raeburn 434: print => \&print_serverstatuses,
435: modify => \&modify_serverstatuses,
1.69 raeburn 436: },
1.160.6.73 raeburn 437: 'helpsettings' =>
438: {text => 'Support settings',
439: help => 'Domain_Configuration_Help_Settings',
440: header => [{col1 => 'Help Page Settings (logged-in users)',
441: col2 => 'Value'},
442: {col1 => 'Helpdesk Roles',
443: col2 => 'Settings'},],
444: print => \&print_helpsettings,
445: modify => \&modify_helpsettings,
446: },
1.160.6.39 raeburn 447: 'coursedefaults' =>
1.160.6.16 raeburn 448: {text => 'Course/Community defaults',
449: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 450: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
451: col2 => 'Value',},
452: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 453: col2 => 'Value',},],
1.160.6.37 raeburn 454: print => \&print_coursedefaults,
455: modify => \&modify_coursedefaults,
456: },
1.160.6.39 raeburn 457: 'selfenrollment' =>
1.160.6.37 raeburn 458: {text => 'Self-enrollment in Course/Community',
459: help => 'Domain_Configuration_Selfenrollment',
460: header => [{col1 => 'Configuration Rights',
461: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
462: {col1 => 'Defaults',
463: col2 => 'Value'},
464: {col1 => 'Self-enrollment validation (optional)',
465: col2 => 'Value'},],
466: print => \&print_selfenrollment,
467: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 468: },
1.141 raeburn 469: 'usersessions' =>
1.145 raeburn 470: {text => 'User session hosting/offloading',
1.137 raeburn 471: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 472: header => [{col1 => 'Domain server',
473: col2 => 'Servers to offload sessions to when busy'},
474: {col1 => 'Hosting of users from other domains',
1.137 raeburn 475: col2 => 'Rules'},
476: {col1 => "Hosting domain's own users elsewhere",
477: col2 => 'Rules'}],
1.160.6.37 raeburn 478: print => \&print_usersessions,
479: modify => \&modify_usersessions,
1.137 raeburn 480: },
1.160.6.78 raeburn 481: 'loadbalancing' =>
1.160.6.7 raeburn 482: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 483: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 484: header => [{col1 => 'Balancers',
1.150 raeburn 485: col2 => 'Default destinations',
1.160.6.13 raeburn 486: col3 => 'User affiliation',
1.150 raeburn 487: col4 => 'Overrides'},
488: ],
1.160.6.37 raeburn 489: print => \&print_loadbalancing,
490: modify => \&modify_loadbalancing,
1.150 raeburn 491: },
1.160.6.84.2. (raeburn 492:): 'ltitools' =>
493:): {text => 'External Tools (LTI)',
494:): help => 'Domain_Configuration_LTI_Tools',
495:): header => [{col1 => 'Setting',
496:): col2 => 'Value',}],
497:): print => \&print_ltitools,
498:): modify => \&modify_ltitools,
499:): },
1.3 raeburn 500: );
1.110 raeburn 501: if (keys(%servers) > 1) {
502: $prefs{'login'} = { text => 'Log-in page options',
503: help => 'Domain_Configuration_Login_Page',
504: header => [{col1 => 'Log-in Service',
505: col2 => 'Server Setting',},
506: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 507: col2 => ''},
508: {col1 => 'Log-in Help',
1.160.6.56 raeburn 509: col2 => 'Value'},
510: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 511: col2 => 'Value'}],
1.160.6.37 raeburn 512: print => \&print_login,
513: modify => \&modify_login,
1.110 raeburn 514: };
515: }
1.160.6.13 raeburn 516:
1.6 raeburn 517: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 518: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 519: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 520: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 521: text=>"Settings to display/modify"});
1.9 raeburn 522: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 523:
1.3 raeburn 524: if ($phase eq 'process') {
1.160.6.27 raeburn 525: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
526: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 527: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 528: $r->rflush();
1.160.6.27 raeburn 529: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 530: }
1.30 raeburn 531: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 532: my $js = &recaptcha_js().
1.160.6.40 raeburn 533: &toggle_display_js();
1.160.6.7 raeburn 534: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 535: my ($othertitle,$usertypes,$types) =
536: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 537: $js .= &lonbalance_targets_js($dom,$types,\%servers,
538: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 539: &new_spares_js().
540: &common_domprefs_js().
541: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 542: }
1.160.6.30 raeburn 543: if (grep(/^requestcourses$/,@actions)) {
544: my $javascript_validations;
545: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
546: $js .= <<END;
547: <script type="text/javascript">
548: $javascript_validations
549: </script>
550: $coursebrowserjs
551: END
552: }
1.160.6.78 raeburn 553: if (grep(/^contacts$/,@actions)) {
554: $js .= &contacts_javascript();
555: }
1.150 raeburn 556: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 557: } else {
1.160.6.11 raeburn 558: # check if domconfig user exists for the domain.
559: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 560: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 561: &config_check($dom,$confname,$servadm);
562: unless ($configuserok eq 'ok') {
563: &Apache::lonconfigsettings::print_header($r,$phase,$context);
564: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
565: $confname).
566: '<br />'
567: );
568: if ($switchserver) {
569: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
570: '<br />'.
571: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
572: '<br />'.
573: &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).
574: '<br />'.
575: &mt('To do that now, use the following link: [_1]',$switchserver)
576: );
577: } else {
578: $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.').
579: '<br />'.
580: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
581: );
582: }
583: $r->print(&Apache::loncommon::end_page());
584: return OK;
585: }
1.21 raeburn 586: if (keys(%domconfig) == 0) {
587: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 588: my @ids=&Apache::lonnet::current_machine_ids();
589: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 590: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 591: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 592: my $custom_img_count = 0;
593: foreach my $img (@loginimages) {
594: if ($designhash{$dom.'.login.'.$img} ne '') {
595: $custom_img_count ++;
596: }
597: }
598: foreach my $role (@roles) {
599: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
600: $custom_img_count ++;
601: }
602: }
603: if ($custom_img_count > 0) {
1.94 raeburn 604: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 605: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 606: $r->print(
607: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
608: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
609: &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 />'.
610: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
611: if ($switch_server) {
1.30 raeburn 612: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 613: }
1.91 raeburn 614: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 615: return OK;
616: }
617: }
618: }
1.91 raeburn 619: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 620: }
621: return OK;
622: }
623:
624: sub process_changes {
1.160.6.24 raeburn 625: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 626: my %domconfig;
627: if (ref($values) eq 'HASH') {
628: %domconfig = %{$values};
629: }
1.3 raeburn 630: my $output;
631: if ($action eq 'login') {
1.160.6.24 raeburn 632: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 633: } elsif ($action eq 'rolecolors') {
1.9 raeburn 634: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 635: $lastactref,%domconfig);
1.3 raeburn 636: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 637: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 638: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 639: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 640: } elsif ($action eq 'autoupdate') {
641: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 642: } elsif ($action eq 'autocreate') {
643: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 644: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 645: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 646: } elsif ($action eq 'usercreation') {
1.28 raeburn 647: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 648: } elsif ($action eq 'selfcreation') {
649: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 650: } elsif ($action eq 'usermodification') {
651: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 652: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 653: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 654: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 655: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 656: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 657: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 658: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 659: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 660: } elsif ($action eq 'serverstatuses') {
661: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 662: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 663: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 664: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 665: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 666: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 667: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 668: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 669: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 670: } elsif ($action eq 'selfenrollment') {
671: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 672: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 673: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 674: } elsif ($action eq 'loadbalancing') {
675: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.84.2. (raeburn 676:): } elsif ($action eq 'ltitools') {
677:): $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 678: }
679: return $output;
680: }
681:
682: sub print_config_box {
1.9 raeburn 683: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 684: my $rowtotal = 0;
1.49 raeburn 685: my $output;
686: if ($action eq 'coursecategories') {
687: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 688: } elsif ($action eq 'defaults') {
689: $output = &defaults_javascript($settings);
1.160.6.73 raeburn 690: } elsif ($action eq 'helpsettings') {
691: my (%privs,%levelscurrent);
692: my %full=();
693: my %levels=(
694: course => {},
695: domain => {},
696: system => {},
697: );
698: my $context = 'domain';
699: my $crstype = 'Course';
700: my $formname = 'display';
701: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
702: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
703: $output =
704: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
705: \@templateroles);
1.91 raeburn 706: }
1.160.6.40 raeburn 707: $output .=
1.30 raeburn 708: '<table class="LC_nested_outer">
1.3 raeburn 709: <tr>
1.66 raeburn 710: <th align="left" valign="middle"><span class="LC_nobreak">'.
711: &mt($item->{text}).' '.
712: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
713: '</tr>';
1.30 raeburn 714: $rowtotal ++;
1.110 raeburn 715: my $numheaders = 1;
716: if (ref($item->{'header'}) eq 'ARRAY') {
717: $numheaders = scalar(@{$item->{'header'}});
718: }
719: if ($numheaders > 1) {
1.64 raeburn 720: my $colspan = '';
1.145 raeburn 721: my $rightcolspan = '';
1.160.6.42 raeburn 722: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 723: ($action eq 'directorysrch') ||
1.160.6.56 raeburn 724: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 725: $colspan = ' colspan="2"';
726: }
1.145 raeburn 727: if ($action eq 'usersessions') {
728: $rightcolspan = ' colspan="3"';
729: }
1.30 raeburn 730: $output .= '
1.3 raeburn 731: <tr>
732: <td>
733: <table class="LC_nested">
734: <tr class="LC_info_row">
1.59 bisitz 735: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 736: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 737: </tr>';
1.69 raeburn 738: $rowtotal ++;
1.160.6.37 raeburn 739: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 740: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 741: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78 raeburn 742: ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37 raeburn 743: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 744: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 745: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 746: } elsif ($action eq 'login') {
1.160.6.56 raeburn 747: if ($numheaders == 4) {
1.160.6.5 raeburn 748: $colspan = ' colspan="2"';
749: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
750: } else {
751: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
752: }
1.160.6.37 raeburn 753: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 754: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 755: } elsif ($action eq 'rolecolors') {
1.30 raeburn 756: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 757: }
1.30 raeburn 758: $output .= '
1.6 raeburn 759: </table>
760: </td>
761: </tr>
762: <tr>
763: <td>
764: <table class="LC_nested">
765: <tr class="LC_info_row">
1.160.6.37 raeburn 766: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 767: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 768: </tr>';
769: $rowtotal ++;
1.160.6.37 raeburn 770: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
771: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 772: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.80 raeburn 773: ($action eq 'contacts') || ($action eq 'defaults')) {
1.160.6.42 raeburn 774: if ($action eq 'coursecategories') {
775: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
776: $colspan = ' colspan="2"';
777: } else {
778: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
779: }
780: $output .= '
1.63 raeburn 781: </table>
782: </td>
783: </tr>
784: <tr>
785: <td>
786: <table class="LC_nested">
787: <tr class="LC_info_row">
788: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 789: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 790: </tr>'."\n";
791: if ($action eq 'coursecategories') {
792: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
793: } else {
794: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
795: }
1.63 raeburn 796: $rowtotal ++;
1.160.6.57 raeburn 797: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 798: ($action eq 'defaults') || ($action eq 'directorysrch') ||
799: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 800: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 801: } elsif ($action eq 'login') {
1.160.6.56 raeburn 802: if ($numheaders == 4) {
1.160.6.5 raeburn 803: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
804: </table>
805: </td>
806: </tr>
807: <tr>
808: <td>
809: <table class="LC_nested">
810: <tr class="LC_info_row">
811: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 812: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 813: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
814: $rowtotal ++;
815: } else {
816: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
817: }
1.160.6.56 raeburn 818: $output .= '
819: </table>
820: </td>
821: </tr>
822: <tr>
823: <td>
824: <table class="LC_nested">
825: <tr class="LC_info_row">';
826: if ($numheaders == 4) {
827: $output .= '
828: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
829: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
830: </tr>';
831: } else {
832: $output .= '
833: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
834: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
835: </tr>';
836: }
837: $rowtotal ++;
838: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 839: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 840: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
841: $rowtotal ++;
842: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 843: </table>
844: </td>
845: </tr>
846: <tr>
847: <td>
848: <table class="LC_nested">
849: <tr class="LC_info_row">
850: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
851: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 852: &textbookcourses_javascript($settings).
853: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
854: </table>
855: </td>
856: </tr>
857: <tr>
858: <td>
859: <table class="LC_nested">
860: <tr class="LC_info_row">
861: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
862: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
863: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 864: </table>
865: </td>
866: </tr>
867: <tr>
868: <td>
869: <table class="LC_nested">
870: <tr class="LC_info_row">
1.160.6.46 raeburn 871: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
872: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 873: </tr>'.
874: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 875: } elsif ($action eq 'requestauthor') {
876: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 877: $rowtotal ++;
1.122 jms 878: } elsif ($action eq 'rolecolors') {
1.30 raeburn 879: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 880: </table>
881: </td>
882: </tr>
883: <tr>
884: <td>
885: <table class="LC_nested">
886: <tr class="LC_info_row">
1.69 raeburn 887: <td class="LC_left_item"'.$colspan.' valign="top">'.
888: &mt($item->{'header'}->[2]->{'col1'}).'</td>
889: <td class="LC_right_item" valign="top">'.
890: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 891: </tr>'.
1.30 raeburn 892: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 893: </table>
894: </td>
895: </tr>
896: <tr>
897: <td>
898: <table class="LC_nested">
899: <tr class="LC_info_row">
1.59 bisitz 900: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
901: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 902: </tr>'.
1.30 raeburn 903: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
904: $rowtotal += 2;
1.6 raeburn 905: }
1.3 raeburn 906: } else {
1.30 raeburn 907: $output .= '
1.3 raeburn 908: <tr>
909: <td>
910: <table class="LC_nested">
1.30 raeburn 911: <tr class="LC_info_row">';
1.160.6.72 raeburn 912: if ($action eq 'login') {
1.30 raeburn 913: $output .= '
1.59 bisitz 914: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 915: } elsif ($action eq 'serverstatuses') {
916: $output .= '
917: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
918: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
919:
1.6 raeburn 920: } else {
1.30 raeburn 921: $output .= '
1.69 raeburn 922: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
923: }
1.72 raeburn 924: if (defined($item->{'header'}->[0]->{'col3'})) {
925: $output .= '<td class="LC_left_item" valign="top">'.
926: &mt($item->{'header'}->[0]->{'col2'});
927: if ($action eq 'serverstatuses') {
928: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
929: }
1.69 raeburn 930: } else {
931: $output .= '<td class="LC_right_item" valign="top">'.
932: &mt($item->{'header'}->[0]->{'col2'});
933: }
934: $output .= '</td>';
935: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 936: if (defined($item->{'header'}->[0]->{'col4'})) {
937: $output .= '<td class="LC_left_item" valign="top">'.
938: &mt($item->{'header'}->[0]->{'col3'});
939: } else {
940: $output .= '<td class="LC_right_item" valign="top">'.
941: &mt($item->{'header'}->[0]->{'col3'});
942: }
1.69 raeburn 943: if ($action eq 'serverstatuses') {
944: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
945: }
946: $output .= '</td>';
1.6 raeburn 947: }
1.150 raeburn 948: if ($item->{'header'}->[0]->{'col4'}) {
949: $output .= '<td class="LC_right_item" valign="top">'.
950: &mt($item->{'header'}->[0]->{'col4'});
951: }
1.69 raeburn 952: $output .= '</tr>';
1.48 raeburn 953: $rowtotal ++;
1.160.6.5 raeburn 954: if ($action eq 'quotas') {
1.86 raeburn 955: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 956: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.84.2. (raeburn 957:): ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
958:): ($action eq 'ltitools')) {
1.160.6.37 raeburn 959: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 960: } elsif ($action eq 'scantron') {
961: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 962: }
1.3 raeburn 963: }
1.30 raeburn 964: $output .= '
1.3 raeburn 965: </table>
966: </td>
967: </tr>
1.30 raeburn 968: </table><br />';
969: return ($output,$rowtotal);
1.1 raeburn 970: }
971:
1.3 raeburn 972: sub print_login {
1.160.6.5 raeburn 973: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 974: my ($css_class,$datatable);
1.6 raeburn 975: my %choices = &login_choices();
1.110 raeburn 976:
1.160.6.5 raeburn 977: if ($caller eq 'service') {
1.149 raeburn 978: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 979: my $choice = $choices{'disallowlogin'};
980: $css_class = ' class="LC_odd_row"';
1.128 raeburn 981: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 982: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 983: '<th>'.$choices{'server'}.'</th>'.
984: '<th>'.$choices{'serverpath'}.'</th>'.
985: '<th>'.$choices{'custompath'}.'</th>'.
986: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 987: my %disallowed;
988: if (ref($settings) eq 'HASH') {
989: if (ref($settings->{'loginvia'}) eq 'HASH') {
990: %disallowed = %{$settings->{'loginvia'}};
991: }
992: }
993: foreach my $lonhost (sort(keys(%servers))) {
994: my $direct = 'selected="selected"';
1.128 raeburn 995: if (ref($disallowed{$lonhost}) eq 'HASH') {
996: if ($disallowed{$lonhost}{'server'} ne '') {
997: $direct = '';
998: }
1.110 raeburn 999: }
1.115 raeburn 1000: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1001: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1002: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1003: '</option>';
1.160.6.13 raeburn 1004: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1005: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1006: my $selected = '';
1.128 raeburn 1007: if (ref($disallowed{$lonhost}) eq 'HASH') {
1008: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1009: $selected = 'selected="selected"';
1010: }
1.110 raeburn 1011: }
1012: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1013: $servers{$hostid}.'</option>';
1014: }
1.128 raeburn 1015: $datatable .= '</select></td>'.
1016: '<td><select name="'.$lonhost.'_serverpath">';
1017: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1018: my $pathname = $path;
1019: if ($path eq 'custom') {
1020: $pathname = &mt('Custom Path').' ->';
1021: }
1022: my $selected = '';
1023: if (ref($disallowed{$lonhost}) eq 'HASH') {
1024: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1025: $selected = 'selected="selected"';
1026: }
1027: } elsif ($path eq '') {
1028: $selected = 'selected="selected"';
1029: }
1030: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1031: }
1032: $datatable .= '</select></td>';
1033: my ($custom,$exempt);
1034: if (ref($disallowed{$lonhost}) eq 'HASH') {
1035: $custom = $disallowed{$lonhost}{'custompath'};
1036: $exempt = $disallowed{$lonhost}{'exempt'};
1037: }
1038: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1039: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1040: '</tr>';
1.110 raeburn 1041: }
1042: $datatable .= '</table></td></tr>';
1043: return $datatable;
1.160.6.5 raeburn 1044: } elsif ($caller eq 'page') {
1045: my %defaultchecked = (
1046: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1047: 'helpdesk' => 'on',
1.160.6.5 raeburn 1048: 'adminmail' => 'off',
1049: 'newuser' => 'off',
1050: );
1.160.6.14 raeburn 1051: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1052: my (%checkedon,%checkedoff);
1.42 raeburn 1053: foreach my $item (@toggles) {
1.160.6.5 raeburn 1054: if ($defaultchecked{$item} eq 'on') {
1055: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1056: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1057: } elsif ($defaultchecked{$item} eq 'off') {
1058: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1059: $checkedon{$item} = ' ';
1060: }
1.1 raeburn 1061: }
1.160.6.5 raeburn 1062: my @images = ('img','logo','domlogo','login');
1063: my @logintext = ('textcol','bgcol');
1064: my @bgs = ('pgbg','mainbg','sidebg');
1065: my @links = ('link','alink','vlink');
1066: my %designhash = &Apache::loncommon::get_domainconf($dom);
1067: my %defaultdesign = %Apache::loncommon::defaultdesign;
1068: my (%is_custom,%designs);
1069: my %defaults = (
1070: font => $defaultdesign{'login.font'},
1071: );
1.6 raeburn 1072: foreach my $item (@images) {
1.160.6.5 raeburn 1073: $defaults{$item} = $defaultdesign{'login.'.$item};
1074: $defaults{'showlogo'}{$item} = 1;
1075: }
1076: foreach my $item (@bgs) {
1077: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1078: }
1.41 raeburn 1079: foreach my $item (@logintext) {
1.160.6.5 raeburn 1080: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1081: }
1.160.6.5 raeburn 1082: foreach my $item (@links) {
1083: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1084: }
1.160.6.5 raeburn 1085: if (ref($settings) eq 'HASH') {
1086: foreach my $item (@toggles) {
1087: if ($settings->{$item} eq '1') {
1088: $checkedon{$item} = ' checked="checked" ';
1089: $checkedoff{$item} = ' ';
1090: } elsif ($settings->{$item} eq '0') {
1091: $checkedoff{$item} = ' checked="checked" ';
1092: $checkedon{$item} = ' ';
1093: }
1.6 raeburn 1094: }
1.160.6.5 raeburn 1095: foreach my $item (@images) {
1096: if (defined($settings->{$item})) {
1097: $designs{$item} = $settings->{$item};
1098: $is_custom{$item} = 1;
1099: }
1100: if (defined($settings->{'showlogo'}{$item})) {
1101: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1102: }
1103: }
1104: foreach my $item (@logintext) {
1105: if ($settings->{$item} ne '') {
1106: $designs{'logintext'}{$item} = $settings->{$item};
1107: $is_custom{$item} = 1;
1108: }
1109: }
1110: if ($settings->{'font'} ne '') {
1111: $designs{'font'} = $settings->{'font'};
1112: $is_custom{'font'} = 1;
1113: }
1114: foreach my $item (@bgs) {
1115: if ($settings->{$item} ne '') {
1116: $designs{'bgs'}{$item} = $settings->{$item};
1117: $is_custom{$item} = 1;
1118: }
1119: }
1120: foreach my $item (@links) {
1121: if ($settings->{$item} ne '') {
1122: $designs{'links'}{$item} = $settings->{$item};
1123: $is_custom{$item} = 1;
1124: }
1125: }
1126: } else {
1127: if ($designhash{$dom.'.login.font'} ne '') {
1128: $designs{'font'} = $designhash{$dom.'.login.font'};
1129: $is_custom{'font'} = 1;
1130: }
1131: foreach my $item (@images) {
1132: if ($designhash{$dom.'.login.'.$item} ne '') {
1133: $designs{$item} = $designhash{$dom.'.login.'.$item};
1134: $is_custom{$item} = 1;
1135: }
1136: }
1137: foreach my $item (@bgs) {
1138: if ($designhash{$dom.'.login.'.$item} ne '') {
1139: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1140: $is_custom{$item} = 1;
1141: }
1142: }
1143: foreach my $item (@links) {
1144: if ($designhash{$dom.'.login.'.$item} ne '') {
1145: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1146: $is_custom{$item} = 1;
1147: }
1.6 raeburn 1148: }
1149: }
1.160.6.5 raeburn 1150: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1151: logo => 'Institution Logo',
1152: domlogo => 'Domain Logo',
1153: login => 'Login box');
1154: my $itemcount = 1;
1155: foreach my $item (@toggles) {
1156: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1157: $datatable .=
1158: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1159: '</td><td>'.
1160: '<span class="LC_nobreak"><label><input type="radio" name="'.
1161: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1162: '</label> <label><input type="radio" name="'.$item.'"'.
1163: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1164: '</tr>';
1165: $itemcount ++;
1.6 raeburn 1166: }
1.160.6.5 raeburn 1167: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1168: $datatable .= '</tr></table></td></tr>';
1169: } elsif ($caller eq 'help') {
1170: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1171: my $switchserver = &check_switchserver($dom,$confname);
1172: my $itemcount = 1;
1173: $defaulturl = '/adm/loginproblems.html';
1174: $defaulttype = 'default';
1175: %lt = &Apache::lonlocal::texthash (
1176: del => 'Delete?',
1177: rep => 'Replace:',
1178: upl => 'Upload:',
1179: default => 'Default',
1180: custom => 'Custom',
1181: );
1182: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1183: my @currlangs;
1184: if (ref($settings) eq 'HASH') {
1185: if (ref($settings->{'helpurl'}) eq 'HASH') {
1186: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1187: next if ($settings->{'helpurl'}{$key} eq '');
1188: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1189: $type{$key} = 'custom';
1190: unless ($key eq 'nolang') {
1191: push(@currlangs,$key);
1192: }
1193: }
1194: } elsif ($settings->{'helpurl'} ne '') {
1195: $type{'nolang'} = 'custom';
1196: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1197: }
1198: }
1.160.6.5 raeburn 1199: foreach my $lang ('nolang',sort(@currlangs)) {
1200: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1201: $datatable .= '<tr'.$css_class.'>';
1202: if ($url{$lang} eq '') {
1203: $url{$lang} = $defaulturl;
1204: }
1205: if ($type{$lang} eq '') {
1206: $type{$lang} = $defaulttype;
1207: }
1208: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1209: if ($lang eq 'nolang') {
1210: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1211: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1212: } else {
1213: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1214: $langchoices{$lang},
1215: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1216: }
1217: $datatable .= '</span></td>'."\n".
1218: '<td class="LC_left_item">';
1219: if ($type{$lang} eq 'custom') {
1220: $datatable .= '<span class="LC_nobreak"><label>'.
1221: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1222: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1223: } else {
1224: $datatable .= $lt{'upl'};
1225: }
1226: $datatable .='<br />';
1227: if ($switchserver) {
1228: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1229: } else {
1230: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1231: }
1.160.6.5 raeburn 1232: $datatable .= '</td></tr>';
1233: $itemcount ++;
1.6 raeburn 1234: }
1.160.6.5 raeburn 1235: my @addlangs;
1236: foreach my $lang (sort(keys(%langchoices))) {
1237: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1238: push(@addlangs,$lang);
1239: }
1240: if (@addlangs > 0) {
1241: my %toadd;
1242: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1243: $toadd{''} = &mt('Select');
1244: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1245: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1246: &mt('Add log-in help page for a specific language:').' '.
1247: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1248: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1249: if ($switchserver) {
1250: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1251: } else {
1252: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1253: }
1.160.6.5 raeburn 1254: $datatable .= '</td></tr>';
1255: $itemcount ++;
1.6 raeburn 1256: }
1.160.6.5 raeburn 1257: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1258: } elsif ($caller eq 'headtag') {
1259: my %domservers = &Apache::lonnet::get_servers($dom);
1260: my $choice = $choices{'headtag'};
1261: $css_class = ' class="LC_odd_row"';
1262: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1263: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1264: '<th>'.$choices{'current'}.'</th>'.
1265: '<th>'.$choices{'action'}.'</th>'.
1266: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1267: my (%currurls,%currexempt);
1268: if (ref($settings) eq 'HASH') {
1269: if (ref($settings->{'headtag'}) eq 'HASH') {
1270: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1271: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1272: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1273: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1274: }
1275: }
1276: }
1277: }
1278: my %lt = &Apache::lonlocal::texthash(
1279: del => 'Delete?',
1280: rep => 'Replace:',
1281: upl => 'Upload:',
1282: curr => 'View contents',
1283: none => 'None',
1284: );
1285: my $switchserver = &check_switchserver($dom,$confname);
1286: foreach my $lonhost (sort(keys(%domservers))) {
1287: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1288: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1289: if ($currurls{$lonhost}) {
1290: $datatable .= '<td class="LC_right_item"><a href="'.
1291: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1292: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1293: '">'.$lt{'curr'}.'</a></td>'.
1294: '<td><span class="LC_nobreak"><label>'.
1295: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1296: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1297: } else {
1298: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1299: }
1300: $datatable .='<br />';
1301: if ($switchserver) {
1302: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1303: } else {
1304: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1305: }
1306: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1307: }
1308: $datatable .= '</table></td></tr>';
1.1 raeburn 1309: }
1.6 raeburn 1310: return $datatable;
1311: }
1312:
1313: sub login_choices {
1314: my %choices =
1315: &Apache::lonlocal::texthash (
1.116 bisitz 1316: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1317: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1318: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1319: disallowlogin => "Login page requests redirected",
1320: hostid => "Server",
1.128 raeburn 1321: server => "Redirect to:",
1322: serverpath => "Path",
1323: custompath => "Custom",
1324: exempt => "Exempt IP(s)",
1.110 raeburn 1325: directlogin => "No redirect",
1326: newuser => "Link to create a user account",
1327: img => "Header",
1328: logo => "Main Logo",
1329: domlogo => "Domain Logo",
1330: login => "Log-in Header",
1331: textcol => "Text color",
1332: bgcol => "Box color",
1333: bgs => "Background colors",
1334: links => "Link colors",
1335: font => "Font color",
1336: pgbg => "Header",
1337: mainbg => "Page",
1338: sidebg => "Login box",
1339: link => "Link",
1340: alink => "Active link",
1341: vlink => "Visited link",
1.160.6.56 raeburn 1342: headtag => "Custom markup",
1343: action => "Action",
1344: current => "Current",
1.6 raeburn 1345: );
1346: return %choices;
1347: }
1348:
1349: sub print_rolecolors {
1.30 raeburn 1350: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1351: my %choices = &color_font_choices();
1352: my @bgs = ('pgbg','tabbg','sidebg');
1353: my @links = ('link','alink','vlink');
1354: my @images = ('img');
1355: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1356: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1357: my %defaultdesign = %Apache::loncommon::defaultdesign;
1358: my (%is_custom,%designs);
1.160.6.22 raeburn 1359: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1360: if (ref($settings) eq 'HASH') {
1361: if (ref($settings->{$role}) eq 'HASH') {
1362: if ($settings->{$role}->{'img'} ne '') {
1363: $designs{'img'} = $settings->{$role}->{'img'};
1364: $is_custom{'img'} = 1;
1365: }
1366: if ($settings->{$role}->{'font'} ne '') {
1367: $designs{'font'} = $settings->{$role}->{'font'};
1368: $is_custom{'font'} = 1;
1369: }
1.97 tempelho 1370: if ($settings->{$role}->{'fontmenu'} ne '') {
1371: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1372: $is_custom{'fontmenu'} = 1;
1373: }
1.6 raeburn 1374: foreach my $item (@bgs) {
1375: if ($settings->{$role}->{$item} ne '') {
1376: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1377: $is_custom{$item} = 1;
1378: }
1379: }
1380: foreach my $item (@links) {
1381: if ($settings->{$role}->{$item} ne '') {
1382: $designs{'links'}{$item} = $settings->{$role}->{$item};
1383: $is_custom{$item} = 1;
1384: }
1385: }
1386: }
1387: } else {
1388: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1389: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1390: $is_custom{'img'} = 1;
1391: }
1.97 tempelho 1392: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1393: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1394: $is_custom{'fontmenu'} = 1;
1395: }
1.6 raeburn 1396: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1397: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1398: $is_custom{'font'} = 1;
1399: }
1400: foreach my $item (@bgs) {
1401: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1402: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1403: $is_custom{$item} = 1;
1404:
1405: }
1406: }
1407: foreach my $item (@links) {
1408: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1409: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1410: $is_custom{$item} = 1;
1411: }
1412: }
1413: }
1414: my $itemcount = 1;
1.30 raeburn 1415: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1416: $datatable .= '</tr></table></td></tr>';
1417: return $datatable;
1418: }
1419:
1.160.6.22 raeburn 1420: sub role_defaults {
1421: my ($role,$bgs,$links,$images,$logintext) = @_;
1422: my %defaults;
1423: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1424: return %defaults;
1425: }
1426: my %defaultdesign = %Apache::loncommon::defaultdesign;
1427: if ($role eq 'login') {
1428: %defaults = (
1429: font => $defaultdesign{$role.'.font'},
1430: );
1431: if (ref($logintext) eq 'ARRAY') {
1432: foreach my $item (@{$logintext}) {
1433: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1434: }
1435: }
1436: foreach my $item (@{$images}) {
1437: $defaults{'showlogo'}{$item} = 1;
1438: }
1439: } else {
1440: %defaults = (
1441: img => $defaultdesign{$role.'.img'},
1442: font => $defaultdesign{$role.'.font'},
1443: fontmenu => $defaultdesign{$role.'.fontmenu'},
1444: );
1445: }
1446: foreach my $item (@{$bgs}) {
1447: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1448: }
1449: foreach my $item (@{$links}) {
1450: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1451: }
1452: foreach my $item (@{$images}) {
1453: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1454: }
1455: return %defaults;
1456: }
1457:
1.6 raeburn 1458: sub display_color_options {
1.9 raeburn 1459: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1460: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1461: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1462: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1463: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1464: '<td>'.$choices->{'font'}.'</td>';
1465: if (!$is_custom->{'font'}) {
1.30 raeburn 1466: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1467: } else {
1468: $datatable .= '<td> </td>';
1469: }
1.160.6.9 raeburn 1470: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1471:
1.8 raeburn 1472: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1473: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1474: ' value="'.$current_color.'" /> '.
1475: ' </td></tr>';
1.107 raeburn 1476: unless ($role eq 'login') {
1477: $datatable .= '<tr'.$css_class.'>'.
1478: '<td>'.$choices->{'fontmenu'}.'</td>';
1479: if (!$is_custom->{'fontmenu'}) {
1480: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1481: } else {
1482: $datatable .= '<td> </td>';
1483: }
1.160.6.22 raeburn 1484: $current_color = $designs->{'fontmenu'} ?
1485: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1486: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1487: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1488: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1489: ' value="'.$current_color.'" /> '.
1490: ' </td></tr>';
1.97 tempelho 1491: }
1.9 raeburn 1492: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1493: foreach my $img (@{$images}) {
1.18 albertel 1494: $itemcount ++;
1.6 raeburn 1495: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1496: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1497: '<td>'.$choices->{$img};
1.41 raeburn 1498: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1499: if ($role eq 'login') {
1500: if ($img eq 'login') {
1501: $login_hdr_pick =
1.135 bisitz 1502: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1503: $logincolors =
1504: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1505: $designs,$defaults);
1.70 raeburn 1506: } elsif ($img ne 'domlogo') {
1507: $datatable.= &logo_display_options($img,$defaults,$designs);
1508: }
1509: }
1510: $datatable .= '</td>';
1.6 raeburn 1511: if ($designs->{$img} ne '') {
1512: $imgfile = $designs->{$img};
1.18 albertel 1513: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1514: } else {
1515: $imgfile = $defaults->{$img};
1516: }
1517: if ($imgfile) {
1.9 raeburn 1518: my ($showfile,$fullsize);
1519: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1520: my $urldir = $1;
1521: my $filename = $2;
1522: my @info = &Apache::lonnet::stat_file($designs->{$img});
1523: if (@info) {
1524: my $thumbfile = 'tn-'.$filename;
1525: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1526: if (@thumb) {
1527: $showfile = $urldir.'/'.$thumbfile;
1528: } else {
1529: $showfile = $imgfile;
1530: }
1531: } else {
1532: $showfile = '';
1533: }
1534: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1535: $showfile = $imgfile;
1.6 raeburn 1536: my $imgdir = $1;
1537: my $filename = $2;
1.159 raeburn 1538: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1539: $showfile = "/$imgdir/tn-".$filename;
1540: } else {
1.159 raeburn 1541: my $input = $londocroot.$imgfile;
1542: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1543: if (!-e $output) {
1.9 raeburn 1544: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1545: my ($fullwidth,$fullheight) = &check_dimensions($input);
1546: if ($fullwidth ne '' && $fullheight ne '') {
1547: if ($fullwidth > $width && $fullheight > $height) {
1548: my $size = $width.'x'.$height;
1549: system("convert -sample $size $input $output");
1.159 raeburn 1550: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1551: }
1552: }
1.6 raeburn 1553: }
1554: }
1.16 raeburn 1555: }
1.6 raeburn 1556: if ($showfile) {
1.40 raeburn 1557: if ($showfile =~ m{^/(adm|res)/}) {
1558: if ($showfile =~ m{^/res/}) {
1559: my $local_showfile =
1560: &Apache::lonnet::filelocation('',$showfile);
1561: &Apache::lonnet::repcopy($local_showfile);
1562: }
1563: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1564: }
1565: if ($imgfile) {
1566: if ($imgfile =~ m{^/(adm|res)/}) {
1567: if ($imgfile =~ m{^/res/}) {
1568: my $local_imgfile =
1569: &Apache::lonnet::filelocation('',$imgfile);
1570: &Apache::lonnet::repcopy($local_imgfile);
1571: }
1572: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1573: } else {
1574: $fullsize = $imgfile;
1575: }
1576: }
1.41 raeburn 1577: $datatable .= '<td>';
1578: if ($img eq 'login') {
1.135 bisitz 1579: $datatable .= $login_hdr_pick;
1580: }
1.41 raeburn 1581: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1582: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1583: } else {
1.160.6.22 raeburn 1584: $datatable .= '<td> </td><td class="LC_left_item">'.
1585: &mt('Upload:').'<br />';
1.6 raeburn 1586: }
1587: } else {
1.160.6.22 raeburn 1588: $datatable .= '<td> </td><td class="LC_left_item">'.
1589: &mt('Upload:').'<br />';
1.6 raeburn 1590: }
1.9 raeburn 1591: if ($switchserver) {
1592: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1593: } else {
1.135 bisitz 1594: if ($img ne 'login') { # suppress file selection for Log-in header
1595: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1596: }
1.9 raeburn 1597: }
1598: $datatable .= '</td></tr>';
1.6 raeburn 1599: }
1600: $itemcount ++;
1601: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1602: $datatable .= '<tr'.$css_class.'>'.
1603: '<td>'.$choices->{'bgs'}.'</td>';
1604: my $bgs_def;
1605: foreach my $item (@{$bgs}) {
1606: if (!$is_custom->{$item}) {
1.70 raeburn 1607: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1608: }
1609: }
1610: if ($bgs_def) {
1.8 raeburn 1611: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1612: } else {
1613: $datatable .= '<td> </td>';
1614: }
1615: $datatable .= '<td class="LC_right_item">'.
1616: '<table border="0"><tr>';
1.160.6.13 raeburn 1617:
1.6 raeburn 1618: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1619: $datatable .= '<td align="center">'.$choices->{$item};
1620: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1621: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1622: $datatable .= ' ';
1.6 raeburn 1623: }
1.160.6.9 raeburn 1624: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1625: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1626: }
1627: $datatable .= '</tr></table></td></tr>';
1628: $itemcount ++;
1629: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1630: $datatable .= '<tr'.$css_class.'>'.
1631: '<td>'.$choices->{'links'}.'</td>';
1632: my $links_def;
1633: foreach my $item (@{$links}) {
1634: if (!$is_custom->{$item}) {
1.30 raeburn 1635: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1636: }
1637: }
1638: if ($links_def) {
1.8 raeburn 1639: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1640: } else {
1641: $datatable .= '<td> </td>';
1642: }
1643: $datatable .= '<td class="LC_right_item">'.
1644: '<table border="0"><tr>';
1645: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1646: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1647: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1648: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1649: $datatable.=' ';
1.6 raeburn 1650: }
1.160.6.9 raeburn 1651: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1652: '" /></td>';
1653: }
1.30 raeburn 1654: $$rowtotal += $itemcount;
1.3 raeburn 1655: return $datatable;
1656: }
1657:
1.70 raeburn 1658: sub logo_display_options {
1659: my ($img,$defaults,$designs) = @_;
1660: my $checkedon;
1661: if (ref($defaults) eq 'HASH') {
1662: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1663: if ($defaults->{'showlogo'}{$img}) {
1664: $checkedon = 'checked="checked" ';
1665: }
1666: }
1667: }
1668: if (ref($designs) eq 'HASH') {
1669: if (ref($designs->{'showlogo'}) eq 'HASH') {
1670: if (defined($designs->{'showlogo'}{$img})) {
1671: if ($designs->{'showlogo'}{$img} == 0) {
1672: $checkedon = '';
1673: } elsif ($designs->{'showlogo'}{$img} == 1) {
1674: $checkedon = 'checked="checked" ';
1675: }
1676: }
1677: }
1678: }
1679: return '<br /><label> <input type="checkbox" name="'.
1680: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1681: &mt('show').'</label>'."\n";
1682: }
1683:
1.41 raeburn 1684: sub login_header_options {
1.135 bisitz 1685: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1686: my $output = '';
1.41 raeburn 1687: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1688: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1689: if (!$is_custom->{'textcol'}) {
1690: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1691: ' ';
1692: }
1693: if (!$is_custom->{'bgcol'}) {
1694: $output .= $choices->{'bgcol'}.': '.
1695: '<span id="css_'.$role.'_font" style="background-color: '.
1696: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1697: }
1698: $output .= '<br />';
1699: }
1700: $output .='<br />';
1701: return $output;
1702: }
1703:
1704: sub login_text_colors {
1.160.6.22 raeburn 1705: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1706: my $color_menu = '<table border="0"><tr>';
1707: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1708: $color_menu .= '<td align="center">'.$choices->{$item};
1709: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1710: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1711: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1712: }
1713: $color_menu .= '</tr></table><br />';
1714: return $color_menu;
1715: }
1716:
1717: sub image_changes {
1718: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1719: my $output;
1.135 bisitz 1720: if ($img eq 'login') {
1721: # suppress image for Log-in header
1722: } elsif (!$is_custom) {
1.70 raeburn 1723: if ($img ne 'domlogo') {
1.41 raeburn 1724: $output .= &mt('Default image:').'<br />';
1725: } else {
1726: $output .= &mt('Default in use:').'<br />';
1727: }
1728: }
1.135 bisitz 1729: if ($img eq 'login') { # suppress image for Log-in header
1730: $output .= '<td>'.$logincolors;
1.41 raeburn 1731: } else {
1.135 bisitz 1732: if ($img_import) {
1733: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1734: }
1735: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1736: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1737: if ($is_custom) {
1738: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1739: '<input type="checkbox" name="'.
1740: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1741: '</label> '.&mt('Replace:').'</span><br />';
1742: } else {
1.160.6.22 raeburn 1743: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1744: }
1.41 raeburn 1745: }
1746: return $output;
1747: }
1748:
1.3 raeburn 1749: sub print_quotas {
1.86 raeburn 1750: my ($dom,$settings,$rowtotal,$action) = @_;
1751: my $context;
1752: if ($action eq 'quotas') {
1753: $context = 'tools';
1754: } else {
1755: $context = $action;
1756: }
1.160.6.20 raeburn 1757: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1758: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1759: my $typecount = 0;
1.101 raeburn 1760: my ($css_class,%titles);
1.86 raeburn 1761: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1762: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1763: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1764: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1765: %titles = &courserequest_titles();
1.160.6.5 raeburn 1766: } elsif ($context eq 'requestauthor') {
1767: @usertools = ('author');
1768: @options = ('norequest','approval','automatic');
1769: %titles = &authorrequest_titles();
1.86 raeburn 1770: } else {
1.160.6.4 raeburn 1771: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1772: %titles = &tool_titles();
1.86 raeburn 1773: }
1.26 raeburn 1774: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1775: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1776: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1777: unless (($context eq 'requestcourses') ||
1778: ($context eq 'requestauthor')) {
1.86 raeburn 1779: if (ref($settings) eq 'HASH') {
1780: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1781: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1782: } else {
1783: $currdefquota = $settings->{$type};
1784: }
1.160.6.20 raeburn 1785: if (ref($settings->{authorquota}) eq 'HASH') {
1786: $currauthorquota = $settings->{authorquota}->{$type};
1787: }
1.78 raeburn 1788: }
1.72 raeburn 1789: }
1.3 raeburn 1790: if (defined($usertypes->{$type})) {
1791: $typecount ++;
1792: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1793: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1794: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1795: '<td class="LC_left_item">';
1.101 raeburn 1796: if ($context eq 'requestcourses') {
1797: $datatable .= '<table><tr>';
1798: }
1799: my %cell;
1.72 raeburn 1800: foreach my $item (@usertools) {
1.101 raeburn 1801: if ($context eq 'requestcourses') {
1802: my ($curroption,$currlimit);
1803: if (ref($settings) eq 'HASH') {
1804: if (ref($settings->{$item}) eq 'HASH') {
1805: $curroption = $settings->{$item}->{$type};
1806: if ($curroption =~ /^autolimit=(\d*)$/) {
1807: $currlimit = $1;
1808: }
1809: }
1810: }
1811: if (!$curroption) {
1812: $curroption = 'norequest';
1813: }
1814: $datatable .= '<th>'.$titles{$item}.'</th>';
1815: foreach my $option (@options) {
1816: my $val = $option;
1817: if ($option eq 'norequest') {
1818: $val = 0;
1819: }
1820: if ($option eq 'validate') {
1821: my $canvalidate = 0;
1822: if (ref($validations{$item}) eq 'HASH') {
1823: if ($validations{$item}{$type}) {
1824: $canvalidate = 1;
1825: }
1826: }
1827: next if (!$canvalidate);
1828: }
1829: my $checked = '';
1830: if ($option eq $curroption) {
1831: $checked = ' checked="checked"';
1832: } elsif ($option eq 'autolimit') {
1833: if ($curroption =~ /^autolimit/) {
1834: $checked = ' checked="checked"';
1835: }
1836: }
1837: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1838: '<input type="radio" name="crsreq_'.$item.
1839: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1840: $titles{$option}.'</label>';
1.101 raeburn 1841: if ($option eq 'autolimit') {
1.127 raeburn 1842: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1843: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1844: 'value="'.$currlimit.'" />';
1.101 raeburn 1845: }
1.127 raeburn 1846: $cell{$item} .= '</span> ';
1.103 raeburn 1847: if ($option eq 'autolimit') {
1.127 raeburn 1848: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1849: }
1.101 raeburn 1850: }
1.160.6.5 raeburn 1851: } elsif ($context eq 'requestauthor') {
1852: my $curroption;
1853: if (ref($settings) eq 'HASH') {
1854: $curroption = $settings->{$type};
1855: }
1856: if (!$curroption) {
1857: $curroption = 'norequest';
1858: }
1859: foreach my $option (@options) {
1860: my $val = $option;
1861: if ($option eq 'norequest') {
1862: $val = 0;
1863: }
1864: my $checked = '';
1865: if ($option eq $curroption) {
1866: $checked = ' checked="checked"';
1867: }
1868: $datatable .= '<span class="LC_nobreak"><label>'.
1869: '<input type="radio" name="authorreq_'.$type.
1870: '" value="'.$val.'"'.$checked.' />'.
1871: $titles{$option}.'</label></span> ';
1872: }
1.101 raeburn 1873: } else {
1874: my $checked = 'checked="checked" ';
1875: if (ref($settings) eq 'HASH') {
1876: if (ref($settings->{$item}) eq 'HASH') {
1877: if ($settings->{$item}->{$type} == 0) {
1878: $checked = '';
1879: } elsif ($settings->{$item}->{$type} == 1) {
1880: $checked = 'checked="checked" ';
1881: }
1.78 raeburn 1882: }
1.72 raeburn 1883: }
1.101 raeburn 1884: $datatable .= '<span class="LC_nobreak"><label>'.
1885: '<input type="checkbox" name="'.$context.'_'.$item.
1886: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1887: '</label></span> ';
1.72 raeburn 1888: }
1.101 raeburn 1889: }
1890: if ($context eq 'requestcourses') {
1891: $datatable .= '</tr><tr>';
1892: foreach my $item (@usertools) {
1.106 raeburn 1893: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1894: }
1895: $datatable .= '</tr></table>';
1.72 raeburn 1896: }
1.86 raeburn 1897: $datatable .= '</td>';
1.160.6.5 raeburn 1898: unless (($context eq 'requestcourses') ||
1899: ($context eq 'requestauthor')) {
1.86 raeburn 1900: $datatable .=
1.160.6.20 raeburn 1901: '<td class="LC_right_item">'.
1902: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1903: '<input type="text" name="quota_'.$type.
1.72 raeburn 1904: '" value="'.$currdefquota.
1.160.6.20 raeburn 1905: '" size="5" /></span>'.(' ' x 2).
1906: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1907: '<input type="text" name="authorquota_'.$type.
1908: '" value="'.$currauthorquota.
1909: '" size="5" /></span></td>';
1.86 raeburn 1910: }
1911: $datatable .= '</tr>';
1.3 raeburn 1912: }
1913: }
1914: }
1.160.6.5 raeburn 1915: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1916: $defaultquota = '20';
1.160.6.20 raeburn 1917: $authorquota = '500';
1.86 raeburn 1918: if (ref($settings) eq 'HASH') {
1919: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1920: $defaultquota = $settings->{'defaultquota'}->{'default'};
1921: } elsif (defined($settings->{'default'})) {
1922: $defaultquota = $settings->{'default'};
1923: }
1.160.6.20 raeburn 1924: if (ref($settings->{'authorquota'}) eq 'HASH') {
1925: $authorquota = $settings->{'authorquota'}->{'default'};
1926: }
1.3 raeburn 1927: }
1928: }
1929: $typecount ++;
1930: $css_class = $typecount%2?' class="LC_odd_row"':'';
1931: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1932: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1933: '<td class="LC_left_item">';
1.101 raeburn 1934: if ($context eq 'requestcourses') {
1935: $datatable .= '<table><tr>';
1936: }
1937: my %defcell;
1.72 raeburn 1938: foreach my $item (@usertools) {
1.101 raeburn 1939: if ($context eq 'requestcourses') {
1940: my ($curroption,$currlimit);
1941: if (ref($settings) eq 'HASH') {
1942: if (ref($settings->{$item}) eq 'HASH') {
1943: $curroption = $settings->{$item}->{'default'};
1944: if ($curroption =~ /^autolimit=(\d*)$/) {
1945: $currlimit = $1;
1946: }
1947: }
1948: }
1949: if (!$curroption) {
1950: $curroption = 'norequest';
1951: }
1952: $datatable .= '<th>'.$titles{$item}.'</th>';
1953: foreach my $option (@options) {
1954: my $val = $option;
1955: if ($option eq 'norequest') {
1956: $val = 0;
1957: }
1958: if ($option eq 'validate') {
1959: my $canvalidate = 0;
1960: if (ref($validations{$item}) eq 'HASH') {
1961: if ($validations{$item}{'default'}) {
1962: $canvalidate = 1;
1963: }
1964: }
1965: next if (!$canvalidate);
1966: }
1967: my $checked = '';
1968: if ($option eq $curroption) {
1969: $checked = ' checked="checked"';
1970: } elsif ($option eq 'autolimit') {
1971: if ($curroption =~ /^autolimit/) {
1972: $checked = ' checked="checked"';
1973: }
1974: }
1975: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1976: '<input type="radio" name="crsreq_'.$item.
1977: '_default" value="'.$val.'"'.$checked.' />'.
1978: $titles{$option}.'</label>';
1979: if ($option eq 'autolimit') {
1.127 raeburn 1980: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1981: $item.'_limit_default" size="1" '.
1982: 'value="'.$currlimit.'" />';
1983: }
1.127 raeburn 1984: $defcell{$item} .= '</span> ';
1.104 raeburn 1985: if ($option eq 'autolimit') {
1.127 raeburn 1986: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1987: }
1.101 raeburn 1988: }
1.160.6.5 raeburn 1989: } elsif ($context eq 'requestauthor') {
1990: my $curroption;
1991: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1992: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1993: }
1994: if (!$curroption) {
1995: $curroption = 'norequest';
1996: }
1997: foreach my $option (@options) {
1998: my $val = $option;
1999: if ($option eq 'norequest') {
2000: $val = 0;
2001: }
2002: my $checked = '';
2003: if ($option eq $curroption) {
2004: $checked = ' checked="checked"';
2005: }
2006: $datatable .= '<span class="LC_nobreak"><label>'.
2007: '<input type="radio" name="authorreq_default"'.
2008: ' value="'.$val.'"'.$checked.' />'.
2009: $titles{$option}.'</label></span> ';
2010: }
1.101 raeburn 2011: } else {
2012: my $checked = 'checked="checked" ';
2013: if (ref($settings) eq 'HASH') {
2014: if (ref($settings->{$item}) eq 'HASH') {
2015: if ($settings->{$item}->{'default'} == 0) {
2016: $checked = '';
2017: } elsif ($settings->{$item}->{'default'} == 1) {
2018: $checked = 'checked="checked" ';
2019: }
1.78 raeburn 2020: }
1.72 raeburn 2021: }
1.101 raeburn 2022: $datatable .= '<span class="LC_nobreak"><label>'.
2023: '<input type="checkbox" name="'.$context.'_'.$item.
2024: '" value="default" '.$checked.'/>'.$titles{$item}.
2025: '</label></span> ';
2026: }
2027: }
2028: if ($context eq 'requestcourses') {
2029: $datatable .= '</tr><tr>';
2030: foreach my $item (@usertools) {
1.106 raeburn 2031: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2032: }
1.101 raeburn 2033: $datatable .= '</tr></table>';
1.72 raeburn 2034: }
1.86 raeburn 2035: $datatable .= '</td>';
1.160.6.5 raeburn 2036: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2037: $datatable .= '<td class="LC_right_item">'.
2038: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2039: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2040: $defaultquota.'" size="5" /></span>'.(' ' x2).
2041: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2042: '<input type="text" name="authorquota" value="'.
2043: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2044: }
2045: $datatable .= '</tr>';
1.72 raeburn 2046: $typecount ++;
2047: $css_class = $typecount%2?' class="LC_odd_row"':'';
2048: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2049: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2050: if ($context eq 'requestcourses') {
1.109 raeburn 2051: $datatable .= &mt('(overrides affiliation, if set)').
2052: '</td>'.
2053: '<td class="LC_left_item">'.
2054: '<table><tr>';
1.101 raeburn 2055: } else {
1.109 raeburn 2056: $datatable .= &mt('(overrides affiliation, if checked)').
2057: '</td>'.
2058: '<td class="LC_left_item" colspan="2">'.
2059: '<br />';
1.101 raeburn 2060: }
2061: my %advcell;
1.72 raeburn 2062: foreach my $item (@usertools) {
1.101 raeburn 2063: if ($context eq 'requestcourses') {
2064: my ($curroption,$currlimit);
2065: if (ref($settings) eq 'HASH') {
2066: if (ref($settings->{$item}) eq 'HASH') {
2067: $curroption = $settings->{$item}->{'_LC_adv'};
2068: if ($curroption =~ /^autolimit=(\d*)$/) {
2069: $currlimit = $1;
2070: }
2071: }
2072: }
2073: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2074: my $checked = '';
2075: if ($curroption eq '') {
2076: $checked = ' checked="checked"';
2077: }
2078: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2079: '<input type="radio" name="crsreq_'.$item.
2080: '__LC_adv" value=""'.$checked.' />'.
2081: &mt('No override set').'</label></span> ';
1.101 raeburn 2082: foreach my $option (@options) {
2083: my $val = $option;
2084: if ($option eq 'norequest') {
2085: $val = 0;
2086: }
2087: if ($option eq 'validate') {
2088: my $canvalidate = 0;
2089: if (ref($validations{$item}) eq 'HASH') {
2090: if ($validations{$item}{'_LC_adv'}) {
2091: $canvalidate = 1;
2092: }
2093: }
2094: next if (!$canvalidate);
2095: }
2096: my $checked = '';
1.104 raeburn 2097: if ($val eq $curroption) {
1.101 raeburn 2098: $checked = ' checked="checked"';
2099: } elsif ($option eq 'autolimit') {
2100: if ($curroption =~ /^autolimit/) {
2101: $checked = ' checked="checked"';
2102: }
2103: }
2104: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2105: '<input type="radio" name="crsreq_'.$item.
2106: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2107: $titles{$option}.'</label>';
2108: if ($option eq 'autolimit') {
1.127 raeburn 2109: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2110: $item.'_limit__LC_adv" size="1" '.
2111: 'value="'.$currlimit.'" />';
2112: }
1.127 raeburn 2113: $advcell{$item} .= '</span> ';
1.104 raeburn 2114: if ($option eq 'autolimit') {
1.127 raeburn 2115: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2116: }
1.101 raeburn 2117: }
1.160.6.5 raeburn 2118: } elsif ($context eq 'requestauthor') {
2119: my $curroption;
2120: if (ref($settings) eq 'HASH') {
2121: $curroption = $settings->{'_LC_adv'};
2122: }
2123: my $checked = '';
2124: if ($curroption eq '') {
2125: $checked = ' checked="checked"';
2126: }
2127: $datatable .= '<span class="LC_nobreak"><label>'.
2128: '<input type="radio" name="authorreq__LC_adv"'.
2129: ' value=""'.$checked.' />'.
2130: &mt('No override set').'</label></span> ';
2131: foreach my $option (@options) {
2132: my $val = $option;
2133: if ($option eq 'norequest') {
2134: $val = 0;
2135: }
2136: my $checked = '';
2137: if ($val eq $curroption) {
2138: $checked = ' checked="checked"';
2139: }
2140: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2141: '<input type="radio" name="authorreq__LC_adv"'.
2142: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2143: $titles{$option}.'</label></span> ';
2144: }
1.101 raeburn 2145: } else {
2146: my $checked = 'checked="checked" ';
2147: if (ref($settings) eq 'HASH') {
2148: if (ref($settings->{$item}) eq 'HASH') {
2149: if ($settings->{$item}->{'_LC_adv'} == 0) {
2150: $checked = '';
2151: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2152: $checked = 'checked="checked" ';
2153: }
1.79 raeburn 2154: }
1.72 raeburn 2155: }
1.101 raeburn 2156: $datatable .= '<span class="LC_nobreak"><label>'.
2157: '<input type="checkbox" name="'.$context.'_'.$item.
2158: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2159: '</label></span> ';
2160: }
2161: }
2162: if ($context eq 'requestcourses') {
2163: $datatable .= '</tr><tr>';
2164: foreach my $item (@usertools) {
1.106 raeburn 2165: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2166: }
1.101 raeburn 2167: $datatable .= '</tr></table>';
1.72 raeburn 2168: }
1.98 raeburn 2169: $datatable .= '</td></tr>';
1.30 raeburn 2170: $$rowtotal += $typecount;
1.3 raeburn 2171: return $datatable;
2172: }
2173:
1.160.6.5 raeburn 2174: sub print_requestmail {
2175: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2176: my ($now,$datatable,%currapp);
1.102 raeburn 2177: $now = time;
2178: if (ref($settings) eq 'HASH') {
2179: if (ref($settings->{'notify'}) eq 'HASH') {
2180: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2181: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2182: }
2183: }
2184: }
1.160.6.16 raeburn 2185: my $numinrow = 2;
1.160.6.34 raeburn 2186: my $css_class;
2187: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2188: my $text;
2189: if ($action eq 'requestcourses') {
2190: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2191: } elsif ($action eq 'requestauthor') {
2192: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2193: } else {
1.160.6.34 raeburn 2194: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2195: }
1.160.6.34 raeburn 2196: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2197: ' <td>'.$text.'</td>'.
1.102 raeburn 2198: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2199: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2200: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2201: if ($numdc > 0) {
2202: $datatable .= $table;
1.102 raeburn 2203: } else {
2204: $datatable .= &mt('There are no active Domain Coordinators');
2205: }
2206: $datatable .='</td></tr>';
2207: return $datatable;
2208: }
2209:
1.160.6.30 raeburn 2210: sub print_studentcode {
2211: my ($settings,$rowtotal) = @_;
2212: my $rownum = 0;
2213: my ($output,%current);
2214: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2215: if (ref($settings) eq 'HASH') {
2216: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2217: foreach my $type (@crstypes) {
2218: $current{$type} = $settings->{'uniquecode'}{$type};
2219: }
1.160.6.30 raeburn 2220: }
2221: }
2222: $output .= '<tr>'.
2223: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2224: '<td class="LC_left_item">';
2225: foreach my $type (@crstypes) {
2226: my $check = ' ';
2227: if ($current{$type}) {
2228: $check = ' checked="checked" ';
2229: }
2230: $output .= '<span class="LC_nobreak"><label>'.
2231: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2232: &mt($type).'</label></span>'.(' 'x2).' ';
2233: }
2234: $output .= '</td></tr>';
2235: $$rowtotal ++;
2236: return $output;
2237: }
2238:
2239: sub print_textbookcourses {
1.160.6.46 raeburn 2240: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2241: my $rownum = 0;
2242: my $css_class;
2243: my $itemcount = 1;
2244: my $maxnum = 0;
2245: my $bookshash;
2246: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2247: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2248: }
2249: my %ordered;
2250: if (ref($bookshash) eq 'HASH') {
2251: foreach my $item (keys(%{$bookshash})) {
2252: if (ref($bookshash->{$item}) eq 'HASH') {
2253: my $num = $bookshash->{$item}{'order'};
2254: $ordered{$num} = $item;
2255: }
2256: }
2257: }
2258: my $confname = $dom.'-domainconfig';
2259: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2260: my $maxnum = scalar(keys(%ordered));
2261: my $datatable;
1.160.6.30 raeburn 2262: if (keys(%ordered)) {
2263: my @items = sort { $a <=> $b } keys(%ordered);
2264: for (my $i=0; $i<@items; $i++) {
2265: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2266: my $key = $ordered{$items[$i]};
2267: my %coursehash=&Apache::lonnet::coursedescription($key);
2268: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2269: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2270: if (ref($bookshash->{$key}) eq 'HASH') {
2271: $subject = $bookshash->{$key}->{'subject'};
2272: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2273: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2274: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2275: $author = $bookshash->{$key}->{'author'};
2276: $image = $bookshash->{$key}->{'image'};
2277: if ($image ne '') {
2278: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2279: my $imagethumb = "$path/tn-".$imagefile;
2280: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2281: }
1.160.6.30 raeburn 2282: }
2283: }
1.160.6.46 raeburn 2284: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2285: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2286: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2287: for (my $k=0; $k<=$maxnum; $k++) {
2288: my $vpos = $k+1;
2289: my $selstr;
2290: if ($k == $i) {
2291: $selstr = ' selected="selected" ';
2292: }
2293: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2294: }
2295: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2296: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2297: &mt('Delete?').'</label></span></td>'.
2298: '<td colspan="2">'.
1.160.6.46 raeburn 2299: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2300: (' 'x2).
1.160.6.46 raeburn 2301: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2302: if ($type eq 'textbooks') {
2303: $datatable .= (' 'x2).
1.160.6.47 raeburn 2304: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2305: (' 'x2).
1.160.6.46 raeburn 2306: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2307: (' 'x2).
2308: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2309: if ($image) {
2310: $datatable .= '<span class="LC_nobreak">'.
2311: $imgsrc.
2312: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2313: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2314: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2315: }
2316: if ($switchserver) {
2317: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2318: } else {
2319: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2320: }
1.160.6.30 raeburn 2321: }
1.160.6.46 raeburn 2322: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2323: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2324: $coursetitle.'</span></td></tr>'."\n";
2325: $itemcount ++;
2326: }
2327: }
2328: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2329: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2330: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2331: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2332: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2333: for (my $k=0; $k<$maxnum+1; $k++) {
2334: my $vpos = $k+1;
2335: my $selstr;
2336: if ($k == $maxnum) {
2337: $selstr = ' selected="selected" ';
2338: }
2339: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2340: }
2341: $datatable .= '</select> '."\n".
1.160.6.46 raeburn 2342: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2343: '<td colspan="2">'.
1.160.6.46 raeburn 2344: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2345: (' 'x2).
1.160.6.46 raeburn 2346: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2347: (' 'x2);
2348: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2349: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2350: (' 'x2).
2351: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2352: (' 'x2).
2353: '<span class="LC_nobreak">'.&mt('Image:').' ';
2354: if ($switchserver) {
2355: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2356: } else {
2357: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2358: }
1.160.6.30 raeburn 2359: }
2360: $datatable .= '</span>'."\n".
2361: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2362: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2363: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2364: &Apache::loncommon::selectcourse_link
1.160.6.46 raeburn 2365: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2366: '</span></td>'."\n".
2367: '</tr>'."\n";
2368: $itemcount ++;
2369: return $datatable;
2370: }
2371:
2372: sub textbookcourses_javascript {
1.160.6.46 raeburn 2373: my ($settings) = @_;
2374: return unless(ref($settings) eq 'HASH');
2375: my (%ordered,%total,%jstext);
2376: foreach my $type ('textbooks','templates') {
2377: $total{$type} = 0;
2378: if (ref($settings->{$type}) eq 'HASH') {
2379: foreach my $item (keys(%{$settings->{$type}})) {
2380: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2381: my $num = $settings->{$type}->{$item}{'order'};
2382: $ordered{$type}{$num} = $item;
2383: }
2384: }
2385: $total{$type} = scalar(keys(%{$settings->{$type}}));
2386: }
2387: my @jsarray = ();
2388: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2389: push(@jsarray,$ordered{$type}{$item});
2390: }
2391: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2392: }
2393: return <<"ENDSCRIPT";
2394: <script type="text/javascript">
2395: // <![CDATA[
1.160.6.46 raeburn 2396: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2397: var changedVal;
1.160.6.46 raeburn 2398: $jstext{'textbooks'};
2399: $jstext{'templates'};
2400: var newpos;
2401: var maxh;
2402: if (caller == 'textbooks') {
2403: newpos = 'textbooks_addbook_pos';
2404: maxh = 1 + $total{'textbooks'};
2405: } else {
2406: newpos = 'templates_addbook_pos';
2407: maxh = 1 + $total{'templates'};
2408: }
1.160.6.30 raeburn 2409: var current = new Array;
2410: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2411: if (item == newpos) {
2412: changedVal = newitemVal;
2413: } else {
2414: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2415: current[newitemVal] = newpos;
2416: }
1.160.6.46 raeburn 2417: if (caller == 'textbooks') {
2418: for (var i=0; i<textbooks.length; i++) {
2419: var elementName = 'textbooks_'+textbooks[i];
2420: if (elementName != item) {
2421: if (form.elements[elementName]) {
2422: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2423: current[currVal] = elementName;
2424: }
2425: }
2426: }
2427: }
2428: if (caller == 'templates') {
2429: for (var i=0; i<templates.length; i++) {
2430: var elementName = 'templates_'+templates[i];
2431: if (elementName != item) {
2432: if (form.elements[elementName]) {
2433: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2434: current[currVal] = elementName;
2435: }
1.160.6.30 raeburn 2436: }
2437: }
2438: }
2439: var oldVal;
2440: for (var j=0; j<maxh; j++) {
2441: if (current[j] == undefined) {
2442: oldVal = j;
2443: }
2444: }
2445: if (oldVal < changedVal) {
2446: for (var k=oldVal+1; k<=changedVal ; k++) {
2447: var elementName = current[k];
2448: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2449: }
2450: } else {
2451: for (var k=changedVal; k<oldVal; k++) {
2452: var elementName = current[k];
2453: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2454: }
2455: }
2456: return;
2457: }
2458:
2459: // ]]>
2460: </script>
2461:
2462: ENDSCRIPT
2463: }
2464:
1.160.6.84.2. (raeburn 2465:): sub ltitools_javascript {
2466:): my ($settings) = @_;
2467:): return unless(ref($settings) eq 'HASH');
2468:): my (%ordered,$total,%jstext);
2469:): $total = 0;
2470:): foreach my $item (keys(%{$settings})) {
2471:): if (ref($settings->{$item}) eq 'HASH') {
2472:): my $num = $settings->{$item}{'order'};
2473:): $ordered{$num} = $item;
2474:): }
2475:): }
2476:): $total = scalar(keys(%{$settings}));
2477:): my @jsarray = ();
2478:): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2479:): push(@jsarray,$ordered{$item});
2480:): }
2481:): my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2482:): return <<"ENDSCRIPT";
2483:): <script type="text/javascript">
2484:): // <![CDATA[
2485:): function reorderLTI(form,item) {
2486:): var changedVal;
2487:): $jstext
2488:): var newpos = 'ltitools_add_pos';
2489:): var maxh = 1 + $total;
2490:): var current = new Array;
2491:): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2492:): if (item == newpos) {
2493:): changedVal = newitemVal;
2494:): } else {
2495:): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2496:): current[newitemVal] = newpos;
2497:): }
2498:): for (var i=0; i<ltitools.length; i++) {
2499:): var elementName = 'ltitools_'+ltitools[i];
2500:): if (elementName != item) {
2501:): if (form.elements[elementName]) {
2502:): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2503:): current[currVal] = elementName;
2504:): }
2505:): }
2506:): }
2507:): var oldVal;
2508:): for (var j=0; j<maxh; j++) {
2509:): if (current[j] == undefined) {
2510:): oldVal = j;
2511:): }
2512:): }
2513:): if (oldVal < changedVal) {
2514:): for (var k=oldVal+1; k<=changedVal ; k++) {
2515:): var elementName = current[k];
2516:): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2517:): }
2518:): } else {
2519:): for (var k=changedVal; k<oldVal; k++) {
2520:): var elementName = current[k];
2521:): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2522:): }
2523:): }
2524:): return;
2525:): }
2526:):
2527:): // ]]>
2528:): </script>
2529:):
2530:): ENDSCRIPT
2531:): }
2532:):
1.3 raeburn 2533: sub print_autoenroll {
1.30 raeburn 2534: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2535: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2536: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2537: if (ref($settings) eq 'HASH') {
2538: if (exists($settings->{'run'})) {
2539: if ($settings->{'run'} eq '0') {
2540: $runoff = ' checked="checked" ';
2541: $runon = ' ';
2542: } else {
2543: $runon = ' checked="checked" ';
2544: $runoff = ' ';
2545: }
2546: } else {
2547: if ($autorun) {
2548: $runon = ' checked="checked" ';
2549: $runoff = ' ';
2550: } else {
2551: $runoff = ' checked="checked" ';
2552: $runon = ' ';
2553: }
2554: }
1.129 raeburn 2555: if (exists($settings->{'co-owners'})) {
2556: if ($settings->{'co-owners'} eq '0') {
2557: $coownersoff = ' checked="checked" ';
2558: $coownerson = ' ';
2559: } else {
2560: $coownerson = ' checked="checked" ';
2561: $coownersoff = ' ';
2562: }
2563: } else {
2564: $coownersoff = ' checked="checked" ';
2565: $coownerson = ' ';
2566: }
1.3 raeburn 2567: if (exists($settings->{'sender_domain'})) {
2568: $defdom = $settings->{'sender_domain'};
2569: }
1.160.6.68 raeburn 2570: if (exists($settings->{'autofailsafe'})) {
2571: $failsafe = $settings->{'autofailsafe'};
2572: }
1.14 raeburn 2573: } else {
2574: if ($autorun) {
2575: $runon = ' checked="checked" ';
2576: $runoff = ' ';
2577: } else {
2578: $runoff = ' checked="checked" ';
2579: $runon = ' ';
2580: }
1.3 raeburn 2581: }
2582: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2583: my $notif_sender;
2584: if (ref($settings) eq 'HASH') {
2585: $notif_sender = $settings->{'sender_uname'};
2586: }
1.3 raeburn 2587: my $datatable='<tr class="LC_odd_row">'.
2588: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2589: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2590: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2591: $runon.' value="1" />'.&mt('Yes').'</label> '.
2592: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2593: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2594: '</tr><tr>'.
2595: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2596: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2597: &mt('username').': '.
2598: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2599: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2600: ': '.$domform.'</span></td></tr>'.
2601: '<tr class="LC_odd_row">'.
2602: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2603: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2604: '<input type="radio" name="autoassign_coowners"'.
2605: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2606: '<label><input type="radio" name="autoassign_coowners"'.
2607: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2608: '</tr><tr>'.
2609: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2610: '<td class="LC_right_item"><span class="LC_nobreak">'.
2611: '<input type="text" name="autoenroll_failsafe"'.
2612: ' value="'.$failsafe.'" size="4" /></td></tr>';
2613: $$rowtotal += 4;
1.3 raeburn 2614: return $datatable;
2615: }
2616:
2617: sub print_autoupdate {
1.30 raeburn 2618: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2619: my $datatable;
2620: if ($position eq 'top') {
2621: my $updateon = ' ';
2622: my $updateoff = ' checked="checked" ';
2623: my $classlistson = ' ';
2624: my $classlistsoff = ' checked="checked" ';
2625: if (ref($settings) eq 'HASH') {
2626: if ($settings->{'run'} eq '1') {
2627: $updateon = $updateoff;
2628: $updateoff = ' ';
2629: }
2630: if ($settings->{'classlists'} eq '1') {
2631: $classlistson = $classlistsoff;
2632: $classlistsoff = ' ';
2633: }
2634: }
2635: my %title = (
2636: run => 'Auto-update active?',
2637: classlists => 'Update information in classlists?',
2638: );
2639: $datatable = '<tr class="LC_odd_row">'.
2640: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2641: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2642: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2643: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2644: '<label><input type="radio" name="autoupdate_run"'.
2645: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2646: '</tr><tr>'.
2647: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2648: '<td class="LC_right_item"><span class="LC_nobreak">'.
2649: '<label><input type="radio" name="classlists"'.
2650: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2651: '<label><input type="radio" name="classlists"'.
2652: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2653: '</tr>';
1.30 raeburn 2654: $$rowtotal += 2;
1.131 raeburn 2655: } elsif ($position eq 'middle') {
2656: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2657: my $numinrow = 3;
2658: my $locknamesettings;
2659: $datatable .= &insttypes_row($settings,$types,$usertypes,
2660: $dom,$numinrow,$othertitle,
1.160.6.84.2. (raeburn 2661:): 'lockablenames',$rowtotal);
1.131 raeburn 2662: $$rowtotal ++;
1.3 raeburn 2663: } else {
1.44 raeburn 2664: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2665: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2666: 'permanentemail','id');
1.33 raeburn 2667: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2668: my $numrows = 0;
1.26 raeburn 2669: if (ref($types) eq 'ARRAY') {
2670: if (@{$types} > 0) {
2671: $datatable =
2672: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2673: \@fields,$types,\$numrows);
1.30 raeburn 2674: $$rowtotal += @{$types};
1.26 raeburn 2675: }
1.3 raeburn 2676: }
2677: $datatable .=
2678: &usertype_update_row($settings,{'default' => $othertitle},
2679: \%fieldtitles,\@fields,['default'],
2680: \$numrows);
1.30 raeburn 2681: $$rowtotal ++;
1.3 raeburn 2682: }
2683: return $datatable;
2684: }
2685:
1.125 raeburn 2686: sub print_autocreate {
2687: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2688: my (%createon,%createoff,%currhash);
1.125 raeburn 2689: my @types = ('xml','req');
2690: if (ref($settings) eq 'HASH') {
2691: foreach my $item (@types) {
2692: $createoff{$item} = ' checked="checked" ';
2693: $createon{$item} = ' ';
2694: if (exists($settings->{$item})) {
2695: if ($settings->{$item}) {
2696: $createon{$item} = ' checked="checked" ';
2697: $createoff{$item} = ' ';
2698: }
2699: }
2700: }
1.160.6.16 raeburn 2701: if ($settings->{'xmldc'} ne '') {
2702: $currhash{$settings->{'xmldc'}} = 1;
2703: }
1.125 raeburn 2704: } else {
2705: foreach my $item (@types) {
2706: $createoff{$item} = ' checked="checked" ';
2707: $createon{$item} = ' ';
2708: }
2709: }
2710: $$rowtotal += 2;
1.160.6.16 raeburn 2711: my $numinrow = 2;
1.125 raeburn 2712: my $datatable='<tr class="LC_odd_row">'.
2713: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2714: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2715: '<input type="radio" name="autocreate_xml"'.
2716: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2717: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2718: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2719: '</td></tr><tr>'.
2720: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2721: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2722: '<input type="radio" name="autocreate_req"'.
2723: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2724: '<label><input type="radio" name="autocreate_req"'.
2725: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2726: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2727: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2728: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2729: if ($numdc > 1) {
1.160.6.50 raeburn 2730: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2731: '</td><td class="LC_left_item">';
1.125 raeburn 2732: } else {
1.160.6.50 raeburn 2733: $datatable .= &mt('Course creation processed as:').
2734: '</td><td class="LC_right_item">';
1.125 raeburn 2735: }
1.160.6.50 raeburn 2736: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2737: $$rowtotal += $rows;
1.125 raeburn 2738: return $datatable;
2739: }
2740:
1.23 raeburn 2741: sub print_directorysrch {
1.160.6.72 raeburn 2742: my ($position,$dom,$settings,$rowtotal) = @_;
2743: my $datatable;
2744: if ($position eq 'top') {
2745: my $instsrchon = ' ';
2746: my $instsrchoff = ' checked="checked" ';
2747: my ($exacton,$containson,$beginson);
2748: my $instlocalon = ' ';
2749: my $instlocaloff = ' checked="checked" ';
2750: if (ref($settings) eq 'HASH') {
2751: if ($settings->{'available'} eq '1') {
2752: $instsrchon = $instsrchoff;
2753: $instsrchoff = ' ';
2754: }
2755: if ($settings->{'localonly'} eq '1') {
2756: $instlocalon = $instlocaloff;
2757: $instlocaloff = ' ';
2758: }
2759: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2760: foreach my $type (@{$settings->{'searchtypes'}}) {
2761: if ($type eq 'exact') {
2762: $exacton = ' checked="checked" ';
2763: } elsif ($type eq 'contains') {
2764: $containson = ' checked="checked" ';
2765: } elsif ($type eq 'begins') {
2766: $beginson = ' checked="checked" ';
2767: }
2768: }
2769: } else {
2770: if ($settings->{'searchtypes'} eq 'exact') {
2771: $exacton = ' checked="checked" ';
2772: } elsif ($settings->{'searchtypes'} eq 'contains') {
2773: $containson = ' checked="checked" ';
2774: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2775: $exacton = ' checked="checked" ';
2776: $containson = ' checked="checked" ';
2777: }
2778: }
1.23 raeburn 2779: }
1.160.6.72 raeburn 2780: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2781: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2782:
1.160.6.72 raeburn 2783: my $numinrow = 4;
2784: my $cansrchrow = 0;
2785: $datatable='<tr class="LC_odd_row">'.
2786: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2787: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2788: '<input type="radio" name="dirsrch_available"'.
2789: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2790: '<label><input type="radio" name="dirsrch_available"'.
2791: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2792: '</tr><tr>'.
2793: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2794: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2795: '<input type="radio" name="dirsrch_instlocalonly"'.
2796: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2797: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2798: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2799: '</tr>';
2800: $$rowtotal += 2;
2801: if (ref($usertypes) eq 'HASH') {
2802: if (keys(%{$usertypes}) > 0) {
2803: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.84.2. (raeburn 2804:): $numinrow,$othertitle,'cansearch',
2805:): $rowtotal);
1.160.6.72 raeburn 2806: $cansrchrow = 1;
2807: }
1.26 raeburn 2808: }
1.160.6.72 raeburn 2809: if ($cansrchrow) {
2810: $$rowtotal ++;
2811: $datatable .= '<tr>';
2812: } else {
2813: $datatable .= '<tr class="LC_odd_row">';
2814: }
2815: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2816: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2817: foreach my $title (@{$titleorder}) {
2818: if (defined($searchtitles->{$title})) {
2819: my $check = ' ';
2820: if (ref($settings) eq 'HASH') {
2821: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2822: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2823: $check = ' checked="checked" ';
2824: }
1.39 raeburn 2825: }
1.25 raeburn 2826: }
1.160.6.72 raeburn 2827: $datatable .= '<td class="LC_left_item">'.
2828: '<span class="LC_nobreak"><label>'.
2829: '<input type="checkbox" name="searchby" '.
2830: 'value="'.$title.'"'.$check.'/>'.
2831: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2832: }
2833: }
1.160.6.72 raeburn 2834: $datatable .= '</tr></table></td></tr>';
2835: $$rowtotal ++;
2836: if ($cansrchrow) {
2837: $datatable .= '<tr class="LC_odd_row">';
2838: } else {
2839: $datatable .= '<tr>';
2840: }
2841: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2842: '<td class="LC_left_item" colspan="2">'.
2843: '<span class="LC_nobreak"><label>'.
2844: '<input type="checkbox" name="searchtypes" '.
2845: $exacton.' value="exact" />'.&mt('Exact match').
2846: '</label> '.
2847: '<label><input type="checkbox" name="searchtypes" '.
2848: $beginson.' value="begins" />'.&mt('Begins with').
2849: '</label> '.
2850: '<label><input type="checkbox" name="searchtypes" '.
2851: $containson.' value="contains" />'.&mt('Contains').
2852: '</label></span></td></tr>';
2853: $$rowtotal ++;
1.26 raeburn 2854: } else {
1.160.6.72 raeburn 2855: my $domsrchon = ' checked="checked" ';
2856: my $domsrchoff = ' ';
2857: my $domlocalon = ' ';
2858: my $domlocaloff = ' checked="checked" ';
2859: if (ref($settings) eq 'HASH') {
2860: if ($settings->{'lclocalonly'} eq '1') {
2861: $domlocalon = $domlocaloff;
2862: $domlocaloff = ' ';
2863: }
2864: if ($settings->{'lcavailable'} eq '0') {
2865: $domsrchoff = $domsrchon;
2866: $domsrchon = ' ';
2867: }
2868: }
2869: $datatable='<tr class="LC_odd_row">'.
2870: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2871: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2872: '<input type="radio" name="dirsrch_domavailable"'.
2873: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2874: '<label><input type="radio" name="dirsrch_domavailable"'.
2875: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2876: '</tr><tr>'.
2877: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2878: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2879: '<input type="radio" name="dirsrch_domlocalonly"'.
2880: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2881: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2882: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2883: '</tr>';
2884: $$rowtotal += 2;
1.26 raeburn 2885: }
1.25 raeburn 2886: return $datatable;
2887: }
2888:
1.28 raeburn 2889: sub print_contacts {
1.160.6.78 raeburn 2890: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2891: my $datatable;
2892: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 2893: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2894: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
2895: if ($position eq 'top') {
2896: if (ref($settings) eq 'HASH') {
2897: foreach my $item (@contacts) {
2898: if (exists($settings->{$item})) {
2899: $to{$item} = $settings->{$item};
2900: }
1.28 raeburn 2901: }
2902: }
1.160.6.78 raeburn 2903: } elsif ($position eq 'middle') {
2904: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
2905: 'updatesmail','idconflictsmail');
1.28 raeburn 2906: foreach my $type (@mailings) {
1.160.6.78 raeburn 2907: $otheremails{$type} = '';
2908: }
2909: } else {
2910: @mailings = ('helpdeskmail','otherdomsmail');
2911: foreach my $type (@mailings) {
2912: $otheremails{$type} = '';
2913: }
2914: $bccemails{'helpdeskmail'} = '';
2915: $bccemails{'otherdomsmail'} = '';
2916: $includestr{'helpdeskmail'} = '';
2917: $includestr{'otherdomsmail'} = '';
2918: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
2919: }
2920: if (ref($settings) eq 'HASH') {
2921: unless ($position eq 'top') {
2922: foreach my $type (@mailings) {
2923: if (exists($settings->{$type})) {
2924: if (ref($settings->{$type}) eq 'HASH') {
2925: foreach my $item (@contacts) {
2926: if ($settings->{$type}{$item}) {
2927: $checked{$type}{$item} = ' checked="checked" ';
2928: }
1.28 raeburn 2929: }
1.160.6.78 raeburn 2930: $otheremails{$type} = $settings->{$type}{'others'};
2931: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2932: $bccemails{$type} = $settings->{$type}{'bcc'};
2933: if ($settings->{$type}{'include'} ne '') {
2934: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2935: $includestr{$type} = &unescape($includestr{$type});
2936: }
2937: }
2938: }
2939: } elsif ($type eq 'lonstatusmail') {
2940: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2941: }
2942: }
2943: }
2944: if ($position eq 'bottom') {
2945: foreach my $type (@mailings) {
2946: $bccemails{$type} = $settings->{$type}{'bcc'};
2947: if ($settings->{$type}{'include'} ne '') {
2948: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2949: $includestr{$type} = &unescape($includestr{$type});
2950: }
2951: }
2952: if (ref($settings->{'helpform'}) eq 'HASH') {
2953: if (ref($fields) eq 'ARRAY') {
2954: foreach my $field (@{$fields}) {
2955: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 2956: }
1.160.6.78 raeburn 2957: }
2958: if (exists($settings->{'helpform'}{'maxsize'})) {
2959: $maxsize = $settings->{'helpform'}{'maxsize'};
2960: } else {
2961: $maxsize = '1.0';
2962: }
2963: } else {
2964: if (ref($fields) eq 'ARRAY') {
2965: foreach my $field (@{$fields}) {
2966: $currfield{$field} = 'yes';
1.134 raeburn 2967: }
1.28 raeburn 2968: }
1.160.6.78 raeburn 2969: $maxsize = '1.0';
1.28 raeburn 2970: }
2971: }
2972: } else {
1.160.6.78 raeburn 2973: if ($position eq 'top') {
2974: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2975: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2976: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2977: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2978: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2979: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2980: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2981: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
2982: } elsif ($position eq 'bottom') {
2983: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2984: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
2985: if (ref($fields) eq 'ARRAY') {
2986: foreach my $field (@{$fields}) {
2987: $currfield{$field} = 'yes';
2988: }
2989: }
2990: $maxsize = '1.0';
2991: }
1.28 raeburn 2992: }
2993: my ($titles,$short_titles) = &contact_titles();
2994: my $rownum = 0;
2995: my $css_class;
1.160.6.78 raeburn 2996: if ($position eq 'top') {
2997: foreach my $item (@contacts) {
2998: $css_class = $rownum%2?' class="LC_odd_row"':'';
2999: $datatable .= '<tr'.$css_class.'>'.
3000: '<td><span class="LC_nobreak">'.$titles->{$item}.
3001: '</span></td><td class="LC_right_item">'.
3002: '<input type="text" name="'.$item.'" value="'.
3003: $to{$item}.'" /></td></tr>';
3004: $rownum ++;
3005: }
1.160.6.84.2. (raeburn 3006:): } elsif ($position eq 'bottom') {
3007:): $css_class = $rownum%2?' class="LC_odd_row"':'';
3008:): $datatable .= '<tr'.$css_class.'>'.
3009:): '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3010:): &mt('(e-mail, subject, and description always shown)').
3011:): '</td><td class="LC_left_item">';
3012:): if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3013:): (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3014:): $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3015:): foreach my $field (@{$fields}) {
3016:): $datatable .= '<tr><td>'.$fieldtitles->{$field};
3017:): if (($field eq 'screenshot') || ($field eq 'cc')) {
3018:): $datatable .= ' '.&mt('(logged-in users)');
3019:): }
3020:): $datatable .='</td><td>';
3021:): my $clickaction;
3022:): if ($field eq 'screenshot') {
3023:): $clickaction = ' onclick="screenshotSize(this);"';
3024:): }
3025:): if (ref($possoptions->{$field}) eq 'ARRAY') {
3026:): foreach my $option (@{$possoptions->{$field}}) {
3027:): my $checked;
3028:): if ($currfield{$field} eq $option) {
3029:): $checked = ' checked="checked"';
3030:): }
3031:): $datatable .= '<span class="LC_nobreak"><label>'.
3032:): '<input type="radio" name="helpform_'.$field.'" '.
3033:): 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3034:): '</label></span>'.(' 'x2);
3035:): }
3036:): }
3037:): if ($field eq 'screenshot') {
3038:): my $display;
3039:): if ($currfield{$field} eq 'no') {
3040:): $display = ' style="display:none"';
3041:): }
3042:): $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3043:): '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3044:): '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3045:): }
3046:): $datatable .= '</td></tr>';
3047:): }
3048:): $datatable .= '</table>';
3049:): }
3050:): $datatable .= '</td></tr>'."\n";
3051:): $rownum ++;
3052:): }
3053:): unless ($position eq 'top') {
1.160.6.78 raeburn 3054: foreach my $type (@mailings) {
3055: $css_class = $rownum%2?' class="LC_odd_row"':'';
3056: $datatable .= '<tr'.$css_class.'>'.
3057: '<td><span class="LC_nobreak">'.
3058: $titles->{$type}.': </span></td>'.
3059: '<td class="LC_left_item">';
3060: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3061: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3062: }
3063: $datatable .= '<span class="LC_nobreak">';
3064: foreach my $item (@contacts) {
3065: $datatable .= '<label>'.
3066: '<input type="checkbox" name="'.$type.'"'.
3067: $checked{$type}{$item}.
3068: ' value="'.$item.'" />'.$short_titles->{$item}.
3069: '</label> ';
3070: }
3071: $datatable .= '</span><br />'.&mt('Others').': '.
3072: '<input type="text" name="'.$type.'_others" '.
3073: 'value="'.$otheremails{$type}.'" />';
3074: my %locchecked;
3075: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3076: foreach my $loc ('s','b') {
3077: if ($includeloc{$type} eq $loc) {
3078: $locchecked{$loc} = ' checked="checked"';
3079: last;
3080: }
3081: }
3082: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3083: '<input type="text" name="'.$type.'_bcc" '.
3084: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3085: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3086: &mt('Text automatically added to e-mail:').' '.
3087: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3088: '<span class="LC_nobreak">'.&mt('Location:').' '.
3089: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3090: (' 'x2).
3091: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3092: '</span></fieldset>';
3093: }
3094: $datatable .= '</td></tr>'."\n";
3095: $rownum ++;
3096: }
1.28 raeburn 3097: }
1.160.6.78 raeburn 3098: if ($position eq 'middle') {
3099: my %choices;
3100: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
3101: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3102: &mt('LON-CAPA core group - MSU'),600,500));
3103: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3104: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3105: &mt('LON-CAPA core group - MSU'),600,500));
3106: my @toggles = ('reporterrors','reportupdates');
3107: my %defaultchecked = ('reporterrors' => 'on',
3108: 'reportupdates' => 'on');
3109: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3110: \%choices,$rownum);
3111: $datatable .= $reports;
3112: } elsif ($position eq 'bottom') {
1.160.6.84.2. (raeburn 3113:): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3114:): my (@posstypes,%usertypeshash);
3115:): if (ref($types) eq 'ARRAY') {
3116:): @posstypes = @{$types};
3117:): }
3118:): if (@posstypes) {
3119:): if (ref($usertypes) eq 'HASH') {
3120:): %usertypeshash = %{$usertypes};
3121:): }
3122:): my @overridden;
3123:): my $numinrow = 4;
3124:): if (ref($settings) eq 'HASH') {
3125:): if (ref($settings->{'overrides'}) eq 'HASH') {
3126:): foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3127:): if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3128:): push(@overridden,$key);
3129:): foreach my $item (@contacts) {
3130:): if ($settings->{'overrides'}{$key}{$item}) {
3131:): $checked{'override_'.$key}{$item} = ' checked="checked" ';
3132:): }
3133:): }
3134:): $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3135:): $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3136:): $includeloc{'override_'.$key} = '';
3137:): $includestr{'override_'.$key} = '';
3138:): if ($settings->{'overrides'}{$key}{'include'} ne '') {
3139:): ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3140:): split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3141:): $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3142:): }
1.160.6.78 raeburn 3143: }
3144: }
3145: }
1.160.6.84.2. (raeburn 3146:): }
3147:): my $customclass = 'LC_helpdesk_override';
3148:): my $optionsprefix = 'LC_options_helpdesk_';
3149:):
3150:): my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3151:):
3152:): $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3153:): $numinrow,$othertitle,'overrides',
3154:): \$rownum,$onclicktypes,$customclass);
3155:): $rownum ++;
3156:): $usertypeshash{'default'} = $othertitle;
3157:): foreach my $status (@posstypes) {
3158:): my $css_class;
3159:): if ($rownum%2) {
3160:): $css_class = 'LC_odd_row ';
3161:): }
3162:): $css_class .= $customclass;
3163:): my $rowid = $optionsprefix.$status;
3164:): my $hidden = 1;
3165:): my $currstyle = 'display:none';
3166:): if (grep(/^\Q$status\E$/,@overridden)) {
3167:): $currstyle = 'display:table-row';
3168:): $hidden = 0;
3169:): }
3170:): my $key = 'override_'.$status;
3171:): $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3172:): $includeloc{$key},$includestr{$key},$status,$rowid,
3173:): $usertypeshash{$status},$css_class,$currstyle,
3174:): \@contacts,$short_titles);
3175:): unless ($hidden) {
3176:): $rownum ++;
1.160.6.78 raeburn 3177: }
3178: }
1.134 raeburn 3179: }
1.28 raeburn 3180: }
1.30 raeburn 3181: $$rowtotal += $rownum;
1.28 raeburn 3182: return $datatable;
3183: }
3184:
1.160.6.84.2. (raeburn 3185:): sub overridden_helpdesk {
3186:): my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3187:): $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3188:): my $class = 'LC_left_item';
3189:): if ($css_class) {
3190:): $css_class = ' class="'.$css_class.'"';
3191:): }
3192:): if ($rowid) {
3193:): $rowid = ' id="'.$rowid.'"';
3194:): }
3195:): if ($rowstyle) {
3196:): $rowstyle = ' style="'.$rowstyle.'"';
3197:): }
3198:): my ($output,$description);
3199:): $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3200:): $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3201:): "<td>$description</td>\n".
3202:): '<td class="'.$class.'" colspan="2">'.
3203:): '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3204:): '<span class="LC_nobreak">';
3205:): if (ref($contacts) eq 'ARRAY') {
3206:): foreach my $item (@{$contacts}) {
3207:): my $check;
3208:): if (ref($checked) eq 'HASH') {
3209:): $check = $checked->{$item};
3210:): }
3211:): my $title;
3212:): if (ref($short_titles) eq 'HASH') {
3213:): $title = $short_titles->{$item};
3214:): }
3215:): $output .= '<label>'.
3216:): '<input type="checkbox" name="override_'.$type.'"'.$check.
3217:): ' value="'.$item.'" />'.$title.'</label> ';
3218:): }
3219:): }
3220:): $output .= '</span><br />'.&mt('Others').': '.
3221:): '<input type="text" name="override_'.$type.'_others" '.
3222:): 'value="'.$otheremails.'" />';
3223:): my %locchecked;
3224:): foreach my $loc ('s','b') {
3225:): if ($includeloc eq $loc) {
3226:): $locchecked{$loc} = ' checked="checked"';
3227:): last;
3228:): }
3229:): }
3230:): $output .= '<br />'.&mt('Bcc:').(' 'x6).
3231:): '<input type="text" name="override_'.$type.'_bcc" '.
3232:): 'value="'.$bccemails.'" /></fieldset>'.
3233:): '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3234:): &mt('Text automatically added to e-mail:').' '.
3235:): '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br >'.
3236:): '<span class="LC_nobreak">'.&mt('Location:').' '.
3237:): '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3238:): (' 'x2).
3239:): '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3240:): '</span></fieldset>'.
3241:): '</td></tr>'."\n";
3242:): return $output;
3243:): }
3244:):
1.160.6.78 raeburn 3245: sub contacts_javascript {
3246: return <<"ENDSCRIPT";
3247:
3248: <script type="text/javascript">
3249: // <![CDATA[
3250:
3251: function screenshotSize(field) {
3252: if (document.getElementById('help_screenshotsize')) {
3253: if (field.value == 'no') {
3254: document.getElementById('help_screenshotsize').style.display="none";
3255: } else {
3256: document.getElementById('help_screenshotsize').style.display="";
3257: }
3258: }
3259: return;
3260: }
3261:
1.160.6.84.2. (raeburn 3262:): function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3263:): if (form.elements[checkbox].length != undefined) {
3264:): var count = 0;
3265:): if (docount) {
3266:): for (var i=0; i<form.elements[checkbox].length; i++) {
3267:): if (form.elements[checkbox][i].checked) {
3268:): count ++;
3269:): }
3270:): }
3271:): }
3272:): for (var i=0; i<form.elements[checkbox].length; i++) {
3273:): var type = form.elements[checkbox][i].value;
3274:): if (document.getElementById(prefix+type)) {
3275:): if (form.elements[checkbox][i].checked) {
3276:): document.getElementById(prefix+type).style.display = 'table-row';
3277:): if (count % 2 == 1) {
3278:): document.getElementById(prefix+type).className = target+' LC_odd_row';
3279:): } else {
3280:): document.getElementById(prefix+type).className = target;
3281:): }
3282:): count ++;
3283:): } else {
3284:): document.getElementById(prefix+type).style.display = 'none';
3285:): }
3286:): }
3287:): }
3288:): }
3289:): return;
3290:): }
3291:):
3292:):
1.160.6.78 raeburn 3293: // ]]>
3294: </script>
3295:
3296: ENDSCRIPT
3297: }
3298:
1.118 jms 3299: sub print_helpsettings {
1.160.6.73 raeburn 3300: my ($position,$dom,$settings,$rowtotal) = @_;
3301: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3302: my $formname = 'display';
1.160.6.5 raeburn 3303: my ($datatable,$itemcount);
1.160.6.73 raeburn 3304: if ($position eq 'top') {
3305: $itemcount = 1;
3306: my (%choices,%defaultchecked,@toggles);
3307: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3308: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3309: &mt('LON-CAPA bug tracker'),600,500));
3310: %defaultchecked = ('submitbugs' => 'on');
3311: @toggles = ('submitbugs');
3312: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3313: \%choices,$itemcount);
3314: $$rowtotal ++;
3315: } else {
3316: my $css_class;
3317: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3318: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 3319: if (ref($settings) eq 'HASH') {
3320: if (ref($settings->{'adhoc'}) eq 'HASH') {
3321: %current = %{$settings->{'adhoc'}};
3322: }
1.160.6.77 raeburn 3323: }
3324: my $count = 0;
3325: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3326: if ($key=~/^rolesdef\_(\w+)$/) {
3327: my $rolename = $1;
1.160.6.77 raeburn 3328: my (%privs,$order);
1.160.6.73 raeburn 3329: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3330: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3331: if (ref($current{$rolename}) eq 'HASH') {
3332: $order = $current{$rolename}{'order'};
3333: }
3334: if ($order eq '') {
3335: $order = $count;
3336: }
3337: $ordered{$order} = $rolename;
3338: $count++;
1.160.6.73 raeburn 3339: }
3340: }
1.160.6.77 raeburn 3341: my $maxnum = scalar(keys(%ordered));
3342: my @roles_by_num = ();
3343: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3344: push(@roles_by_num,$item);
3345: }
3346: my $context = 'domprefs';
3347: my $crstype = 'Course';
3348: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3349: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3350: my ($numstatustypes,@jsarray);
3351: if (ref($types) eq 'ARRAY') {
3352: if (@{$types} > 0) {
3353: $numstatustypes = scalar(@{$types});
3354: push(@accesstypes,'status');
3355: @jsarray = ('bystatus');
3356: }
3357: }
1.160.6.84.2. (raeburn 3358:): my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3359: if (keys(%domhelpdesk)) {
3360: push(@accesstypes,('inc','exc'));
3361: push(@jsarray,('notinc','notexc'));
3362: }
3363: my $hiddenstr = join("','",@jsarray);
3364: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3365: my $context = 'domprefs';
3366: my $crstype = 'Course';
1.160.6.77 raeburn 3367: my $prefix = 'helproles_';
3368: my $add_class = 'LC_hidden';
3369: foreach my $num (@roles_by_num) {
3370: my $role = $ordered{$num};
3371: my ($desc,$access,@statuses);
3372: if (ref($current{$role}) eq 'HASH') {
3373: $desc = $current{$role}{'desc'};
3374: $access = $current{$role}{'access'};
3375: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3376: @statuses = @{$current{$role}{'insttypes'}};
3377: }
3378: }
3379: if ($desc eq '') {
3380: $desc = $role;
3381: }
3382: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3383: my %full=();
3384: my %levels= (
3385: course => {},
3386: domain => {},
3387: system => {},
3388: );
3389: my %levelscurrent=(
3390: course => {},
3391: domain => {},
3392: system => {},
3393: );
3394: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3395: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3396: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3397: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3398: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3399: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3400: for (my $k=0; $k<=$maxnum; $k++) {
3401: my $vpos = $k+1;
3402: my $selstr;
3403: if ($k == $num) {
3404: $selstr = ' selected="selected" ';
3405: }
3406: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3407: }
3408: $datatable .= '</select>'.(' 'x2).
3409: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3410: '</td>'.
3411: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3412: &mt('Name shown to users:').
3413: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3414: '</fieldset>'.
3415: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3416: $othertitle,$usertypes,$types,\%domhelpdesk).
3417: '<fieldset>'.
3418: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3419: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3420: \%levelscurrent,$identifier,
3421: 'LC_hidden',$prefix.$num.'_privs').
3422: '</fieldset></td>';
1.160.6.73 raeburn 3423: $itemcount ++;
3424: }
3425: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3426: my $newcust = 'custhelp'.$count;
3427: my (%privs,%levelscurrent);
3428: my %full=();
3429: my %levels= (
3430: course => {},
3431: domain => {},
3432: system => {},
3433: );
3434: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3435: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3436: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3437: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3438: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3439: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3440: for (my $k=0; $k<$maxnum+1; $k++) {
3441: my $vpos = $k+1;
3442: my $selstr;
3443: if ($k == $maxnum) {
3444: $selstr = ' selected="selected" ';
3445: }
3446: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3447: }
3448: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3449: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3450: '</label></span></td>'.
1.160.6.77 raeburn 3451: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3452: '<span class="LC_nobreak">'.
3453: &mt('Internal name:').
3454: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3455: '</span>'.(' 'x4).
3456: '<span class="LC_nobreak">'.
3457: &mt('Name shown to users:').
3458: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3459: '</span></fieldset>'.
3460: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3461: $usertypes,$types,\%domhelpdesk).
3462: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3463: &Apache::lonuserutils::custom_role_header($context,$crstype,
3464: \@templateroles,$newcust).
3465: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3466: \%levelscurrent,$newcust).
1.160.6.77 raeburn 3467: '</fieldset></td></tr>';
1.160.6.73 raeburn 3468: $count ++;
3469: $$rowtotal += $count;
3470: }
1.160.6.5 raeburn 3471: return $datatable;
1.121 raeburn 3472: }
3473:
1.160.6.77 raeburn 3474: sub adhocbutton {
3475: my ($prefix,$num,$field,$visibility) = @_;
3476: my %lt = &Apache::lonlocal::texthash(
3477: show => 'Show details',
3478: hide => 'Hide details',
3479: );
3480: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3481: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3482: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3483: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3484: }
3485:
3486: sub helpsettings_javascript {
3487: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3488: return unless(ref($roles_by_num) eq 'ARRAY');
3489: my %html_js_lt = &Apache::lonlocal::texthash(
3490: show => 'Show details',
3491: hide => 'Hide details',
3492: );
3493: &html_escape(\%html_js_lt);
3494: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3495: return <<"ENDSCRIPT";
3496: <script type="text/javascript">
3497: // <![CDATA[
3498:
3499: function reorderHelpRoles(form,item) {
3500: var changedVal;
3501: $jstext
3502: var newpos = 'helproles_${total}_pos';
3503: var maxh = 1 + $total;
3504: var current = new Array();
3505: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3506: if (item == newpos) {
3507: changedVal = newitemVal;
3508: } else {
3509: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3510: current[newitemVal] = newpos;
3511: }
3512: for (var i=0; i<helproles.length; i++) {
3513: var elementName = 'helproles_'+helproles[i]+'_pos';
3514: if (elementName != item) {
3515: if (form.elements[elementName]) {
3516: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3517: current[currVal] = elementName;
3518: }
3519: }
3520: }
3521: var oldVal;
3522: for (var j=0; j<maxh; j++) {
3523: if (current[j] == undefined) {
3524: oldVal = j;
3525: }
3526: }
3527: if (oldVal < changedVal) {
3528: for (var k=oldVal+1; k<=changedVal ; k++) {
3529: var elementName = current[k];
3530: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3531: }
3532: } else {
3533: for (var k=changedVal; k<oldVal; k++) {
3534: var elementName = current[k];
3535: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3536: }
3537: }
3538: return;
3539: }
3540:
3541: function helpdeskAccess(num) {
3542: var curraccess = null;
3543: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3544: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3545: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3546: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3547: }
3548: }
3549: }
3550: var shown = Array();
3551: var hidden = Array();
3552: if (curraccess == 'none') {
3553: hidden = Array('$hiddenstr');
3554: } else {
3555: if (curraccess == 'status') {
3556: shown = Array('bystatus');
3557: hidden = Array('notinc','notexc');
3558: } else {
3559: if (curraccess == 'exc') {
3560: shown = Array('notexc');
3561: hidden = Array('notinc','bystatus');
3562: }
3563: if (curraccess == 'inc') {
3564: shown = Array('notinc');
3565: hidden = Array('notexc','bystatus');
3566: }
1.160.6.79 raeburn 3567: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3568: hidden = Array('notinc','notexc','bystatus');
3569: }
3570: }
3571: }
3572: if (hidden.length > 0) {
3573: for (var i=0; i<hidden.length; i++) {
3574: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3575: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3576: }
3577: }
3578: }
3579: if (shown.length > 0) {
3580: for (var i=0; i<shown.length; i++) {
3581: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3582: if (shown[i] == 'privs') {
3583: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3584: } else {
3585: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3586: }
3587: }
3588: }
3589: }
3590: return;
3591: }
3592:
3593: function toggleHelpdeskItem(num,field) {
3594: if (document.getElementById('helproles_'+num+'_'+field)) {
3595: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3596: document.getElementById('helproles_'+num+'_'+field).className =
3597: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3598: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3599: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3600: }
3601: } else {
3602: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3603: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3604: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3605: }
3606: }
3607: }
3608: return;
3609: }
3610:
3611: // ]]>
3612: </script>
3613:
3614: ENDSCRIPT
3615: }
3616:
3617: sub helpdeskroles_access {
3618: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3619: $usertypes,$types,$domhelpdesk) = @_;
3620: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3621: my %lt = &Apache::lonlocal::texthash(
3622: 'rou' => 'Role usage',
3623: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3624: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3625: 'dh' => 'All with domain helpdesk role',
3626: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3627: 'none' => 'None',
3628: 'status' => 'Determined based on institutional status',
3629: 'inc' => 'Include all, but exclude specific personnel',
3630: 'exc' => 'Exclude all, but include specific personnel',
3631: );
3632: my %usecheck = (
3633: all => ' checked="checked"',
3634: );
3635: my %displaydiv = (
3636: status => 'none',
3637: inc => 'none',
3638: exc => 'none',
3639: priv => 'block',
3640: );
3641: my $output;
3642: if (ref($current) eq 'HASH') {
3643: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3644: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3645: $usecheck{$current->{access}} = $usecheck{'all'};
3646: delete($usecheck{'all'});
3647: if ($current->{access} =~ /^(status|inc|exc)$/) {
3648: my $access = $1;
3649: $displaydiv{$access} = 'inline';
3650: } elsif ($current->{access} eq 'none') {
3651: $displaydiv{'priv'} = 'none';
3652: }
3653: }
3654: }
3655: }
3656: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3657: '<p>'.$lt{'whi'}.'</p>';
3658: foreach my $access (@{$accesstypes}) {
3659: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3660: ' onclick="helpdeskAccess('."'$num'".');" />'.
3661: $lt{$access}.'</label>';
3662: if ($access eq 'status') {
3663: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3664: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3665: $othertitle,$usertypes,$types).
3666: '</div>';
3667: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3668: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3669: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3670: '</div>';
3671: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3672: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3673: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3674: '</div>';
3675: }
3676: $output .= '</p>';
3677: }
3678: $output .= '</fieldset>';
3679: return $output;
3680: }
3681:
1.121 raeburn 3682: sub radiobutton_prefs {
1.160.6.16 raeburn 3683: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3684: $additional,$align) = @_;
1.121 raeburn 3685: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3686: (ref($choices) eq 'HASH'));
3687:
3688: my (%checkedon,%checkedoff,$datatable,$css_class);
3689:
3690: foreach my $item (@{$toggles}) {
3691: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3692: $checkedon{$item} = ' checked="checked" ';
3693: $checkedoff{$item} = ' ';
1.121 raeburn 3694: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3695: $checkedoff{$item} = ' checked="checked" ';
3696: $checkedon{$item} = ' ';
3697: }
3698: }
3699: if (ref($settings) eq 'HASH') {
1.121 raeburn 3700: foreach my $item (@{$toggles}) {
1.118 jms 3701: if ($settings->{$item} eq '1') {
3702: $checkedon{$item} = ' checked="checked" ';
3703: $checkedoff{$item} = ' ';
3704: } elsif ($settings->{$item} eq '0') {
3705: $checkedoff{$item} = ' checked="checked" ';
3706: $checkedon{$item} = ' ';
3707: }
3708: }
1.121 raeburn 3709: }
1.160.6.16 raeburn 3710: if ($onclick) {
3711: $onclick = ' onclick="'.$onclick.'"';
3712: }
1.121 raeburn 3713: foreach my $item (@{$toggles}) {
1.118 jms 3714: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3715: $datatable .=
1.160.6.16 raeburn 3716: '<tr'.$css_class.'><td valign="top">'.
3717: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3718: '</span></td>';
3719: if ($align eq 'left') {
3720: $datatable .= '<td class="LC_left_item">';
3721: } else {
3722: $datatable .= '<td class="LC_right_item">';
3723: }
3724: $datatable .=
3725: '<span class="LC_nobreak">'.
1.118 jms 3726: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3727: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3728: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3729: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3730: '</span>'.$additional.
3731: '</td>'.
1.118 jms 3732: '</tr>';
3733: $itemcount ++;
1.121 raeburn 3734: }
3735: return ($datatable,$itemcount);
3736: }
3737:
1.160.6.84.2. (raeburn 3738:): sub print_ltitools {
3739:): my ($dom,$settings,$rowtotal) = @_;
3740:): my $rownum = 0;
3741:): my $css_class;
3742:): my $itemcount = 1;
3743:): my $maxnum = 0;
3744:): my %ordered;
3745:): if (ref($settings) eq 'HASH') {
3746:): foreach my $item (keys(%{$settings})) {
3747:): if (ref($settings->{$item}) eq 'HASH') {
3748:): my $num = $settings->{$item}{'order'};
3749:): $ordered{$num} = $item;
3750:): }
3751:): }
3752:): }
3753:): my $confname = $dom.'-domainconfig';
3754:): my $switchserver = &check_switchserver($dom,$confname);
3755:): my $maxnum = scalar(keys(%ordered));
3756:): my $datatable = <itools_javascript($settings);
3757:): my %lt = <itools_names();
3758:): my @courseroles = ('cc','in','ta','ep','st');
3759:): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3760:): my @fields = ('fullname','firstname','lastname','email','user','roles');
3761:): if (keys(%ordered)) {
3762:): my @items = sort { $a <=> $b } keys(%ordered);
3763:): for (my $i=0; $i<@items; $i++) {
3764:): $css_class = $itemcount%2?' class="LC_odd_row"':'';
3765:): my $item = $ordered{$items[$i]};
3766:): my ($title,$key,$secret,$url,$imgsrc,$version);
3767:): if (ref($settings->{$item}) eq 'HASH') {
3768:): $title = $settings->{$item}->{'title'};
3769:): $url = $settings->{$item}->{'url'};
3770:): $key = $settings->{$item}->{'key'};
3771:): $secret = $settings->{$item}->{'secret'};
3772:): my $image = $settings->{$item}->{'image'};
3773:): if ($image ne '') {
3774:): $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3775:): }
3776:): }
3777:): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3778:): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3779:): .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3780:): for (my $k=0; $k<=$maxnum; $k++) {
3781:): my $vpos = $k+1;
3782:): my $selstr;
3783:): if ($k == $i) {
3784:): $selstr = ' selected="selected" ';
3785:): }
3786:): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3787:): }
3788:): $datatable .= '</select>'.(' 'x2).
3789:): '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3790:): &mt('Delete?').'</label></span></td>'.
3791:): '<td colspan="2">'.
3792:): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3793:): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3794:): (' 'x2).
3795:): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3796:): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3797:): (' 'x2).
3798:): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3799:): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3800:): '<br /><br />'.
3801:): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3802:): ' value="'.$url.'" /></span>'.
3803:): (' 'x2).
3804:): '<span class="LC_nobreak">'.$lt{'key'}.
3805:): '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3806:): (' 'x2).
3807:): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3808:): '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3809:): '<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>'.
3810:): '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3811:): '</fieldset>'.
3812:): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3813:): '<span class="LC_nobreak">'.&mt('Display target:');
3814:): my %currdisp;
3815:): if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3816:): if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3817:): $currdisp{'window'} = ' checked="checked"';
3818:): } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
3819:): $currdisp{'tab'} = ' checked="checked"';
3820:): } else {
3821:): $currdisp{'iframe'} = ' checked="checked"';
3822:): }
3823:): if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3824:): $currdisp{'width'} = $1;
3825:): }
3826:): if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3827:): $currdisp{'height'} = $1;
3828:): }
3829:): $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
3830:): $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
3831:): } else {
3832:): $currdisp{'iframe'} = ' checked="checked"';
3833:): }
3834:): foreach my $disp ('iframe','tab','window') {
3835:): $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3836:): $lt{$disp}.'</label>'.(' 'x2);
3837:): }
3838:): $datatable .= (' 'x4);
3839:): foreach my $dimen ('width','height') {
3840:): $datatable .= '<label>'.$lt{$dimen}.' '.
3841:): '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3842:): (' 'x2);
3843:): }
3844:): $datatable .= '<br />'.
3845:): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3846:): '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
3847:): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3848:): '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
3849:): '</textarea></div><div style=""></div><br />';
3850:): $datatable .= '<br />';
3851:): foreach my $extra ('passback','roster') {
3852:): my $checkedon = '';
3853:): my $checkedoff = ' checked="checked"';
3854:): if ($settings->{$item}->{$extra}) {
3855:): $checkedon = $checkedoff;
3856:): $checkedoff = '';
3857:): }
3858:): $datatable .= $lt{$extra}.' '.
3859:): '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3860:): &mt('Yes').'</label>'.(' 'x2).
3861:): '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3862:): &mt('No').'</label>'.(' 'x4);
3863:): }
3864:): $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3865:): if ($imgsrc) {
3866:): $datatable .= $imgsrc.
3867:): '<label><input type="checkbox" name="ltitools_image_del"'.
3868:): ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3869:): '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3870:): } else {
3871:): $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3872:): }
3873:): if ($switchserver) {
3874:): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3875:): } else {
3876:): $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3877:): }
3878:): $datatable .= '</span></fieldset>';
3879:): my (%checkedfields,%rolemaps);
3880:): if (ref($settings->{$item}) eq 'HASH') {
3881:): if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3882:): %checkedfields = %{$settings->{$item}->{'fields'}};
3883:): }
3884:): if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3885:): %rolemaps = %{$settings->{$item}->{'roles'}};
3886:): $checkedfields{'roles'} = 1;
3887:): }
3888:): }
3889:): $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3890:): '<span class="LC_nobreak">';
3891:): foreach my $field (@fields) {
3892:): my $checked;
3893:): if ($checkedfields{$field}) {
3894:): $checked = ' checked="checked"';
3895:): }
3896:): $datatable .= '<label>'.
3897:): '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3898:): $lt{$field}.'</label>'.(' ' x2);
3899:): }
3900:): $datatable .= '</span></fieldset>'.
3901:): '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3902:): foreach my $role (@courseroles) {
3903:): my ($selected,$selectnone);
3904:): if (!$rolemaps{$role}) {
3905:): $selectnone = ' selected="selected"';
3906:): }
3907:): $datatable .= '<td align="center">'.
3908:): &Apache::lonnet::plaintext($role,'Course').'<br />'.
3909:): '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3910:): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3911:): foreach my $ltirole (@ltiroles) {
3912:): unless ($selectnone) {
3913:): if ($rolemaps{$role} eq $ltirole) {
3914:): $selected = ' selected="selected"';
3915:): } else {
3916:): $selected = '';
3917:): }
3918:): }
3919:): $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3920:): }
3921:): $datatable .= '</select></td>';
3922:): }
3923:): $datatable .= '</tr></table></fieldset>';
3924:): my %courseconfig;
3925:): if (ref($settings->{$item}) eq 'HASH') {
3926:): if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3927:): %courseconfig = %{$settings->{$item}->{'crsconf'}};
3928:): }
3929:): }
3930:): $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3931:): foreach my $item ('label','title','target','linktext','explanation') {
3932:): my $checked;
3933:): if ($courseconfig{$item}) {
3934:): $checked = ' checked="checked"';
3935:): }
3936:): $datatable .= '<label>'.
3937:): '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3938:): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3939:): }
3940:): $datatable .= '</span></fieldset>'.
3941:): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3942:): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3943:): if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3944:): my %custom = %{$settings->{$item}->{'custom'}};
3945:): if (keys(%custom) > 0) {
3946:): foreach my $key (sort(keys(%custom))) {
3947:): $datatable .= '<tr><td><span class="LC_nobreak">'.
3948:): '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3949:): $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3950:): '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3951:): ' value="'.$custom{$key}.'" /></td></tr>';
3952:): }
3953:): }
3954:): }
3955:): $datatable .= '<tr><td><span class="LC_nobreak">'.
3956:): '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3957:): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3958:): '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3959:): $datatable .= '</table></fieldset></td></tr>'."\n";
3960:): $itemcount ++;
3961:): }
3962:): }
3963:): $css_class = $itemcount%2?' class="LC_odd_row"':'';
3964:): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3965:): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3966:): '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3967:): '<select name="ltitools_add_pos"'.$chgstr.'>';
3968:): for (my $k=0; $k<$maxnum+1; $k++) {
3969:): my $vpos = $k+1;
3970:): my $selstr;
3971:): if ($k == $maxnum) {
3972:): $selstr = ' selected="selected" ';
3973:): }
3974:): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3975:): }
3976:): $datatable .= '</select> '."\n".
3977:): '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3978:): '<td colspan="2">'.
3979:): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3980:): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3981:): (' 'x2).
3982:): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3983:): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3984:): (' 'x2).
3985:): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3986:): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3987:): '<br />'.
3988:): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3989:): (' 'x2).
3990:): '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3991:): (' 'x2).
3992:): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3993:): '<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".
3994:): '</fieldset>'.
3995:): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3996:): '<span class="LC_nobreak">'.&mt('Display target:');
3997:): my %defaultdisp;
3998:): $defaultdisp{'iframe'} = ' checked="checked"';
3999:): foreach my $disp ('iframe','tab','window') {
4000:): $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4001:): $lt{$disp}.'</label>'.(' 'x2);
4002:): }
4003:): $datatable .= (' 'x4);
4004:): foreach my $dimen ('width','height') {
4005:): $datatable .= '<label>'.$lt{$dimen}.' '.
4006:): '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4007:): (' 'x2);
4008:): }
4009:): $datatable .= '<br />'.
4010:): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4011:): '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
4012:): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4013:): '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4014:): '</div><div style=""></div><br />';
4015:): foreach my $extra ('passback','roster') {
4016:): $datatable .= $lt{$extra}.' '.
4017:): '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
4018:): &mt('Yes').'</label>'.(' 'x2).
4019:): '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
4020:): &mt('No').'</label>'.(' 'x4);
4021:): }
4022:): $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
4023:): '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4024:): if ($switchserver) {
4025:): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4026:): } else {
4027:): $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4028:): }
4029:): $datatable .= '</span></fieldset>'.
4030:): '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4031:): '<span class="LC_nobreak">';
4032:): foreach my $field (@fields) {
4033:): $datatable .= '<label>'.
4034:): '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
4035:): $lt{$field}.'</label>'.(' ' x2);
4036:): }
4037:): $datatable .= '</span></fieldset>'.
4038:): '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4039:): foreach my $role (@courseroles) {
4040:): my ($checked,$checkednone);
4041:): $datatable .= '<td align="center">'.
4042:): &Apache::lonnet::plaintext($role,'Course').'<br />'.
4043:): '<select name="ltitools_add_roles_'.$role.'">'.
4044:): '<option value="" selected="selected">'.&mt('Select').'</option>';
4045:): foreach my $ltirole (@ltiroles) {
4046:): $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4047:): }
4048:): $datatable .= '</select></td>';
4049:): }
4050:): $datatable .= '</tr></table></fieldset>'.
4051:): '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
4052:): foreach my $item ('label','title','target','linktext','explanation') {
4053:): $datatable .= '<label>'.
4054:): '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4055:): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4056:): }
4057:): $datatable .= '</span></fieldset>'.
4058:): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4059:): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4060:): '<tr><td><span class="LC_nobreak">'.
4061:): '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4062:): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4063:): '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4064:): '</table></fieldset></td></tr>'."\n".
4065:): '</td>'."\n".
4066:): '</tr>'."\n";
4067:): $itemcount ++;
4068:): return $datatable;
4069:): }
4070:):
4071:): sub ltitools_names {
4072:): my %lt = &Apache::lonlocal::texthash(
4073:): 'title' => 'Title',
4074:): 'version' => 'Version',
4075:): 'msgtype' => 'Message Type',
4076:): 'url' => 'URL',
4077:): 'key' => 'Key',
4078:): 'secret' => 'Secret',
4079:): 'icon' => 'Icon',
4080:): 'user' => 'Username:domain',
4081:): 'fullname' => 'Full Name',
4082:): 'firstname' => 'First Name',
4083:): 'lastname' => 'Last Name',
4084:): 'email' => 'E-mail',
4085:): 'roles' => 'Role',
4086:): 'window' => 'Window',
4087:): 'tab' => 'Tab',
4088:): 'iframe' => 'iFrame',
4089:): 'height' => 'Height',
4090:): 'width' => 'Width',
4091:): 'linktext' => 'Default Link Text',
4092:): 'explanation' => 'Default Explanation',
4093:): 'passback' => 'Tool can return grades:',
4094:): 'roster' => 'Tool can retrieve roster:',
4095:): 'crstarget' => 'Display target',
4096:): 'crslabel' => 'Course label',
4097:): 'crstitle' => 'Course title',
4098:): 'crslinktext' => 'Link Text',
4099:): 'crsexplanation' => 'Explanation',
4100:): );
4101:):
4102:): return %lt;
4103:): }
4104:):
1.121 raeburn 4105: sub print_coursedefaults {
1.139 raeburn 4106: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 4107: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4108: my $itemcount = 1;
1.160.6.16 raeburn 4109: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 4110: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 4111: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4112: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 4113: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4114: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
4115: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 4116: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 4117: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 4118: );
1.160.6.21 raeburn 4119: my %staticdefaults = (
4120: anonsurvey_threshold => 10,
4121: uploadquota => 500,
1.160.6.57 raeburn 4122: postsubmit => 60,
1.160.6.70 raeburn 4123: mysqltables => 172800,
1.160.6.21 raeburn 4124: );
1.139 raeburn 4125: if ($position eq 'top') {
1.160.6.57 raeburn 4126: %defaultchecked = (
4127: 'uselcmath' => 'on',
4128: 'usejsme' => 'on',
1.160.6.64 raeburn 4129: 'canclone' => 'none',
1.160.6.57 raeburn 4130: );
4131: @toggles = ('uselcmath','usejsme');
1.139 raeburn 4132: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4133: \%choices,$itemcount);
1.160.6.64 raeburn 4134: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4135: $datatable .=
4136: '<tr'.$css_class.'><td valign="top">'.
4137: '<span class="LC_nobreak">'.$choices{'canclone'}.
4138: '</span></td><td class="LC_left_item">';
4139: my $currcanclone = 'none';
4140: my $onclick;
4141: my @cloneoptions = ('none','domain');
4142: my %clonetitles = (
4143: none => 'No additional course requesters',
4144: domain => "Any course requester in course's domain",
4145: instcode => 'Course requests for official courses ...',
4146: );
4147: my (%codedefaults,@code_order,@posscodes);
4148: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4149: \@code_order) eq 'ok') {
4150: if (@code_order > 0) {
4151: push(@cloneoptions,'instcode');
4152: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4153: }
4154: }
4155: if (ref($settings) eq 'HASH') {
4156: if ($settings->{'canclone'}) {
4157: if (ref($settings->{'canclone'}) eq 'HASH') {
4158: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4159: if (@code_order > 0) {
4160: $currcanclone = 'instcode';
4161: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4162: }
4163: }
4164: } elsif ($settings->{'canclone'} eq 'domain') {
4165: $currcanclone = $settings->{'canclone'};
4166: }
4167: }
4168: }
4169: foreach my $option (@cloneoptions) {
4170: my ($checked,$additional);
4171: if ($currcanclone eq $option) {
4172: $checked = ' checked="checked"';
4173: }
4174: if ($option eq 'instcode') {
4175: if (@code_order) {
4176: my $show = 'none';
4177: if ($checked) {
4178: $show = 'block';
4179: }
4180: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4181: &mt('Institutional codes for new and cloned course have identical:').
4182: '<br />';
4183: foreach my $item (@code_order) {
4184: my $codechk;
4185: if ($checked) {
4186: if (grep(/^\Q$item\E$/,@posscodes)) {
4187: $codechk = ' checked="checked"';
4188: }
4189: }
4190: $additional .= '<label>'.
4191: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4192: $item.'</label>';
4193: }
4194: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4195: }
4196: }
4197: $datatable .=
4198: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4199: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4200: '</label> '.$additional.'</span><br />';
4201: }
4202: $datatable .= '</td>'.
4203: '</tr>';
4204: $itemcount ++;
1.139 raeburn 4205: } else {
4206: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 4207: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 4208: my $currusecredits = 0;
1.160.6.57 raeburn 4209: my $postsubmitclient = 1;
1.160.6.30 raeburn 4210: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 4211: if (ref($settings) eq 'HASH') {
4212: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 4213: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4214: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4215: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4216: }
4217: }
1.160.6.16 raeburn 4218: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 4219: foreach my $type (@types) {
4220: next if ($type eq 'community');
4221: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4222: if ($defcredits{$type} ne '') {
4223: $currusecredits = 1;
4224: }
4225: }
4226: }
4227: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4228: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4229: $postsubmitclient = 0;
4230: foreach my $type (@types) {
4231: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4232: }
4233: } else {
4234: foreach my $type (@types) {
4235: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4236: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4237: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4238: } else {
4239: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4240: }
4241: } else {
4242: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4243: }
4244: }
4245: }
4246: } else {
4247: foreach my $type (@types) {
4248: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 4249: }
4250: }
1.160.6.70 raeburn 4251: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4252: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4253: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4254: }
4255: } else {
4256: foreach my $type (@types) {
4257: $currmysql{$type} = $staticdefaults{'mysqltables'};
4258: }
4259: }
1.160.6.58 raeburn 4260: } else {
4261: foreach my $type (@types) {
4262: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4263: }
1.139 raeburn 4264: }
4265: if (!$currdefresponder) {
1.160.6.21 raeburn 4266: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4267: } elsif ($currdefresponder < 1) {
4268: $currdefresponder = 1;
4269: }
1.160.6.21 raeburn 4270: foreach my $type (@types) {
4271: if ($curruploadquota{$type} eq '') {
4272: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4273: }
4274: }
1.139 raeburn 4275: $datatable .=
1.160.6.16 raeburn 4276: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4277: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4278: '</span></td>'.
4279: '<td class="LC_right_item"><span class="LC_nobreak">'.
4280: '<input type="text" name="anonsurvey_threshold"'.
4281: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 4282: '</td></tr>'."\n";
4283: $itemcount ++;
4284: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4285: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4286: $choices{'uploadquota'}.
4287: '</span></td>'.
4288: '<td align="right" class="LC_right_item">'.
4289: '<table><tr>';
1.160.6.21 raeburn 4290: foreach my $type (@types) {
4291: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4292: '<input type="text" name="uploadquota_'.$type.'"'.
4293: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4294: }
4295: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 4296: $itemcount ++;
1.160.6.40 raeburn 4297: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 4298: my $display = 'none';
4299: if ($currusecredits) {
4300: $display = 'block';
4301: }
4302: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 4303: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4304: foreach my $type (@types) {
4305: next if ($type eq 'community');
4306: $additional .= '<td align="center">'.&mt($type).'<br />'.
4307: '<input type="text" name="'.$type.'_credits"'.
4308: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4309: }
4310: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 4311: %defaultchecked = ('coursecredits' => 'off');
4312: @toggles = ('coursecredits');
4313: my $current = {
4314: 'coursecredits' => $currusecredits,
4315: };
4316: (my $table,$itemcount) =
4317: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4318: \%choices,$itemcount,$onclick,$additional,'left');
4319: $datatable .= $table;
4320: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4321: my $display = 'none';
4322: if ($postsubmitclient) {
4323: $display = 'block';
4324: }
4325: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 4326: &mt('Number of seconds submit is disabled').'<br />'.
4327: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4328: '<table><tr>';
1.160.6.57 raeburn 4329: foreach my $type (@types) {
4330: $additional .= '<td align="center">'.&mt($type).'<br />'.
4331: '<input type="text" name="'.$type.'_timeout" value="'.
4332: $deftimeout{$type}.'" size="5" /></td>';
4333: }
4334: $additional .= '</tr></table></div>'."\n";
4335: %defaultchecked = ('postsubmit' => 'on');
4336: @toggles = ('postsubmit');
1.160.6.70 raeburn 4337: $current = {
4338: 'postsubmit' => $postsubmitclient,
4339: };
1.160.6.57 raeburn 4340: ($table,$itemcount) =
4341: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4342: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 4343: $datatable .= $table;
1.160.6.70 raeburn 4344: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4345: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4346: $choices{'mysqltables'}.
4347: '</span></td>'.
4348: '<td align="right" class="LC_right_item">'.
4349: '<table><tr>';
4350: foreach my $type (@types) {
4351: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4352: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 4353: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 4354: }
4355: $datatable .= '</tr></table></td></tr>'."\n";
4356: $itemcount ++;
4357:
1.160.6.37 raeburn 4358: }
4359: $$rowtotal += $itemcount;
4360: return $datatable;
4361: }
4362:
4363: sub print_selfenrollment {
4364: my ($position,$dom,$settings,$rowtotal) = @_;
4365: my ($css_class,$datatable);
4366: my $itemcount = 1;
4367: my @types = ('official','unofficial','community','textbook');
4368: if (($position eq 'top') || ($position eq 'middle')) {
4369: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4370: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4371: my @rows;
4372: my $key;
4373: if ($position eq 'top') {
4374: $key = 'admin';
4375: if (ref($rowsref) eq 'ARRAY') {
4376: @rows = @{$rowsref};
4377: }
4378: } elsif ($position eq 'middle') {
4379: $key = 'default';
4380: @rows = ('types','registered','approval','limit');
4381: }
4382: foreach my $row (@rows) {
4383: if (defined($titlesref->{$row})) {
4384: $itemcount ++;
4385: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4386: $datatable .= '<tr'.$css_class.'>'.
4387: '<td>'.$titlesref->{$row}.'</td>'.
4388: '<td class="LC_left_item">'.
4389: '<table><tr>';
4390: my (%current,%currentcap);
4391: if (ref($settings) eq 'HASH') {
4392: if (ref($settings->{$key}) eq 'HASH') {
4393: foreach my $type (@types) {
4394: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4395: $current{$type} = $settings->{$key}->{$type}->{$row};
4396: }
4397: if (($row eq 'limit') && ($key eq 'default')) {
4398: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4399: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4400: }
4401: }
4402: }
4403: }
4404: }
4405: my %roles = (
4406: '0' => &Apache::lonnet::plaintext('dc'),
4407: );
4408:
4409: foreach my $type (@types) {
4410: unless (($row eq 'registered') && ($key eq 'default')) {
4411: $datatable .= '<th>'.&mt($type).'</th>';
4412: }
4413: }
4414: unless (($row eq 'registered') && ($key eq 'default')) {
4415: $datatable .= '</tr><tr>';
4416: }
4417: foreach my $type (@types) {
4418: if ($type eq 'community') {
4419: $roles{'1'} = &mt('Community personnel');
4420: } else {
4421: $roles{'1'} = &mt('Course personnel');
4422: }
4423: $datatable .= '<td style="vertical-align: top">';
4424: if ($position eq 'top') {
4425: my %checked;
4426: if ($current{$type} eq '0') {
4427: $checked{'0'} = ' checked="checked"';
4428: } else {
4429: $checked{'1'} = ' checked="checked"';
4430: }
4431: foreach my $role ('1','0') {
4432: $datatable .= '<span class="LC_nobreak"><label>'.
4433: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4434: 'value="'.$role.'"'.$checked{$role}.' />'.
4435: $roles{$role}.'</label></span> ';
4436: }
4437: } else {
4438: if ($row eq 'types') {
4439: my %checked;
4440: if ($current{$type} =~ /^(all|dom)$/) {
4441: $checked{$1} = ' checked="checked"';
4442: } else {
4443: $checked{''} = ' checked="checked"';
4444: }
4445: foreach my $val ('','dom','all') {
4446: $datatable .= '<span class="LC_nobreak"><label>'.
4447: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4448: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4449: }
4450: } elsif ($row eq 'registered') {
4451: my %checked;
4452: if ($current{$type} eq '1') {
4453: $checked{'1'} = ' checked="checked"';
4454: } else {
4455: $checked{'0'} = ' checked="checked"';
4456: }
4457: foreach my $val ('0','1') {
4458: $datatable .= '<span class="LC_nobreak"><label>'.
4459: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4460: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4461: }
4462: } elsif ($row eq 'approval') {
4463: my %checked;
4464: if ($current{$type} =~ /^([12])$/) {
4465: $checked{$1} = ' checked="checked"';
4466: } else {
4467: $checked{'0'} = ' checked="checked"';
4468: }
4469: for my $val (0..2) {
4470: $datatable .= '<span class="LC_nobreak"><label>'.
4471: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4472: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4473: }
4474: } elsif ($row eq 'limit') {
4475: my %checked;
4476: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4477: $checked{$1} = ' checked="checked"';
4478: } else {
4479: $checked{'none'} = ' checked="checked"';
4480: }
4481: my $cap;
4482: if ($currentcap{$type} =~ /^\d+$/) {
4483: $cap = $currentcap{$type};
4484: }
4485: foreach my $val ('none','allstudents','selfenrolled') {
4486: $datatable .= '<span class="LC_nobreak"><label>'.
4487: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4488: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4489: }
4490: $datatable .= '<br />'.
4491: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4492: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4493: '</span>';
4494: }
4495: }
4496: $datatable .= '</td>';
4497: }
4498: $datatable .= '</tr>';
4499: }
4500: $datatable .= '</table></td></tr>';
4501: }
4502: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 4503: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4504: }
4505: $$rowtotal += $itemcount;
4506: return $datatable;
4507: }
4508:
4509: sub print_validation_rows {
4510: my ($caller,$dom,$settings,$rowtotal) = @_;
4511: my ($itemsref,$namesref,$fieldsref);
4512: if ($caller eq 'selfenroll') {
4513: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4514: } elsif ($caller eq 'requestcourses') {
4515: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4516: }
4517: my %currvalidation;
4518: if (ref($settings) eq 'HASH') {
4519: if (ref($settings->{'validation'}) eq 'HASH') {
4520: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 4521: }
1.160.6.39 raeburn 4522: }
4523: my $datatable;
4524: my $itemcount = 0;
4525: foreach my $item (@{$itemsref}) {
4526: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4527: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4528: $namesref->{$item}.
4529: '</span></td>'.
4530: '<td class="LC_left_item">';
4531: if (($item eq 'url') || ($item eq 'button')) {
4532: $datatable .= '<span class="LC_nobreak">'.
4533: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4534: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4535: } elsif ($item eq 'fields') {
4536: my @currfields;
4537: if (ref($currvalidation{$item}) eq 'ARRAY') {
4538: @currfields = @{$currvalidation{$item}};
4539: }
4540: foreach my $field (@{$fieldsref}) {
4541: my $check = '';
4542: if (grep(/^\Q$field\E$/,@currfields)) {
4543: $check = ' checked="checked"';
4544: }
4545: $datatable .= '<span class="LC_nobreak"><label>'.
4546: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4547: ' value="'.$field.'"'.$check.' />'.$field.
4548: '</label></span> ';
4549: }
4550: } elsif ($item eq 'markup') {
4551: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4552: $currvalidation{$item}.
1.160.6.37 raeburn 4553: '</textarea>';
1.160.6.39 raeburn 4554: }
4555: $datatable .= '</td></tr>'."\n";
4556: if (ref($rowtotal)) {
1.160.6.37 raeburn 4557: $itemcount ++;
4558: }
1.139 raeburn 4559: }
1.160.6.39 raeburn 4560: if ($caller eq 'requestcourses') {
4561: my %currhash;
1.160.6.51 raeburn 4562: if (ref($settings) eq 'HASH') {
4563: if (ref($settings->{'validation'}) eq 'HASH') {
4564: if ($settings->{'validation'}{'dc'} ne '') {
4565: $currhash{$settings->{'validation'}{'dc'}} = 1;
4566: }
1.160.6.39 raeburn 4567: }
4568: }
4569: my $numinrow = 2;
4570: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4571: 'validationdc',%currhash);
1.160.6.50 raeburn 4572: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4573: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39 raeburn 4574: if ($numdc > 1) {
1.160.6.50 raeburn 4575: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 4576: } else {
1.160.6.50 raeburn 4577: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 4578: }
1.160.6.50 raeburn 4579: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 4580: $itemcount ++;
4581: }
4582: if (ref($rowtotal)) {
4583: $$rowtotal += $itemcount;
4584: }
1.121 raeburn 4585: return $datatable;
1.118 jms 4586: }
4587:
1.137 raeburn 4588: sub print_usersessions {
4589: my ($position,$dom,$settings,$rowtotal) = @_;
4590: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 4591: my (%by_ip,%by_location,@intdoms);
4592: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 4593:
4594: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4595: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4596: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4597: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4598: my $itemcount = 1;
4599: if ($position eq 'top') {
1.152 raeburn 4600: if (keys(%serverhomes) > 1) {
1.145 raeburn 4601: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 4602: my $curroffloadnow;
4603: if (ref($settings) eq 'HASH') {
4604: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4605: $curroffloadnow = $settings->{'offloadnow'};
4606: }
4607: }
4608: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4609: } else {
1.140 raeburn 4610: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4611: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 4612: }
1.137 raeburn 4613: } else {
1.145 raeburn 4614: if (keys(%by_location) == 0) {
4615: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4616: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 4617: } else {
4618: my %lt = &usersession_titles();
4619: my $numinrow = 5;
4620: my $prefix;
4621: my @types;
4622: if ($position eq 'bottom') {
4623: $prefix = 'remote';
4624: @types = ('version','excludedomain','includedomain');
4625: } else {
4626: $prefix = 'hosted';
4627: @types = ('excludedomain','includedomain');
4628: }
4629: my (%current,%checkedon,%checkedoff);
4630: my @lcversions = &Apache::lonnet::all_loncaparevs();
4631: my @locations = sort(keys(%by_location));
4632: foreach my $type (@types) {
4633: $checkedon{$type} = '';
4634: $checkedoff{$type} = ' checked="checked"';
4635: }
4636: if (ref($settings) eq 'HASH') {
4637: if (ref($settings->{$prefix}) eq 'HASH') {
4638: foreach my $key (keys(%{$settings->{$prefix}})) {
4639: $current{$key} = $settings->{$prefix}{$key};
4640: if ($key eq 'version') {
4641: if ($current{$key} ne '') {
4642: $checkedon{$key} = ' checked="checked"';
4643: $checkedoff{$key} = '';
4644: }
4645: } elsif (ref($current{$key}) eq 'ARRAY') {
4646: $checkedon{$key} = ' checked="checked"';
4647: $checkedoff{$key} = '';
4648: }
1.137 raeburn 4649: }
4650: }
4651: }
1.145 raeburn 4652: foreach my $type (@types) {
4653: next if ($type ne 'version' && !@locations);
4654: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4655: $datatable .= '<tr'.$css_class.'>
4656: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4657: <span class="LC_nobreak">
4658: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4659: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4660: if ($type eq 'version') {
4661: my $selector = '<select name="'.$prefix.'_version">';
4662: foreach my $version (@lcversions) {
4663: my $selected = '';
4664: if ($current{'version'} eq $version) {
4665: $selected = ' selected="selected"';
4666: }
4667: $selector .= ' <option value="'.$version.'"'.
4668: $selected.'>'.$version.'</option>';
4669: }
4670: $selector .= '</select> ';
4671: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4672: } else {
4673: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4674: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4675: ' />'.(' 'x2).
4676: '<input type="button" value="'.&mt('uncheck all').'" '.
4677: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4678: "\n".
4679: '</div><div><table>';
4680: my $rem;
4681: for (my $i=0; $i<@locations; $i++) {
4682: my ($showloc,$value,$checkedtype);
4683: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4684: my $ip = $by_location{$locations[$i]}->[0];
4685: if (ref($by_ip{$ip}) eq 'ARRAY') {
4686: $value = join(':',@{$by_ip{$ip}});
4687: $showloc = join(', ',@{$by_ip{$ip}});
4688: if (ref($current{$type}) eq 'ARRAY') {
4689: foreach my $loc (@{$by_ip{$ip}}) {
4690: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4691: $checkedtype = ' checked="checked"';
4692: last;
4693: }
4694: }
1.138 raeburn 4695: }
4696: }
4697: }
1.145 raeburn 4698: $rem = $i%($numinrow);
4699: if ($rem == 0) {
4700: if ($i > 0) {
4701: $datatable .= '</tr>';
4702: }
4703: $datatable .= '<tr>';
4704: }
4705: $datatable .= '<td class="LC_left_item">'.
4706: '<span class="LC_nobreak"><label>'.
4707: '<input type="checkbox" name="'.$prefix.'_'.$type.
4708: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4709: '</label></span></td>';
1.137 raeburn 4710: }
1.145 raeburn 4711: $rem = @locations%($numinrow);
4712: my $colsleft = $numinrow - $rem;
4713: if ($colsleft > 1 ) {
4714: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4715: ' </td>';
4716: } elsif ($colsleft == 1) {
4717: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4718: }
1.145 raeburn 4719: $datatable .= '</tr></table>';
1.137 raeburn 4720: }
1.145 raeburn 4721: $datatable .= '</td></tr>';
4722: $itemcount ++;
1.137 raeburn 4723: }
4724: }
4725: }
4726: $$rowtotal += $itemcount;
4727: return $datatable;
4728: }
4729:
1.138 raeburn 4730: sub build_location_hashes {
4731: my ($intdoms,$by_ip,$by_location) = @_;
4732: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4733: (ref($by_location) eq 'HASH'));
4734: my %iphost = &Apache::lonnet::get_iphost();
4735: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4736: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4737: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4738: foreach my $id (@{$iphost{$primary_ip}}) {
4739: my $intdom = &Apache::lonnet::internet_dom($id);
4740: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4741: push(@{$intdoms},$intdom);
4742: }
4743: }
4744: }
4745: foreach my $ip (keys(%iphost)) {
4746: if (ref($iphost{$ip}) eq 'ARRAY') {
4747: foreach my $id (@{$iphost{$ip}}) {
4748: my $location = &Apache::lonnet::internet_dom($id);
4749: if ($location) {
4750: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4751: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4752: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4753: push(@{$by_ip->{$ip}},$location);
4754: }
4755: } else {
4756: $by_ip->{$ip} = [$location];
4757: }
4758: }
4759: }
4760: }
4761: }
4762: foreach my $ip (sort(keys(%{$by_ip}))) {
4763: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4764: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4765: my $first = $by_ip->{$ip}->[0];
4766: if (ref($by_location->{$first}) eq 'ARRAY') {
4767: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4768: push(@{$by_location->{$first}},$ip);
4769: }
4770: } else {
4771: $by_location->{$first} = [$ip];
4772: }
4773: }
4774: }
4775: return;
4776: }
4777:
1.145 raeburn 4778: sub current_offloads_to {
4779: my ($dom,$settings,$servers) = @_;
4780: my (%spareid,%otherdomconfigs);
1.152 raeburn 4781: if (ref($servers) eq 'HASH') {
1.145 raeburn 4782: foreach my $lonhost (sort(keys(%{$servers}))) {
4783: my $gotspares;
1.152 raeburn 4784: if (ref($settings) eq 'HASH') {
4785: if (ref($settings->{'spares'}) eq 'HASH') {
4786: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4787: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4788: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4789: $gotspares = 1;
4790: }
1.145 raeburn 4791: }
4792: }
4793: unless ($gotspares) {
4794: my $gotspares;
4795: my $serverhomeID =
4796: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4797: my $serverhomedom =
4798: &Apache::lonnet::host_domain($serverhomeID);
4799: if ($serverhomedom ne $dom) {
4800: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4801: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4802: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4803: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4804: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4805: $gotspares = 1;
4806: }
4807: }
4808: } else {
4809: $otherdomconfigs{$serverhomedom} =
4810: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4811: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4812: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4813: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4814: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4815: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4816: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4817: $gotspares = 1;
4818: }
4819: }
4820: }
4821: }
4822: }
4823: }
4824: }
4825: unless ($gotspares) {
4826: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4827: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4828: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4829: } else {
4830: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4831: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4832: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4833: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4834: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4835: } else {
1.150 raeburn 4836: my %what = (
4837: spareid => 1,
4838: );
4839: my ($result,$returnhash) =
4840: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4841: if ($result eq 'ok') {
4842: if (ref($returnhash) eq 'HASH') {
4843: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4844: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4845: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4846: }
4847: }
1.145 raeburn 4848: }
4849: }
4850: }
4851: }
4852: }
4853: }
4854: return %spareid;
4855: }
4856:
4857: sub spares_row {
1.160.6.61 raeburn 4858: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4859: my $css_class;
4860: my $numinrow = 4;
4861: my $itemcount = 1;
4862: my $datatable;
1.152 raeburn 4863: my %typetitles = &sparestype_titles();
4864: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4865: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4866: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4867: my ($othercontrol,$serverdom);
4868: if ($serverhome ne $server) {
4869: $serverdom = &Apache::lonnet::host_domain($serverhome);
4870: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4871: } else {
4872: $serverdom = &Apache::lonnet::host_domain($server);
4873: if ($serverdom ne $dom) {
4874: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4875: }
4876: }
4877: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 4878: my $checkednow;
4879: if (ref($curroffloadnow) eq 'HASH') {
4880: if ($curroffloadnow->{$server}) {
4881: $checkednow = ' checked="checked"';
4882: }
4883: }
1.145 raeburn 4884: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4885: $datatable .= '<tr'.$css_class.'>
4886: <td rowspan="2">
1.160.6.13 raeburn 4887: <span class="LC_nobreak">'.
4888: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 4889: ,'<b>'.$server.'</b>').'</span><br />'.
4890: '<span class="LC_nobreak">'."\n".
4891: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4892: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 4893: "\n";
1.145 raeburn 4894: my (%current,%canselect);
1.152 raeburn 4895: my @choices =
4896: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4897: foreach my $type ('primary','default') {
4898: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4899: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4900: my @spares = @{$spareid->{$server}{$type}};
4901: if (@spares > 0) {
1.152 raeburn 4902: if ($othercontrol) {
4903: $current{$type} = join(', ',@spares);
4904: } else {
4905: $current{$type} .= '<table>';
4906: my $numspares = scalar(@spares);
4907: for (my $i=0; $i<@spares; $i++) {
4908: my $rem = $i%($numinrow);
4909: if ($rem == 0) {
4910: if ($i > 0) {
4911: $current{$type} .= '</tr>';
4912: }
4913: $current{$type} .= '<tr>';
1.145 raeburn 4914: }
1.152 raeburn 4915: $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'".');" /> '.
4916: $spareid->{$server}{$type}[$i].
4917: '</label></td>'."\n";
4918: }
4919: my $rem = @spares%($numinrow);
4920: my $colsleft = $numinrow - $rem;
4921: if ($colsleft > 1 ) {
4922: $current{$type} .= '<td colspan="'.$colsleft.
4923: '" class="LC_left_item">'.
4924: ' </td>';
4925: } elsif ($colsleft == 1) {
4926: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4927: }
1.152 raeburn 4928: $current{$type} .= '</tr></table>';
1.150 raeburn 4929: }
1.145 raeburn 4930: }
4931: }
4932: if ($current{$type} eq '') {
4933: $current{$type} = &mt('None specified');
4934: }
1.152 raeburn 4935: if ($othercontrol) {
4936: if ($type eq 'primary') {
4937: $canselect{$type} = $othercontrol;
4938: }
4939: } else {
4940: $canselect{$type} =
4941: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4942: '<select name="newspare_'.$type.'_'.$server.'" '.
4943: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4944: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4945: if (@choices > 0) {
4946: foreach my $lonhost (@choices) {
4947: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4948: }
4949: }
4950: $canselect{$type} .= '</select>'."\n";
4951: }
4952: } else {
4953: $current{$type} = &mt('Could not be determined');
4954: if ($type eq 'primary') {
4955: $canselect{$type} = $othercontrol;
4956: }
1.145 raeburn 4957: }
1.152 raeburn 4958: if ($type eq 'default') {
4959: $datatable .= '<tr'.$css_class.'>';
4960: }
4961: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4962: '<td>'.$current{$type}.'</td>'."\n".
4963: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4964: }
4965: $itemcount ++;
4966: }
4967: }
4968: $$rowtotal += $itemcount;
4969: return $datatable;
4970: }
4971:
1.152 raeburn 4972: sub possible_newspares {
4973: my ($server,$currspares,$serverhomes,$altids) = @_;
4974: my $serverhostname = &Apache::lonnet::hostname($server);
4975: my %excluded;
4976: if ($serverhostname ne '') {
4977: %excluded = (
4978: $serverhostname => 1,
4979: );
4980: }
4981: if (ref($currspares) eq 'HASH') {
4982: foreach my $type (keys(%{$currspares})) {
4983: if (ref($currspares->{$type}) eq 'ARRAY') {
4984: if (@{$currspares->{$type}} > 0) {
4985: foreach my $curr (@{$currspares->{$type}}) {
4986: my $hostname = &Apache::lonnet::hostname($curr);
4987: $excluded{$hostname} = 1;
4988: }
4989: }
4990: }
4991: }
4992: }
4993: my @choices;
4994: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4995: if (keys(%{$serverhomes}) > 1) {
4996: foreach my $name (sort(keys(%{$serverhomes}))) {
4997: unless ($excluded{$name}) {
4998: if (exists($altids->{$serverhomes->{$name}})) {
4999: push(@choices,$altids->{$serverhomes->{$name}});
5000: } else {
5001: push(@choices,$serverhomes->{$name});
1.145 raeburn 5002: }
5003: }
5004: }
5005: }
5006: }
1.152 raeburn 5007: return sort(@choices);
1.145 raeburn 5008: }
5009:
1.150 raeburn 5010: sub print_loadbalancing {
5011: my ($dom,$settings,$rowtotal) = @_;
5012: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5013: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5014: my $numinrow = 1;
5015: my $datatable;
5016: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 5017: my (%currbalancer,%currtargets,%currrules,%existing);
5018: if (ref($settings) eq 'HASH') {
5019: %existing = %{$settings};
5020: }
5021: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5022: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5023: \%currtargets,\%currrules);
1.150 raeburn 5024: } else {
5025: return;
5026: }
5027: my ($othertitle,$usertypes,$types) =
5028: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 5029: my $rownum = 8;
1.150 raeburn 5030: if (ref($types) eq 'ARRAY') {
5031: $rownum += scalar(@{$types});
5032: }
1.160.6.7 raeburn 5033: my @css_class = ('LC_odd_row','LC_even_row');
5034: my $balnum = 0;
5035: my $islast;
5036: my (@toshow,$disabledtext);
5037: if (keys(%currbalancer) > 0) {
5038: @toshow = sort(keys(%currbalancer));
5039: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5040: push(@toshow,'');
5041: }
5042: } else {
5043: @toshow = ('');
5044: $disabledtext = &mt('No existing load balancer');
5045: }
5046: foreach my $lonhost (@toshow) {
5047: if ($balnum == scalar(@toshow)-1) {
5048: $islast = 1;
5049: } else {
5050: $islast = 0;
5051: }
5052: my $cssidx = $balnum%2;
5053: my $targets_div_style = 'display: none';
5054: my $disabled_div_style = 'display: block';
5055: my $homedom_div_style = 'display: none';
5056: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5057: '<td rowspan="'.$rownum.'" valign="top">'.
5058: '<p>';
5059: if ($lonhost eq '') {
5060: $datatable .= '<span class="LC_nobreak">';
5061: if (keys(%currbalancer) > 0) {
5062: $datatable .= &mt('Add balancer:');
5063: } else {
5064: $datatable .= &mt('Enable balancer:');
5065: }
5066: $datatable .= ' '.
5067: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5068: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5069: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5070: '<option value="" selected="selected">'.&mt('None').
5071: '</option>'."\n";
5072: foreach my $server (sort(keys(%servers))) {
5073: next if ($currbalancer{$server});
5074: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5075: }
5076: $datatable .=
5077: '</select>'."\n".
5078: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5079: } else {
5080: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5081: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5082: &mt('Stop balancing').'</label>'.
5083: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5084: $targets_div_style = 'display: block';
5085: $disabled_div_style = 'display: none';
5086: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5087: $homedom_div_style = 'display: block';
5088: }
5089: }
5090: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5091: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5092: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5093: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5094: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5095: my @sparestypes = ('primary','default');
5096: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 5097: my %hostherechecked = (
5098: no => ' checked="checked"',
5099: );
1.160.6.7 raeburn 5100: foreach my $sparetype (@sparestypes) {
5101: my $targettable;
5102: for (my $i=0; $i<$numspares; $i++) {
5103: my $checked;
5104: if (ref($currtargets{$lonhost}) eq 'HASH') {
5105: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5106: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5107: $checked = ' checked="checked"';
5108: }
5109: }
5110: }
5111: my ($chkboxval,$disabled);
5112: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5113: $chkboxval = $spares[$i];
5114: }
5115: if (exists($currbalancer{$spares[$i]})) {
5116: $disabled = ' disabled="disabled"';
5117: }
5118: $targettable .=
1.160.6.55 raeburn 5119: '<td><span class="LC_nobreak"><label>'.
5120: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 5121: $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 5122: '</span></label></span></td>';
1.160.6.7 raeburn 5123: my $rem = $i%($numinrow);
5124: if ($rem == 0) {
5125: if (($i > 0) && ($i < $numspares-1)) {
5126: $targettable .= '</tr>';
5127: }
5128: if ($i < $numspares-1) {
5129: $targettable .= '<tr>';
1.150 raeburn 5130: }
5131: }
5132: }
1.160.6.7 raeburn 5133: if ($targettable ne '') {
5134: my $rem = $numspares%($numinrow);
5135: my $colsleft = $numinrow - $rem;
5136: if ($colsleft > 1 ) {
5137: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5138: ' </td>';
5139: } elsif ($colsleft == 1) {
5140: $targettable .= '<td class="LC_left_item"> </td>';
5141: }
5142: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5143: '<table><tr>'.$targettable.'</tr></table><br />';
5144: }
1.160.6.76 raeburn 5145: $hostherechecked{$sparetype} = '';
5146: if (ref($currtargets{$lonhost}) eq 'HASH') {
5147: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5148: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5149: $hostherechecked{$sparetype} = ' checked="checked"';
5150: $hostherechecked{'no'} = '';
5151: }
5152: }
5153: }
5154: }
5155: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5156: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5157: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5158: foreach my $sparetype (@sparestypes) {
5159: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5160: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5161: '</i></label><br />';
1.160.6.7 raeburn 5162: }
5163: $datatable .= '</div></td></tr>'.
5164: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5165: $othertitle,$usertypes,$types,\%servers,
5166: \%currbalancer,$lonhost,
5167: $targets_div_style,$homedom_div_style,
5168: $css_class[$cssidx],$balnum,$islast);
5169: $$rowtotal += $rownum;
5170: $balnum ++;
5171: }
5172: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5173: return $datatable;
5174: }
5175:
5176: sub get_loadbalancers_config {
5177: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5178: return unless ((ref($servers) eq 'HASH') &&
5179: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5180: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5181: if (keys(%{$existing}) > 0) {
5182: my $oldlonhost;
5183: foreach my $key (sort(keys(%{$existing}))) {
5184: if ($key eq 'lonhost') {
5185: $oldlonhost = $existing->{'lonhost'};
5186: $currbalancer->{$oldlonhost} = 1;
5187: } elsif ($key eq 'targets') {
5188: if ($oldlonhost) {
5189: $currtargets->{$oldlonhost} = $existing->{'targets'};
5190: }
5191: } elsif ($key eq 'rules') {
5192: if ($oldlonhost) {
5193: $currrules->{$oldlonhost} = $existing->{'rules'};
5194: }
5195: } elsif (ref($existing->{$key}) eq 'HASH') {
5196: $currbalancer->{$key} = 1;
5197: $currtargets->{$key} = $existing->{$key}{'targets'};
5198: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 5199: }
5200: }
1.160.6.7 raeburn 5201: } else {
5202: my ($balancerref,$targetsref) =
5203: &Apache::lonnet::get_lonbalancer_config($servers);
5204: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5205: foreach my $server (sort(keys(%{$balancerref}))) {
5206: $currbalancer->{$server} = 1;
5207: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5208: }
5209: }
5210: }
1.160.6.7 raeburn 5211: return;
1.150 raeburn 5212: }
5213:
5214: sub loadbalancing_rules {
5215: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 5216: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5217: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5218: my $output;
1.160.6.7 raeburn 5219: my $num = 0;
5220: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5221: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5222: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5223: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 5224: $num ++;
1.150 raeburn 5225: my $current;
5226: if (ref($currrules) eq 'HASH') {
5227: $current = $currrules->{$type};
5228: }
1.160.6.55 raeburn 5229: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 5230: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5231: $current = '';
5232: }
5233: }
5234: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 5235: $servers,$currbalancer,$lonhost,$dom,
5236: $targets_div_style,$homedom_div_style,
5237: $css_class,$balnum,$num,$islast);
1.150 raeburn 5238: }
5239: }
5240: return $output;
5241: }
5242:
5243: sub loadbalancing_titles {
5244: my ($dom,$intdom,$usertypes,$types) = @_;
5245: my %othertypes = (
5246: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5247: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5248: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5249: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 5250: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5251: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5252: );
1.160.6.26 raeburn 5253: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.84.2. (raeburn 5254:): my @available;
1.150 raeburn 5255: if (ref($types) eq 'ARRAY') {
1.160.6.84.2. (raeburn 5256:): @available = @{$types};
1.150 raeburn 5257: }
1.160.6.84.2. (raeburn 5258:): unless (grep(/^default$/,@available)) {
5259:): push(@available,'default');
5260:): }
5261:): unshift(@alltypes,@available);
1.150 raeburn 5262: my %titles;
5263: foreach my $type (@alltypes) {
5264: if ($type =~ /^_LC_/) {
5265: $titles{$type} = $othertypes{$type};
5266: } elsif ($type eq 'default') {
5267: $titles{$type} = &mt('All users from [_1]',$dom);
5268: if (ref($types) eq 'ARRAY') {
5269: if (@{$types} > 0) {
5270: $titles{$type} = &mt('Other users from [_1]',$dom);
5271: }
5272: }
5273: } elsif (ref($usertypes) eq 'HASH') {
5274: $titles{$type} = $usertypes->{$type};
5275: }
5276: }
5277: return (\@alltypes,\%othertypes,\%titles);
5278: }
5279:
5280: sub loadbalance_rule_row {
1.160.6.7 raeburn 5281: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5282: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 5283: my @rulenames;
1.150 raeburn 5284: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 5285: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 5286: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5287: } else {
1.160.6.26 raeburn 5288: @rulenames = ('default','homeserver');
5289: if ($type eq '_LC_external') {
5290: push(@rulenames,'externalbalancer');
5291: } else {
5292: push(@rulenames,'specific');
5293: }
5294: push(@rulenames,'none');
1.150 raeburn 5295: }
5296: my $style = $targets_div_style;
1.160.6.55 raeburn 5297: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5298: $style = $homedom_div_style;
5299: }
1.160.6.7 raeburn 5300: my $space;
5301: if ($islast && $num == 1) {
5302: $space = '<div display="inline-block"> </div>';
5303: }
5304: my $output =
5305: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5306: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5307: '<td valaign="top">'.$space.
5308: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5309: for (my $i=0; $i<@rulenames; $i++) {
5310: my $rule = $rulenames[$i];
5311: my ($checked,$extra);
5312: if ($rulenames[$i] eq 'default') {
5313: $rule = '';
5314: }
5315: if ($rulenames[$i] eq 'specific') {
5316: if (ref($servers) eq 'HASH') {
5317: my $default;
5318: if (($current ne '') && (exists($servers->{$current}))) {
5319: $checked = ' checked="checked"';
5320: }
5321: unless ($checked) {
5322: $default = ' selected="selected"';
5323: }
1.160.6.7 raeburn 5324: $extra =
5325: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5326: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5327: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5328: '<option value=""'.$default.'></option>'."\n";
5329: foreach my $server (sort(keys(%{$servers}))) {
5330: if (ref($currbalancer) eq 'HASH') {
5331: next if (exists($currbalancer->{$server}));
5332: }
1.150 raeburn 5333: my $selected;
1.160.6.7 raeburn 5334: if ($server eq $current) {
1.150 raeburn 5335: $selected = ' selected="selected"';
5336: }
1.160.6.7 raeburn 5337: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5338: }
5339: $extra .= '</select>';
5340: }
5341: } elsif ($rule eq $current) {
5342: $checked = ' checked="checked"';
5343: }
5344: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 5345: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5346: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5347: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 5348: ')"'.$checked.' /> ';
1.160.6.56 raeburn 5349: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 5350: $output .= $ruletitles{'particular'};
5351: } else {
5352: $output .= $ruletitles{$rulenames[$i]};
5353: }
5354: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5355: }
5356: $output .= '</div></td></tr>'."\n";
5357: return $output;
5358: }
5359:
5360: sub offloadtype_text {
5361: my %ruletitles = &Apache::lonlocal::texthash (
5362: 'default' => 'Offloads to default destinations',
5363: 'homeserver' => "Offloads to user's home server",
5364: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5365: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 5366: 'none' => 'No offload',
1.160.6.26 raeburn 5367: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5368: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 5369: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5370: );
5371: return %ruletitles;
5372: }
5373:
5374: sub sparestype_titles {
5375: my %typestitles = &Apache::lonlocal::texthash (
5376: 'primary' => 'primary',
5377: 'default' => 'default',
5378: );
5379: return %typestitles;
5380: }
5381:
1.28 raeburn 5382: sub contact_titles {
5383: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 5384: 'supportemail' => 'Support E-mail address',
5385: 'adminemail' => 'Default Server Admin E-mail address',
5386: 'errormail' => 'Error reports to be e-mailed to',
5387: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.84.2. (raeburn 5388:): 'helpdeskmail' => "Helpdesk requests from all users in this domain",
5389:): 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 5390: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5391: 'requestsmail' => 'E-mail from course requests requiring approval',
5392: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 5393: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 5394: );
5395: my %short_titles = &Apache::lonlocal::texthash (
5396: adminemail => 'Admin E-mail address',
5397: supportemail => 'Support E-mail',
5398: );
5399: return (\%titles,\%short_titles);
5400: }
5401:
1.160.6.78 raeburn 5402: sub helpform_fields {
5403: my %titles = &Apache::lonlocal::texthash (
5404: 'username' => 'Name',
5405: 'user' => 'Username/domain',
5406: 'phone' => 'Phone',
5407: 'cc' => 'Cc e-mail',
5408: 'course' => 'Course Details',
5409: 'section' => 'Sections',
5410: 'screenshot' => 'File upload',
5411: );
5412: my @fields = ('username','phone','user','course','section','cc','screenshot');
5413: my %possoptions = (
5414: username => ['yes','no','req'],
5415: phone => ['yes','no','req'],
5416: user => ['yes','no'],
5417: cc => ['yes','no'],
5418: course => ['yes','no'],
5419: section => ['yes','no'],
5420: screenshot => ['yes','no'],
5421: );
5422: my %fieldoptions = &Apache::lonlocal::texthash (
5423: 'yes' => 'Optional',
5424: 'req' => 'Required',
5425: 'no' => "Not shown",
5426: );
5427: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5428: }
5429:
1.72 raeburn 5430: sub tool_titles {
5431: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 5432: aboutme => 'Personal web page',
1.86 raeburn 5433: blog => 'Blog',
1.160.6.4 raeburn 5434: webdav => 'WebDAV',
1.86 raeburn 5435: portfolio => 'Portfolio',
1.88 bisitz 5436: official => 'Official courses (with institutional codes)',
5437: unofficial => 'Unofficial courses',
1.98 raeburn 5438: community => 'Communities',
1.160.6.30 raeburn 5439: textbook => 'Textbook courses',
1.86 raeburn 5440: );
1.72 raeburn 5441: return %titles;
5442: }
5443:
1.101 raeburn 5444: sub courserequest_titles {
5445: my %titles = &Apache::lonlocal::texthash (
5446: official => 'Official',
5447: unofficial => 'Unofficial',
5448: community => 'Communities',
1.160.6.30 raeburn 5449: textbook => 'Textbook',
1.101 raeburn 5450: norequest => 'Not allowed',
1.104 raeburn 5451: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5452: validate => 'With validation',
5453: autolimit => 'Numerical limit',
1.103 raeburn 5454: unlimited => '(blank for unlimited)',
1.101 raeburn 5455: );
5456: return %titles;
5457: }
5458:
1.160.6.5 raeburn 5459: sub authorrequest_titles {
5460: my %titles = &Apache::lonlocal::texthash (
5461: norequest => 'Not allowed',
5462: approval => 'Approval by Dom. Coord.',
5463: automatic => 'Automatic approval',
5464: );
5465: return %titles;
5466: }
5467:
1.101 raeburn 5468: sub courserequest_conditions {
5469: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5470: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 5471: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5472: );
5473: return %conditions;
5474: }
5475:
5476:
1.27 raeburn 5477: sub print_usercreation {
1.30 raeburn 5478: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5479: my $numinrow = 4;
1.28 raeburn 5480: my $datatable;
5481: if ($position eq 'top') {
1.30 raeburn 5482: $$rowtotal ++;
1.34 raeburn 5483: my $rowcount = 0;
1.32 raeburn 5484: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5485: if (ref($rules) eq 'HASH') {
5486: if (keys(%{$rules}) > 0) {
1.32 raeburn 5487: $datatable .= &user_formats_row('username',$settings,$rules,
5488: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5489: $$rowtotal ++;
1.32 raeburn 5490: $rowcount ++;
5491: }
5492: }
5493: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5494: if (ref($idrules) eq 'HASH') {
5495: if (keys(%{$idrules}) > 0) {
5496: $datatable .= &user_formats_row('id',$settings,$idrules,
5497: $idruleorder,$numinrow,$rowcount);
5498: $$rowtotal ++;
5499: $rowcount ++;
1.28 raeburn 5500: }
5501: }
1.39 raeburn 5502: if ($rowcount == 0) {
5503: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5504: $$rowtotal ++;
5505: $rowcount ++;
5506: }
1.34 raeburn 5507: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 5508: my @creators = ('author','course','requestcrs');
1.37 raeburn 5509: my ($rules,$ruleorder) =
5510: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5511: my %lt = &usercreation_types();
5512: my %checked;
5513: if (ref($settings) eq 'HASH') {
5514: if (ref($settings->{'cancreate'}) eq 'HASH') {
5515: foreach my $item (@creators) {
5516: $checked{$item} = $settings->{'cancreate'}{$item};
5517: }
5518: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5519: foreach my $item (@creators) {
5520: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5521: $checked{$item} = 'none';
5522: }
5523: }
5524: }
5525: }
5526: my $rownum = 0;
5527: foreach my $item (@creators) {
5528: $rownum ++;
1.160.6.34 raeburn 5529: if ($checked{$item} eq '') {
5530: $checked{$item} = 'any';
1.34 raeburn 5531: }
5532: my $css_class;
5533: if ($rownum%2) {
5534: $css_class = '';
5535: } else {
5536: $css_class = ' class="LC_odd_row" ';
5537: }
5538: $datatable .= '<tr'.$css_class.'>'.
5539: '<td><span class="LC_nobreak">'.$lt{$item}.
5540: '</span></td><td align="right">';
1.160.6.34 raeburn 5541: my @options = ('any');
5542: if (ref($rules) eq 'HASH') {
5543: if (keys(%{$rules}) > 0) {
5544: push(@options,('official','unofficial'));
1.37 raeburn 5545: }
5546: }
1.160.6.34 raeburn 5547: push(@options,'none');
1.37 raeburn 5548: foreach my $option (@options) {
1.50 raeburn 5549: my $type = 'radio';
1.34 raeburn 5550: my $check = ' ';
1.160.6.34 raeburn 5551: if ($checked{$item} eq $option) {
5552: $check = ' checked="checked" ';
1.34 raeburn 5553: }
5554: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5555: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5556: $item.'" value="'.$option.'"'.$check.'/> '.
5557: $lt{$option}.'</label> </span>';
5558: }
5559: $datatable .= '</td></tr>';
5560: }
1.28 raeburn 5561: } else {
5562: my @contexts = ('author','course','domain');
5563: my @authtypes = ('int','krb4','krb5','loc');
5564: my %checked;
5565: if (ref($settings) eq 'HASH') {
5566: if (ref($settings->{'authtypes'}) eq 'HASH') {
5567: foreach my $item (@contexts) {
5568: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5569: foreach my $auth (@authtypes) {
5570: if ($settings->{'authtypes'}{$item}{$auth}) {
5571: $checked{$item}{$auth} = ' checked="checked" ';
5572: }
5573: }
5574: }
5575: }
1.27 raeburn 5576: }
1.35 raeburn 5577: } else {
5578: foreach my $item (@contexts) {
1.36 raeburn 5579: foreach my $auth (@authtypes) {
1.35 raeburn 5580: $checked{$item}{$auth} = ' checked="checked" ';
5581: }
5582: }
1.27 raeburn 5583: }
1.28 raeburn 5584: my %title = &context_names();
5585: my %authname = &authtype_names();
5586: my $rownum = 0;
5587: my $css_class;
5588: foreach my $item (@contexts) {
5589: if ($rownum%2) {
5590: $css_class = '';
5591: } else {
5592: $css_class = ' class="LC_odd_row" ';
5593: }
1.30 raeburn 5594: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5595: '<td>'.$title{$item}.
5596: '</td><td class="LC_left_item">'.
5597: '<span class="LC_nobreak">';
5598: foreach my $auth (@authtypes) {
5599: $datatable .= '<label>'.
5600: '<input type="checkbox" name="'.$item.'_auth" '.
5601: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5602: $authname{$auth}.'</label> ';
5603: }
5604: $datatable .= '</span></td></tr>';
5605: $rownum ++;
1.27 raeburn 5606: }
1.30 raeburn 5607: $$rowtotal += $rownum;
1.27 raeburn 5608: }
5609: return $datatable;
5610: }
5611:
1.160.6.34 raeburn 5612: sub print_selfcreation {
5613: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 5614: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 5615: if (ref($settings) eq 'HASH') {
5616: if (ref($settings->{'cancreate'}) eq 'HASH') {
5617: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 5618: if (ref($createsettings) eq 'HASH') {
5619: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5620: @selfcreate = @{$createsettings->{'selfcreate'}};
5621: } elsif ($createsettings->{'selfcreate'} ne '') {
5622: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5623: @selfcreate = ('email','login','sso');
5624: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5625: @selfcreate = ($createsettings->{'selfcreate'});
5626: }
5627: }
5628: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5629: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5630: }
5631: }
5632: }
5633: }
5634: my %radiohash;
5635: my $numinrow = 4;
5636: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.84.2. (raeburn 5637:): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 5638: if ($position eq 'top') {
5639: my %choices = &Apache::lonlocal::texthash (
5640: cancreate_login => 'Institutional Login',
5641: cancreate_sso => 'Institutional Single Sign On',
5642: );
5643: my @toggles = sort(keys(%choices));
5644: my %defaultchecked = (
5645: 'cancreate_login' => 'off',
5646: 'cancreate_sso' => 'off',
5647: );
1.160.6.35 raeburn 5648: my ($onclick,$itemcount);
1.160.6.34 raeburn 5649: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5650: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5651: $$rowtotal += $itemcount;
1.160.6.39 raeburn 5652:
1.160.6.34 raeburn 5653: if (ref($usertypes) eq 'HASH') {
5654: if (keys(%{$usertypes}) > 0) {
5655: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5656: $dom,$numinrow,$othertitle,
1.160.6.84.2. (raeburn 5657:): 'statustocreate',$rowtotal);
1.160.6.34 raeburn 5658: $$rowtotal ++;
5659: }
5660: }
1.160.6.44 raeburn 5661: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5662: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5663: $fieldtitles{'inststatus'} = &mt('Institutional status');
5664: my $rem;
5665: my $numperrow = 2;
5666: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5667: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5668: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5669: '<td class="LC_left_item">'."\n".
5670: '<table><tr><td>'."\n";
5671: for (my $i=0; $i<@fields; $i++) {
5672: $rem = $i%($numperrow);
5673: if ($rem == 0) {
5674: if ($i > 0) {
5675: $datatable .= '</tr>';
5676: }
5677: $datatable .= '<tr>';
5678: }
5679: my $currval;
1.160.6.51 raeburn 5680: if (ref($createsettings) eq 'HASH') {
5681: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5682: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5683: }
1.160.6.44 raeburn 5684: }
5685: $datatable .= '<td class="LC_left_item">'.
5686: '<span class="LC_nobreak">'.
5687: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5688: 'value="'.$currval.'" size="10" /> '.
5689: $fieldtitles{$fields[$i]}.'</span></td>';
5690: }
5691: my $colsleft = $numperrow - $rem;
5692: if ($colsleft > 1 ) {
5693: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5694: ' </td>';
5695: } elsif ($colsleft == 1) {
5696: $datatable .= '<td class="LC_left_item"> </td>';
5697: }
5698: $datatable .= '</tr></table></td></tr>';
5699: $$rowtotal ++;
1.160.6.34 raeburn 5700: } elsif ($position eq 'middle') {
5701: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.84.2. (raeburn 5702:): my @posstypes;
1.160.6.34 raeburn 5703: if (ref($types) eq 'ARRAY') {
1.160.6.84.2. (raeburn 5704:): @posstypes = @{$types};
5705:): }
5706:): unless (grep(/^default$/,@posstypes)) {
5707:): push(@posstypes,'default');
5708:): }
5709:): my %usertypeshash;
5710:): if (ref($usertypes) eq 'HASH') {
5711:): %usertypeshash = %{$usertypes};
5712:): }
5713:): $usertypeshash{'default'} = $othertitle;
5714:): foreach my $status (@posstypes) {
5715:): $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
5716:): $numinrow,$$rowtotal,\%usertypeshash);
5717:): $$rowtotal ++;
1.160.6.34 raeburn 5718: }
5719: } else {
1.160.6.40 raeburn 5720: my %choices = &Apache::lonlocal::texthash (
5721: cancreate_email => 'E-mail address as username',
5722: );
5723: my @toggles = sort(keys(%choices));
5724: my %defaultchecked = (
5725: 'cancreate_email' => 'off',
5726: );
5727: my $itemcount = 0;
5728: my $display = 'none';
5729: if (grep(/^\Qemail\E$/,@selfcreate)) {
5730: $display = 'block';
5731: }
5732: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5733: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5734: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.84.2. (raeburn 5735:): my (@ordered,%usertypeshash);
5736:): if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
5737:): @ordered = @{$domdefaults{'inststatusguest'}};
5738:): }
5739:): if (@ordered) {
5740:): unless (grep(/^default$/,@ordered)) {
5741:): push(@ordered,'default');
5742:): }
5743:): if (ref($usertypes) eq 'HASH') {
5744:): %usertypeshash = %{$usertypes};
5745:): }
5746:): $usertypeshash{'default'} = $othertitle;
5747:): $additional .= '<table><tr>';
5748:): foreach my $status (@ordered) {
5749:): $additional .= '<th>'.$usertypeshash{$status}.'</th>';
5750:): }
5751:): $additional .= '</tr><tr>';
5752:): foreach my $status (@ordered) {
5753:): $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 5754: }
1.160.6.84.2. (raeburn 5755:): $additional .= '</tr></table>';
5756:): } else {
5757:): $usertypeshash{'default'} = $othertitle;
5758:): $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 5759: }
1.160.6.40 raeburn 5760: $additional .= '</div>'."\n";
5761:
5762: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 5763: \%choices,$$rowtotal,$onclick,$additional);
5764: $$rowtotal ++;
1.160.6.40 raeburn 5765: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 5766: $$rowtotal ++;
1.160.6.35 raeburn 5767: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5768: $numinrow = 1;
1.160.6.84.2. (raeburn 5769:): foreach my $status (@ordered) {
5770:): $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5771:): $numinrow,$$rowtotal,\%usertypeshash,$infofields,$infotitles);
5772:): $$rowtotal ++;
1.160.6.35 raeburn 5773: }
1.160.6.34 raeburn 5774: my ($emailrules,$emailruleorder) =
5775: &Apache::lonnet::inst_userrules($dom,'email');
5776: if (ref($emailrules) eq 'HASH') {
5777: if (keys(%{$emailrules}) > 0) {
5778: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 5779: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 5780: $$rowtotal ++;
5781: }
5782: }
1.160.6.35 raeburn 5783: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 5784: }
5785: return $datatable;
5786: }
5787:
1.160.6.40 raeburn 5788: sub email_as_username {
5789: my ($rowtotal,$processing,$type) = @_;
5790: my %choices =
5791: &Apache::lonlocal::texthash (
5792: automatic => 'Automatic approval',
5793: approval => 'Queued for approval',
5794: );
5795: my $output;
5796: foreach my $option ('automatic','approval') {
5797: my $checked;
5798: if (ref($processing) eq 'HASH') {
5799: if ($type eq '') {
5800: if (!exists($processing->{'default'})) {
5801: if ($option eq 'automatic') {
5802: $checked = ' checked="checked"';
5803: }
5804: } else {
5805: if ($processing->{'default'} eq $option) {
5806: $checked = ' checked="checked"';
5807: }
5808: }
5809: } else {
5810: if (!exists($processing->{$type})) {
5811: if ($option eq 'automatic') {
5812: $checked = ' checked="checked"';
5813: }
5814: } else {
5815: if ($processing->{$type} eq $option) {
5816: $checked = ' checked="checked"';
5817: }
5818: }
5819: }
5820: } elsif ($option eq 'automatic') {
5821: $checked = ' checked="checked"';
5822: }
5823: my $name = 'cancreate_emailprocess';
5824: if (($type ne '') && ($type ne 'default')) {
5825: $name .= '_'.$type;
5826: }
5827: $output .= '<span class="LC_nobreak"><label>'.
5828: '<input type="radio" name="'.$name.'"'.
5829: $checked.' value="'.$option.'" />'.
5830: $choices{$option}.'</label></span>';
5831: if ($type eq '') {
5832: $output .= ' ';
5833: } else {
5834: $output .= '<br />';
5835: }
5836: }
5837: $$rowtotal ++;
5838: return $output;
5839: }
5840:
1.160.6.5 raeburn 5841: sub captcha_choice {
5842: my ($context,$settings,$itemcount) = @_;
1.160.6.69 raeburn 5843: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5844: $vertext,$currver);
1.160.6.5 raeburn 5845: my %lt = &captcha_phrases();
5846: $keyentry = 'hidden';
5847: if ($context eq 'cancreate') {
1.160.6.34 raeburn 5848: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 5849: } elsif ($context eq 'login') {
5850: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
5851: }
5852: if (ref($settings) eq 'HASH') {
5853: if ($settings->{'captcha'}) {
5854: $checked{$settings->{'captcha'}} = ' checked="checked"';
5855: } else {
5856: $checked{'original'} = ' checked="checked"';
5857: }
5858: if ($settings->{'captcha'} eq 'recaptcha') {
5859: $pubtext = $lt{'pub'};
5860: $privtext = $lt{'priv'};
5861: $keyentry = 'text';
1.160.6.69 raeburn 5862: $vertext = $lt{'ver'};
5863: $currver = $settings->{'recaptchaversion'};
5864: if ($currver ne '2') {
5865: $currver = 1;
5866: }
1.160.6.5 raeburn 5867: }
5868: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5869: $currpub = $settings->{'recaptchakeys'}{'public'};
5870: $currpriv = $settings->{'recaptchakeys'}{'private'};
5871: }
5872: } else {
5873: $checked{'original'} = ' checked="checked"';
5874: }
5875: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5876: my $output = '<tr'.$css_class.'>'.
5877: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
5878: '<table><tr><td>'."\n";
5879: foreach my $option ('original','recaptcha','notused') {
5880: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5881: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5882: $lt{$option}.'</label></span>';
5883: unless ($option eq 'notused') {
5884: $output .= (' 'x2)."\n";
5885: }
5886: }
5887: #
5888: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5889: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
5890: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
5891: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
5892: #
5893: $output .= '</td></tr>'."\n".
5894: '<tr><td>'."\n".
5895: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5896: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5897: $currpub.'" size="40" /></span><br />'."\n".
5898: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5899: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 5900: $currpriv.'" size="40" /></span><br />'.
5901: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5902: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5903: $currver.'" size="3" /></span><br />'.
5904: '</td></tr></table>'."\n".
1.160.6.5 raeburn 5905: '</td></tr>';
5906: return $output;
5907: }
5908:
1.32 raeburn 5909: sub user_formats_row {
5910: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5911: my $output;
5912: my %text = (
5913: 'username' => 'new usernames',
5914: 'id' => 'IDs',
1.45 raeburn 5915: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5916: );
5917: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5918: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5919: '<td><span class="LC_nobreak">';
5920: if ($type eq 'email') {
5921: $output .= &mt("Formats disallowed for $text{$type}: ");
5922: } else {
5923: $output .= &mt("Format rules to check for $text{$type}: ");
5924: }
5925: $output .= '</span></td>'.
5926: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5927: my $rem;
5928: if (ref($ruleorder) eq 'ARRAY') {
5929: for (my $i=0; $i<@{$ruleorder}; $i++) {
5930: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5931: my $rem = $i%($numinrow);
5932: if ($rem == 0) {
5933: if ($i > 0) {
5934: $output .= '</tr>';
5935: }
5936: $output .= '<tr>';
5937: }
5938: my $check = ' ';
1.39 raeburn 5939: if (ref($settings) eq 'HASH') {
5940: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5941: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5942: $check = ' checked="checked" ';
5943: }
1.27 raeburn 5944: }
5945: }
5946: $output .= '<td class="LC_left_item">'.
5947: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5948: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5949: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5950: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5951: }
5952: }
5953: $rem = @{$ruleorder}%($numinrow);
5954: }
5955: my $colsleft = $numinrow - $rem;
5956: if ($colsleft > 1 ) {
5957: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5958: ' </td>';
5959: } elsif ($colsleft == 1) {
5960: $output .= '<td class="LC_left_item"> </td>';
5961: }
5962: $output .= '</tr></table></td></tr>';
5963: return $output;
5964: }
5965:
1.34 raeburn 5966: sub usercreation_types {
5967: my %lt = &Apache::lonlocal::texthash (
5968: author => 'When adding a co-author',
5969: course => 'When adding a user to a course',
1.100 raeburn 5970: requestcrs => 'When requesting a course',
1.34 raeburn 5971: any => 'Any',
5972: official => 'Institutional only ',
5973: unofficial => 'Non-institutional only',
5974: none => 'None',
5975: );
5976: return %lt;
1.48 raeburn 5977: }
1.34 raeburn 5978:
1.160.6.34 raeburn 5979: sub selfcreation_types {
5980: my %lt = &Apache::lonlocal::texthash (
5981: selfcreate => 'User creates own account',
5982: any => 'Any',
5983: official => 'Institutional only ',
5984: unofficial => 'Non-institutional only',
5985: email => 'E-mail address',
5986: login => 'Institutional Login',
5987: sso => 'SSO',
5988: );
5989: }
5990:
1.28 raeburn 5991: sub authtype_names {
5992: my %lt = &Apache::lonlocal::texthash(
5993: int => 'Internal',
5994: krb4 => 'Kerberos 4',
5995: krb5 => 'Kerberos 5',
5996: loc => 'Local',
5997: );
5998: return %lt;
5999: }
6000:
6001: sub context_names {
6002: my %context_title = &Apache::lonlocal::texthash(
6003: author => 'Creating users when an Author',
6004: course => 'Creating users when in a course',
6005: domain => 'Creating users when a Domain Coordinator',
6006: );
6007: return %context_title;
6008: }
6009:
1.33 raeburn 6010: sub print_usermodification {
6011: my ($position,$dom,$settings,$rowtotal) = @_;
6012: my $numinrow = 4;
6013: my ($context,$datatable,$rowcount);
6014: if ($position eq 'top') {
6015: $rowcount = 0;
6016: $context = 'author';
6017: foreach my $role ('ca','aa') {
6018: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6019: $numinrow,$rowcount);
6020: $$rowtotal ++;
6021: $rowcount ++;
6022: }
1.160.6.37 raeburn 6023: } elsif ($position eq 'bottom') {
1.33 raeburn 6024: $context = 'course';
6025: $rowcount = 0;
6026: foreach my $role ('st','ep','ta','in','cr') {
6027: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6028: $numinrow,$rowcount);
6029: $$rowtotal ++;
6030: $rowcount ++;
6031: }
6032: }
6033: return $datatable;
6034: }
6035:
1.43 raeburn 6036: sub print_defaults {
1.160.6.40 raeburn 6037: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6038: my $rownum = 0;
1.160.6.80 raeburn 6039: my ($datatable,$css_class,$titles);
6040: unless ($position eq 'bottom') {
6041: $titles = &defaults_titles($dom);
6042: }
1.160.6.40 raeburn 6043: if ($position eq 'top') {
6044: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6045: 'datelocale_def','portal_def');
6046: my %defaults;
6047: if (ref($settings) eq 'HASH') {
6048: %defaults = %{$settings};
1.43 raeburn 6049: } else {
1.160.6.40 raeburn 6050: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6051: foreach my $item (@items) {
6052: $defaults{$item} = $domdefaults{$item};
6053: }
1.43 raeburn 6054: }
1.160.6.40 raeburn 6055: foreach my $item (@items) {
6056: if ($rownum%2) {
6057: $css_class = '';
6058: } else {
6059: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 6060: }
1.160.6.40 raeburn 6061: $datatable .= '<tr'.$css_class.'>'.
6062: '<td><span class="LC_nobreak">'.$titles->{$item}.
6063: '</span></td><td class="LC_right_item" colspan="3">';
6064: if ($item eq 'auth_def') {
6065: my @authtypes = ('internal','krb4','krb5','localauth');
6066: my %shortauth = (
6067: internal => 'int',
6068: krb4 => 'krb4',
6069: krb5 => 'krb5',
6070: localauth => 'loc'
6071: );
6072: my %authnames = &authtype_names();
6073: foreach my $auth (@authtypes) {
6074: my $checked = ' ';
6075: if ($defaults{$item} eq $auth) {
6076: $checked = ' checked="checked" ';
6077: }
6078: $datatable .= '<label><input type="radio" name="'.$item.
6079: '" value="'.$auth.'"'.$checked.'/>'.
6080: $authnames{$shortauth{$auth}}.'</label> ';
6081: }
6082: } elsif ($item eq 'timezone_def') {
6083: my $includeempty = 1;
6084: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6085: } elsif ($item eq 'datelocale_def') {
6086: my $includeempty = 1;
6087: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6088: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 6089: my $includeempty = 1;
6090: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 6091: } else {
6092: my $size;
6093: if ($item eq 'portal_def') {
6094: $size = ' size="25"';
6095: }
6096: $datatable .= '<input type="text" name="'.$item.'" value="'.
6097: $defaults{$item}.'"'.$size.' />';
6098: }
6099: $datatable .= '</td></tr>';
6100: $rownum ++;
6101: }
1.160.6.80 raeburn 6102: } elsif ($position eq 'middle') {
6103: my @items = ('intauth_cost','intauth_check','intauth_switch');
6104: my %defaults;
6105: if (ref($settings) eq 'HASH') {
6106: %defaults = %{$settings};
6107: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6108: $defaults{'intauth_cost'} = 10;
6109: }
6110: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6111: $defaults{'intauth_check'} = 0;
6112: }
6113: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6114: $defaults{'intauth_switch'} = 0;
6115: }
6116: } else {
6117: %defaults = (
6118: 'intauth_cost' => 10,
6119: 'intauth_check' => 0,
6120: 'intauth_switch' => 0,
6121: );
6122: }
6123: foreach my $item (@items) {
6124: if ($rownum%2) {
6125: $css_class = '';
6126: } else {
6127: $css_class = ' class="LC_odd_row" ';
6128: }
6129: $datatable .= '<tr'.$css_class.'>'.
6130: '<td><span class="LC_nobreak">'.$titles->{$item}.
6131: '</span></td><td class="LC_left_item" colspan="3">';
6132: if ($item eq 'intauth_switch') {
6133: my @options = (0,1,2);
6134: my %optiondesc = &Apache::lonlocal::texthash (
6135: 0 => 'No',
6136: 1 => 'Yes',
6137: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6138: );
6139: $datatable .= '<table width="100%">';
6140: foreach my $option (@options) {
6141: my $checked = ' ';
6142: if ($defaults{$item} eq $option) {
6143: $checked = ' checked="checked"';
6144: }
6145: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6146: '<label><input type="radio" name="'.$item.
6147: '" value="'.$option.'"'.$checked.' />'.
6148: $optiondesc{$option}.'</label></span></td></tr>';
6149: }
6150: $datatable .= '</table>';
6151: } elsif ($item eq 'intauth_check') {
6152: my @options = (0,1,2);
6153: my %optiondesc = &Apache::lonlocal::texthash (
6154: 0 => 'No',
6155: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6156: 2 => 'Yes, disallow login if stored cost is less than domain default',
6157: );
6158: $datatable .= '<table wisth="100%">';
6159: foreach my $option (@options) {
6160: my $checked = ' ';
6161: my $onclick;
6162: if ($defaults{$item} eq $option) {
6163: $checked = ' checked="checked"';
6164: }
6165: if ($option == 2) {
6166: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6167: }
6168: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6169: '<label><input type="radio" name="'.$item.
6170: '" value="'.$option.'"'.$checked.$onclick.' />'.
6171: $optiondesc{$option}.'</label></span></td></tr>';
6172: }
6173: $datatable .= '</table>';
6174: } else {
6175: $datatable .= '<input type="text" name="'.$item.'" value="'.
6176: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6177: }
6178: $datatable .= '</td></tr>';
6179: $rownum ++;
6180: }
1.160.6.40 raeburn 6181: } else {
1.160.6.80 raeburn 6182: my %defaults;
1.160.6.40 raeburn 6183: if (ref($settings) eq 'HASH') {
6184: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
6185: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
6186: my $maxnum = @{$settings->{'inststatusorder'}};
6187: for (my $i=0; $i<$maxnum; $i++) {
6188: $css_class = $rownum%2?' class="LC_odd_row"':'';
6189: my $item = $settings->{'inststatusorder'}->[$i];
6190: my $title = $settings->{'inststatustypes'}->{$item};
6191: my $guestok;
6192: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
6193: $guestok = 1;
6194: }
6195: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6196: $datatable .= '<tr'.$css_class.'>'.
6197: '<td><span class="LC_nobreak">'.
6198: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6199: for (my $k=0; $k<=$maxnum; $k++) {
6200: my $vpos = $k+1;
6201: my $selstr;
6202: if ($k == $i) {
6203: $selstr = ' selected="selected" ';
6204: }
6205: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6206: }
6207: my ($checkedon,$checkedoff);
6208: $checkedoff = ' checked="checked"';
6209: if ($guestok) {
6210: $checkedon = $checkedoff;
6211: $checkedoff = '';
6212: }
6213: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6214: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6215: &mt('delete').'</span></td>'.
6216: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6217: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
6218: '</span></td>'.
6219: '<td class="LC_right_item"><span class="LC_nobreak">'.
6220: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
6221: &mt('Yes').'</label>'.(' 'x2).
6222: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
6223: &mt('No').'</label></span></td></tr>';
6224: }
6225: $css_class = $rownum%2?' class="LC_odd_row"':'';
6226: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6227: $datatable .= '<tr '.$css_class.'>'.
6228: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6229: for (my $k=0; $k<=$maxnum; $k++) {
6230: my $vpos = $k+1;
6231: my $selstr;
6232: if ($k == $maxnum) {
6233: $selstr = ' selected="selected" ';
6234: }
6235: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6236: }
6237: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 6238: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 6239: ' '.&mt('(new)').
6240: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6241: &mt('Name displayed:').
6242: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6243: '<td class="LC_right_item"><span class="LC_nobreak">'.
6244: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
6245: &mt('Yes').'</label>'.(' 'x2).
6246: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
6247: &mt('No').'</label></span></td></tr>';
6248: '</tr>'."\n";
6249: $rownum ++;
1.141 raeburn 6250: }
1.43 raeburn 6251: }
6252: }
6253: $$rowtotal += $rownum;
6254: return $datatable;
6255: }
6256:
1.160.6.5 raeburn 6257: sub get_languages_hash {
6258: my %langchoices;
6259: foreach my $id (&Apache::loncommon::languageids()) {
6260: my $code = &Apache::loncommon::supportedlanguagecode($id);
6261: if ($code ne '') {
6262: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6263: }
6264: }
6265: return %langchoices;
6266: }
6267:
1.43 raeburn 6268: sub defaults_titles {
1.141 raeburn 6269: my ($dom) = @_;
1.43 raeburn 6270: my %titles = &Apache::lonlocal::texthash (
6271: 'auth_def' => 'Default authentication type',
6272: 'auth_arg_def' => 'Default authentication argument',
6273: 'lang_def' => 'Default language',
1.54 raeburn 6274: 'timezone_def' => 'Default timezone',
1.68 raeburn 6275: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6276: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 6277: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6278: 'intauth_check' => 'Check bcrypt cost if authenticated',
6279: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6280: );
1.141 raeburn 6281: if ($dom) {
6282: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6283: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6284: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6285: $protocol = 'http' if ($protocol ne 'https');
6286: if ($uint_dom) {
6287: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6288: $uint_dom);
6289: }
6290: }
1.43 raeburn 6291: return (\%titles);
6292: }
6293:
1.46 raeburn 6294: sub print_scantronformat {
6295: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6296: my $itemcount = 1;
1.60 raeburn 6297: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6298: %confhash);
1.46 raeburn 6299: my $switchserver = &check_switchserver($dom,$confname);
6300: my %lt = &Apache::lonlocal::texthash (
1.95 www 6301: default => 'Default bubblesheet format file error',
6302: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6303: );
6304: my %scantronfiles = (
6305: default => 'default.tab',
6306: custom => 'custom.tab',
6307: );
6308: foreach my $key (keys(%scantronfiles)) {
6309: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6310: .$scantronfiles{$key};
6311: }
6312: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6313: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6314: if (!$switchserver) {
6315: my $servadm = $r->dir_config('lonAdmEMail');
6316: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6317: if ($configuserok eq 'ok') {
6318: if ($author_ok eq 'ok') {
6319: my %legacyfile = (
6320: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6321: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6322: );
6323: my %md5chk;
6324: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6325: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6326: chomp($md5chk{$type});
1.46 raeburn 6327: }
6328: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6329: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6330: ($scantronurls{$type},my $error) =
1.46 raeburn 6331: &legacy_scantronformat($r,$dom,$confname,
6332: $type,$legacyfile{$type},
6333: $scantronurls{$type},
6334: $scantronfiles{$type});
1.60 raeburn 6335: if ($error ne '') {
6336: $error{$type} = $error;
6337: }
6338: }
6339: if (keys(%error) == 0) {
6340: $is_custom = 1;
6341: $confhash{'scantron'}{'scantronformat'} =
6342: $scantronurls{'custom'};
6343: my $putresult =
6344: &Apache::lonnet::put_dom('configuration',
6345: \%confhash,$dom);
6346: if ($putresult ne 'ok') {
6347: $error{'custom'} =
6348: '<span class="LC_error">'.
6349: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6350: }
1.46 raeburn 6351: }
6352: } else {
1.60 raeburn 6353: ($scantronurls{'default'},my $error) =
1.46 raeburn 6354: &legacy_scantronformat($r,$dom,$confname,
6355: 'default',$legacyfile{'default'},
6356: $scantronurls{'default'},
6357: $scantronfiles{'default'});
1.60 raeburn 6358: if ($error eq '') {
6359: $confhash{'scantron'}{'scantronformat'} = '';
6360: my $putresult =
6361: &Apache::lonnet::put_dom('configuration',
6362: \%confhash,$dom);
6363: if ($putresult ne 'ok') {
6364: $error{'default'} =
6365: '<span class="LC_error">'.
6366: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6367: }
6368: } else {
6369: $error{'default'} = $error;
6370: }
1.46 raeburn 6371: }
6372: }
6373: }
6374: } else {
1.95 www 6375: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6376: }
6377: }
6378: if (ref($settings) eq 'HASH') {
6379: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6380: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
1.160.6.84.2. (raeburn 6381:): if ((!@info) || ($info[0] eq 'no_such_dir')) {
1.46 raeburn 6382: $scantronurl = '';
6383: } else {
6384: $scantronurl = $settings->{'scantronformat'};
6385: }
6386: $is_custom = 1;
6387: } else {
6388: $scantronurl = $scantronurls{'default'};
6389: }
6390: } else {
1.60 raeburn 6391: if ($is_custom) {
6392: $scantronurl = $scantronurls{'custom'};
6393: } else {
6394: $scantronurl = $scantronurls{'default'};
6395: }
1.46 raeburn 6396: }
6397: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6398: $datatable .= '<tr'.$css_class.'>';
6399: if (!$is_custom) {
1.65 raeburn 6400: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6401: '<span class="LC_nobreak">';
1.46 raeburn 6402: if ($scantronurl) {
1.160.6.21 raeburn 6403: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6404: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6405: } else {
6406: $datatable = &mt('File unavailable for display');
6407: }
1.65 raeburn 6408: $datatable .= '</span></td>';
1.60 raeburn 6409: if (keys(%error) == 0) {
6410: $datatable .= '<td valign="bottom">';
6411: if (!$switchserver) {
6412: $datatable .= &mt('Upload:').'<br />';
6413: }
6414: } else {
6415: my $errorstr;
6416: foreach my $key (sort(keys(%error))) {
6417: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6418: }
6419: $datatable .= '<td>'.$errorstr;
6420: }
1.46 raeburn 6421: } else {
6422: if (keys(%error) > 0) {
6423: my $errorstr;
6424: foreach my $key (sort(keys(%error))) {
6425: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6426: }
1.60 raeburn 6427: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6428: } elsif ($scantronurl) {
1.160.6.26 raeburn 6429: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 6430: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6431: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 6432: $link.
6433: '<label><input type="checkbox" name="scantronformat_del"'.
6434: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6435: '<td><span class="LC_nobreak"> '.
6436: &mt('Replace:').'</span><br />';
1.46 raeburn 6437: }
6438: }
6439: if (keys(%error) == 0) {
6440: if ($switchserver) {
6441: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6442: } else {
1.65 raeburn 6443: $datatable .='<span class="LC_nobreak"> '.
6444: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6445: }
6446: }
6447: $datatable .= '</td></tr>';
6448: $$rowtotal ++;
6449: return $datatable;
6450: }
6451:
6452: sub legacy_scantronformat {
6453: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6454: my ($url,$error);
6455: my @statinfo = &Apache::lonnet::stat_file($newurl);
6456: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6457: (my $result,$url) =
6458: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6459: '','',$newfile);
6460: if ($result ne 'ok') {
1.130 raeburn 6461: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6462: }
6463: }
6464: return ($url,$error);
6465: }
1.43 raeburn 6466:
1.49 raeburn 6467: sub print_coursecategories {
1.57 raeburn 6468: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6469: my $datatable;
6470: if ($position eq 'top') {
1.160.6.42 raeburn 6471: my (%checked);
6472: my @catitems = ('unauth','auth');
6473: my @cattypes = ('std','domonly','codesrch','none');
6474: $checked{'unauth'} = 'std';
6475: $checked{'auth'} = 'std';
6476: if (ref($settings) eq 'HASH') {
6477: foreach my $type (@cattypes) {
6478: if ($type eq $settings->{'unauth'}) {
6479: $checked{'unauth'} = $type;
6480: }
6481: if ($type eq $settings->{'auth'}) {
6482: $checked{'auth'} = $type;
6483: }
6484: }
6485: }
6486: my %lt = &Apache::lonlocal::texthash (
6487: unauth => 'Catalog type for unauthenticated users',
6488: auth => 'Catalog type for authenticated users',
6489: none => 'No catalog',
6490: std => 'Standard catalog',
6491: domonly => 'Domain-only catalog',
6492: codesrch => "Code search form",
6493: );
6494: my $itemcount = 0;
6495: foreach my $item (@catitems) {
6496: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6497: $datatable .= '<tr '.$css_class.'>'.
6498: '<td>'.$lt{$item}.'</td>'.
6499: '<td class="LC_right_item"><span class="LC_nobreak">';
6500: foreach my $type (@cattypes) {
6501: my $ischecked;
6502: if ($checked{$item} eq $type) {
6503: $ischecked=' checked="checked"';
6504: }
6505: $datatable .= '<label>'.
6506: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6507: ' />'.$lt{$type}.'</label> ';
6508: }
6509: $datatable .= '</td></tr>';
6510: $itemcount ++;
6511: }
6512: $$rowtotal += $itemcount;
6513: } elsif ($position eq 'middle') {
1.57 raeburn 6514: my $toggle_cats_crs = ' ';
6515: my $toggle_cats_dom = ' checked="checked" ';
6516: my $can_cat_crs = ' ';
6517: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6518: my $toggle_catscomm_comm = ' ';
6519: my $toggle_catscomm_dom = ' checked="checked" ';
6520: my $can_catcomm_comm = ' ';
6521: my $can_catcomm_dom = ' checked="checked" ';
6522:
1.57 raeburn 6523: if (ref($settings) eq 'HASH') {
6524: if ($settings->{'togglecats'} eq 'crs') {
6525: $toggle_cats_crs = $toggle_cats_dom;
6526: $toggle_cats_dom = ' ';
6527: }
6528: if ($settings->{'categorize'} eq 'crs') {
6529: $can_cat_crs = $can_cat_dom;
6530: $can_cat_dom = ' ';
6531: }
1.120 raeburn 6532: if ($settings->{'togglecatscomm'} eq 'comm') {
6533: $toggle_catscomm_comm = $toggle_catscomm_dom;
6534: $toggle_catscomm_dom = ' ';
6535: }
6536: if ($settings->{'categorizecomm'} eq 'comm') {
6537: $can_catcomm_comm = $can_catcomm_dom;
6538: $can_catcomm_dom = ' ';
6539: }
1.57 raeburn 6540: }
6541: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 6542: togglecats => 'Show/Hide a course in catalog',
6543: togglecatscomm => 'Show/Hide a community in catalog',
6544: categorize => 'Assign a category to a course',
6545: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6546: );
6547: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 6548: dom => 'Set in Domain',
6549: crs => 'Set in Course',
6550: comm => 'Set in Community',
1.57 raeburn 6551: );
6552: $datatable = '<tr class="LC_odd_row">'.
6553: '<td>'.$title{'togglecats'}.'</td>'.
6554: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6555: '<input type="radio" name="togglecats"'.
6556: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6557: '<label><input type="radio" name="togglecats"'.
6558: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6559: '</tr><tr>'.
6560: '<td>'.$title{'categorize'}.'</td>'.
6561: '<td class="LC_right_item"><span class="LC_nobreak">'.
6562: '<label><input type="radio" name="categorize"'.
6563: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6564: '<label><input type="radio" name="categorize"'.
6565: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6566: '</tr><tr class="LC_odd_row">'.
6567: '<td>'.$title{'togglecatscomm'}.'</td>'.
6568: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6569: '<input type="radio" name="togglecatscomm"'.
6570: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6571: '<label><input type="radio" name="togglecatscomm"'.
6572: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6573: '</tr><tr>'.
6574: '<td>'.$title{'categorizecomm'}.'</td>'.
6575: '<td class="LC_right_item"><span class="LC_nobreak">'.
6576: '<label><input type="radio" name="categorizecomm"'.
6577: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6578: '<label><input type="radio" name="categorizecomm"'.
6579: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 6580: '</tr>';
1.120 raeburn 6581: $$rowtotal += 4;
1.57 raeburn 6582: } else {
6583: my $css_class;
6584: my $itemcount = 1;
6585: my $cathash;
6586: if (ref($settings) eq 'HASH') {
6587: $cathash = $settings->{'cats'};
6588: }
6589: if (ref($cathash) eq 'HASH') {
6590: my (@cats,@trails,%allitems,%idx,@jsarray);
6591: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6592: \%allitems,\%idx,\@jsarray);
6593: my $maxdepth = scalar(@cats);
6594: my $colattrib = '';
6595: if ($maxdepth > 2) {
6596: $colattrib = ' colspan="2" ';
6597: }
6598: my @path;
6599: if (@cats > 0) {
6600: if (ref($cats[0]) eq 'ARRAY') {
6601: my $numtop = @{$cats[0]};
6602: my $maxnum = $numtop;
1.120 raeburn 6603: my %default_names = (
6604: instcode => &mt('Official courses'),
6605: communities => &mt('Communities'),
6606: );
6607:
6608: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6609: ($cathash->{'instcode::0'} eq '') ||
6610: (!grep(/^communities$/,@{$cats[0]})) ||
6611: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 6612: $maxnum ++;
6613: }
6614: my $lastidx;
6615: for (my $i=0; $i<$numtop; $i++) {
6616: my $parent = $cats[0][$i];
6617: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6618: my $item = &escape($parent).'::0';
6619: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6620: $lastidx = $idx{$item};
6621: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6622: .'<select name="'.$item.'"'.$chgstr.'>';
6623: for (my $k=0; $k<=$maxnum; $k++) {
6624: my $vpos = $k+1;
6625: my $selstr;
6626: if ($k == $i) {
6627: $selstr = ' selected="selected" ';
6628: }
6629: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6630: }
1.160.6.29 raeburn 6631: $datatable .= '</select></span></td><td>';
1.120 raeburn 6632: if ($parent eq 'instcode' || $parent eq 'communities') {
6633: $datatable .= '<span class="LC_nobreak">'
6634: .$default_names{$parent}.'</span>';
6635: if ($parent eq 'instcode') {
6636: $datatable .= '<br /><span class="LC_nobreak">('
6637: .&mt('with institutional codes')
6638: .')</span></td><td'.$colattrib.'>';
6639: } else {
6640: $datatable .= '<table><tr><td>';
6641: }
6642: $datatable .= '<span class="LC_nobreak">'
6643: .'<label><input type="radio" name="'
6644: .$parent.'" value="1" checked="checked" />'
6645: .&mt('Display').'</label>';
6646: if ($parent eq 'instcode') {
6647: $datatable .= ' ';
6648: } else {
6649: $datatable .= '</span></td></tr><tr><td>'
6650: .'<span class="LC_nobreak">';
6651: }
6652: $datatable .= '<label><input type="radio" name="'
6653: .$parent.'" value="0" />'
6654: .&mt('Do not display').'</label></span>';
6655: if ($parent eq 'communities') {
6656: $datatable .= '</td></tr></table>';
6657: }
6658: $datatable .= '</td>';
1.57 raeburn 6659: } else {
6660: $datatable .= $parent
1.160.6.29 raeburn 6661: .' <span class="LC_nobreak"><label>'
6662: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6663: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6664: }
6665: my $depth = 1;
6666: push(@path,$parent);
6667: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6668: pop(@path);
6669: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6670: $itemcount ++;
6671: }
1.48 raeburn 6672: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6673: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6674: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6675: for (my $k=0; $k<=$maxnum; $k++) {
6676: my $vpos = $k+1;
6677: my $selstr;
1.57 raeburn 6678: if ($k == $numtop) {
1.48 raeburn 6679: $selstr = ' selected="selected" ';
6680: }
6681: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6682: }
1.59 bisitz 6683: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6684: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6685: .'</tr>'."\n";
1.48 raeburn 6686: $itemcount ++;
1.120 raeburn 6687: foreach my $default ('instcode','communities') {
6688: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6689: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6690: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6691: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6692: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6693: for (my $k=0; $k<=$maxnum; $k++) {
6694: my $vpos = $k+1;
6695: my $selstr;
6696: if ($k == $maxnum) {
6697: $selstr = ' selected="selected" ';
6698: }
6699: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6700: }
1.120 raeburn 6701: $datatable .= '</select></span></td>'.
6702: '<td><span class="LC_nobreak">'.
6703: $default_names{$default}.'</span>';
6704: if ($default eq 'instcode') {
6705: $datatable .= '<br /><span class="LC_nobreak">('
6706: .&mt('with institutional codes').')</span>';
6707: }
6708: $datatable .= '</td>'
6709: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6710: .&mt('Display').'</label> '
6711: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6712: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6713: }
6714: }
6715: }
1.57 raeburn 6716: } else {
6717: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6718: }
6719: } else {
1.160.6.42 raeburn 6720: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6721: .&initialize_categories($itemcount);
1.48 raeburn 6722: }
1.57 raeburn 6723: $$rowtotal += $itemcount;
1.48 raeburn 6724: }
6725: return $datatable;
6726: }
6727:
1.69 raeburn 6728: sub print_serverstatuses {
6729: my ($dom,$settings,$rowtotal) = @_;
6730: my $datatable;
6731: my @pages = &serverstatus_pages();
6732: my (%namedaccess,%machineaccess);
6733: foreach my $type (@pages) {
6734: $namedaccess{$type} = '';
6735: $machineaccess{$type}= '';
6736: }
6737: if (ref($settings) eq 'HASH') {
6738: foreach my $type (@pages) {
6739: if (exists($settings->{$type})) {
6740: if (ref($settings->{$type}) eq 'HASH') {
6741: foreach my $key (keys(%{$settings->{$type}})) {
6742: if ($key eq 'namedusers') {
6743: $namedaccess{$type} = $settings->{$type}->{$key};
6744: } elsif ($key eq 'machines') {
6745: $machineaccess{$type} = $settings->{$type}->{$key};
6746: }
6747: }
6748: }
6749: }
6750: }
6751: }
1.81 raeburn 6752: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6753: my $rownum = 0;
6754: my $css_class;
6755: foreach my $type (@pages) {
6756: $rownum ++;
6757: $css_class = $rownum%2?' class="LC_odd_row"':'';
6758: $datatable .= '<tr'.$css_class.'>'.
6759: '<td><span class="LC_nobreak">'.
6760: $titles->{$type}.'</span></td>'.
6761: '<td class="LC_left_item">'.
6762: '<input type="text" name="'.$type.'_namedusers" '.
6763: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6764: '<td class="LC_right_item">'.
6765: '<span class="LC_nobreak">'.
6766: '<input type="text" name="'.$type.'_machines" '.
6767: 'value="'.$machineaccess{$type}.'" size="10" />'.
6768: '</td></tr>'."\n";
6769: }
6770: $$rowtotal += $rownum;
6771: return $datatable;
6772: }
6773:
6774: sub serverstatus_pages {
6775: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 6776: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 6777: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 6778: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6779: }
6780:
1.160.6.40 raeburn 6781: sub defaults_javascript {
6782: my ($settings) = @_;
1.160.6.80 raeburn 6783: my $intauthcheck = &mt('Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.');
6784: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6785: &js_escape(\$intauthcheck);
6786: &js_escape(\$intauthcost);
6787: my $intauthjs = <<"ENDSCRIPT";
6788:
6789: function warnIntAuth(field) {
6790: if (field.name == 'intauth_check') {
6791: if (field.value == '2') {
6792: alert('$intauthcheck');
6793: }
6794: }
6795: if (field.name == 'intauth_cost') {
6796: field.value.replace(/\s/g,'');
6797: if (field.value != '') {
6798: var regexdigit=/^\\d+\$/;
6799: if (!regexdigit.test(field.value)) {
6800: alert('$intauthcost');
6801: }
6802: }
6803: }
6804: return;
6805: }
6806:
6807: ENDSCRIPT
6808:
6809: if (ref($settings) ne 'HASH') {
6810: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6811: }
1.160.6.40 raeburn 6812: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6813: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6814: if ($maxnum eq '') {
6815: $maxnum = 0;
6816: }
6817: $maxnum ++;
1.160.6.51 raeburn 6818: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 6819: return <<"ENDSCRIPT";
6820: <script type="text/javascript">
6821: // <![CDATA[
6822: function reorderTypes(form,caller) {
6823: var changedVal;
6824: $jstext
6825: var newpos = 'addinststatus_pos';
6826: var current = new Array;
6827: var maxh = $maxnum;
6828: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6829: var oldVal;
6830: if (caller == newpos) {
6831: changedVal = newitemVal;
6832: } else {
6833: var curritem = 'inststatus_pos_'+caller;
6834: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6835: current[newitemVal] = newpos;
6836: }
6837: for (var i=0; i<inststatuses.length; i++) {
6838: if (inststatuses[i] != caller) {
6839: var elementName = 'inststatus_pos_'+inststatuses[i];
6840: if (form.elements[elementName]) {
6841: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6842: current[currVal] = elementName;
6843: }
6844: }
6845: }
6846: for (var j=0; j<maxh; j++) {
6847: if (current[j] == undefined) {
6848: oldVal = j;
6849: }
6850: }
6851: if (oldVal < changedVal) {
6852: for (var k=oldVal+1; k<=changedVal ; k++) {
6853: var elementName = current[k];
6854: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6855: }
6856: } else {
6857: for (var k=changedVal; k<oldVal; k++) {
6858: var elementName = current[k];
6859: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6860: }
6861: }
6862: return;
6863: }
6864:
1.160.6.80 raeburn 6865: $intauthjs
6866:
1.160.6.40 raeburn 6867: // ]]>
6868: </script>
6869:
6870: ENDSCRIPT
1.160.6.80 raeburn 6871: } else {
6872: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.160.6.40 raeburn 6873: }
6874: }
6875:
1.49 raeburn 6876: sub coursecategories_javascript {
6877: my ($settings) = @_;
1.57 raeburn 6878: my ($output,$jstext,$cathash);
1.49 raeburn 6879: if (ref($settings) eq 'HASH') {
1.57 raeburn 6880: $cathash = $settings->{'cats'};
6881: }
6882: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6883: my (@cats,@jsarray,%idx);
1.57 raeburn 6884: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6885: if (@jsarray > 0) {
6886: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6887: for (my $i=0; $i<@jsarray; $i++) {
6888: if (ref($jsarray[$i]) eq 'ARRAY') {
6889: my $catstr = join('","',@{$jsarray[$i]});
6890: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6891: }
6892: }
6893: }
6894: } else {
6895: $jstext = ' var categories = Array(1);'."\n".
6896: ' categories[0] = Array("instcode_pos");'."\n";
6897: }
1.160.6.42 raeburn 6898: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6899: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 6900: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6901: &js_escape(\$instcode_reserved);
6902: &js_escape(\$communities_reserved);
6903: &js_escape(\$choose_again);
1.49 raeburn 6904: $output = <<"ENDSCRIPT";
6905: <script type="text/javascript">
1.109 raeburn 6906: // <![CDATA[
1.49 raeburn 6907: function reorderCats(form,parent,item,idx) {
6908: var changedVal;
6909: $jstext
6910: var newpos = 'addcategory_pos';
6911: if (parent == '') {
6912: var has_instcode = 0;
6913: var maxtop = categories[idx].length;
6914: for (var j=0; j<maxtop; j++) {
6915: if (categories[idx][j] == 'instcode::0') {
6916: has_instcode == 1;
6917: }
6918: }
6919: if (has_instcode == 0) {
6920: categories[idx][maxtop] = 'instcode_pos';
6921: }
6922: } else {
6923: newpos += '_'+parent;
6924: }
6925: var maxh = 1 + categories[idx].length;
6926: var current = new Array;
6927: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6928: if (item == newpos) {
6929: changedVal = newitemVal;
6930: } else {
6931: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6932: current[newitemVal] = newpos;
6933: }
6934: for (var i=0; i<categories[idx].length; i++) {
6935: var elementName = categories[idx][i];
6936: if (elementName != item) {
6937: if (form.elements[elementName]) {
6938: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6939: current[currVal] = elementName;
6940: }
6941: }
6942: }
6943: var oldVal;
6944: for (var j=0; j<maxh; j++) {
6945: if (current[j] == undefined) {
6946: oldVal = j;
6947: }
6948: }
6949: if (oldVal < changedVal) {
6950: for (var k=oldVal+1; k<=changedVal ; k++) {
6951: var elementName = current[k];
6952: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6953: }
6954: } else {
6955: for (var k=changedVal; k<oldVal; k++) {
6956: var elementName = current[k];
6957: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6958: }
6959: }
6960: return;
6961: }
1.120 raeburn 6962:
6963: function categoryCheck(form) {
6964: if (form.elements['addcategory_name'].value == 'instcode') {
6965: alert('$instcode_reserved\\n$choose_again');
6966: return false;
6967: }
6968: if (form.elements['addcategory_name'].value == 'communities') {
6969: alert('$communities_reserved\\n$choose_again');
6970: return false;
6971: }
6972: return true;
6973: }
6974:
1.109 raeburn 6975: // ]]>
1.49 raeburn 6976: </script>
6977:
6978: ENDSCRIPT
6979: return $output;
6980: }
6981:
1.48 raeburn 6982: sub initialize_categories {
6983: my ($itemcount) = @_;
1.120 raeburn 6984: my ($datatable,$css_class,$chgstr);
6985: my %default_names = (
6986: instcode => 'Official courses (with institutional codes)',
6987: communities => 'Communities',
6988: );
6989: my $select0 = ' selected="selected"';
6990: my $select1 = '';
6991: foreach my $default ('instcode','communities') {
6992: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6993: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
6994: if ($default eq 'communities') {
6995: $select1 = $select0;
6996: $select0 = '';
6997: }
6998: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6999: .'<select name="'.$default.'_pos">'
7000: .'<option value="0"'.$select0.'>1</option>'
7001: .'<option value="1"'.$select1.'>2</option>'
7002: .'<option value="2">3</option></select> '
7003: .$default_names{$default}
7004: .'</span></td><td><span class="LC_nobreak">'
7005: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7006: .&mt('Display').'</label> <label>'
7007: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7008: .'</label></span></td></tr>';
1.120 raeburn 7009: $itemcount ++;
7010: }
1.48 raeburn 7011: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7012: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7013: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7014: .'<select name="addcategory_pos"'.$chgstr.'>'
7015: .'<option value="0">1</option>'
7016: .'<option value="1">2</option>'
7017: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 7018: .&mt('Add category').'</td><td>'.&mt('Name:')
7019: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
7020: return $datatable;
7021: }
7022:
7023: sub build_category_rows {
1.49 raeburn 7024: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7025: my ($text,$name,$item,$chgstr);
1.48 raeburn 7026: if (ref($cats) eq 'ARRAY') {
7027: my $maxdepth = scalar(@{$cats});
7028: if (ref($cats->[$depth]) eq 'HASH') {
7029: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7030: my $numchildren = @{$cats->[$depth]{$parent}};
7031: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 7032: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 7033: my ($idxnum,$parent_name,$parent_item);
7034: my $higher = $depth - 1;
7035: if ($higher == 0) {
7036: $parent_name = &escape($parent).'::'.$higher;
7037: } else {
7038: if (ref($path) eq 'ARRAY') {
7039: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7040: }
7041: }
7042: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7043: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7044: if ($j < $numchildren) {
1.48 raeburn 7045: $name = $cats->[$depth]{$parent}[$j];
7046: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7047: $idxnum = $idx->{$item};
7048: } else {
7049: $name = $parent_name;
7050: $item = $parent_item;
1.48 raeburn 7051: }
1.49 raeburn 7052: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7053: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7054: for (my $i=0; $i<=$numchildren; $i++) {
7055: my $vpos = $i+1;
7056: my $selstr;
7057: if ($j == $i) {
7058: $selstr = ' selected="selected" ';
7059: }
7060: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7061: }
7062: $text .= '</select> ';
7063: if ($j < $numchildren) {
7064: my $deeper = $depth+1;
7065: $text .= $name.' '
7066: .'<label><input type="checkbox" name="deletecategory" value="'
7067: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7068: if(ref($path) eq 'ARRAY') {
7069: push(@{$path},$name);
1.49 raeburn 7070: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7071: pop(@{$path});
7072: }
7073: } else {
1.59 bisitz 7074: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 7075: if ($j == $numchildren) {
7076: $text .= $name;
7077: } else {
7078: $text .= $item;
7079: }
7080: $text .= '" value="" />';
7081: }
7082: $text .= '</td></tr>';
7083: }
7084: $text .= '</table></td>';
7085: } else {
7086: my $higher = $depth-1;
7087: if ($higher == 0) {
7088: $name = &escape($parent).'::'.$higher;
7089: } else {
7090: if (ref($path) eq 'ARRAY') {
7091: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7092: }
7093: }
7094: my $colspan;
7095: if ($parent ne 'instcode') {
7096: $colspan = $maxdepth - $depth - 1;
7097: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7098: }
7099: }
7100: }
7101: }
7102: return $text;
7103: }
7104:
1.33 raeburn 7105: sub modifiable_userdata_row {
1.160.6.35 raeburn 7106: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
7107: my ($role,$rolename,$statustype);
7108: $role = $item;
1.160.6.34 raeburn 7109: if ($context eq 'cancreate') {
1.160.6.35 raeburn 7110: if ($item =~ /^emailusername_(.+)$/) {
7111: $statustype = $1;
7112: $role = 'emailusername';
7113: if (ref($usertypes) eq 'HASH') {
7114: if ($usertypes->{$statustype}) {
7115: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7116: } else {
7117: $rolename = &mt('Data provided by user');
7118: }
7119: }
1.160.6.34 raeburn 7120: }
7121: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7122: if (ref($usertypes) eq 'HASH') {
7123: $rolename = $usertypes->{$role};
7124: } else {
7125: $rolename = $role;
7126: }
1.33 raeburn 7127: } else {
1.63 raeburn 7128: if ($role eq 'cr') {
7129: $rolename = &mt('Custom role');
7130: } else {
7131: $rolename = &Apache::lonnet::plaintext($role);
7132: }
1.33 raeburn 7133: }
1.160.6.34 raeburn 7134: my (@fields,%fieldtitles);
7135: if (ref($fieldsref) eq 'ARRAY') {
7136: @fields = @{$fieldsref};
7137: } else {
7138: @fields = ('lastname','firstname','middlename','generation',
7139: 'permanentemail','id');
7140: }
7141: if ((ref($titlesref) eq 'HASH')) {
7142: %fieldtitles = %{$titlesref};
7143: } else {
7144: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7145: }
1.33 raeburn 7146: my $output;
7147: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7148: $output = '<tr '.$css_class.'>'.
7149: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7150: '<td class="LC_left_item" colspan="2"><table>';
7151: my $rem;
7152: my %checks;
7153: if (ref($settings) eq 'HASH') {
7154: if (ref($settings->{$context}) eq 'HASH') {
7155: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 7156: my $hashref = $settings->{$context}->{$role};
7157: if ($role eq 'emailusername') {
7158: if ($statustype) {
7159: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7160: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 7161: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 7162: foreach my $field (@fields) {
7163: if ($hashref->{$field}) {
7164: $checks{$field} = $hashref->{$field};
7165: }
7166: }
7167: }
7168: }
7169: }
7170: } else {
7171: if (ref($hashref) eq 'HASH') {
7172: foreach my $field (@fields) {
7173: if ($hashref->{$field}) {
7174: $checks{$field} = ' checked="checked" ';
7175: }
7176: }
1.33 raeburn 7177: }
7178: }
7179: }
7180: }
7181: }
1.160.6.39 raeburn 7182:
1.33 raeburn 7183: for (my $i=0; $i<@fields; $i++) {
7184: my $rem = $i%($numinrow);
7185: if ($rem == 0) {
7186: if ($i > 0) {
7187: $output .= '</tr>';
7188: }
7189: $output .= '<tr>';
7190: }
7191: my $check = ' ';
1.160.6.35 raeburn 7192: unless ($role eq 'emailusername') {
7193: if (exists($checks{$fields[$i]})) {
7194: $check = $checks{$fields[$i]}
7195: } else {
7196: if ($role eq 'st') {
7197: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 7198: $check = ' checked="checked" ';
1.160.6.35 raeburn 7199: }
1.33 raeburn 7200: }
7201: }
7202: }
7203: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 7204: '<span class="LC_nobreak">';
7205: if ($role eq 'emailusername') {
7206: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7207: $checks{$fields[$i]} = 'omit';
7208: }
7209: foreach my $option ('required','optional','omit') {
7210: my $checked='';
7211: if ($checks{$fields[$i]} eq $option) {
7212: $checked='checked="checked" ';
7213: }
7214: $output .= '<label>'.
7215: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7216: &mt($option).'</label>'.(' ' x2);
7217: }
7218: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7219: } else {
7220: $output .= '<label>'.
7221: '<input type="checkbox" name="canmodify_'.$role.'" '.
7222: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7223: '</label>';
7224: }
7225: $output .= '</span></td>';
1.33 raeburn 7226: $rem = @fields%($numinrow);
7227: }
7228: my $colsleft = $numinrow - $rem;
7229: if ($colsleft > 1 ) {
7230: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7231: ' </td>';
7232: } elsif ($colsleft == 1) {
7233: $output .= '<td class="LC_left_item"> </td>';
7234: }
7235: $output .= '</tr></table></td></tr>';
7236: return $output;
7237: }
1.28 raeburn 7238:
1.93 raeburn 7239: sub insttypes_row {
1.160.6.84.2. (raeburn 7240:): my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
7241:): $customcss,$rowstyle) = @_;
1.93 raeburn 7242: my %lt = &Apache::lonlocal::texthash (
7243: cansearch => 'Users allowed to search',
7244: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7245: lockablenames => 'User preference to lock name',
1.160.6.84.2. (raeburn 7246:): overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 7247: );
7248: my $showdom;
7249: if ($context eq 'cansearch') {
7250: $showdom = ' ('.$dom.')';
7251: }
1.160.6.5 raeburn 7252: my $class = 'LC_left_item';
7253: if ($context eq 'statustocreate') {
7254: $class = 'LC_right_item';
7255: }
1.160.6.84.2. (raeburn 7256:): my $css_class;
7257:): if ($$rowtotal%2) {
7258:): $css_class = 'LC_odd_row';
7259:): }
7260:): if ($customcss) {
7261:): $css_class .= ' '.$customcss;
7262:): }
7263:): $css_class =~ s/^\s+//;
7264:): if ($css_class) {
7265:): $css_class = ' class="'.$css_class.'"';
7266:): }
7267:): if ($rowstyle) {
7268:): $css_class .= ' style="'.$rowstyle.'"';
7269:): }
7270:): if ($onclick) {
7271:): $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 7272: }
7273: my $output = '<tr'.$css_class.'>'.
7274: '<td>'.$lt{$context}.$showdom.
7275: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7276: my $rem;
7277: if (ref($types) eq 'ARRAY') {
7278: for (my $i=0; $i<@{$types}; $i++) {
7279: if (defined($usertypes->{$types->[$i]})) {
7280: my $rem = $i%($numinrow);
7281: if ($rem == 0) {
7282: if ($i > 0) {
7283: $output .= '</tr>';
7284: }
7285: $output .= '<tr>';
1.23 raeburn 7286: }
1.26 raeburn 7287: my $check = ' ';
1.99 raeburn 7288: if (ref($settings) eq 'HASH') {
7289: if (ref($settings->{$context}) eq 'ARRAY') {
7290: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7291: $check = ' checked="checked" ';
7292: }
1.160.6.84.2. (raeburn 7293:): } elsif (ref($settings->{$context}) eq 'HASH') {
7294:): if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
7295:): $check = ' checked="checked" ';
7296:): }
1.99 raeburn 7297: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7298: $check = ' checked="checked" ';
7299: }
1.23 raeburn 7300: }
1.26 raeburn 7301: $output .= '<td class="LC_left_item">'.
7302: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7303: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 7304: 'value="'.$types->[$i].'"'.$check.'/>'.
7305: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7306: }
7307: }
1.26 raeburn 7308: $rem = @{$types}%($numinrow);
1.23 raeburn 7309: }
7310: my $colsleft = $numinrow - $rem;
1.160.6.84.2. (raeburn 7311:): if ($context eq 'overrides') {
7312:): if ($colsleft > 1) {
7313:): $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
7314:): } else {
7315:): $output .= '<td class="LC_left_item">';
7316:): }
7317:): $output .= ' ';
1.23 raeburn 7318: } else {
1.160.6.84.2. (raeburn 7319:): if (($rem == 0) && (@{$types} > 0)) {
7320:): $output .= '<tr>';
7321:): }
7322:): if ($colsleft > 1) {
7323:): $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
7324:): } else {
7325:): $output .= '<td class="LC_left_item">';
7326:): }
7327:): my $defcheck = ' ';
7328:): if (ref($settings) eq 'HASH') {
7329:): if (ref($settings->{$context}) eq 'ARRAY') {
7330:): if (grep(/^default$/,@{$settings->{$context}})) {
7331:): $defcheck = ' checked="checked" ';
7332:): }
7333:): } elsif ($context eq 'statustocreate') {
1.99 raeburn 7334: $defcheck = ' checked="checked" ';
7335: }
1.26 raeburn 7336: }
1.160.6.84.2. (raeburn 7337:): $output .= '<span class="LC_nobreak"><label>'.
7338:): '<input type="checkbox" name="'.$context.'" '.
7339:): 'value="default"'.$defcheck.'/>'.
7340:): $othertitle.'</label></span>';
1.23 raeburn 7341: }
1.160.6.84.2. (raeburn 7342:): $output .= '</td></tr></table></td></tr>';
1.25 raeburn 7343: return $output;
1.23 raeburn 7344: }
7345:
7346: sub sorted_searchtitles {
7347: my %searchtitles = &Apache::lonlocal::texthash(
7348: 'uname' => 'username',
7349: 'lastname' => 'last name',
7350: 'lastfirst' => 'last name, first name',
7351: );
7352: my @titleorder = ('uname','lastname','lastfirst');
7353: return (\%searchtitles,\@titleorder);
7354: }
7355:
1.25 raeburn 7356: sub sorted_searchtypes {
7357: my %srchtypes_desc = (
7358: exact => 'is exact match',
7359: contains => 'contains ..',
7360: begins => 'begins with ..',
7361: );
7362: my @srchtypeorder = ('exact','begins','contains');
7363: return (\%srchtypes_desc,\@srchtypeorder);
7364: }
7365:
1.3 raeburn 7366: sub usertype_update_row {
7367: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7368: my $datatable;
7369: my $numinrow = 4;
7370: foreach my $type (@{$types}) {
7371: if (defined($usertypes->{$type})) {
7372: $$rownums ++;
7373: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7374: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7375: '</td><td class="LC_left_item"><table>';
7376: for (my $i=0; $i<@{$fields}; $i++) {
7377: my $rem = $i%($numinrow);
7378: if ($rem == 0) {
7379: if ($i > 0) {
7380: $datatable .= '</tr>';
7381: }
7382: $datatable .= '<tr>';
7383: }
7384: my $check = ' ';
1.39 raeburn 7385: if (ref($settings) eq 'HASH') {
7386: if (ref($settings->{'fields'}) eq 'HASH') {
7387: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7388: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7389: $check = ' checked="checked" ';
7390: }
1.3 raeburn 7391: }
7392: }
7393: }
7394:
7395: if ($i == @{$fields}-1) {
7396: my $colsleft = $numinrow - $rem;
7397: if ($colsleft > 1) {
7398: $datatable .= '<td colspan="'.$colsleft.'">';
7399: } else {
7400: $datatable .= '<td>';
7401: }
7402: } else {
7403: $datatable .= '<td>';
7404: }
1.8 raeburn 7405: $datatable .= '<span class="LC_nobreak"><label>'.
7406: '<input type="checkbox" name="updateable_'.$type.
7407: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7408: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7409: }
7410: $datatable .= '</tr></table></td></tr>';
7411: }
7412: }
7413: return $datatable;
1.1 raeburn 7414: }
7415:
7416: sub modify_login {
1.160.6.24 raeburn 7417: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 7418: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7419: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7420: %title = ( coursecatalog => 'Display course catalog',
7421: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 7422: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 7423: newuser => 'Link for visitors to create a user account',
7424: loginheader => 'Log-in box header');
7425: @offon = ('off','on');
1.112 raeburn 7426: if (ref($domconfig{login}) eq 'HASH') {
7427: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7428: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7429: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7430: }
7431: }
7432: }
1.9 raeburn 7433: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7434: \%domconfig,\%loginhash);
1.160.6.14 raeburn 7435: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7436: foreach my $item (@toggles) {
7437: $loginhash{login}{$item} = $env{'form.'.$item};
7438: }
1.41 raeburn 7439: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7440: if (ref($colchanges{'login'}) eq 'HASH') {
7441: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7442: \%loginhash);
7443: }
1.110 raeburn 7444:
1.149 raeburn 7445: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 7446: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7447: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7448: if (keys(%servers) > 1) {
7449: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7450: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7451: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7452: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7453: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7454: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7455: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7456: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7457: $changes{'loginvia'}{$lonhost} = 1;
7458: } else {
7459: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7460: $changes{'loginvia'}{$lonhost} = 1;
7461: }
7462: } else {
7463: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7464: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7465: $changes{'loginvia'}{$lonhost} = 1;
7466: }
7467: }
7468: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7469: foreach my $item (@loginvia_attribs) {
7470: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7471: }
7472: } else {
7473: foreach my $item (@loginvia_attribs) {
7474: my $new = $env{'form.'.$lonhost.'_'.$item};
7475: if (($item eq 'serverpath') && ($new eq 'custom')) {
7476: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7477: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7478: $new = '/';
7479: }
7480: }
7481: if (($item eq 'custompath') &&
7482: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7483: $new = '';
7484: }
7485: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7486: $changes{'loginvia'}{$lonhost} = 1;
7487: }
7488: if ($item eq 'exempt') {
1.160.6.56 raeburn 7489: $new = &check_exempt_addresses($new);
1.128 raeburn 7490: }
7491: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7492: }
7493: }
1.112 raeburn 7494: } else {
1.128 raeburn 7495: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7496: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7497: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7498: foreach my $item (@loginvia_attribs) {
7499: my $new = $env{'form.'.$lonhost.'_'.$item};
7500: if (($item eq 'serverpath') && ($new eq 'custom')) {
7501: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7502: $new = '/';
7503: }
7504: }
7505: if (($item eq 'custompath') &&
7506: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7507: $new = '';
7508: }
7509: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7510: }
1.110 raeburn 7511: }
7512: }
7513: }
7514: }
1.119 raeburn 7515:
1.160.6.5 raeburn 7516: my $servadm = $r->dir_config('lonAdmEMail');
7517: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7518: if (ref($domconfig{'login'}) eq 'HASH') {
7519: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7520: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7521: if ($lang eq 'nolang') {
7522: push(@currlangs,$lang);
7523: } elsif (defined($langchoices{$lang})) {
7524: push(@currlangs,$lang);
7525: } else {
7526: next;
7527: }
7528: }
7529: }
7530: }
7531: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7532: if (@currlangs > 0) {
7533: foreach my $lang (@currlangs) {
7534: if (grep(/^\Q$lang\E$/,@delurls)) {
7535: $changes{'helpurl'}{$lang} = 1;
7536: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7537: $changes{'helpurl'}{$lang} = 1;
7538: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7539: push(@newlangs,$lang);
7540: } else {
7541: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7542: }
7543: }
7544: }
7545: unless (grep(/^nolang$/,@currlangs)) {
7546: if ($env{'form.loginhelpurl_nolang.filename'}) {
7547: $changes{'helpurl'}{'nolang'} = 1;
7548: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7549: push(@newlangs,'nolang');
7550: }
7551: }
7552: if ($env{'form.loginhelpurl_add_lang'}) {
7553: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7554: ($env{'form.loginhelpurl_add_file.filename'})) {
7555: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7556: $addedfile = $env{'form.loginhelpurl_add_lang'};
7557: }
7558: }
7559: if ((@newlangs > 0) || ($addedfile)) {
7560: my $error;
7561: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7562: if ($configuserok eq 'ok') {
7563: if ($switchserver) {
7564: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7565: } elsif ($author_ok eq 'ok') {
7566: my @allnew = @newlangs;
7567: if ($addedfile ne '') {
7568: push(@allnew,$addedfile);
7569: }
7570: foreach my $lang (@allnew) {
7571: my $formelem = 'loginhelpurl_'.$lang;
7572: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7573: $formelem = 'loginhelpurl_add_file';
7574: }
7575: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7576: "help/$lang",'','',$newfile{$lang});
7577: if ($result eq 'ok') {
7578: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7579: $changes{'helpurl'}{$lang} = 1;
7580: } else {
7581: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7582: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7583: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
7584: (!grep(/^\Q$lang\E$/,@delurls))) {
7585: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7586: }
7587: }
7588: }
7589: } else {
7590: $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);
7591: }
7592: } else {
7593: $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);
7594: }
7595: if ($error) {
7596: &Apache::lonnet::logthis($error);
7597: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7598: }
7599: }
1.160.6.56 raeburn 7600:
7601: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7602: if (ref($domconfig{'login'}) eq 'HASH') {
7603: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7604: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7605: if ($domservers{$lonhost}) {
7606: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7607: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 7608: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 7609: }
7610: }
7611: }
7612: }
7613: }
7614: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7615: foreach my $lonhost (sort(keys(%domservers))) {
7616: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7617: $changes{'headtag'}{$lonhost} = 1;
7618: } else {
7619: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7620: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7621: }
7622: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7623: push(@newhosts,$lonhost);
7624: } elsif ($currheadtagurls{$lonhost}) {
7625: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7626: if ($currexempt{$lonhost}) {
7627: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
7628: $changes{'headtag'}{$lonhost} = 1;
7629: }
7630: } elsif ($possexempt{$lonhost}) {
7631: $changes{'headtag'}{$lonhost} = 1;
7632: }
7633: if ($possexempt{$lonhost}) {
7634: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7635: }
7636: }
7637: }
7638: }
7639: if (@newhosts) {
7640: my $error;
7641: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7642: if ($configuserok eq 'ok') {
7643: if ($switchserver) {
7644: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7645: } elsif ($author_ok eq 'ok') {
7646: foreach my $lonhost (@newhosts) {
7647: my $formelem = 'loginheadtag_'.$lonhost;
7648: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7649: "login/headtag/$lonhost",'','',
7650: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7651: if ($result eq 'ok') {
7652: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7653: $changes{'headtag'}{$lonhost} = 1;
7654: if ($possexempt{$lonhost}) {
7655: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7656: }
7657: } else {
7658: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7659: $newheadtagurls{$lonhost},$result);
7660: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7661: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7662: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7663: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7664: }
7665: }
7666: }
7667: } else {
7668: $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);
7669: }
7670: } else {
7671: $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);
7672: }
7673: if ($error) {
7674: &Apache::lonnet::logthis($error);
7675: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7676: }
7677: }
1.160.6.5 raeburn 7678: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
7679:
7680: my $defaulthelpfile = '/adm/loginproblems.html';
7681: my $defaulttext = &mt('Default in use');
7682:
1.1 raeburn 7683: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7684: $dom);
7685: if ($putresult eq 'ok') {
1.160.6.14 raeburn 7686: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7687: my %defaultchecked = (
7688: 'coursecatalog' => 'on',
1.160.6.14 raeburn 7689: 'helpdesk' => 'on',
1.42 raeburn 7690: 'adminmail' => 'off',
1.43 raeburn 7691: 'newuser' => 'off',
1.42 raeburn 7692: );
1.55 raeburn 7693: if (ref($domconfig{'login'}) eq 'HASH') {
7694: foreach my $item (@toggles) {
7695: if ($defaultchecked{$item} eq 'on') {
7696: if (($domconfig{'login'}{$item} eq '0') &&
7697: ($env{'form.'.$item} eq '1')) {
7698: $changes{$item} = 1;
7699: } elsif (($domconfig{'login'}{$item} eq '' ||
7700: $domconfig{'login'}{$item} eq '1') &&
7701: ($env{'form.'.$item} eq '0')) {
7702: $changes{$item} = 1;
7703: }
7704: } elsif ($defaultchecked{$item} eq 'off') {
7705: if (($domconfig{'login'}{$item} eq '1') &&
7706: ($env{'form.'.$item} eq '0')) {
7707: $changes{$item} = 1;
7708: } elsif (($domconfig{'login'}{$item} eq '' ||
7709: $domconfig{'login'}{$item} eq '0') &&
7710: ($env{'form.'.$item} eq '1')) {
7711: $changes{$item} = 1;
7712: }
1.42 raeburn 7713: }
7714: }
1.41 raeburn 7715: }
1.6 raeburn 7716: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7717: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7718: if (ref($lastactref) eq 'HASH') {
7719: $lastactref->{'domainconfig'} = 1;
7720: }
1.1 raeburn 7721: $resulttext = &mt('Changes made:').'<ul>';
7722: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7723: if ($item eq 'loginvia') {
1.112 raeburn 7724: if (ref($changes{$item}) eq 'HASH') {
7725: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7726: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7727: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7728: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7729: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7730: $protocol = 'http' if ($protocol ne 'https');
7731: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7732:
7733: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7734: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7735: } else {
7736: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7737: }
7738: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7739: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7740: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7741: }
7742: $resulttext .= '</li>';
7743: } else {
7744: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7745: }
1.112 raeburn 7746: } else {
1.128 raeburn 7747: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7748: }
7749: }
1.128 raeburn 7750: $resulttext .= '</ul></li>';
1.112 raeburn 7751: }
1.160.6.5 raeburn 7752: } elsif ($item eq 'helpurl') {
7753: if (ref($changes{$item}) eq 'HASH') {
7754: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7755: if (grep(/^\Q$lang\E$/,@delurls)) {
7756: my ($chg,$link);
7757: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7758: if ($lang eq 'nolang') {
7759: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7760: } else {
7761: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7762: }
7763: $resulttext .= '<li>'.$chg.'</li>';
7764: } else {
7765: my $chg;
7766: if ($lang eq 'nolang') {
7767: $chg = &mt('custom log-in help file for no preferred language');
7768: } else {
7769: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7770: }
7771: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7772: $loginhash{'login'}{'helpurl'}{$lang}.
7773: '?inhibitmenu=yes',$chg,600,500).
7774: '</li>';
7775: }
7776: }
7777: }
1.160.6.56 raeburn 7778: } elsif ($item eq 'headtag') {
7779: if (ref($changes{$item}) eq 'HASH') {
7780: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7781: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7782: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7783: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7784: $resulttext .= '<li><a href="'.
7785: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7786: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7787: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7788: if ($possexempt{$lonhost}) {
7789: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7790: } else {
7791: $resulttext .= &mt('included for any client IP');
7792: }
7793: $resulttext .= '</li>';
7794: }
7795: }
7796: }
1.160.6.5 raeburn 7797: } elsif ($item eq 'captcha') {
7798: if (ref($loginhash{'login'}) eq 'HASH') {
7799: my $chgtxt;
7800: if ($loginhash{'login'}{$item} eq 'notused') {
7801: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7802: } else {
7803: my %captchas = &captcha_phrases();
7804: if ($captchas{$loginhash{'login'}{$item}}) {
7805: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7806: } else {
7807: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7808: }
7809: }
7810: $resulttext .= '<li>'.$chgtxt.'</li>';
7811: }
7812: } elsif ($item eq 'recaptchakeys') {
7813: if (ref($loginhash{'login'}) eq 'HASH') {
7814: my ($privkey,$pubkey);
7815: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7816: $pubkey = $loginhash{'login'}{$item}{'public'};
7817: $privkey = $loginhash{'login'}{$item}{'private'};
7818: }
7819: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7820: if (!$pubkey) {
7821: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7822: } else {
7823: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7824: }
7825: if (!$privkey) {
7826: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7827: } else {
1.160.6.53 raeburn 7828: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 7829: }
7830: $chgtxt .= '</ul>';
7831: $resulttext .= '<li>'.$chgtxt.'</li>';
7832: }
1.160.6.69 raeburn 7833: } elsif ($item eq 'recaptchaversion') {
7834: if (ref($loginhash{'login'}) eq 'HASH') {
7835: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
7836: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
7837: '</li>';
7838: }
7839: }
1.41 raeburn 7840: } else {
7841: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7842: }
1.1 raeburn 7843: }
1.6 raeburn 7844: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7845: } else {
7846: $resulttext = &mt('No changes made to log-in page settings');
7847: }
7848: } else {
1.11 albertel 7849: $resulttext = '<span class="LC_error">'.
7850: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7851: }
1.6 raeburn 7852: if ($errors) {
1.9 raeburn 7853: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7854: $errors.'</ul>';
7855: }
7856: return $resulttext;
7857: }
7858:
1.160.6.56 raeburn 7859: sub check_exempt_addresses {
7860: my ($iplist) = @_;
7861: $iplist =~ s/^\s+//;
7862: $iplist =~ s/\s+$//;
7863: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7864: my (@okips,$new);
7865: foreach my $ip (@poss_ips) {
7866: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7867: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7868: push(@okips,$ip);
7869: }
7870: }
7871: }
7872: if (@okips > 0) {
7873: $new = join(',',@okips);
7874: } else {
7875: $new = '';
7876: }
7877: return $new;
7878: }
7879:
1.6 raeburn 7880: sub color_font_choices {
7881: my %choices =
7882: &Apache::lonlocal::texthash (
7883: img => "Header",
7884: bgs => "Background colors",
7885: links => "Link colors",
1.55 raeburn 7886: images => "Images",
1.6 raeburn 7887: font => "Font color",
1.160.6.22 raeburn 7888: fontmenu => "Font menu",
1.76 raeburn 7889: pgbg => "Page",
1.6 raeburn 7890: tabbg => "Header",
7891: sidebg => "Border",
7892: link => "Link",
7893: alink => "Active link",
7894: vlink => "Visited link",
7895: );
7896: return %choices;
7897: }
7898:
7899: sub modify_rolecolors {
1.160.6.24 raeburn 7900: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7901: my ($resulttext,%rolehash);
7902: $rolehash{'rolecolors'} = {};
1.55 raeburn 7903: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7904: if ($domconfig{'rolecolors'} eq '') {
7905: $domconfig{'rolecolors'} = {};
7906: }
7907: }
1.9 raeburn 7908: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7909: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7910: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7911: $dom);
7912: if ($putresult eq 'ok') {
7913: if (keys(%changes) > 0) {
1.41 raeburn 7914: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7915: if (ref($lastactref) eq 'HASH') {
7916: $lastactref->{'domainconfig'} = 1;
7917: }
1.6 raeburn 7918: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7919: $rolehash{'rolecolors'});
7920: } else {
7921: $resulttext = &mt('No changes made to default color schemes');
7922: }
7923: } else {
1.11 albertel 7924: $resulttext = '<span class="LC_error">'.
7925: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7926: }
7927: if ($errors) {
7928: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7929: $errors.'</ul>';
7930: }
7931: return $resulttext;
7932: }
7933:
7934: sub modify_colors {
1.9 raeburn 7935: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7936: my (%changes,%choices);
1.51 raeburn 7937: my @bgs;
1.6 raeburn 7938: my @links = ('link','alink','vlink');
1.41 raeburn 7939: my @logintext;
1.6 raeburn 7940: my @images;
7941: my $servadm = $r->dir_config('lonAdmEMail');
7942: my $errors;
1.160.6.22 raeburn 7943: my %defaults;
1.6 raeburn 7944: foreach my $role (@{$roles}) {
7945: if ($role eq 'login') {
1.12 raeburn 7946: %choices = &login_choices();
1.41 raeburn 7947: @logintext = ('textcol','bgcol');
1.12 raeburn 7948: } else {
7949: %choices = &color_font_choices();
7950: }
7951: if ($role eq 'login') {
1.41 raeburn 7952: @images = ('img','logo','domlogo','login');
1.51 raeburn 7953: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7954: } else {
7955: @images = ('img');
1.160.6.22 raeburn 7956: @bgs = ('pgbg','tabbg','sidebg');
7957: }
7958: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7959: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7960: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7961: }
7962: if ($role eq 'login') {
7963: foreach my $item (@logintext) {
1.160.6.39 raeburn 7964: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7965: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7966: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7967: }
7968: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 7969: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7970: }
7971: }
7972: } else {
1.160.6.39 raeburn 7973: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7974: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7975: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7976: }
7977: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 7978: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7979: }
1.6 raeburn 7980: }
1.160.6.22 raeburn 7981: foreach my $item (@bgs) {
1.160.6.39 raeburn 7982: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7983: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7984: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7985: }
7986: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 7987: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7988: }
7989: }
7990: foreach my $item (@links) {
1.160.6.39 raeburn 7991: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7992: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7993: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7994: }
7995: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 7996: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7997: }
1.6 raeburn 7998: }
1.46 raeburn 7999: my ($configuserok,$author_ok,$switchserver) =
8000: &config_check($dom,$confname,$servadm);
1.9 raeburn 8001: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8002: if (ref($domconfig->{$role}) ne 'HASH') {
8003: $domconfig->{$role} = {};
8004: }
1.8 raeburn 8005: foreach my $img (@images) {
1.70 raeburn 8006: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8007: if (defined($env{'form.login_showlogo_'.$img})) {
8008: $confhash->{$role}{'showlogo'}{$img} = 1;
8009: } else {
8010: $confhash->{$role}{'showlogo'}{$img} = 0;
8011: }
8012: }
1.18 albertel 8013: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8014: && !defined($domconfig->{$role}{$img})
8015: && !$env{'form.'.$role.'_del_'.$img}
8016: && $env{'form.'.$role.'_import_'.$img}) {
8017: # import the old configured image from the .tab setting
8018: # if they haven't provided a new one
8019: $domconfig->{$role}{$img} =
8020: $env{'form.'.$role.'_import_'.$img};
8021: }
1.6 raeburn 8022: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8023: my $error;
1.6 raeburn 8024: if ($configuserok eq 'ok') {
1.9 raeburn 8025: if ($switchserver) {
1.12 raeburn 8026: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8027: } else {
8028: if ($author_ok eq 'ok') {
8029: my ($result,$logourl) =
8030: &publishlogo($r,'upload',$role.'_'.$img,
8031: $dom,$confname,$img,$width,$height);
8032: if ($result eq 'ok') {
8033: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8034: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8035: } else {
1.12 raeburn 8036: $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 8037: }
8038: } else {
1.46 raeburn 8039: $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 8040: }
8041: }
8042: } else {
1.46 raeburn 8043: $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 8044: }
8045: if ($error) {
1.8 raeburn 8046: &Apache::lonnet::logthis($error);
1.11 albertel 8047: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8048: }
8049: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8050: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8051: my $error;
8052: if ($configuserok eq 'ok') {
8053: # is confname an author?
8054: if ($switchserver eq '') {
8055: if ($author_ok eq 'ok') {
8056: my ($result,$logourl) =
8057: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8058: $dom,$confname,$img,$width,$height);
8059: if ($result eq 'ok') {
8060: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8061: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8062: }
8063: }
8064: }
8065: }
1.6 raeburn 8066: }
8067: }
8068: }
8069: if (ref($domconfig) eq 'HASH') {
8070: if (ref($domconfig->{$role}) eq 'HASH') {
8071: foreach my $img (@images) {
8072: if ($domconfig->{$role}{$img} ne '') {
8073: if ($env{'form.'.$role.'_del_'.$img}) {
8074: $confhash->{$role}{$img} = '';
1.12 raeburn 8075: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8076: } else {
1.9 raeburn 8077: if ($confhash->{$role}{$img} eq '') {
8078: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8079: }
1.6 raeburn 8080: }
8081: } else {
8082: if ($env{'form.'.$role.'_del_'.$img}) {
8083: $confhash->{$role}{$img} = '';
1.12 raeburn 8084: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8085: }
8086: }
1.70 raeburn 8087: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8088: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8089: if ($confhash->{$role}{'showlogo'}{$img} ne
8090: $domconfig->{$role}{'showlogo'}{$img}) {
8091: $changes{$role}{'showlogo'}{$img} = 1;
8092: }
8093: } else {
8094: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8095: $changes{$role}{'showlogo'}{$img} = 1;
8096: }
8097: }
8098: }
8099: }
1.6 raeburn 8100: if ($domconfig->{$role}{'font'} ne '') {
8101: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8102: $changes{$role}{'font'} = 1;
8103: }
8104: } else {
8105: if ($confhash->{$role}{'font'}) {
8106: $changes{$role}{'font'} = 1;
8107: }
8108: }
1.107 raeburn 8109: if ($role ne 'login') {
8110: if ($domconfig->{$role}{'fontmenu'} ne '') {
8111: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8112: $changes{$role}{'fontmenu'} = 1;
8113: }
8114: } else {
8115: if ($confhash->{$role}{'fontmenu'}) {
8116: $changes{$role}{'fontmenu'} = 1;
8117: }
1.97 tempelho 8118: }
8119: }
1.6 raeburn 8120: foreach my $item (@bgs) {
8121: if ($domconfig->{$role}{$item} ne '') {
8122: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8123: $changes{$role}{'bgs'}{$item} = 1;
8124: }
8125: } else {
8126: if ($confhash->{$role}{$item}) {
8127: $changes{$role}{'bgs'}{$item} = 1;
8128: }
8129: }
8130: }
8131: foreach my $item (@links) {
8132: if ($domconfig->{$role}{$item} ne '') {
8133: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8134: $changes{$role}{'links'}{$item} = 1;
8135: }
8136: } else {
8137: if ($confhash->{$role}{$item}) {
8138: $changes{$role}{'links'}{$item} = 1;
8139: }
8140: }
8141: }
1.41 raeburn 8142: foreach my $item (@logintext) {
8143: if ($domconfig->{$role}{$item} ne '') {
8144: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8145: $changes{$role}{'logintext'}{$item} = 1;
8146: }
8147: } else {
8148: if ($confhash->{$role}{$item}) {
8149: $changes{$role}{'logintext'}{$item} = 1;
8150: }
8151: }
8152: }
1.6 raeburn 8153: } else {
8154: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8155: \@logintext,$confhash,\%changes);
1.6 raeburn 8156: }
8157: } else {
8158: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8159: \@logintext,$confhash,\%changes);
1.6 raeburn 8160: }
8161: }
8162: return ($errors,%changes);
8163: }
8164:
1.46 raeburn 8165: sub config_check {
8166: my ($dom,$confname,$servadm) = @_;
8167: my ($configuserok,$author_ok,$switchserver,%currroles);
8168: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8169: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8170: $confname,$servadm);
8171: if ($configuserok eq 'ok') {
8172: $switchserver = &check_switchserver($dom,$confname);
8173: if ($switchserver eq '') {
8174: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8175: }
8176: }
8177: return ($configuserok,$author_ok,$switchserver);
8178: }
8179:
1.6 raeburn 8180: sub default_change_checker {
1.41 raeburn 8181: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8182: foreach my $item (@{$links}) {
8183: if ($confhash->{$role}{$item}) {
8184: $changes->{$role}{'links'}{$item} = 1;
8185: }
8186: }
8187: foreach my $item (@{$bgs}) {
8188: if ($confhash->{$role}{$item}) {
8189: $changes->{$role}{'bgs'}{$item} = 1;
8190: }
8191: }
1.41 raeburn 8192: foreach my $item (@{$logintext}) {
8193: if ($confhash->{$role}{$item}) {
8194: $changes->{$role}{'logintext'}{$item} = 1;
8195: }
8196: }
1.6 raeburn 8197: foreach my $img (@{$images}) {
8198: if ($env{'form.'.$role.'_del_'.$img}) {
8199: $confhash->{$role}{$img} = '';
1.12 raeburn 8200: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8201: }
1.70 raeburn 8202: if ($role eq 'login') {
8203: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8204: $changes->{$role}{'showlogo'}{$img} = 1;
8205: }
8206: }
1.6 raeburn 8207: }
8208: if ($confhash->{$role}{'font'}) {
8209: $changes->{$role}{'font'} = 1;
8210: }
1.48 raeburn 8211: }
1.6 raeburn 8212:
8213: sub display_colorchgs {
8214: my ($dom,$changes,$roles,$confhash) = @_;
8215: my (%choices,$resulttext);
8216: if (!grep(/^login$/,@{$roles})) {
8217: $resulttext = &mt('Changes made:').'<br />';
8218: }
8219: foreach my $role (@{$roles}) {
8220: if ($role eq 'login') {
8221: %choices = &login_choices();
8222: } else {
8223: %choices = &color_font_choices();
8224: }
8225: if (ref($changes->{$role}) eq 'HASH') {
8226: if ($role ne 'login') {
8227: $resulttext .= '<h4>'.&mt($role).'</h4>';
8228: }
8229: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8230: if ($role ne 'login') {
8231: $resulttext .= '<ul>';
8232: }
8233: if (ref($changes->{$role}{$key}) eq 'HASH') {
8234: if ($role ne 'login') {
8235: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8236: }
8237: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8238: if (($role eq 'login') && ($key eq 'showlogo')) {
8239: if ($confhash->{$role}{$key}{$item}) {
8240: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8241: } else {
8242: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8243: }
8244: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8245: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8246: } else {
1.12 raeburn 8247: my $newitem = $confhash->{$role}{$item};
8248: if ($key eq 'images') {
8249: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8250: }
8251: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8252: }
8253: }
8254: if ($role ne 'login') {
8255: $resulttext .= '</ul></li>';
8256: }
8257: } else {
8258: if ($confhash->{$role}{$key} eq '') {
8259: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8260: } else {
8261: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8262: }
8263: }
8264: if ($role ne 'login') {
8265: $resulttext .= '</ul>';
8266: }
8267: }
8268: }
8269: }
1.3 raeburn 8270: return $resulttext;
1.1 raeburn 8271: }
8272:
1.9 raeburn 8273: sub thumb_dimensions {
8274: return ('200','50');
8275: }
8276:
1.16 raeburn 8277: sub check_dimensions {
8278: my ($inputfile) = @_;
8279: my ($fullwidth,$fullheight);
8280: if ($inputfile =~ m|^[/\w.\-]+$|) {
8281: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8282: my $imageinfo = <PIPE>;
8283: if (!close(PIPE)) {
8284: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8285: }
8286: chomp($imageinfo);
8287: my ($fullsize) =
1.21 raeburn 8288: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8289: if ($fullsize) {
8290: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8291: }
8292: }
8293: }
8294: return ($fullwidth,$fullheight);
8295: }
8296:
1.9 raeburn 8297: sub check_configuser {
8298: my ($uhome,$dom,$confname,$servadm) = @_;
8299: my ($configuserok,%currroles);
8300: if ($uhome eq 'no_host') {
8301: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8302: my $configpass = &LONCAPA::Enrollment::create_password();
8303: $configuserok =
8304: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8305: $configpass,'','','','','',undef,$servadm);
8306: } else {
8307: $configuserok = 'ok';
8308: %currroles =
8309: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8310: }
8311: return ($configuserok,%currroles);
8312: }
8313:
8314: sub check_authorstatus {
8315: my ($dom,$confname,%currroles) = @_;
8316: my $author_ok;
1.40 raeburn 8317: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8318: my $start = time;
8319: my $end = 0;
8320: $author_ok =
8321: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8322: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8323: } else {
8324: $author_ok = 'ok';
8325: }
8326: return $author_ok;
8327: }
8328:
8329: sub publishlogo {
1.46 raeburn 8330: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 8331: my ($output,$fname,$logourl);
8332: if ($action eq 'upload') {
8333: $fname=$env{'form.'.$formname.'.filename'};
8334: chop($env{'form.'.$formname});
8335: } else {
8336: ($fname) = ($formname =~ /([^\/]+)$/);
8337: }
1.46 raeburn 8338: if ($savefileas ne '') {
8339: $fname = $savefileas;
8340: }
1.9 raeburn 8341: $fname=&Apache::lonnet::clean_filename($fname);
8342: # See if there is anything left
8343: unless ($fname) { return ('error: no uploaded file'); }
8344: $fname="$subdir/$fname";
1.160.6.5 raeburn 8345: my $docroot=$r->dir_config('lonDocRoot');
8346: my $filepath="$docroot/priv";
8347: my $relpath = "$dom/$confname";
1.9 raeburn 8348: my ($fnamepath,$file,$fetchthumb);
8349: $file=$fname;
8350: if ($fname=~m|/|) {
8351: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8352: }
1.160.6.26 raeburn 8353: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8354: my $count;
1.160.6.5 raeburn 8355: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8356: $filepath.="/$parts[$count]";
8357: if ((-e $filepath)!=1) {
8358: mkdir($filepath,02770);
8359: }
8360: }
8361: # Check for bad extension and disallow upload
8362: if ($file=~/\.(\w+)$/ &&
8363: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8364: $output =
1.160.6.25 raeburn 8365: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8366: } elsif ($file=~/\.(\w+)$/ &&
8367: !defined(&Apache::loncommon::fileembstyle($1))) {
8368: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8369: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 8370: $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 8371: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 8372: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8373: } else {
8374: my $source = $filepath.'/'.$file;
8375: my $logfile;
8376: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 8377: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8378: }
8379: print $logfile
8380: "\n================= Publish ".localtime()." ================\n".
8381: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8382: # Save the file
8383: if (!open(FH,'>'.$source)) {
8384: &Apache::lonnet::logthis('Failed to create '.$source);
8385: return (&mt('Failed to create file'));
8386: }
8387: if ($action eq 'upload') {
8388: if (!print FH ($env{'form.'.$formname})) {
8389: &Apache::lonnet::logthis('Failed to write to '.$source);
8390: return (&mt('Failed to write file'));
8391: }
8392: } else {
8393: my $original = &Apache::lonnet::filelocation('',$formname);
8394: if(!copy($original,$source)) {
8395: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8396: return (&mt('Failed to write file'));
8397: }
8398: }
8399: close(FH);
8400: chmod(0660, $source); # Permissions to rw-rw---.
8401:
8402: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8403: my $copyfile=$targetdir.'/'.$file;
8404:
8405: my @parts=split(/\//,$targetdir);
8406: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8407: for (my $count=5;$count<=$#parts;$count++) {
8408: $path.="/$parts[$count]";
8409: if (!-e $path) {
8410: print $logfile "\nCreating directory ".$path;
8411: mkdir($path,02770);
8412: }
8413: }
8414: my $versionresult;
8415: if (-e $copyfile) {
8416: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8417: } else {
8418: $versionresult = 'ok';
8419: }
8420: if ($versionresult eq 'ok') {
8421: if (copy($source,$copyfile)) {
8422: print $logfile "\nCopied original source to ".$copyfile."\n";
8423: $output = 'ok';
8424: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8425: push(@{$modified_urls},[$copyfile,$source]);
8426: my $metaoutput =
8427: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8428: unless ($registered_cleanup) {
8429: my $handlers = $r->get_handlers('PerlCleanupHandler');
8430: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8431: $registered_cleanup=1;
8432: }
1.9 raeburn 8433: } else {
8434: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8435: $output = &mt('Failed to copy file to RES space').", $!";
8436: }
8437: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8438: my $inputfile = $filepath.'/'.$file;
8439: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8440: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8441: if ($fullwidth ne '' && $fullheight ne '') {
8442: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8443: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8444: system("convert -sample $thumbsize $inputfile $outfile");
8445: chmod(0660, $filepath.'/tn-'.$file);
8446: if (-e $outfile) {
8447: my $copyfile=$targetdir.'/tn-'.$file;
8448: if (copy($outfile,$copyfile)) {
8449: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8450: my $thumb_metaoutput =
8451: &write_metadata($dom,$confname,$formname,
8452: $targetdir,'tn-'.$file,$logfile);
8453: push(@{$modified_urls},[$copyfile,$outfile]);
8454: unless ($registered_cleanup) {
8455: my $handlers = $r->get_handlers('PerlCleanupHandler');
8456: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8457: $registered_cleanup=1;
8458: }
1.16 raeburn 8459: } else {
8460: print $logfile "\nUnable to write ".$copyfile.
8461: ':'.$!."\n";
8462: }
8463: }
1.9 raeburn 8464: }
8465: }
8466: }
8467: } else {
8468: $output = $versionresult;
8469: }
8470: }
8471: return ($output,$logourl);
8472: }
8473:
8474: sub logo_versioning {
8475: my ($targetdir,$file,$logfile) = @_;
8476: my $target = $targetdir.'/'.$file;
8477: my ($maxversion,$fn,$extn,$output);
8478: $maxversion = 0;
8479: if ($file =~ /^(.+)\.(\w+)$/) {
8480: $fn=$1;
8481: $extn=$2;
8482: }
8483: opendir(DIR,$targetdir);
8484: while (my $filename=readdir(DIR)) {
8485: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8486: $maxversion=($1>$maxversion)?$1:$maxversion;
8487: }
8488: }
8489: $maxversion++;
8490: print $logfile "\nCreating old version ".$maxversion."\n";
8491: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8492: if (copy($target,$copyfile)) {
8493: print $logfile "Copied old target to ".$copyfile."\n";
8494: $copyfile=$copyfile.'.meta';
8495: if (copy($target.'.meta',$copyfile)) {
8496: print $logfile "Copied old target metadata to ".$copyfile."\n";
8497: $output = 'ok';
8498: } else {
8499: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8500: $output = &mt('Failed to copy old meta').", $!, ";
8501: }
8502: } else {
8503: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8504: $output = &mt('Failed to copy old target').", $!, ";
8505: }
8506: return $output;
8507: }
8508:
8509: sub write_metadata {
8510: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8511: my (%metadatafields,%metadatakeys,$output);
8512: $metadatafields{'title'}=$formname;
8513: $metadatafields{'creationdate'}=time;
8514: $metadatafields{'lastrevisiondate'}=time;
8515: $metadatafields{'copyright'}='public';
8516: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8517: $env{'user.domain'};
8518: $metadatafields{'authorspace'}=$confname.':'.$dom;
8519: $metadatafields{'domain'}=$dom;
8520: {
8521: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8522: my $mfh;
1.155 raeburn 8523: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 8524: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8525: unless ($_=~/\./) {
8526: my $unikey=$_;
8527: $unikey=~/^([A-Za-z]+)/;
8528: my $tag=$1;
8529: $tag=~tr/A-Z/a-z/;
8530: print $mfh "\n\<$tag";
8531: foreach (split(/\,/,$metadatakeys{$unikey})) {
8532: my $value=$metadatafields{$unikey.'.'.$_};
8533: $value=~s/\"/\'\'/g;
8534: print $mfh ' '.$_.'="'.$value.'"';
8535: }
8536: print $mfh '>'.
8537: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8538: .'</'.$tag.'>';
8539: }
8540: }
8541: $output = 'ok';
8542: print $logfile "\nWrote metadata";
8543: close($mfh);
8544: } else {
8545: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8546: $output = &mt('Could not write metadata');
8547: }
8548: }
1.155 raeburn 8549: return $output;
8550: }
8551:
8552: sub notifysubscribed {
8553: foreach my $targetsource (@{$modified_urls}){
8554: next unless (ref($targetsource) eq 'ARRAY');
8555: my ($target,$source)=@{$targetsource};
8556: if ($source ne '') {
8557: if (open(my $logfh,'>>'.$source.'.log')) {
8558: print $logfh "\nCleanup phase: Notifications\n";
8559: my @subscribed=&subscribed_hosts($target);
8560: foreach my $subhost (@subscribed) {
8561: print $logfh "\nNotifying host ".$subhost.':';
8562: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8563: print $logfh $reply;
8564: }
8565: my @subscribedmeta=&subscribed_hosts("$target.meta");
8566: foreach my $subhost (@subscribedmeta) {
8567: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8568: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8569: $subhost);
8570: print $logfh $reply;
8571: }
8572: print $logfh "\n============ Done ============\n";
1.160 raeburn 8573: close($logfh);
1.155 raeburn 8574: }
8575: }
8576: }
8577: return OK;
8578: }
8579:
8580: sub subscribed_hosts {
8581: my ($target) = @_;
8582: my @subscribed;
8583: if (open(my $fh,"<$target.subscription")) {
8584: while (my $subline=<$fh>) {
8585: if ($subline =~ /^($match_lonid):/) {
8586: my $host = $1;
8587: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8588: unless (grep(/^\Q$host\E$/,@subscribed)) {
8589: push(@subscribed,$host);
8590: }
8591: }
8592: }
8593: }
8594: }
8595: return @subscribed;
1.9 raeburn 8596: }
8597:
8598: sub check_switchserver {
8599: my ($dom,$confname) = @_;
8600: my ($allowed,$switchserver);
8601: my $home = &Apache::lonnet::homeserver($confname,$dom);
8602: if ($home eq 'no_host') {
8603: $home = &Apache::lonnet::domain($dom,'primary');
8604: }
8605: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8606: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8607: if (!$allowed) {
1.160.6.11 raeburn 8608: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8609: }
8610: return $switchserver;
8611: }
8612:
1.1 raeburn 8613: sub modify_quotas {
1.160.6.30 raeburn 8614: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8615: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 8616: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 8617: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8618: $validationfieldsref);
1.86 raeburn 8619: if ($action eq 'quotas') {
8620: $context = 'tools';
1.160.6.26 raeburn 8621: } else {
1.86 raeburn 8622: $context = $action;
8623: }
8624: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 8625: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 8626: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8627: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8628: %titles = &courserequest_titles();
8629: $toolregexp = join('|',@usertools);
8630: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 8631: $confname = $dom.'-domainconfig';
8632: my $servadm = $r->dir_config('lonAdmEMail');
8633: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 8634: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8635: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 8636: } elsif ($context eq 'requestauthor') {
8637: @usertools = ('author');
8638: %titles = &authorrequest_titles();
1.86 raeburn 8639: } else {
1.160.6.4 raeburn 8640: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8641: %titles = &tool_titles();
1.86 raeburn 8642: }
1.160.6.27 raeburn 8643: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8644: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8645: foreach my $key (keys(%env)) {
1.101 raeburn 8646: if ($context eq 'requestcourses') {
8647: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8648: my $item = $1;
8649: my $type = $2;
8650: if ($type =~ /^limit_(.+)/) {
8651: $limithash{$item}{$1} = $env{$key};
8652: } else {
8653: $confhash{$item}{$type} = $env{$key};
8654: }
8655: }
1.160.6.5 raeburn 8656: } elsif ($context eq 'requestauthor') {
8657: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8658: $confhash{$1} = $env{$key};
8659: }
1.101 raeburn 8660: } else {
1.86 raeburn 8661: if ($key =~ /^form\.quota_(.+)$/) {
8662: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 8663: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8664: $confhash{'authorquota'}{$1} = $env{$key};
8665: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8666: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8667: }
1.72 raeburn 8668: }
8669: }
1.160.6.5 raeburn 8670: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 8671: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8672: @approvalnotify = sort(@approvalnotify);
8673: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 8674: my @crstypes = ('official','unofficial','community','textbook');
8675: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8676: foreach my $type (@hasuniquecode) {
8677: if (grep(/^\Q$type\E$/,@crstypes)) {
8678: $confhash{'uniquecode'}{$type} = 1;
8679: }
8680: }
1.160.6.46 raeburn 8681: my (%newbook,%allpos);
1.160.6.30 raeburn 8682: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8683: foreach my $type ('textbooks','templates') {
8684: @{$allpos{$type}} = ();
8685: my $invalid;
8686: if ($type eq 'textbooks') {
8687: $invalid = &mt('Invalid LON-CAPA course for textbook');
8688: } else {
8689: $invalid = &mt('Invalid LON-CAPA course for template');
8690: }
8691: if ($env{'form.'.$type.'_addbook'}) {
8692: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8693: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8694: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8695: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8696: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8697: } else {
8698: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8699: my $position = $env{'form.'.$type.'_addbook_pos'};
8700: $position =~ s/\D+//g;
8701: if ($position ne '') {
8702: $allpos{$type}[$position] = $newbook{$type};
8703: }
1.160.6.30 raeburn 8704: }
1.160.6.46 raeburn 8705: } else {
8706: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 8707: }
8708: }
1.160.6.46 raeburn 8709: }
1.160.6.30 raeburn 8710: }
1.102 raeburn 8711: if (ref($domconfig{$action}) eq 'HASH') {
8712: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8713: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8714: $changes{'notify'}{'approval'} = 1;
8715: }
8716: } else {
1.144 raeburn 8717: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8718: $changes{'notify'}{'approval'} = 1;
8719: }
8720: }
1.160.6.30 raeburn 8721: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8722: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8723: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8724: unless ($confhash{'uniquecode'}{$crstype}) {
8725: $changes{'uniquecode'} = 1;
8726: }
8727: }
8728: unless ($changes{'uniquecode'}) {
8729: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8730: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8731: $changes{'uniquecode'} = 1;
8732: }
8733: }
8734: }
8735: } else {
8736: $changes{'uniquecode'} = 1;
8737: }
8738: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8739: $changes{'uniquecode'} = 1;
8740: }
8741: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8742: foreach my $type ('textbooks','templates') {
8743: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8744: my %deletions;
8745: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8746: if (@todelete) {
8747: map { $deletions{$_} = 1; } @todelete;
8748: }
8749: my %imgdeletions;
8750: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8751: if (@todeleteimages) {
8752: map { $imgdeletions{$_} = 1; } @todeleteimages;
8753: }
8754: my $maxnum = $env{'form.'.$type.'_maxnum'};
8755: for (my $i=0; $i<=$maxnum; $i++) {
8756: my $itemid = $env{'form.'.$type.'_id_'.$i};
8757: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8758: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8759: if ($deletions{$key}) {
8760: if ($domconfig{$action}{$type}{$key}{'image'}) {
8761: #FIXME need to obsolete item in RES space
8762: }
8763: next;
8764: } else {
8765: my $newpos = $env{'form.'.$itemid};
8766: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 8767: foreach my $item ('subject','title','publisher','author') {
8768: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8769: ($type eq 'templates'));
1.160.6.46 raeburn 8770: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8771: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8772: $changes{$type}{$key} = 1;
8773: }
8774: }
8775: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 8776: }
1.160.6.46 raeburn 8777: if ($imgdeletions{$key}) {
8778: $changes{$type}{$key} = 1;
8779: #FIXME need to obsolete item in RES space
8780: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8781: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.84.2. (raeburn 8782:): if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
8783:): $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
8784:): } else {
8785:): my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8786:): $cdom,$cnum,$type,$configuserok,
8787:): $switchserver,$author_ok);
8788:): if ($imgurl) {
8789:): $confhash{$type}{$key}{'image'} = $imgurl;
8790:): $changes{$type}{$key} = 1;
8791:): }
8792:): if ($error) {
8793:): &Apache::lonnet::logthis($error);
8794:): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8795:): }
1.160.6.46 raeburn 8796: }
8797: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8798: $confhash{$type}{$key}{'image'} =
8799: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 8800: }
8801: }
8802: }
8803: }
8804: }
8805: }
1.102 raeburn 8806: } else {
1.144 raeburn 8807: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8808: $changes{'notify'}{'approval'} = 1;
8809: }
1.160.6.30 raeburn 8810: if (ref($confhash{'uniquecode'} eq 'HASH')) {
8811: $changes{'uniquecode'} = 1;
8812: }
8813: }
8814: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8815: foreach my $type ('textbooks','templates') {
8816: if ($newbook{$type}) {
8817: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 8818: foreach my $item ('subject','title','publisher','author') {
8819: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8820: ($type eq 'template'));
1.160.6.46 raeburn 8821: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8822: if ($env{'form.'.$type.'_addbook_'.$item}) {
8823: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8824: }
8825: }
8826: if ($type eq 'textbooks') {
8827: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8828: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8829: my ($imageurl,$error) =
8830: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8831: $configuserok,$switchserver,$author_ok);
8832: if ($imageurl) {
8833: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8834: }
8835: if ($error) {
8836: &Apache::lonnet::logthis($error);
8837: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8838: }
8839: }
1.160.6.30 raeburn 8840: }
8841: }
1.160.6.46 raeburn 8842: if (@{$allpos{$type}} > 0) {
8843: my $idx = 0;
8844: foreach my $item (@{$allpos{$type}}) {
8845: if ($item ne '') {
8846: $confhash{$type}{$item}{'order'} = $idx;
8847: if (ref($domconfig{$action}) eq 'HASH') {
8848: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8849: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8850: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8851: $changes{$type}{$item} = 1;
8852: }
1.160.6.30 raeburn 8853: }
8854: }
8855: }
1.160.6.46 raeburn 8856: $idx ++;
1.160.6.30 raeburn 8857: }
8858: }
8859: }
8860: }
1.160.6.39 raeburn 8861: if (ref($validationitemsref) eq 'ARRAY') {
8862: foreach my $item (@{$validationitemsref}) {
8863: if ($item eq 'fields') {
8864: my @changed;
8865: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8866: if (@{$confhash{'validation'}{$item}} > 0) {
8867: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8868: }
1.160.6.65 raeburn 8869: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8870: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8871: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8872: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8873: $domconfig{'requestcourses'}{'validation'}{$item});
8874: } else {
8875: @changed = @{$confhash{'validation'}{$item}};
8876: }
1.160.6.39 raeburn 8877: } else {
8878: @changed = @{$confhash{'validation'}{$item}};
8879: }
8880: } else {
8881: @changed = @{$confhash{'validation'}{$item}};
8882: }
8883: if (@changed) {
8884: if ($confhash{'validation'}{$item}) {
8885: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8886: } else {
8887: $changes{'validation'}{$item} = &mt('None');
8888: }
8889: }
8890: } else {
8891: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8892: if ($item eq 'markup') {
8893: if ($env{'form.requestcourses_validation_'.$item}) {
8894: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8895: }
8896: }
1.160.6.65 raeburn 8897: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8898: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8899: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8900: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8901: }
8902: } else {
8903: if ($confhash{'validation'}{$item} ne '') {
8904: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8905: }
1.160.6.39 raeburn 8906: }
8907: } else {
8908: if ($confhash{'validation'}{$item} ne '') {
8909: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8910: }
8911: }
8912: }
8913: }
8914: }
8915: if ($env{'form.validationdc'}) {
8916: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 8917: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 8918: if (exists($domcoords{$newval})) {
8919: $confhash{'validation'}{'dc'} = $newval;
8920: }
8921: }
8922: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 8923: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8924: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8925: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8926: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8927: if ($confhash{'validation'}{'dc'} eq '') {
8928: $changes{'validation'}{'dc'} = &mt('None');
8929: } else {
8930: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8931: }
1.160.6.39 raeburn 8932: }
1.160.6.65 raeburn 8933: } elsif ($confhash{'validation'}{'dc'} ne '') {
8934: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 8935: }
8936: } elsif ($confhash{'validation'}{'dc'} ne '') {
8937: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8938: }
8939: } elsif ($confhash{'validation'}{'dc'} ne '') {
8940: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8941: }
1.160.6.65 raeburn 8942: } else {
8943: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8944: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8945: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8946: $changes{'validation'}{'dc'} = &mt('None');
8947: }
8948: }
1.160.6.39 raeburn 8949: }
8950: }
1.102 raeburn 8951: }
8952: } else {
1.86 raeburn 8953: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 8954: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8955: }
1.72 raeburn 8956: foreach my $item (@usertools) {
8957: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8958: my $unset;
1.101 raeburn 8959: if ($context eq 'requestcourses') {
1.104 raeburn 8960: $unset = '0';
8961: if ($type eq '_LC_adv') {
8962: $unset = '';
8963: }
1.101 raeburn 8964: if ($confhash{$item}{$type} eq 'autolimit') {
8965: $confhash{$item}{$type} .= '=';
8966: unless ($limithash{$item}{$type} =~ /\D/) {
8967: $confhash{$item}{$type} .= $limithash{$item}{$type};
8968: }
8969: }
1.160.6.5 raeburn 8970: } elsif ($context eq 'requestauthor') {
8971: $unset = '0';
8972: if ($type eq '_LC_adv') {
8973: $unset = '';
8974: }
1.72 raeburn 8975: } else {
1.101 raeburn 8976: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8977: $confhash{$item}{$type} = 1;
8978: } else {
8979: $confhash{$item}{$type} = 0;
8980: }
1.72 raeburn 8981: }
1.86 raeburn 8982: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 8983: if ($action eq 'requestauthor') {
8984: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8985: $changes{$type} = 1;
8986: }
8987: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8988: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8989: $changes{$item}{$type} = 1;
8990: }
8991: } else {
8992: if ($context eq 'requestcourses') {
1.104 raeburn 8993: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8994: $changes{$item}{$type} = 1;
8995: }
8996: } else {
8997: if (!$confhash{$item}{$type}) {
8998: $changes{$item}{$type} = 1;
8999: }
9000: }
9001: }
9002: } else {
9003: if ($context eq 'requestcourses') {
1.104 raeburn 9004: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9005: $changes{$item}{$type} = 1;
9006: }
1.160.6.5 raeburn 9007: } elsif ($context eq 'requestauthor') {
9008: if ($confhash{$type} ne $unset) {
9009: $changes{$type} = 1;
9010: }
1.72 raeburn 9011: } else {
9012: if (!$confhash{$item}{$type}) {
9013: $changes{$item}{$type} = 1;
9014: }
9015: }
9016: }
1.1 raeburn 9017: }
9018: }
1.160.6.5 raeburn 9019: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9020: if (ref($domconfig{'quotas'}) eq 'HASH') {
9021: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9022: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9023: if (exists($confhash{'defaultquota'}{$key})) {
9024: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9025: $changes{'defaultquota'}{$key} = 1;
9026: }
9027: } else {
9028: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9029: }
9030: }
1.86 raeburn 9031: } else {
9032: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9033: if (exists($confhash{'defaultquota'}{$key})) {
9034: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9035: $changes{'defaultquota'}{$key} = 1;
9036: }
9037: } else {
9038: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9039: }
1.1 raeburn 9040: }
9041: }
1.160.6.20 raeburn 9042: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9043: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9044: if (exists($confhash{'authorquota'}{$key})) {
9045: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9046: $changes{'authorquota'}{$key} = 1;
9047: }
9048: } else {
9049: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9050: }
9051: }
9052: }
1.1 raeburn 9053: }
1.86 raeburn 9054: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9055: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9056: if (ref($domconfig{'quotas'}) eq 'HASH') {
9057: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9058: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9059: $changes{'defaultquota'}{$key} = 1;
9060: }
9061: } else {
9062: if (!exists($domconfig{'quotas'}{$key})) {
9063: $changes{'defaultquota'}{$key} = 1;
9064: }
1.72 raeburn 9065: }
9066: } else {
1.86 raeburn 9067: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9068: }
1.1 raeburn 9069: }
9070: }
1.160.6.20 raeburn 9071: if (ref($confhash{'authorquota'}) eq 'HASH') {
9072: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9073: if (ref($domconfig{'quotas'}) eq 'HASH') {
9074: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9075: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9076: $changes{'authorquota'}{$key} = 1;
9077: }
9078: } else {
9079: $changes{'authorquota'}{$key} = 1;
9080: }
9081: } else {
9082: $changes{'authorquota'}{$key} = 1;
9083: }
9084: }
9085: }
1.1 raeburn 9086: }
1.72 raeburn 9087:
1.160.6.5 raeburn 9088: if ($context eq 'requestauthor') {
9089: $domdefaults{'requestauthor'} = \%confhash;
9090: } else {
9091: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 9092: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 9093: $domdefaults{$key} = $confhash{$key};
9094: }
1.160.6.5 raeburn 9095: }
1.72 raeburn 9096: }
1.160.6.5 raeburn 9097:
1.1 raeburn 9098: my %quotahash = (
1.86 raeburn 9099: $action => { %confhash }
1.1 raeburn 9100: );
9101: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9102: $dom);
9103: if ($putresult eq 'ok') {
9104: if (keys(%changes) > 0) {
1.72 raeburn 9105: my $cachetime = 24*60*60;
9106: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9107: if (ref($lastactref) eq 'HASH') {
9108: $lastactref->{'domdefaults'} = 1;
9109: }
1.1 raeburn 9110: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 9111: unless (($context eq 'requestcourses') ||
9112: ($context eq 'requestauthor')) {
1.86 raeburn 9113: if (ref($changes{'defaultquota'}) eq 'HASH') {
9114: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9115: foreach my $type (@{$types},'default') {
9116: if (defined($changes{'defaultquota'}{$type})) {
9117: my $typetitle = $usertypes->{$type};
9118: if ($type eq 'default') {
9119: $typetitle = $othertitle;
9120: }
1.160.6.28 raeburn 9121: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9122: }
9123: }
1.86 raeburn 9124: $resulttext .= '</ul></li>';
1.72 raeburn 9125: }
1.160.6.20 raeburn 9126: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 9127: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 9128: foreach my $type (@{$types},'default') {
9129: if (defined($changes{'authorquota'}{$type})) {
9130: my $typetitle = $usertypes->{$type};
9131: if ($type eq 'default') {
9132: $typetitle = $othertitle;
9133: }
1.160.6.28 raeburn 9134: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 9135: }
9136: }
9137: $resulttext .= '</ul></li>';
9138: }
1.72 raeburn 9139: }
1.80 raeburn 9140: my %newenv;
1.72 raeburn 9141: foreach my $item (@usertools) {
1.160.6.5 raeburn 9142: my (%haschgs,%inconf);
9143: if ($context eq 'requestauthor') {
9144: %haschgs = %changes;
9145: %inconf = %confhash;
9146: } else {
9147: if (ref($changes{$item}) eq 'HASH') {
9148: %haschgs = %{$changes{$item}};
9149: }
9150: if (ref($confhash{$item}) eq 'HASH') {
9151: %inconf = %{$confhash{$item}};
9152: }
9153: }
9154: if (keys(%haschgs) > 0) {
1.80 raeburn 9155: my $newacc =
9156: &Apache::lonnet::usertools_access($env{'user.name'},
9157: $env{'user.domain'},
1.86 raeburn 9158: $item,'reload',$context);
1.160.6.5 raeburn 9159: if (($context eq 'requestcourses') ||
9160: ($context eq 'requestauthor')) {
1.108 raeburn 9161: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9162: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9163: }
9164: } else {
9165: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9166: $newenv{'environment.availabletools.'.$item} = $newacc;
9167: }
1.80 raeburn 9168: }
1.160.6.5 raeburn 9169: unless ($context eq 'requestauthor') {
9170: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9171: }
1.72 raeburn 9172: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 9173: if ($haschgs{$type}) {
1.72 raeburn 9174: my $typetitle = $usertypes->{$type};
9175: if ($type eq 'default') {
9176: $typetitle = $othertitle;
9177: } elsif ($type eq '_LC_adv') {
9178: $typetitle = 'LON-CAPA Advanced Users';
9179: }
1.160.6.5 raeburn 9180: if ($inconf{$type}) {
1.101 raeburn 9181: if ($context eq 'requestcourses') {
9182: my $cond;
1.160.6.5 raeburn 9183: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9184: if ($1 eq '') {
9185: $cond = &mt('(Automatic processing of any request).');
9186: } else {
9187: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9188: }
9189: } else {
1.160.6.5 raeburn 9190: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9191: }
9192: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 9193: } elsif ($context eq 'requestauthor') {
9194: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9195: $titles{$inconf{$type}},$typetitle);
9196:
1.101 raeburn 9197: } else {
9198: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9199: }
1.72 raeburn 9200: } else {
1.104 raeburn 9201: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 9202: if ($inconf{$type} eq '0') {
1.104 raeburn 9203: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9204: } else {
9205: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9206: }
9207: } else {
9208: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9209: }
1.72 raeburn 9210: }
9211: }
1.26 raeburn 9212: }
1.160.6.5 raeburn 9213: unless ($context eq 'requestauthor') {
9214: $resulttext .= '</ul></li>';
9215: }
1.26 raeburn 9216: }
1.1 raeburn 9217: }
1.160.6.5 raeburn 9218: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9219: if (ref($changes{'notify'}) eq 'HASH') {
9220: if ($changes{'notify'}{'approval'}) {
9221: if (ref($confhash{'notify'}) eq 'HASH') {
9222: if ($confhash{'notify'}{'approval'}) {
9223: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9224: } else {
1.160.6.5 raeburn 9225: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9226: }
9227: }
9228: }
9229: }
9230: }
1.160.6.30 raeburn 9231: if ($action eq 'requestcourses') {
9232: my @offon = ('off','on');
9233: if ($changes{'uniquecode'}) {
9234: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9235: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9236: $resulttext .= '<li>'.
9237: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9238: '</li>';
9239: } else {
9240: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9241: '</li>';
9242: }
9243: }
1.160.6.46 raeburn 9244: foreach my $type ('textbooks','templates') {
9245: if (ref($changes{$type}) eq 'HASH') {
9246: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9247: foreach my $key (sort(keys(%{$changes{$type}}))) {
9248: my %coursehash = &Apache::lonnet::coursedescription($key);
9249: my $coursetitle = $coursehash{'description'};
9250: my $position = $confhash{$type}{$key}{'order'} + 1;
9251: $resulttext .= '<li>';
1.160.6.47 raeburn 9252: foreach my $item ('subject','title','publisher','author') {
9253: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9254: ($type eq 'templates'));
1.160.6.46 raeburn 9255: my $name = $item.':';
9256: $name =~ s/^(\w)/\U$1/;
9257: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9258: }
9259: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9260: if ($type eq 'textbooks') {
9261: if ($confhash{$type}{$key}{'image'}) {
9262: $resulttext .= ' '.&mt('Image: [_1]',
9263: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9264: ' alt="Textbook cover" />').'<br />';
9265: }
9266: }
9267: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 9268: }
1.160.6.46 raeburn 9269: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 9270: }
9271: }
1.160.6.39 raeburn 9272: if (ref($changes{'validation'}) eq 'HASH') {
9273: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9274: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9275: foreach my $item (@{$validationitemsref}) {
9276: if (exists($changes{'validation'}{$item})) {
9277: if ($item eq 'markup') {
9278: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9279: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9280: } else {
9281: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9282: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9283: }
9284: }
9285: }
9286: if (exists($changes{'validation'}{'dc'})) {
9287: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9288: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9289: }
9290: }
9291: }
1.160.6.30 raeburn 9292: }
1.1 raeburn 9293: $resulttext .= '</ul>';
1.80 raeburn 9294: if (keys(%newenv)) {
9295: &Apache::lonnet::appenv(\%newenv);
9296: }
1.1 raeburn 9297: } else {
1.86 raeburn 9298: if ($context eq 'requestcourses') {
9299: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 9300: } elsif ($context eq 'requestauthor') {
9301: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9302: } else {
1.90 weissno 9303: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9304: }
1.1 raeburn 9305: }
9306: } else {
1.11 albertel 9307: $resulttext = '<span class="LC_error">'.
9308: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9309: }
1.160.6.30 raeburn 9310: if ($errors) {
9311: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9312: '<ul>'.$errors.'</ul></p>';
9313: }
1.3 raeburn 9314: return $resulttext;
1.1 raeburn 9315: }
9316:
1.160.6.30 raeburn 9317: sub process_textbook_image {
1.160.6.46 raeburn 9318: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 9319: my $filename = $env{'form.'.$caller.'.filename'};
9320: my ($error,$url);
9321: my ($width,$height) = (50,50);
9322: if ($configuserok eq 'ok') {
9323: if ($switchserver) {
9324: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9325: $switchserver);
9326: } elsif ($author_ok eq 'ok') {
9327: my ($result,$imageurl) =
9328: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.84.2. (raeburn 9329:): "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 9330: if ($result eq 'ok') {
9331: $url = $imageurl;
9332: } else {
9333: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9334: }
9335: } else {
9336: $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);
9337: }
9338: } else {
9339: $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);
9340: }
9341: return ($url,$error);
9342: }
9343:
1.160.6.84.2. (raeburn 9344:): sub modify_ltitools {
9345:): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9346:): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9347:): my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
9348:): my $confname = $dom.'-domainconfig';
9349:): my $servadm = $r->dir_config('lonAdmEMail');
9350:): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9351:): my (%posslti,%possfield);
9352:): my @courseroles = ('cc','in','ta','ep','st');
9353:): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9354:): map { $posslti{$_} = 1; } @ltiroles;
9355:): my @allfields = ('fullname','firstname','lastname','email','user','roles');
9356:): map { $possfield{$_} = 1; } @allfields;
9357:): my %lt = <itools_names();
9358:): if ($env{'form.ltitools_add'}) {
9359:): my $title = $env{'form.ltitools_add_title'};
9360:): $title =~ s/(`)/'/g;
9361:): ($newid,my $error) = &get_ltitools_id($dom,$title);
9362:): if ($newid) {
9363:): my $position = $env{'form.ltitools_add_pos'};
9364:): $position =~ s/\D+//g;
9365:): if ($position ne '') {
9366:): $allpos[$position] = $newid;
9367:): }
9368:): $changes{$newid} = 1;
9369:): foreach my $item ('title','url','key','secret') {
9370:): $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9371:): if ($env{'form.ltitools_add_'.$item}) {
9372:): if (($item eq 'key') || ($item eq 'secret')) {
9373:): $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9374:): } else {
9375:): $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9376:): }
9377:): }
9378:): }
9379:): if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9380:): $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9381:): }
9382:): if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9383:): $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9384:): }
9385:): foreach my $item ('width','height','linktext','explanation') {
9386:): $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9387:): $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
9388:): if (($item eq 'width') || ($item eq 'height')) {
9389:): if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
9390:): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9391:): }
9392:): } else {
9393:): if ($env{'form.ltitools_add_'.$item} ne '') {
9394:): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9395:): }
9396:): }
9397:): }
9398:): if ($env{'form.ltitools_add_target'} eq 'window') {
9399:): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9400:): } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
9401:): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9402:): } else {
9403:): $confhash{$newid}{'display'}{'target'} = 'iframe';
9404:): }
9405:): foreach my $item ('passback','roster') {
9406:): if ($env{'form.ltitools_add_'.$item}) {
9407:): $confhash{$newid}{$item} = 1;
9408:): }
9409:): }
9410:): if ($env{'form.ltitools_add_image.filename'} ne '') {
9411:): my ($imageurl,$error) =
9412:): &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
9413:): $configuserok,$switchserver,$author_ok);
9414:): if ($imageurl) {
9415:): $confhash{$newid}{'image'} = $imageurl;
9416:): }
9417:): if ($error) {
9418:): &Apache::lonnet::logthis($error);
9419:): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9420:): }
9421:): }
9422:): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9423:): foreach my $field (@fields) {
9424:): if ($possfield{$field}) {
9425:): if ($field eq 'roles') {
9426:): foreach my $role (@courseroles) {
9427:): my $choice = $env{'form.ltitools_add_roles_'.$role};
9428:): if (($choice ne '') && ($posslti{$choice})) {
9429:): $confhash{$newid}{'roles'}{$role} = $choice;
9430:): if ($role eq 'cc') {
9431:): $confhash{$newid}{'roles'}{'co'} = $choice;
9432:): }
9433:): }
9434:): }
9435:): } else {
9436:): $confhash{$newid}{'fields'}{$field} = 1;
9437:): }
9438:): }
9439:): }
9440:): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9441:): foreach my $item (@courseconfig) {
9442:): $confhash{$newid}{'crsconf'}{$item} = 1;
9443:): }
9444:): if ($env{'form.ltitools_add_custom'}) {
9445:): my $name = $env{'form.ltitools_add_custom_name'};
9446:): my $value = $env{'form.ltitools_add_custom_value'};
9447:): $value =~ s/(`)/'/g;
9448:): $name =~ s/(`)/'/g;
9449:): $confhash{$newid}{'custom'}{$name} = $value;
9450:): }
9451:): } else {
9452:): my $error = &mt('Failed to acquire unique ID for new external tool');
9453:): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9454:): }
9455:): }
9456:): if (ref($domconfig{$action}) eq 'HASH') {
9457:): my %deletions;
9458:): my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9459:): if (@todelete) {
9460:): map { $deletions{$_} = 1; } @todelete;
9461:): }
9462:): my %customadds;
9463:): my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9464:): if (@newcustom) {
9465:): map { $customadds{$_} = 1; } @newcustom;
9466:): }
9467:): my %imgdeletions;
9468:): my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9469:): if (@todeleteimages) {
9470:): map { $imgdeletions{$_} = 1; } @todeleteimages;
9471:): }
9472:): my $maxnum = $env{'form.ltitools_maxnum'};
9473:): for (my $i=0; $i<=$maxnum; $i++) {
9474:): my $itemid = $env{'form.ltitools_id_'.$i};
9475:): $itemid =~ s/\D+//g;
9476:): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9477:): if ($deletions{$itemid}) {
9478:): if ($domconfig{$action}{$itemid}{'image'}) {
9479:): #FIXME need to obsolete item in RES space
9480:): }
9481:): $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9482:): next;
9483:): } else {
9484:): my $newpos = $env{'form.ltitools_'.$itemid};
9485:): $newpos =~ s/\D+//g;
9486:): foreach my $item ('title','url') {
9487:): $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9488:): if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9489:): $changes{$itemid} = 1;
9490:): }
9491:): }
9492:): foreach my $item ('key','secret') {
9493:): $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9494:): if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
9495:): $changes{$itemid} = 1;
9496:): }
9497:): }
9498:): if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9499:): $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9500:): }
9501:): if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9502:): $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9503:): }
9504:): foreach my $size ('width','height') {
9505:): $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9506:): $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9507:): if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9508:): $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9509:): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9510:): if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9511:): $changes{$itemid} = 1;
9512:): }
9513:): } else {
9514:): $changes{$itemid} = 1;
9515:): }
9516:): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9517:): if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
9518:): $changes{$itemid} = 1;
9519:): }
9520:): }
9521:): }
9522:): foreach my $item ('linktext','explanation') {
9523:): $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
9524:): $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
9525:): if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
9526:): $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9527:): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9528:): if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
9529:): $changes{$itemid} = 1;
9530:): }
9531:): } else {
9532:): $changes{$itemid} = 1;
9533:): }
9534:): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9535:): if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
9536:): $changes{$itemid} = 1;
9537:): }
9538:): }
9539:): }
9540:): if ($env{'form.ltitools_target_'.$i} eq 'window') {
9541:): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
9542:): } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
9543:): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
9544:): } else {
9545:): $confhash{$itemid}{'display'}{'target'} = 'iframe';
9546:): }
9547:): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9548:): if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
9549:): $changes{$itemid} = 1;
9550:): }
9551:): } else {
9552:): $changes{$itemid} = 1;
9553:): }
9554:): foreach my $extra ('passback','roster') {
9555:): if ($env{'form.ltitools_'.$extra.'_'.$i}) {
9556:): $confhash{$itemid}{$extra} = 1;
9557:): }
9558:): if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
9559:): $changes{$itemid} = 1;
9560:): }
9561:): }
9562:): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
9563:): foreach my $item ('label','title','target','linktext','explanation') {
9564:): if (grep(/^\Q$item\E$/,@courseconfig)) {
9565:): $confhash{$itemid}{'crsconf'}{$item} = 1;
9566:): if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
9567:): if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
9568:): $changes{$itemid} = 1;
9569:): }
9570:): } else {
9571:): $changes{$itemid} = 1;
9572:): }
9573:): }
9574:): }
9575:): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
9576:): foreach my $field (@fields) {
9577:): if ($possfield{$field}) {
9578:): if ($field eq 'roles') {
9579:): foreach my $role (@courseroles) {
9580:): my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
9581:): if (($choice ne '') && ($posslti{$choice})) {
9582:): $confhash{$itemid}{'roles'}{$role} = $choice;
9583:): if ($role eq 'cc') {
9584:): $confhash{$itemid}{'roles'}{'co'} = $choice;
9585:): }
9586:): }
9587:): if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
9588:): if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
9589:): $changes{$itemid} = 1;
9590:): }
9591:): } elsif ($confhash{$itemid}{'roles'}{$role}) {
9592:): $changes{$itemid} = 1;
9593:): }
9594:): }
9595:): } else {
9596:): $confhash{$itemid}{'fields'}{$field} = 1;
9597:): if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
9598:): if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
9599:): $changes{$itemid} = 1;
9600:): }
9601:): } else {
9602:): $changes{$itemid} = 1;
9603:): }
9604:): }
9605:): }
9606:): }
9607:): $allpos[$newpos] = $itemid;
9608:): }
9609:): if ($imgdeletions{$itemid}) {
9610:): $changes{$itemid} = 1;
9611:): #FIXME need to obsolete item in RES space
9612:): } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
9613:): my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
9614:): $itemid,$configuserok,$switchserver,
9615:): $author_ok);
9616:): if ($imgurl) {
9617:): $confhash{$itemid}{'image'} = $imgurl;
9618:): $changes{$itemid} = 1;
9619:): }
9620:): if ($error) {
9621:): &Apache::lonnet::logthis($error);
9622:): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9623:): }
9624:): } elsif ($domconfig{$action}{$itemid}{'image'}) {
9625:): $confhash{$itemid}{'image'} =
9626:): $domconfig{$action}{$itemid}{'image'};
9627:): }
9628:): if ($customadds{$i}) {
9629:): my $name = $env{'form.ltitools_custom_name_'.$i};
9630:): $name =~ s/(`)/'/g;
9631:): $name =~ s/^\s+//;
9632:): $name =~ s/\s+$//;
9633:): my $value = $env{'form.ltitools_custom_value_'.$i};
9634:): $value =~ s/(`)/'/g;
9635:): $value =~ s/^\s+//;
9636:): $value =~ s/\s+$//;
9637:): if ($name ne '') {
9638:): $confhash{$itemid}{'custom'}{$name} = $value;
9639:): $changes{$itemid} = 1;
9640:): }
9641:): }
9642:): my %customdels;
9643:): my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
9644:): if (@customdeletions) {
9645:): $changes{$itemid} = 1;
9646:): }
9647:): map { $customdels{$_} = 1; } @customdeletions;
9648:): if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
9649:): foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
9650:): unless ($customdels{$key}) {
9651:): if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
9652:): $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
9653:): }
9654:): if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
9655:): $changes{$itemid} = 1;
9656:): }
9657:): }
9658:): }
9659:): }
9660:): unless ($changes{$itemid}) {
9661:): foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
9662:): if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
9663:): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
9664:): foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
9665:): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
9666:): $changes{$itemid} = 1;
9667:): last;
9668:): }
9669:): }
9670:): } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
9671:): $changes{$itemid} = 1;
9672:): }
9673:): }
9674:): last if ($changes{$itemid});
9675:): }
9676:): }
9677:): }
9678:): }
9679:): }
9680:): if (@allpos > 0) {
9681:): my $idx = 0;
9682:): foreach my $itemid (@allpos) {
9683:): if ($itemid ne '') {
9684:): $confhash{$itemid}{'order'} = $idx;
9685:): if (ref($domconfig{$action}) eq 'HASH') {
9686:): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9687:): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
9688:): $changes{$itemid} = 1;
9689:): }
9690:): }
9691:): }
9692:): $idx ++;
9693:): }
9694:): }
9695:): }
9696:): my %ltitoolshash = (
9697:): $action => { %confhash }
9698:): );
9699:): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
9700:): $dom);
9701:): if ($putresult eq 'ok') {
9702:): my %ltienchash = (
9703:): $action => { %encconfig }
9704:): );
9705:): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
9706:): if (keys(%changes) > 0) {
9707:): my $cachetime = 24*60*60;
9708:): my %ltiall = %confhash;
9709:): foreach my $id (keys(%ltiall)) {
9710:): if (ref($encconfig{$id}) eq 'HASH') {
9711:): foreach my $item ('key','secret') {
9712:): $ltiall{$id}{$item} = $encconfig{$id}{$item};
9713:): }
9714:): }
9715:): }
9716:): &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
9717:): if (ref($lastactref) eq 'HASH') {
9718:): $lastactref->{'ltitools'} = 1;
9719:): }
9720:): $resulttext = &mt('Changes made:').'<ul>';
9721:): my %bynum;
9722:): foreach my $itemid (sort(keys(%changes))) {
9723:): my $position = $confhash{$itemid}{'order'};
9724:): $bynum{$position} = $itemid;
9725:): }
9726:): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9727:): my $itemid = $bynum{$pos};
9728:): if (ref($confhash{$itemid}) ne 'HASH') {
9729:): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9730:): } else {
9731:): $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9732:): if ($confhash{$itemid}{'image'}) {
9733:): $resulttext .= ' '.
9734:): '<img src="'.$confhash{$itemid}{'image'}.'"'.
9735:): ' alt="'.&mt('Tool Provider icon').'" />';
9736:): }
9737:): $resulttext .= '</li><ul>';
9738:): my $position = $pos + 1;
9739:): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9740:): foreach my $item ('version','msgtype','url') {
9741:): if ($confhash{$itemid}{$item} ne '') {
9742:): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9743:): }
9744:): }
9745:): if ($encconfig{$itemid}{'key'} ne '') {
9746:): $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
9747:): }
9748:): if ($encconfig{$itemid}{'secret'} ne '') {
9749:): $resulttext .= '<li>'.$lt{'secret'}.': ';
9750:): my $num = length($encconfig{$itemid}{'secret'});
9751:): $resulttext .= ('*'x$num).'</li>';
9752:): }
9753:): $resulttext .= '<li>'.&mt('Configurable in course:');
9754:): my @possconfig = ('label','title','target','linktext','explanation');
9755:): my $numconfig = 0;
9756:): if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
9757:): foreach my $item (@possconfig) {
9758:): if ($confhash{$itemid}{'crsconf'}{$item}) {
9759:): $numconfig ++;
9760:): $resulttext .= ' "'.$lt{'crs'.$item}.'"';
9761:): }
9762:): }
9763:): }
9764:): if (!$numconfig) {
9765:): $resulttext .= &mt('None');
9766:): }
9767:): $resulttext .= '</li>';
9768:): foreach my $item ('passback','roster') {
9769:): $resulttext .= '<li>'.$lt{$item}.' ';
9770:): if ($confhash{$itemid}{$item}) {
9771:): $resulttext .= &mt('Yes');
9772:): } else {
9773:): $resulttext .= &mt('No');
9774:): }
9775:): $resulttext .= '</li>';
9776:): }
9777:): if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9778:): my $displaylist;
9779:): if ($confhash{$itemid}{'display'}{'target'}) {
9780:): $displaylist = &mt('Display target').': '.
9781:): $confhash{$itemid}{'display'}{'target'}.',';
9782:): }
9783:): foreach my $size ('width','height') {
9784:): if ($confhash{$itemid}{'display'}{$size}) {
9785:): $displaylist .= (' 'x2).$lt{$size}.': '.
9786:): $confhash{$itemid}{'display'}{$size}.',';
9787:): }
9788:): }
9789:): if ($displaylist) {
9790:): $displaylist =~ s/,$//;
9791:): $resulttext .= '<li>'.$displaylist.'</li>';
9792:): }
9793:): foreach my $item ('linktext','explanation') {
9794:): if ($confhash{$itemid}{'display'}{$item}) {
9795:): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
9796:): }
9797:): }
9798:): }
9799:): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9800:): my $fieldlist;
9801:): foreach my $field (@allfields) {
9802:): if ($confhash{$itemid}{'fields'}{$field}) {
9803:): $fieldlist .= (' 'x2).$lt{$field}.',';
9804:): }
9805:): }
9806:): if ($fieldlist) {
9807:): $fieldlist =~ s/,$//;
9808:): $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9809:): }
9810:): }
9811:): if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9812:): my $rolemaps;
9813:): foreach my $role (@courseroles) {
9814:): if ($confhash{$itemid}{'roles'}{$role}) {
9815:): $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9816:): $confhash{$itemid}{'roles'}{$role}.',';
9817:): }
9818:): }
9819:): if ($rolemaps) {
9820:): $rolemaps =~ s/,$//;
9821:): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9822:): }
9823:): }
9824:): if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9825:): my $customlist;
9826:): if (keys(%{$confhash{$itemid}{'custom'}})) {
9827:): foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9828:): $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9829:): }
9830:): }
9831:): if ($customlist) {
9832:): $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9833:): }
9834:): }
9835:): $resulttext .= '</ul></li>';
9836:): }
9837:): }
9838:): $resulttext .= '</ul>';
9839:): } else {
9840:): $resulttext = &mt('No changes made.');
9841:): }
9842:): } else {
9843:): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9844:): }
9845:): if ($errors) {
9846:): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9847:): $errors.'</ul>';
9848:): }
9849:): return $resulttext;
9850:): }
9851:):
9852:): sub process_ltitools_image {
9853:): my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9854:): my $filename = $env{'form.'.$caller.'.filename'};
9855:): my ($error,$url);
9856:): my ($width,$height) = (21,21);
9857:): if ($configuserok eq 'ok') {
9858:): if ($switchserver) {
9859:): $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9860:): $switchserver);
9861:): } elsif ($author_ok eq 'ok') {
9862:): my ($result,$imageurl,$madethumb) =
9863:): &publishlogo($r,'upload',$caller,$dom,$confname,
9864:): "ltitools/$itemid/icon",$width,$height);
9865:): if ($result eq 'ok') {
9866:): if ($madethumb) {
9867:): my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9868:): my $imagethumb = "$path/tn-".$imagefile;
9869:): $url = $imagethumb;
9870:): } else {
9871:): $url = $imageurl;
9872:): }
9873:): } else {
9874:): $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9875:): }
9876:): } else {
9877:): $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);
9878:): }
9879:): } else {
9880:): $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);
9881:): }
9882:): return ($url,$error);
9883:): }
9884:):
9885:): sub get_ltitools_id {
9886:): my ($cdom,$title) = @_;
9887:): # get lock on ltitools db
9888:): my $lockhash = {
9889:): lock => $env{'user.name'}.
9890:): ':'.$env{'user.domain'},
9891:): };
9892:): my $tries = 0;
9893:): my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9894:): my ($id,$error);
9895:):
9896:): while (($gotlock ne 'ok') && ($tries<10)) {
9897:): $tries ++;
9898:): sleep (0.1);
9899:): $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9900:): }
9901:): if ($gotlock eq 'ok') {
9902:): my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
9903:): if ($currids{'lock'}) {
9904:): delete($currids{'lock'});
9905:): if (keys(%currids)) {
9906:): my @curr = sort { $a <=> $b } keys(%currids);
9907:): if ($curr[-1] =~ /^\d+$/) {
9908:): $id = 1 + $curr[-1];
9909:): }
9910:): } else {
9911:): $id = 1;
9912:): }
9913:): if ($id) {
9914:): unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
9915:): $error = 'nostore';
9916:): }
9917:): } else {
9918:): $error = 'nonumber';
9919:): }
9920:): }
9921:): my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
9922:): } else {
9923:): $error = 'nolock';
9924:): }
9925:): return ($id,$error);
9926:): }
9927:):
1.3 raeburn 9928: sub modify_autoenroll {
1.160.6.24 raeburn 9929: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9930: my ($resulttext,%changes);
9931: my %currautoenroll;
9932: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9933: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9934: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9935: }
9936: }
9937: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9938: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9939: sender => 'Sender for notification messages',
1.160.6.68 raeburn 9940: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9941: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9942: my @offon = ('off','on');
1.17 raeburn 9943: my $sender_uname = $env{'form.sender_uname'};
9944: my $sender_domain = $env{'form.sender_domain'};
9945: if ($sender_domain eq '') {
9946: $sender_uname = '';
9947: } elsif ($sender_uname eq '') {
9948: $sender_domain = '';
9949: }
1.129 raeburn 9950: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 9951: my $failsafe = $env{'form.autoenroll_failsafe'};
9952: $failsafe =~ s{^\s+|\s+$}{}g;
9953: if ($failsafe =~ /\D/) {
9954: undef($failsafe);
9955: }
1.1 raeburn 9956: my %autoenrollhash = (
1.129 raeburn 9957: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9958: 'sender_uname' => $sender_uname,
9959: 'sender_domain' => $sender_domain,
9960: 'co-owners' => $coowners,
1.160.6.68 raeburn 9961: 'autofailsafe' => $failsafe,
1.1 raeburn 9962: }
9963: );
1.4 raeburn 9964: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9965: $dom);
1.1 raeburn 9966: if ($putresult eq 'ok') {
9967: if (exists($currautoenroll{'run'})) {
9968: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9969: $changes{'run'} = 1;
9970: }
9971: } elsif ($autorun) {
9972: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9973: $changes{'run'} = 1;
1.1 raeburn 9974: }
9975: }
1.17 raeburn 9976: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9977: $changes{'sender'} = 1;
9978: }
1.17 raeburn 9979: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9980: $changes{'sender'} = 1;
9981: }
1.129 raeburn 9982: if ($currautoenroll{'co-owners'} ne '') {
9983: if ($currautoenroll{'co-owners'} ne $coowners) {
9984: $changes{'coowners'} = 1;
9985: }
9986: } elsif ($coowners) {
9987: $changes{'coowners'} = 1;
1.160.6.68 raeburn 9988: }
9989: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9990: $changes{'autofailsafe'} = 1;
9991: }
1.1 raeburn 9992: if (keys(%changes) > 0) {
9993: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9994: if ($changes{'run'}) {
1.1 raeburn 9995: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9996: }
9997: if ($changes{'sender'}) {
1.17 raeburn 9998: if ($sender_uname eq '' || $sender_domain eq '') {
9999: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
10000: } else {
10001: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
10002: }
1.1 raeburn 10003: }
1.129 raeburn 10004: if ($changes{'coowners'}) {
10005: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
10006: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10007: if (ref($lastactref) eq 'HASH') {
10008: $lastactref->{'domainconfig'} = 1;
10009: }
1.129 raeburn 10010: }
1.160.6.68 raeburn 10011: if ($changes{'autofailsafe'}) {
10012: if ($failsafe ne '') {
1.160.6.82 raeburn 10013: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 10014: } else {
1.160.6.82 raeburn 10015: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 10016: }
10017: &Apache::lonnet::get_domain_defaults($dom,1);
10018: if (ref($lastactref) eq 'HASH') {
10019: $lastactref->{'domdefaults'} = 1;
10020: }
10021: }
1.1 raeburn 10022: $resulttext .= '</ul>';
10023: } else {
10024: $resulttext = &mt('No changes made to auto-enrollment settings');
10025: }
10026: } else {
1.11 albertel 10027: $resulttext = '<span class="LC_error">'.
10028: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10029: }
1.3 raeburn 10030: return $resulttext;
1.1 raeburn 10031: }
10032:
10033: sub modify_autoupdate {
1.3 raeburn 10034: my ($dom,%domconfig) = @_;
1.1 raeburn 10035: my ($resulttext,%currautoupdate,%fields,%changes);
10036: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
10037: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
10038: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
10039: }
10040: }
10041: my @offon = ('off','on');
10042: my %title = &Apache::lonlocal::texthash (
10043: run => 'Auto-update:',
10044: classlists => 'Updates to user information in classlists?'
10045: );
1.44 raeburn 10046: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10047: my %fieldtitles = &Apache::lonlocal::texthash (
10048: id => 'Student/Employee ID',
1.20 raeburn 10049: permanentemail => 'E-mail address',
1.1 raeburn 10050: lastname => 'Last Name',
10051: firstname => 'First Name',
10052: middlename => 'Middle Name',
1.132 raeburn 10053: generation => 'Generation',
1.1 raeburn 10054: );
1.142 raeburn 10055: $othertitle = &mt('All users');
1.1 raeburn 10056: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 10057: $othertitle = &mt('Other users');
1.1 raeburn 10058: }
10059: foreach my $key (keys(%env)) {
10060: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 10061: my ($usertype,$item) = ($1,$2);
10062: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10063: if ($usertype eq 'default') {
10064: push(@{$fields{$1}},$2);
10065: } elsif (ref($types) eq 'ARRAY') {
10066: if (grep(/^\Q$usertype\E$/,@{$types})) {
10067: push(@{$fields{$1}},$2);
10068: }
10069: }
10070: }
1.1 raeburn 10071: }
10072: }
1.131 raeburn 10073: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10074: @lockablenames = sort(@lockablenames);
10075: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10076: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10077: if (@changed) {
10078: $changes{'lockablenames'} = 1;
10079: }
10080: } else {
10081: if (@lockablenames) {
10082: $changes{'lockablenames'} = 1;
10083: }
10084: }
1.1 raeburn 10085: my %updatehash = (
10086: autoupdate => { run => $env{'form.autoupdate_run'},
10087: classlists => $env{'form.classlists'},
10088: fields => {%fields},
1.131 raeburn 10089: lockablenames => \@lockablenames,
1.1 raeburn 10090: }
10091: );
10092: foreach my $key (keys(%currautoupdate)) {
10093: if (($key eq 'run') || ($key eq 'classlists')) {
10094: if (exists($updatehash{autoupdate}{$key})) {
10095: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10096: $changes{$key} = 1;
10097: }
10098: }
10099: } elsif ($key eq 'fields') {
10100: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 10101: foreach my $item (@{$types},'default') {
1.1 raeburn 10102: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10103: my $change = 0;
10104: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10105: if (!exists($fields{$item})) {
10106: $change = 1;
1.132 raeburn 10107: last;
1.1 raeburn 10108: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 10109: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 10110: $change = 1;
1.132 raeburn 10111: last;
1.1 raeburn 10112: }
10113: }
10114: }
10115: if ($change) {
10116: push(@{$changes{$key}},$item);
10117: }
1.26 raeburn 10118: }
1.1 raeburn 10119: }
10120: }
1.131 raeburn 10121: } elsif ($key eq 'lockablenames') {
10122: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10123: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10124: if (@changed) {
10125: $changes{'lockablenames'} = 1;
10126: }
10127: } else {
10128: if (@lockablenames) {
10129: $changes{'lockablenames'} = 1;
10130: }
10131: }
10132: }
10133: }
10134: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10135: if (@lockablenames) {
10136: $changes{'lockablenames'} = 1;
1.1 raeburn 10137: }
10138: }
1.26 raeburn 10139: foreach my $item (@{$types},'default') {
10140: if (defined($fields{$item})) {
10141: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10142: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10143: my $change = 0;
10144: if (ref($fields{$item}) eq 'ARRAY') {
10145: foreach my $type (@{$fields{$item}}) {
10146: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10147: $change = 1;
10148: last;
10149: }
10150: }
10151: }
10152: if ($change) {
10153: push(@{$changes{'fields'}},$item);
10154: }
10155: } else {
1.26 raeburn 10156: push(@{$changes{'fields'}},$item);
10157: }
10158: } else {
10159: push(@{$changes{'fields'}},$item);
1.1 raeburn 10160: }
10161: }
10162: }
10163: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10164: $dom);
10165: if ($putresult eq 'ok') {
10166: if (keys(%changes) > 0) {
10167: $resulttext = &mt('Changes made:').'<ul>';
10168: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10169: if ($key eq 'lockablenames') {
10170: $resulttext .= '<li>';
10171: if (@lockablenames) {
10172: $usertypes->{'default'} = $othertitle;
10173: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10174: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10175: } else {
10176: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10177: }
10178: $resulttext .= '</li>';
10179: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10180: foreach my $item (@{$changes{$key}}) {
10181: my @newvalues;
10182: foreach my $type (@{$fields{$item}}) {
10183: push(@newvalues,$fieldtitles{$type});
10184: }
1.3 raeburn 10185: my $newvaluestr;
10186: if (@newvalues > 0) {
10187: $newvaluestr = join(', ',@newvalues);
10188: } else {
10189: $newvaluestr = &mt('none');
1.6 raeburn 10190: }
1.1 raeburn 10191: if ($item eq 'default') {
1.26 raeburn 10192: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10193: } else {
1.26 raeburn 10194: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10195: }
10196: }
10197: } else {
10198: my $newvalue;
10199: if ($key eq 'run') {
10200: $newvalue = $offon[$env{'form.autoupdate_run'}];
10201: } else {
10202: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10203: }
1.1 raeburn 10204: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10205: }
10206: }
10207: $resulttext .= '</ul>';
10208: } else {
1.3 raeburn 10209: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10210: }
10211: } else {
1.11 albertel 10212: $resulttext = '<span class="LC_error">'.
10213: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10214: }
1.3 raeburn 10215: return $resulttext;
1.1 raeburn 10216: }
10217:
1.125 raeburn 10218: sub modify_autocreate {
10219: my ($dom,%domconfig) = @_;
10220: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10221: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10222: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10223: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10224: }
10225: }
10226: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10227: req => 'Auto-creation of validated requests for official courses',
10228: xmldc => 'Identity of course creator of courses from XML files',
10229: );
10230: my @types = ('xml','req');
10231: foreach my $item (@types) {
10232: $newvals{$item} = $env{'form.autocreate_'.$item};
10233: $newvals{$item} =~ s/\D//g;
10234: $newvals{$item} = 0 if ($newvals{$item} eq '');
10235: }
10236: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 10237: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10238: unless (exists($domcoords{$newvals{'xmldc'}})) {
10239: $newvals{'xmldc'} = '';
10240: }
10241: %autocreatehash = (
10242: autocreate => { xml => $newvals{'xml'},
10243: req => $newvals{'req'},
10244: }
10245: );
10246: if ($newvals{'xmldc'} ne '') {
10247: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10248: }
10249: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10250: $dom);
10251: if ($putresult eq 'ok') {
10252: my @items = @types;
10253: if ($newvals{'xml'}) {
10254: push(@items,'xmldc');
10255: }
10256: foreach my $item (@items) {
10257: if (exists($currautocreate{$item})) {
10258: if ($currautocreate{$item} ne $newvals{$item}) {
10259: $changes{$item} = 1;
10260: }
10261: } elsif ($newvals{$item}) {
10262: $changes{$item} = 1;
10263: }
10264: }
10265: if (keys(%changes) > 0) {
10266: my @offon = ('off','on');
10267: $resulttext = &mt('Changes made:').'<ul>';
10268: foreach my $item (@types) {
10269: if ($changes{$item}) {
10270: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 10271: $resulttext .= '<li>'.
10272: &mt("$title{$item} set to [_1]$newtxt [_2]",
10273: '<b>','</b>').
10274: '</li>';
1.125 raeburn 10275: }
10276: }
10277: if ($changes{'xmldc'}) {
10278: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10279: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 10280: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10281: }
10282: $resulttext .= '</ul>';
10283: } else {
10284: $resulttext = &mt('No changes made to auto-creation settings');
10285: }
10286: } else {
10287: $resulttext = '<span class="LC_error">'.
10288: &mt('An error occurred: [_1]',$putresult).'</span>';
10289: }
10290: return $resulttext;
10291: }
10292:
1.23 raeburn 10293: sub modify_directorysrch {
1.160.6.81 raeburn 10294: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 10295: my ($resulttext,%changes);
10296: my %currdirsrch;
10297: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10298: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10299: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10300: }
10301: }
1.160.6.72 raeburn 10302: my %title = ( available => 'Institutional directory search available',
10303: localonly => 'Other domains can search institution',
10304: lcavailable => 'LON-CAPA directory search available',
10305: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10306: searchby => 'Search types',
10307: searchtypes => 'Search latitude');
10308: my @offon = ('off','on');
1.24 raeburn 10309: my @otherdoms = ('Yes','No');
1.23 raeburn 10310:
1.25 raeburn 10311: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10312: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10313: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10314:
1.44 raeburn 10315: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10316: if (keys(%{$usertypes}) == 0) {
10317: @cansearch = ('default');
10318: } else {
10319: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10320: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10321: if (!grep(/^\Q$type\E$/,@cansearch)) {
10322: push(@{$changes{'cansearch'}},$type);
10323: }
1.23 raeburn 10324: }
1.26 raeburn 10325: foreach my $type (@cansearch) {
10326: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10327: push(@{$changes{'cansearch'}},$type);
10328: }
1.23 raeburn 10329: }
1.26 raeburn 10330: } else {
10331: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10332: }
10333: }
10334:
10335: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10336: foreach my $by (@{$currdirsrch{'searchby'}}) {
10337: if (!grep(/^\Q$by\E$/,@searchby)) {
10338: push(@{$changes{'searchby'}},$by);
10339: }
10340: }
10341: foreach my $by (@searchby) {
10342: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10343: push(@{$changes{'searchby'}},$by);
10344: }
10345: }
10346: } else {
10347: push(@{$changes{'searchby'}},@searchby);
10348: }
1.25 raeburn 10349:
10350: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10351: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10352: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10353: push(@{$changes{'searchtypes'}},$type);
10354: }
10355: }
10356: foreach my $type (@searchtypes) {
10357: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10358: push(@{$changes{'searchtypes'}},$type);
10359: }
10360: }
10361: } else {
10362: if (exists($currdirsrch{'searchtypes'})) {
10363: foreach my $type (@searchtypes) {
10364: if ($type ne $currdirsrch{'searchtypes'}) {
10365: push(@{$changes{'searchtypes'}},$type);
10366: }
10367: }
10368: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10369: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10370: }
10371: } else {
10372: push(@{$changes{'searchtypes'}},@searchtypes);
10373: }
10374: }
10375:
1.23 raeburn 10376: my %dirsrch_hash = (
10377: directorysrch => { available => $env{'form.dirsrch_available'},
10378: cansearch => \@cansearch,
1.160.6.72 raeburn 10379: localonly => $env{'form.dirsrch_instlocalonly'},
10380: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10381: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10382: searchby => \@searchby,
1.25 raeburn 10383: searchtypes => \@searchtypes,
1.23 raeburn 10384: }
10385: );
10386: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10387: $dom);
10388: if ($putresult eq 'ok') {
10389: if (exists($currdirsrch{'available'})) {
10390: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10391: $changes{'available'} = 1;
10392: }
10393: } else {
10394: if ($env{'form.dirsrch_available'} eq '1') {
10395: $changes{'available'} = 1;
10396: }
10397: }
1.160.6.72 raeburn 10398: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 10399: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10400: $changes{'lcavailable'} = 1;
10401: }
1.24 raeburn 10402: } else {
1.160.6.72 raeburn 10403: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10404: $changes{'lcavailable'} = 1;
10405: }
10406: }
10407: if (exists($currdirsrch{'localonly'})) {
10408: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 10409: $changes{'localonly'} = 1;
10410: }
1.160.6.72 raeburn 10411: } else {
10412: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
10413: $changes{'localonly'} = 1;
10414: }
10415: }
10416: if (exists($currdirsrch{'lclocalonly'})) {
10417: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10418: $changes{'lclocalonly'} = 1;
10419: }
10420: } else {
10421: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10422: $changes{'lclocalonly'} = 1;
10423: }
1.24 raeburn 10424: }
1.23 raeburn 10425: if (keys(%changes) > 0) {
10426: $resulttext = &mt('Changes made:').'<ul>';
10427: if ($changes{'available'}) {
10428: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10429: }
1.160.6.72 raeburn 10430: if ($changes{'lcavailable'}) {
10431: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10432: }
1.24 raeburn 10433: if ($changes{'localonly'}) {
1.160.6.72 raeburn 10434: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
10435: }
10436: if ($changes{'lclocalonly'}) {
10437: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 10438: }
1.23 raeburn 10439: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10440: my $chgtext;
1.26 raeburn 10441: if (ref($usertypes) eq 'HASH') {
10442: if (keys(%{$usertypes}) > 0) {
10443: foreach my $type (@{$types}) {
10444: if (grep(/^\Q$type\E$/,@cansearch)) {
10445: $chgtext .= $usertypes->{$type}.'; ';
10446: }
10447: }
10448: if (grep(/^default$/,@cansearch)) {
10449: $chgtext .= $othertitle;
10450: } else {
10451: $chgtext =~ s/\; $//;
10452: }
1.160.6.13 raeburn 10453: $resulttext .=
10454: '<li>'.
10455: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10456: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10457: '</li>';
1.23 raeburn 10458: }
10459: }
10460: }
10461: if (ref($changes{'searchby'}) eq 'ARRAY') {
10462: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10463: my $chgtext;
10464: foreach my $type (@{$titleorder}) {
10465: if (grep(/^\Q$type\E$/,@searchby)) {
10466: if (defined($searchtitles->{$type})) {
10467: $chgtext .= $searchtitles->{$type}.'; ';
10468: }
10469: }
10470: }
10471: $chgtext =~ s/\; $//;
10472: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10473: }
1.25 raeburn 10474: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10475: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10476: my $chgtext;
10477: foreach my $type (@{$srchtypeorder}) {
10478: if (grep(/^\Q$type\E$/,@searchtypes)) {
10479: if (defined($srchtypes_desc->{$type})) {
10480: $chgtext .= $srchtypes_desc->{$type}.'; ';
10481: }
10482: }
10483: }
10484: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 10485: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10486: }
10487: $resulttext .= '</ul>';
1.160.6.81 raeburn 10488: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10489: if (ref($lastactref) eq 'HASH') {
10490: $lastactref->{'directorysrch'} = 1;
10491: }
1.23 raeburn 10492: } else {
1.160.6.72 raeburn 10493: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10494: }
10495: } else {
10496: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10497: &mt('An error occurred: [_1]',$putresult).'</span>';
10498: }
10499: return $resulttext;
10500: }
10501:
1.28 raeburn 10502: sub modify_contacts {
1.160.6.24 raeburn 10503: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10504: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10505: if (ref($domconfig{'contacts'}) eq 'HASH') {
10506: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10507: $currsetting{$key} = $domconfig{'contacts'}{$key};
10508: }
10509: }
1.160.6.78 raeburn 10510: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10511: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 10512: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10513: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.160.6.23 raeburn 10514: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 10515: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10516: foreach my $type (@mailings) {
10517: @{$newsetting{$type}} =
10518: &Apache::loncommon::get_env_multiple('form.'.$type);
10519: foreach my $item (@contacts) {
10520: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10521: $contacts_hash{contacts}{$type}{$item} = 1;
10522: } else {
10523: $contacts_hash{contacts}{$type}{$item} = 0;
10524: }
1.160.6.78 raeburn 10525: }
1.28 raeburn 10526: $others{$type} = $env{'form.'.$type.'_others'};
10527: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 10528: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10529: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10530: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 10531: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10532: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10533: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10534: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10535: }
1.134 raeburn 10536: }
1.28 raeburn 10537: }
10538: foreach my $item (@contacts) {
10539: $to{$item} = $env{'form.'.$item};
10540: $contacts_hash{'contacts'}{$item} = $to{$item};
10541: }
1.160.6.23 raeburn 10542: foreach my $item (@toggles) {
10543: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10544: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10545: }
10546: }
1.160.6.78 raeburn 10547: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10548: foreach my $field (@{$fields}) {
10549: if (ref($possoptions->{$field}) eq 'ARRAY') {
10550: my $value = $env{'form.helpform_'.$field};
10551: $value =~ s/^\s+|\s+$//g;
10552: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.84.2. (raeburn 10553:): $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 10554: if ($field eq 'screenshot') {
10555: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10556: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.84.2. (raeburn 10557:): $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 10558: }
10559: }
10560: }
10561: }
10562: }
10563: }
1.160.6.84.2. (raeburn 10564:): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10565:): my (@statuses,%usertypeshash,@overrides);
10566:): if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
10567:): @statuses = @{$types};
10568:): if (ref($usertypes) eq 'HASH') {
10569:): %usertypeshash = %{$usertypes};
10570:): }
10571:): }
10572:): if (@statuses) {
10573:): my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
10574:): foreach my $type (@possoverrides) {
10575:): if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
10576:): push(@overrides,$type);
10577:): }
10578:): }
10579:): if (@overrides) {
10580:): foreach my $type (@overrides) {
10581:): my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
10582:): foreach my $item (@contacts) {
10583:): if (grep(/^\Q$item\E$/,@standard)) {
10584:): $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
10585:): $newsetting{'override_'.$type}{$item} = 1;
10586:): } else {
10587:): $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
10588:): $newsetting{'override_'.$type}{$item} = 0;
10589:): }
10590:): }
10591:): $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
10592:): $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
10593:): $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
10594:): $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
10595:): if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
10596:): $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
10597:): $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
10598:): $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10599:): $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
10600:): }
10601:): }
10602:): }
10603:): }
1.28 raeburn 10604: if (keys(%currsetting) > 0) {
10605: foreach my $item (@contacts) {
10606: if ($to{$item} ne $currsetting{$item}) {
10607: $changes{$item} = 1;
10608: }
10609: }
10610: foreach my $type (@mailings) {
10611: foreach my $item (@contacts) {
10612: if (ref($currsetting{$type}) eq 'HASH') {
10613: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10614: push(@{$changes{$type}},$item);
10615: }
10616: } else {
10617: push(@{$changes{$type}},@{$newsetting{$type}});
10618: }
10619: }
10620: if ($others{$type} ne $currsetting{$type}{'others'}) {
10621: push(@{$changes{$type}},'others');
10622: }
1.160.6.78 raeburn 10623: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10624: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10625: push(@{$changes{$type}},'bcc');
10626: }
1.160.6.78 raeburn 10627: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10628: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10629: push(@{$changes{$type}},'include');
10630: }
10631: }
10632: }
10633: if (ref($fields) eq 'ARRAY') {
10634: if (ref($currsetting{'helpform'}) eq 'HASH') {
10635: foreach my $field (@{$fields}) {
10636: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10637: push(@{$changes{'helpform'}},$field);
10638: }
10639: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10640: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10641: push(@{$changes{'helpform'}},'maxsize');
10642: }
10643: }
10644: }
10645: } else {
10646: foreach my $field (@{$fields}) {
10647: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10648: push(@{$changes{'helpform'}},$field);
10649: }
10650: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10651: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10652: push(@{$changes{'helpform'}},'maxsize');
10653: }
10654: }
10655: }
1.134 raeburn 10656: }
1.28 raeburn 10657: }
1.160.6.84.2. (raeburn 10658:): if (@statuses) {
10659:): if (ref($currsetting{'overrides'}) eq 'HASH') {
10660:): foreach my $key (keys(%{$currsetting{'overrides'}})) {
10661:): if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
10662:): if (ref($newsetting{'override_'.$key}) eq 'HASH') {
10663:): foreach my $item (@contacts,'bcc','others','include') {
10664:): if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
10665:): push(@{$changes{'overrides'}},$key);
10666:): last;
10667:): }
10668:): }
10669:): } else {
10670:): push(@{$changes{'overrides'}},$key);
10671:): }
10672:): }
10673:): }
10674:): foreach my $key (@overrides) {
10675:): unless (exists($currsetting{'overrides'}{$key})) {
10676:): push(@{$changes{'overrides'}},$key);
10677:): }
10678:): }
10679:): } else {
10680:): foreach my $key (@overrides) {
10681:): push(@{$changes{'overrides'}},$key);
10682:): }
10683:): }
10684:): }
1.28 raeburn 10685: } else {
10686: my %default;
10687: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10688: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10689: $default{'errormail'} = 'adminemail';
10690: $default{'packagesmail'} = 'adminemail';
10691: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 10692: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10693: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10694: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 10695: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 10696: foreach my $item (@contacts) {
10697: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 10698: $changes{$item} = 1;
1.160.6.23 raeburn 10699: }
1.28 raeburn 10700: }
10701: foreach my $type (@mailings) {
10702: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10703: push(@{$changes{$type}},@{$newsetting{$type}});
10704: }
10705: if ($others{$type} ne '') {
10706: push(@{$changes{$type}},'others');
1.134 raeburn 10707: }
1.160.6.78 raeburn 10708: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10709: if ($bcc{$type} ne '') {
10710: push(@{$changes{$type}},'bcc');
10711: }
1.160.6.78 raeburn 10712: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10713: push(@{$changes{$type}},'include');
10714: }
10715: }
10716: }
10717: if (ref($fields) eq 'ARRAY') {
10718: foreach my $field (@{$fields}) {
10719: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10720: push(@{$changes{'helpform'}},$field);
10721: }
10722: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10723: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10724: push(@{$changes{'helpform'}},'maxsize');
10725: }
10726: }
1.134 raeburn 10727: }
1.28 raeburn 10728: }
10729: }
1.160.6.23 raeburn 10730: foreach my $item (@toggles) {
10731: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10732: $changes{$item} = 1;
10733: } elsif ((!$env{'form.'.$item}) &&
10734: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10735: $changes{$item} = 1;
10736: }
10737: }
1.28 raeburn 10738: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10739: $dom);
10740: if ($putresult eq 'ok') {
10741: if (keys(%changes) > 0) {
1.160.6.24 raeburn 10742: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10743: if (ref($lastactref) eq 'HASH') {
10744: $lastactref->{'domainconfig'} = 1;
10745: }
1.28 raeburn 10746: my ($titles,$short_titles) = &contact_titles();
10747: $resulttext = &mt('Changes made:').'<ul>';
10748: foreach my $item (@contacts) {
10749: if ($changes{$item}) {
10750: $resulttext .= '<li>'.$titles->{$item}.
10751: &mt(' set to: ').
10752: '<span class="LC_cusr_emph">'.
10753: $to{$item}.'</span></li>';
10754: }
10755: }
10756: foreach my $type (@mailings) {
10757: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 10758: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
10759: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
10760: } else {
10761: $resulttext .= '<li>'.$titles->{$type}.': ';
10762: }
1.28 raeburn 10763: my @text;
10764: foreach my $item (@{$newsetting{$type}}) {
10765: push(@text,$short_titles->{$item});
10766: }
10767: if ($others{$type} ne '') {
10768: push(@text,$others{$type});
10769: }
1.160.6.78 raeburn 10770: if (@text) {
10771: $resulttext .= '<span class="LC_cusr_emph">'.
10772: join(', ',@text).'</span>';
10773: }
10774: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10775: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 10776: my $bcctext;
10777: if (@text) {
10778: $bcctext = ' '.&mt('with Bcc to');
10779: } else {
10780: $bcctext = '(Bcc)';
10781: }
10782: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10783: } elsif (!@text) {
10784: $resulttext .= &mt('No one');
1.134 raeburn 10785: }
1.160.6.78 raeburn 10786: if ($includestr{$type} ne '') {
10787: if ($includeloc{$type} eq 'b') {
10788: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10789: } elsif ($includeloc{$type} eq 's') {
10790: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10791: }
10792: }
10793: } elsif (!@text) {
10794: $resulttext .= &mt('No recipients');
1.134 raeburn 10795: }
10796: $resulttext .= '</li>';
1.28 raeburn 10797: }
10798: }
1.160.6.84.2. (raeburn 10799:): if (ref($changes{'overrides'}) eq 'ARRAY') {
10800:): my @deletions;
10801:): foreach my $type (@{$changes{'overrides'}}) {
10802:): if ($usertypeshash{$type}) {
10803:): if (grep(/^\Q$type\E/,@overrides)) {
10804:): $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
10805:): $usertypeshash{$type}).'<ul><li>';
10806:): if (ref($newsetting{'override_'.$type}) eq 'HASH') {
10807:): my @text;
10808:): foreach my $item (@contacts) {
10809:): if ($newsetting{'override_'.$type}{$item}) {
10810:): push(@text,$short_titles->{$item});
10811:): }
10812:): }
10813:): if ($newsetting{'override_'.$type}{'others'} ne '') {
10814:): push(@text,$newsetting{'override_'.$type}{'others'});
10815:): }
10816:):
10817:): if (@text) {
10818:): $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
10819:): '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
10820:): }
10821:): if ($newsetting{'override_'.$type}{'bcc'} ne '') {
10822:): my $bcctext;
10823:): if (@text) {
10824:): $bcctext = ' '.&mt('with Bcc to');
10825:): } else {
10826:): $bcctext = '(Bcc)';
10827:): }
10828:): $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
10829:): } elsif (!@text) {
10830:): $resulttext .= &mt('Helpdesk e-mail sent to no one');
10831:): }
10832:): $resulttext .= '</li>';
10833:): if ($newsetting{'override_'.$type}{'include'} ne '') {
10834:): my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
10835:): if ($loc eq 'b') {
10836:): $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
10837:): } elsif ($loc eq 's') {
10838:): $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
10839:): }
10840:): }
10841:): }
10842:): $resulttext .= '</li></ul></li>';
10843:): } else {
10844:): push(@deletions,$usertypeshash{$type});
10845:): }
10846:): }
10847:): }
10848:): if (@deletions) {
10849:): $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
10850:): join(', ',@deletions)).'</li>';
10851:): }
10852:): }
1.160.6.23 raeburn 10853: my @offon = ('off','on');
10854: if ($changes{'reporterrors'}) {
10855: $resulttext .= '<li>'.
10856: &mt('E-mail error reports to [_1] set to "'.
10857: $offon[$env{'form.reporterrors'}].'".',
10858: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10859: &mt('LON-CAPA core group - MSU'),600,500)).
10860: '</li>';
10861: }
10862: if ($changes{'reportupdates'}) {
10863: $resulttext .= '<li>'.
10864: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10865: $offon[$env{'form.reportupdates'}].'".',
10866: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10867: &mt('LON-CAPA core group - MSU'),600,500)).
10868: '</li>';
10869: }
1.160.6.78 raeburn 10870: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10871: my (@optional,@required,@unused,$maxsizechg);
10872: foreach my $field (@{$changes{'helpform'}}) {
10873: if ($field eq 'maxsize') {
10874: $maxsizechg = 1;
10875: next;
10876: }
10877: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
10878: push(@optional,$field);
10879: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10880: push(@unused,$field);
10881: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
10882: push(@required,$field);
10883: }
10884: }
10885: if (@optional) {
10886: $resulttext .= '<li>'.
10887: &mt('Help form fields changed to "Optional": [_1].',
10888: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10889: '</li>';
10890: }
10891: if (@required) {
10892: $resulttext .= '<li>'.
10893: &mt('Help form fields changed to "Required": [_1].',
10894: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10895: '</li>';
10896: }
10897: if (@unused) {
10898: $resulttext .= '<li>'.
10899: &mt('Help form fields changed to "Not shown": [_1].',
10900: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10901: '</li>';
10902: }
10903: if ($maxsizechg) {
10904: $resulttext .= '<li>'.
10905: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10906: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10907: '</li>';
10908: }
10909: }
1.28 raeburn 10910: $resulttext .= '</ul>';
10911: } else {
1.160.6.78 raeburn 10912: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 10913: }
10914: } else {
10915: $resulttext = '<span class="LC_error">'.
10916: &mt('An error occurred: [_1].',$putresult).'</span>';
10917: }
10918: return $resulttext;
10919: }
10920:
10921: sub modify_usercreation {
1.27 raeburn 10922: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 10923: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 10924: my $warningmsg;
1.27 raeburn 10925: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10926: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 10927: if ($key eq 'cancreate') {
10928: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10929: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10930: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69 raeburn 10931: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10932: ($item eq 'recaptchaversion')) {
1.160.6.34 raeburn 10933: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10934: } else {
10935: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10936: }
1.50 raeburn 10937: }
1.43 raeburn 10938: }
1.160.6.34 raeburn 10939: } elsif ($key eq 'email_rule') {
10940: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10941: } else {
10942: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 10943: }
10944: }
1.34 raeburn 10945: }
1.160.6.34 raeburn 10946: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
10947: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
10948: my @contexts = ('author','course','requestcrs');
10949: foreach my $item(@contexts) {
10950: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 10951: }
1.34 raeburn 10952: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10953: foreach my $item (@contexts) {
1.160.6.34 raeburn 10954: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
10955: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 10956: }
1.27 raeburn 10957: }
1.34 raeburn 10958: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
10959: foreach my $item (@contexts) {
1.43 raeburn 10960: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 10961: if ($cancreate{$item} ne 'any') {
10962: push(@{$changes{'cancreate'}},$item);
10963: }
10964: } else {
10965: if ($cancreate{$item} ne 'none') {
10966: push(@{$changes{'cancreate'}},$item);
10967: }
1.27 raeburn 10968: }
10969: }
10970: } else {
1.43 raeburn 10971: foreach my $item (@contexts) {
1.34 raeburn 10972: push(@{$changes{'cancreate'}},$item);
10973: }
1.27 raeburn 10974: }
1.34 raeburn 10975:
1.27 raeburn 10976: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10977: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10978: if (!grep(/^\Q$type\E$/,@username_rule)) {
10979: push(@{$changes{'username_rule'}},$type);
10980: }
10981: }
10982: foreach my $type (@username_rule) {
10983: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
10984: push(@{$changes{'username_rule'}},$type);
10985: }
10986: }
10987: } else {
10988: push(@{$changes{'username_rule'}},@username_rule);
10989: }
10990:
1.32 raeburn 10991: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
10992: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
10993: if (!grep(/^\Q$type\E$/,@id_rule)) {
10994: push(@{$changes{'id_rule'}},$type);
10995: }
10996: }
10997: foreach my $type (@id_rule) {
10998: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
10999: push(@{$changes{'id_rule'}},$type);
11000: }
11001: }
11002: } else {
11003: push(@{$changes{'id_rule'}},@id_rule);
11004: }
11005:
1.43 raeburn 11006: my @authen_contexts = ('author','course','domain');
1.28 raeburn 11007: my @authtypes = ('int','krb4','krb5','loc');
11008: my %authhash;
1.43 raeburn 11009: foreach my $item (@authen_contexts) {
1.28 raeburn 11010: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11011: foreach my $auth (@authtypes) {
11012: if (grep(/^\Q$auth\E$/,@authallowed)) {
11013: $authhash{$item}{$auth} = 1;
11014: } else {
11015: $authhash{$item}{$auth} = 0;
11016: }
11017: }
11018: }
11019: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 11020: foreach my $item (@authen_contexts) {
1.28 raeburn 11021: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11022: foreach my $auth (@authtypes) {
11023: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11024: push(@{$changes{'authtypes'}},$item);
11025: last;
11026: }
11027: }
11028: }
11029: }
11030: } else {
1.43 raeburn 11031: foreach my $item (@authen_contexts) {
1.28 raeburn 11032: push(@{$changes{'authtypes'}},$item);
11033: }
11034: }
11035:
1.160.6.34 raeburn 11036: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11037: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11038: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11039: $save_usercreate{'id_rule'} = \@id_rule;
11040: $save_usercreate{'username_rule'} = \@username_rule,
11041: $save_usercreate{'authtypes'} = \%authhash;
11042:
1.27 raeburn 11043: my %usercreation_hash = (
1.160.6.34 raeburn 11044: usercreation => \%save_usercreate,
11045: );
1.27 raeburn 11046:
11047: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11048: $dom);
1.50 raeburn 11049:
1.160.6.34 raeburn 11050: if ($putresult eq 'ok') {
11051: if (keys(%changes) > 0) {
11052: $resulttext = &mt('Changes made:').'<ul>';
11053: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11054: my %lt = &usercreation_types();
11055: foreach my $type (@{$changes{'cancreate'}}) {
11056: my $chgtext = $lt{$type}.', ';
11057: if ($cancreate{$type} eq 'none') {
11058: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11059: } elsif ($cancreate{$type} eq 'any') {
11060: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11061: } elsif ($cancreate{$type} eq 'official') {
11062: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11063: } elsif ($cancreate{$type} eq 'unofficial') {
11064: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11065: }
11066: $resulttext .= '<li>'.$chgtext.'</li>';
11067: }
11068: }
11069: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11070: my ($rules,$ruleorder) =
11071: &Apache::lonnet::inst_userrules($dom,'username');
11072: my $chgtext = '<ul>';
11073: foreach my $type (@username_rule) {
11074: if (ref($rules->{$type}) eq 'HASH') {
11075: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11076: }
11077: }
11078: $chgtext .= '</ul>';
11079: if (@username_rule > 0) {
11080: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11081: } else {
11082: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11083: }
11084: }
11085: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11086: my ($idrules,$idruleorder) =
11087: &Apache::lonnet::inst_userrules($dom,'id');
11088: my $chgtext = '<ul>';
11089: foreach my $type (@id_rule) {
11090: if (ref($idrules->{$type}) eq 'HASH') {
11091: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11092: }
11093: }
11094: $chgtext .= '</ul>';
11095: if (@id_rule > 0) {
11096: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11097: } else {
11098: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11099: }
11100: }
11101: my %authname = &authtype_names();
11102: my %context_title = &context_names();
11103: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11104: my $chgtext = '<ul>';
11105: foreach my $type (@{$changes{'authtypes'}}) {
11106: my @allowed;
11107: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11108: foreach my $auth (@authtypes) {
11109: if ($authhash{$type}{$auth}) {
11110: push(@allowed,$authname{$auth});
11111: }
11112: }
11113: if (@allowed > 0) {
11114: $chgtext .= join(', ',@allowed).'</li>';
11115: } else {
11116: $chgtext .= &mt('none').'</li>';
11117: }
11118: }
11119: $chgtext .= '</ul>';
11120: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11121: $resulttext .= '</li>';
11122: }
11123: $resulttext .= '</ul>';
11124: } else {
11125: $resulttext = &mt('No changes made to user creation settings');
11126: }
11127: } else {
11128: $resulttext = '<span class="LC_error">'.
11129: &mt('An error occurred: [_1]',$putresult).'</span>';
11130: }
11131: if ($warningmsg ne '') {
11132: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11133: }
11134: return $resulttext;
11135: }
11136:
11137: sub modify_selfcreation {
11138: my ($dom,%domconfig) = @_;
11139: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
11140: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 11141: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11142: if (ref($types) eq 'ARRAY') {
11143: $usertypes->{'default'} = $othertitle;
11144: push(@{$types},'default');
11145: }
1.160.6.34 raeburn 11146: #
11147: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11148: #
11149: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11150: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11151: if ($key eq 'cancreate') {
11152: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11153: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11154: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
11155: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.69 raeburn 11156: ($item eq 'recaptchaversion') ||
1.160.6.40 raeburn 11157: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 11158: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 11159: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11160: } else {
11161: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11162: }
11163: }
11164: }
11165: } elsif ($key eq 'email_rule') {
11166: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11167: } else {
11168: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11169: }
11170: }
11171: }
11172: #
11173: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11174: #
11175: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11176: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11177: if ($key eq 'selfcreate') {
11178: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11179: } else {
11180: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11181: }
11182: }
11183: }
11184:
11185: my @contexts = ('selfcreate');
11186: @{$cancreate{'selfcreate'}} = ();
11187: %{$cancreate{'emailusername'}} = ();
11188: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 11189: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 11190: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 11191: my %selfcreatetypes = (
11192: sso => 'users authenticated by institutional single sign on',
11193: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 11194: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 11195: );
1.160.6.34 raeburn 11196: #
11197: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11198: # is permitted.
11199: #
1.160.6.40 raeburn 11200:
11201: my @statuses;
11202: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11203: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
11204: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
11205: }
11206: }
11207: push(@statuses,'default');
11208:
1.160.6.35 raeburn 11209: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 11210: if ($item eq 'email') {
1.160.6.40 raeburn 11211: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 11212: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 11213: push(@contexts,'selfcreateprocessing');
11214: foreach my $type (@statuses) {
11215: if ($type eq 'default') {
11216: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
11217: } else {
11218: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11219: }
11220: }
1.160.6.34 raeburn 11221: }
11222: } else {
11223: if ($env{'form.cancreate_'.$item}) {
11224: push(@{$cancreate{'selfcreate'}},$item);
11225: }
11226: }
11227: }
11228: my (@email_rule,%userinfo,%savecaptcha);
11229: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11230: #
1.160.6.35 raeburn 11231: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11232: # 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 11233: #
1.160.6.40 raeburn 11234:
1.160.6.48 raeburn 11235: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 11236: push(@contexts,'emailusername');
1.160.6.35 raeburn 11237: if (ref($types) eq 'ARRAY') {
11238: foreach my $type (@{$types}) {
11239: if (ref($infofields) eq 'ARRAY') {
11240: foreach my $field (@{$infofields}) {
11241: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11242: $cancreate{'emailusername'}{$type}{$field} = $1;
11243: }
11244: }
1.160.6.34 raeburn 11245: }
11246: }
11247: }
11248: #
11249: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
11250: # queued requests for self-creation of account using e-mail address as username
11251: #
11252:
11253: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11254: @approvalnotify = sort(@approvalnotify);
11255: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11256: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11257: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11258: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11259: push(@{$changes{'cancreate'}},'notify');
11260: }
11261: } else {
11262: if ($cancreate{'notify'}{'approval'}) {
11263: push(@{$changes{'cancreate'}},'notify');
11264: }
11265: }
11266: } elsif ($cancreate{'notify'}{'approval'}) {
11267: push(@{$changes{'cancreate'}},'notify');
11268: }
11269:
11270: #
11271: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
11272: #
11273: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
11274: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11275: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11276: if (@{$curr_usercreation{'email_rule'}} > 0) {
11277: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
11278: if (!grep(/^\Q$type\E$/,@email_rule)) {
11279: push(@{$changes{'email_rule'}},$type);
11280: }
11281: }
11282: }
11283: if (@email_rule > 0) {
11284: foreach my $type (@email_rule) {
11285: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
11286: push(@{$changes{'email_rule'}},$type);
11287: }
11288: }
11289: }
11290: } elsif (@email_rule > 0) {
11291: push(@{$changes{'email_rule'}},@email_rule);
11292: }
11293: }
11294: #
1.160.6.40 raeburn 11295: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 11296: # institutional log-in.
11297: #
11298: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11299: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11300: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11301: ($domdefaults{'auth_def'} eq 'localauth'))) {
11302: $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.').' '.
11303: &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.');
11304: }
11305: }
11306: my @fields = ('lastname','firstname','middlename','generation',
11307: 'permanentemail','id');
1.160.6.44 raeburn 11308: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 11309: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11310: #
11311: # Where usernames may created for institutional log-in and/or institutional single sign on:
11312: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11313: # may self-create accounts
11314: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11315: # which the user may supply, if institutional data is unavailable.
11316: #
11317: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
11318: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 11319: if (@{$types} > 1) {
1.160.6.34 raeburn 11320: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11321: push(@contexts,'statustocreate');
11322: } else {
11323: undef($cancreate{'statustocreate'});
11324: }
11325: foreach my $type (@{$types}) {
11326: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11327: foreach my $field (@fields) {
11328: if (grep(/^\Q$field\E$/,@modifiable)) {
11329: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11330: } else {
11331: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11332: }
11333: }
11334: }
11335: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
11336: foreach my $type (@{$types}) {
11337: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11338: foreach my $field (@fields) {
11339: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11340: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11341: push(@{$changes{'selfcreate'}},$type);
11342: last;
11343: }
11344: }
11345: }
11346: }
11347: } else {
11348: foreach my $type (@{$types}) {
11349: push(@{$changes{'selfcreate'}},$type);
11350: }
11351: }
11352: }
1.160.6.44 raeburn 11353: foreach my $field (@shibfields) {
11354: if ($env{'form.shibenv_'.$field} ne '') {
11355: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11356: }
11357: }
11358: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11359: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11360: foreach my $field (@shibfields) {
11361: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11362: push(@{$changes{'cancreate'}},'shibenv');
11363: }
11364: }
11365: } else {
11366: foreach my $field (@shibfields) {
11367: if ($env{'form.shibenv_'.$field}) {
11368: push(@{$changes{'cancreate'}},'shibenv');
11369: last;
11370: }
11371: }
11372: }
11373: }
1.160.6.34 raeburn 11374: }
11375: foreach my $item (@contexts) {
11376: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11377: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11378: if (ref($cancreate{$item}) eq 'ARRAY') {
11379: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11380: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11381: push(@{$changes{'cancreate'}},$item);
11382: }
11383: }
11384: }
11385: }
11386: if (ref($cancreate{$item}) eq 'ARRAY') {
11387: foreach my $type (@{$cancreate{$item}}) {
11388: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11389: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11390: push(@{$changes{'cancreate'}},$item);
11391: }
11392: }
11393: }
11394: }
11395: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11396: if (ref($cancreate{$item}) eq 'HASH') {
11397: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 11398: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
11399: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
11400: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
11401: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11402: push(@{$changes{'cancreate'}},$item);
11403: }
11404: }
11405: }
1.160.6.40 raeburn 11406: } elsif ($item eq 'selfcreateprocessing') {
11407: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
11408: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11409: push(@{$changes{'cancreate'}},$item);
11410: }
11411: }
1.160.6.35 raeburn 11412: } else {
11413: if (!$cancreate{$item}{$curr}) {
11414: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11415: push(@{$changes{'cancreate'}},$item);
11416: }
1.160.6.34 raeburn 11417: }
11418: }
11419: }
11420: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 11421: if (ref($cancreate{$item}{$field}) eq 'HASH') {
11422: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
11423: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
11424: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
11425: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11426: push(@{$changes{'cancreate'}},$item);
11427: }
11428: }
11429: } else {
11430: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11431: push(@{$changes{'cancreate'}},$item);
11432: }
11433: }
11434: }
1.160.6.40 raeburn 11435: } elsif ($item eq 'selfcreateprocessing') {
11436: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
11437: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11438: push(@{$changes{'cancreate'}},$item);
11439: }
11440: }
1.160.6.35 raeburn 11441: } else {
11442: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
11443: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11444: push(@{$changes{'cancreate'}},$item);
11445: }
1.160.6.34 raeburn 11446: }
11447: }
11448: }
11449: }
11450: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11451: if (ref($cancreate{$item}) eq 'ARRAY') {
11452: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11453: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11454: push(@{$changes{'cancreate'}},$item);
11455: }
11456: }
11457: } elsif (ref($cancreate{$item}) eq 'HASH') {
11458: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
11459: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11460: push(@{$changes{'cancreate'}},$item);
11461: }
11462: }
11463: }
11464: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 11465: if (ref($cancreate{$item}) eq 'HASH') {
11466: foreach my $type (keys(%{$cancreate{$item}})) {
11467: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11468: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11469: if ($cancreate{$item}{$type}{$field}) {
11470: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11471: push(@{$changes{'cancreate'}},$item);
11472: }
11473: last;
11474: }
11475: }
11476: }
11477: }
1.160.6.34 raeburn 11478: }
11479: }
11480: }
11481: #
11482: # Populate %save_usercreate hash with updates to self-creation configuration.
11483: #
11484: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11485: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 11486: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 11487: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11488: if (ref($cancreate{'notify'}) eq 'HASH') {
11489: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11490: }
1.160.6.40 raeburn 11491: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11492: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11493: }
1.160.6.34 raeburn 11494: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11495: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11496: }
1.160.6.44 raeburn 11497: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11498: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11499: }
1.160.6.34 raeburn 11500: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.84.2. (raeburn 11501:): $save_usercreate{'email_rule'} = \@email_rule;
1.160.6.34 raeburn 11502:
11503: my %userconfig_hash = (
11504: usercreation => \%save_usercreate,
11505: usermodification => \%save_usermodify,
11506: );
11507: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11508: $dom);
11509: #
11510: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
11511: #
1.27 raeburn 11512: if ($putresult eq 'ok') {
11513: if (keys(%changes) > 0) {
11514: $resulttext = &mt('Changes made:').'<ul>';
11515: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 11516: my %lt = &selfcreation_types();
1.34 raeburn 11517: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 11518: my $chgtext;
1.45 raeburn 11519: if ($type eq 'selfcreate') {
1.50 raeburn 11520: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 11521: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11522: } else {
1.160.6.34 raeburn 11523: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11524: '<ul>';
1.50 raeburn 11525: foreach my $case (@{$cancreate{$type}}) {
11526: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11527: }
11528: $chgtext .= '</ul>';
1.100 raeburn 11529: if (ref($cancreate{$type}) eq 'ARRAY') {
11530: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11531: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11532: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 11533: $chgtext .= '<br />'.
11534: '<span class="LC_warning">'.
11535: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11536: '</span>';
1.100 raeburn 11537: }
11538: }
11539: }
11540: }
1.43 raeburn 11541: }
1.160.6.44 raeburn 11542: } elsif ($type eq 'shibenv') {
11543: if (keys(%{$cancreate{$type}}) == 0) {
11544: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
11545: } else {
11546: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11547: '<ul>';
11548: foreach my $field (@shibfields) {
11549: next if ($cancreate{$type}{$field} eq '');
11550: if ($field eq 'inststatus') {
11551: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11552: } else {
11553: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11554: }
11555: }
11556: $chgtext .= '</ul>';
11557: }
1.93 raeburn 11558: } elsif ($type eq 'statustocreate') {
1.96 raeburn 11559: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11560: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11561: if (@{$cancreate{'selfcreate'}} > 0) {
11562: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 11563: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 11564: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 11565: $chgtext .= '<br />'.
11566: '<span class="LC_warning">'.
11567: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11568: '</span>';
11569: }
1.96 raeburn 11570: } elsif (ref($usertypes) eq 'HASH') {
11571: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 11572: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11573: } else {
11574: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11575: }
11576: $chgtext .= '<ul>';
11577: foreach my $case (@{$cancreate{$type}}) {
11578: if ($case eq 'default') {
11579: $chgtext .= '<li>'.$othertitle.'</li>';
11580: } else {
11581: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 11582: }
11583: }
1.100 raeburn 11584: $chgtext .= '</ul>';
11585: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 11586: $chgtext .= '<br /><span class="LC_warning">'.
11587: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11588: '</span>';
1.100 raeburn 11589: }
11590: }
11591: } else {
11592: if (@{$cancreate{$type}} == 0) {
11593: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11594: } else {
11595: $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 11596: }
11597: }
11598: }
1.160.6.40 raeburn 11599: } elsif ($type eq 'selfcreateprocessing') {
11600: my %choices = &Apache::lonlocal::texthash (
11601: automatic => 'Automatic approval',
11602: approval => 'Queued for approval',
11603: );
11604: if (@statuses > 1) {
11605: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
11606: '<ul>';
11607: foreach my $type (@statuses) {
11608: if ($type eq 'default') {
11609: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11610: } else {
11611: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11612: }
11613: }
11614: $chgtext .= '</ul>';
11615: } else {
11616: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
11617: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
11618: }
1.160.6.5 raeburn 11619: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 11620: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 11621: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11622: } else {
11623: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 11624: if ($captchas{$savecaptcha{$type}}) {
11625: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 11626: } else {
11627: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
11628: }
11629: }
11630: } elsif ($type eq 'recaptchakeys') {
11631: my ($privkey,$pubkey);
1.160.6.34 raeburn 11632: if (ref($savecaptcha{$type}) eq 'HASH') {
11633: $pubkey = $savecaptcha{$type}{'public'};
11634: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 11635: }
11636: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11637: if (!$pubkey) {
11638: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11639: } else {
11640: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11641: }
11642: if (!$privkey) {
11643: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11644: } else {
11645: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11646: }
11647: $chgtext .= '</ul>';
1.160.6.69 raeburn 11648: } elsif ($type eq 'recaptchaversion') {
11649: if ($savecaptcha{'captcha'} eq 'recaptcha') {
11650: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
11651: }
1.160.6.34 raeburn 11652: } elsif ($type eq 'emailusername') {
11653: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 11654: if (ref($types) eq 'ARRAY') {
11655: foreach my $type (@{$types}) {
11656: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11657: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 11658: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.160.6.35 raeburn 11659: '<ul>';
11660: foreach my $field (@{$infofields}) {
11661: if ($cancreate{'emailusername'}{$type}{$field}) {
11662: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11663: }
11664: }
1.160.6.50 raeburn 11665: $chgtext .= '</ul>';
11666: } else {
11667: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.160.6.35 raeburn 11668: }
11669: } else {
1.160.6.50 raeburn 11670: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.160.6.34 raeburn 11671: }
11672: }
11673: }
11674: }
11675: } elsif ($type eq 'notify') {
11676: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
11677: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11678: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11679: if ($cancreate{'notify'}{'approval'}) {
11680: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
11681: }
11682: }
1.43 raeburn 11683: }
1.34 raeburn 11684: }
1.160.6.34 raeburn 11685: if ($chgtext) {
11686: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 11687: }
11688: }
11689: }
1.43 raeburn 11690: if (ref($changes{'email_rule'}) eq 'ARRAY') {
11691: my ($emailrules,$emailruleorder) =
11692: &Apache::lonnet::inst_userrules($dom,'email');
11693: my $chgtext = '<ul>';
11694: foreach my $type (@email_rule) {
11695: if (ref($emailrules->{$type}) eq 'HASH') {
11696: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
11697: }
11698: }
11699: $chgtext .= '</ul>';
11700: if (@email_rule > 0) {
1.160.6.34 raeburn 11701: $resulttext .= '<li>'.
11702: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
11703: $chgtext.
11704: '</li>';
1.43 raeburn 11705: } else {
1.160.6.34 raeburn 11706: $resulttext .= '<li>'.
11707: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
11708: '</li>';
1.43 raeburn 11709: }
11710: }
1.160.6.34 raeburn 11711: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
11712: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
11713: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11714: foreach my $type (@{$changes{'selfcreate'}}) {
11715: my $typename = $type;
11716: if (ref($usertypes) eq 'HASH') {
11717: if ($usertypes->{$type} ne '') {
11718: $typename = $usertypes->{$type};
1.28 raeburn 11719: }
11720: }
1.160.6.34 raeburn 11721: my @modifiable;
11722: $resulttext .= '<li>'.
11723: &mt('Self-creation of account by users with status: [_1]',
11724: '<span class="LC_cusr_emph">'.$typename.'</span>').
11725: ' - '.&mt('modifiable fields (if institutional data blank): ');
11726: foreach my $field (@fields) {
11727: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11728: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
11729: }
11730: }
11731: if (@modifiable > 0) {
11732: $resulttext .= join(', ',@modifiable);
1.43 raeburn 11733: } else {
1.160.6.34 raeburn 11734: $resulttext .= &mt('none');
1.43 raeburn 11735: }
1.160.6.34 raeburn 11736: $resulttext .= '</li>';
1.28 raeburn 11737: }
1.160.6.34 raeburn 11738: $resulttext .= '</ul></li>';
1.28 raeburn 11739: }
1.27 raeburn 11740: $resulttext .= '</ul>';
11741: } else {
1.160.6.34 raeburn 11742: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 11743: }
11744: } else {
11745: $resulttext = '<span class="LC_error">'.
1.23 raeburn 11746: &mt('An error occurred: [_1]',$putresult).'</span>';
11747: }
1.43 raeburn 11748: if ($warningmsg ne '') {
11749: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11750: }
1.23 raeburn 11751: return $resulttext;
11752: }
11753:
1.160.6.5 raeburn 11754: sub process_captcha {
11755: my ($container,$changes,$newsettings,$current) = @_;
11756: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
11757: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
11758: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
11759: $newsettings->{'captcha'} = 'original';
11760: }
11761: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
11762: if ($container eq 'cancreate') {
11763: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11764: push(@{$changes->{'cancreate'}},'captcha');
11765: } elsif (!defined($changes->{'cancreate'})) {
11766: $changes->{'cancreate'} = ['captcha'];
11767: }
11768: } else {
11769: $changes->{'captcha'} = 1;
11770: }
11771: }
1.160.6.69 raeburn 11772: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 11773: if ($newsettings->{'captcha'} eq 'recaptcha') {
11774: $newpub = $env{'form.'.$container.'_recaptchapub'};
11775: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 11776: $newpub =~ s/[^\w\-]//g;
11777: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 11778: $newsettings->{'recaptchakeys'} = {
11779: public => $newpub,
11780: private => $newpriv,
11781: };
1.160.6.69 raeburn 11782: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11783: $newversion =~ s/\D//g;
11784: if ($newversion ne '2') {
11785: $newversion = 1;
11786: }
11787: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 11788: }
11789: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11790: $currpub = $current->{'recaptchakeys'}{'public'};
11791: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 11792: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11793: $newsettings->{'recaptchakeys'} = {
11794: public => '',
11795: private => '',
11796: }
11797: }
1.160.6.5 raeburn 11798: }
1.160.6.69 raeburn 11799: if ($current->{'captcha'} eq 'recaptcha') {
11800: $currversion = $current->{'recaptchaversion'};
11801: if ($currversion ne '2') {
11802: $currversion = 1;
11803: }
11804: }
11805: if ($currversion ne $newversion) {
11806: if ($container eq 'cancreate') {
11807: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11808: push(@{$changes->{'cancreate'}},'recaptchaversion');
11809: } elsif (!defined($changes->{'cancreate'})) {
11810: $changes->{'cancreate'} = ['recaptchaversion'];
11811: }
11812: } else {
11813: $changes->{'recaptchaversion'} = 1;
11814: }
11815: }
1.160.6.5 raeburn 11816: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
11817: if ($container eq 'cancreate') {
11818: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11819: push(@{$changes->{'cancreate'}},'recaptchakeys');
11820: } elsif (!defined($changes->{'cancreate'})) {
11821: $changes->{'cancreate'} = ['recaptchakeys'];
11822: }
11823: } else {
11824: $changes->{'recaptchakeys'} = 1;
11825: }
11826: }
11827: return;
11828: }
11829:
1.33 raeburn 11830: sub modify_usermodification {
11831: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 11832: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 11833: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11834: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 11835: if ($key eq 'selfcreate') {
11836: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
11837: } else {
11838: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
11839: }
1.33 raeburn 11840: }
11841: }
1.160.6.34 raeburn 11842: my @contexts = ('author','course');
1.33 raeburn 11843: my %context_title = (
11844: author => 'In author context',
11845: course => 'In course context',
11846: );
11847: my @fields = ('lastname','firstname','middlename','generation',
11848: 'permanentemail','id');
11849: my %roles = (
11850: author => ['ca','aa'],
11851: course => ['st','ep','ta','in','cr'],
11852: );
11853: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11854: foreach my $context (@contexts) {
11855: foreach my $role (@{$roles{$context}}) {
11856: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
11857: foreach my $item (@fields) {
11858: if (grep(/^\Q$item\E$/,@modifiable)) {
11859: $modifyhash{$context}{$role}{$item} = 1;
11860: } else {
11861: $modifyhash{$context}{$role}{$item} = 0;
11862: }
11863: }
11864: }
11865: if (ref($curr_usermodification{$context}) eq 'HASH') {
11866: foreach my $role (@{$roles{$context}}) {
11867: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11868: foreach my $field (@fields) {
11869: if ($modifyhash{$context}{$role}{$field} ne
11870: $curr_usermodification{$context}{$role}{$field}) {
11871: push(@{$changes{$context}},$role);
11872: last;
11873: }
11874: }
11875: }
11876: }
11877: } else {
11878: foreach my $context (@contexts) {
11879: foreach my $role (@{$roles{$context}}) {
11880: push(@{$changes{$context}},$role);
11881: }
11882: }
11883: }
11884: }
11885: my %usermodification_hash = (
11886: usermodification => \%modifyhash,
11887: );
11888: my $putresult = &Apache::lonnet::put_dom('configuration',
11889: \%usermodification_hash,$dom);
11890: if ($putresult eq 'ok') {
11891: if (keys(%changes) > 0) {
11892: $resulttext = &mt('Changes made: ').'<ul>';
11893: foreach my $context (@contexts) {
11894: if (ref($changes{$context}) eq 'ARRAY') {
11895: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11896: if (ref($changes{$context}) eq 'ARRAY') {
11897: foreach my $role (@{$changes{$context}}) {
11898: my $rolename;
1.160.6.34 raeburn 11899: if ($role eq 'cr') {
11900: $rolename = &mt('Custom');
1.33 raeburn 11901: } else {
1.160.6.34 raeburn 11902: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 11903: }
11904: my @modifiable;
1.160.6.34 raeburn 11905: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 11906: foreach my $field (@fields) {
11907: if ($modifyhash{$context}{$role}{$field}) {
11908: push(@modifiable,$fieldtitles{$field});
11909: }
11910: }
11911: if (@modifiable > 0) {
11912: $resulttext .= join(', ',@modifiable);
11913: } else {
11914: $resulttext .= &mt('none');
11915: }
11916: $resulttext .= '</li>';
11917: }
11918: $resulttext .= '</ul></li>';
11919: }
11920: }
11921: }
11922: $resulttext .= '</ul>';
11923: } else {
11924: $resulttext = &mt('No changes made to user modification settings');
11925: }
11926: } else {
11927: $resulttext = '<span class="LC_error">'.
11928: &mt('An error occurred: [_1]',$putresult).'</span>';
11929: }
11930: return $resulttext;
11931: }
11932:
1.43 raeburn 11933: sub modify_defaults {
1.160.6.27 raeburn 11934: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 11935: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 11936: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 11937: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
11938: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 11939: my @authtypes = ('internal','krb4','krb5','localauth');
11940: foreach my $item (@items) {
11941: $newvalues{$item} = $env{'form.'.$item};
11942: if ($item eq 'auth_def') {
11943: if ($newvalues{$item} ne '') {
11944: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11945: push(@errors,$item);
11946: }
11947: }
11948: } elsif ($item eq 'lang_def') {
11949: if ($newvalues{$item} ne '') {
11950: if ($newvalues{$item} =~ /^(\w+)/) {
11951: my $langcode = $1;
1.103 raeburn 11952: if ($langcode ne 'x_chef') {
11953: if (code2language($langcode) eq '') {
11954: push(@errors,$item);
11955: }
1.43 raeburn 11956: }
11957: } else {
11958: push(@errors,$item);
11959: }
11960: }
1.54 raeburn 11961: } elsif ($item eq 'timezone_def') {
11962: if ($newvalues{$item} ne '') {
1.62 raeburn 11963: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 11964: push(@errors,$item);
11965: }
11966: }
1.68 raeburn 11967: } elsif ($item eq 'datelocale_def') {
11968: if ($newvalues{$item} ne '') {
11969: my @datelocale_ids = DateTime::Locale->ids();
11970: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11971: push(@errors,$item);
11972: }
11973: }
1.141 raeburn 11974: } elsif ($item eq 'portal_def') {
11975: if ($newvalues{$item} ne '') {
11976: 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])\/?$/) {
11977: push(@errors,$item);
11978: }
11979: }
1.160.6.80 raeburn 11980: } elsif ($item eq 'intauth_cost') {
11981: if ($newvalues{$item} ne '') {
11982: if ($newvalues{$item} =~ /\D/) {
11983: push(@errors,$item);
11984: }
11985: }
11986: } elsif ($item eq 'intauth_check') {
11987: if ($newvalues{$item} ne '') {
11988: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11989: push(@errors,$item);
11990: }
11991: }
11992: } elsif ($item eq 'intauth_switch') {
11993: if ($newvalues{$item} ne '') {
11994: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11995: push(@errors,$item);
11996: }
11997: }
1.43 raeburn 11998: }
11999: if (grep(/^\Q$item\E$/,@errors)) {
12000: $newvalues{$item} = $domdefaults{$item};
12001: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
12002: $changes{$item} = 1;
12003: }
1.72 raeburn 12004: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 12005: }
12006: my %defaults_hash = (
1.72 raeburn 12007: defaults => \%newvalues,
12008: );
1.43 raeburn 12009: my $title = &defaults_titles();
1.160.6.40 raeburn 12010:
12011: my $currinststatus;
12012: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12013: $currinststatus = $domconfig{'inststatus'};
12014: } else {
12015: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12016: $currinststatus = {
12017: inststatustypes => $usertypes,
12018: inststatusorder => $types,
12019: inststatusguest => [],
12020: };
12021: }
12022: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
12023: my @allpos;
12024: my %guests;
12025: my %alltypes;
12026: my ($currtitles,$currguests,$currorder);
12027: if (ref($currinststatus) eq 'HASH') {
12028: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
12029: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
12030: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
12031: if ($currinststatus->{inststatustypes}->{$type} ne '') {
12032: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
12033: }
12034: }
12035: unless (grep(/^\Q$type\E$/,@todelete)) {
12036: my $position = $env{'form.inststatus_pos_'.$type};
12037: $position =~ s/\D+//g;
12038: $allpos[$position] = $type;
12039: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
12040: $alltypes{$type} =~ s/`//g;
12041: if ($env{'form.inststatus_guest_'.$type}) {
12042: $guests{$type} = 1;
12043: }
12044: }
12045: }
12046: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
12047: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
12048: }
12049: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
12050: $currtitles =~ s/,$//;
12051: }
12052: }
12053: if ($env{'form.addinststatus'}) {
12054: my $newtype = $env{'form.addinststatus'};
12055: $newtype =~ s/\W//g;
12056: unless (exists($alltypes{$newtype})) {
12057: if ($env{'form.addinststatus_guest'}) {
12058: $guests{$newtype} = 1;
12059: }
12060: $alltypes{$newtype} = $env{'form.addinststatus_title'};
12061: $alltypes{$newtype} =~ s/`//g;
12062: my $position = $env{'form.addinststatus_pos'};
12063: $position =~ s/\D+//g;
12064: if ($position ne '') {
12065: $allpos[$position] = $newtype;
12066: }
12067: }
12068: }
12069: my (@orderedstatus,@orderedguests);
12070: foreach my $type (@allpos) {
12071: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
12072: push(@orderedstatus,$type);
12073: if ($guests{$type}) {
12074: push(@orderedguests,$type);
12075: }
12076: }
12077: }
12078: foreach my $type (keys(%alltypes)) {
12079: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
12080: delete($alltypes{$type});
12081: }
12082: }
12083: $defaults_hash{'inststatus'} = {
12084: inststatustypes => \%alltypes,
12085: inststatusorder => \@orderedstatus,
12086: inststatusguest => \@orderedguests,
12087: };
12088: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12089: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12090: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12091: }
12092: }
12093: if ($currorder ne join(',',@orderedstatus)) {
12094: $changes{'inststatus'}{'inststatusorder'} = 1;
12095: }
12096: if ($currguests ne join(',',@orderedguests)) {
12097: $changes{'inststatus'}{'inststatusguest'} = 1;
12098: }
12099: my $newtitles;
12100: foreach my $item (@orderedstatus) {
12101: $newtitles .= $alltypes{$item}.',';
12102: }
12103: $newtitles =~ s/,$//;
12104: if ($currtitles ne $newtitles) {
12105: $changes{'inststatus'}{'inststatustypes'} = 1;
12106: }
1.43 raeburn 12107: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12108: $dom);
12109: if ($putresult eq 'ok') {
12110: if (keys(%changes) > 0) {
12111: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 12112: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 12113: 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";
12114: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 12115: if ($item eq 'inststatus') {
12116: if (ref($changes{'inststatus'}) eq 'HASH') {
12117: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
12118: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12119: foreach my $type (@orderedstatus) {
12120: $resulttext .= $alltypes{$type}.', ';
12121: }
12122: $resulttext =~ s/, $//;
12123: $resulttext .= '</li>';
12124: }
12125: if ($changes{'inststatus'}{'inststatusguest'}) {
12126: $resulttext .= '<li>';
12127: if (@orderedguests) {
12128: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
12129: foreach my $type (@orderedguests) {
12130: $resulttext .= $alltypes{$type}.', ';
12131: }
12132: $resulttext =~ s/, $//;
12133: } else {
12134: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
12135: }
12136: $resulttext .= '</li>';
12137: }
12138: }
12139: } else {
12140: my $value = $env{'form.'.$item};
12141: if ($value eq '') {
12142: $value = &mt('none');
12143: } elsif ($item eq 'auth_def') {
12144: my %authnames = &authtype_names();
12145: my %shortauth = (
12146: internal => 'int',
12147: krb4 => 'krb4',
12148: krb5 => 'krb5',
12149: localauth => 'loc',
12150: );
12151: $value = $authnames{$shortauth{$value}};
1.160.6.80 raeburn 12152: } elsif ($item eq 'intauth_switch') {
12153: my %optiondesc = &Apache::lonlocal::texthash (
12154: 0 => 'No',
12155: 1 => 'Yes',
12156: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12157: );
12158: if ($value =~ /^(0|1|2)$/) {
12159: $value = $optiondesc{$value};
12160: } else {
12161: $value = &mt('none -- defaults to No');
12162: }
12163: } elsif ($item eq 'intauth_check') {
12164: my %optiondesc = &Apache::lonlocal::texthash (
12165: 0 => 'No',
12166: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12167: 2 => 'Yes, disallow login if stored cost is less than domain default',
12168: );
12169: if ($value =~ /^(0|1|2)$/) {
12170: $value = $optiondesc{$value};
12171: } else {
12172: $value = &mt('none -- defaults to No');
12173: }
1.160.6.40 raeburn 12174: }
12175: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12176: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 12177: }
12178: }
12179: $resulttext .= '</ul>';
12180: $mailmsgtext .= "\n";
12181: my $cachetime = 24*60*60;
1.72 raeburn 12182: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 12183: if (ref($lastactref) eq 'HASH') {
12184: $lastactref->{'domdefaults'} = 1;
12185: }
1.68 raeburn 12186: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 12187: my $notify = 1;
12188: if (ref($domconfig{'contacts'}) eq 'HASH') {
12189: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12190: $notify = 0;
12191: }
12192: }
12193: if ($notify) {
12194: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12195: "LON-CAPA Domain Settings Change - $dom",
12196: $mailmsgtext);
12197: }
1.54 raeburn 12198: }
1.43 raeburn 12199: } else {
1.54 raeburn 12200: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 12201: }
12202: } else {
12203: $resulttext = '<span class="LC_error">'.
12204: &mt('An error occurred: [_1]',$putresult).'</span>';
12205: }
12206: if (@errors > 0) {
12207: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12208: foreach my $item (@errors) {
12209: $resulttext .= ' "'.$title->{$item}.'",';
12210: }
12211: $resulttext =~ s/,$//;
12212: }
12213: return $resulttext;
12214: }
12215:
1.46 raeburn 12216: sub modify_scantron {
1.160.6.24 raeburn 12217: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 12218: my ($resulttext,%confhash,%changes,$errors);
12219: my $custom = 'custom.tab';
12220: my $default = 'default.tab';
12221: my $servadm = $r->dir_config('lonAdmEMail');
12222: my ($configuserok,$author_ok,$switchserver) =
12223: &config_check($dom,$confname,$servadm);
12224: if ($env{'form.scantronformat.filename'} ne '') {
12225: my $error;
12226: if ($configuserok eq 'ok') {
12227: if ($switchserver) {
1.130 raeburn 12228: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 12229: } else {
12230: if ($author_ok eq 'ok') {
12231: my ($result,$scantronurl) =
12232: &publishlogo($r,'upload','scantronformat',$dom,
12233: $confname,'scantron','','',$custom);
12234: if ($result eq 'ok') {
12235: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 12236: $changes{'scantronformat'} = 1;
1.46 raeburn 12237: } else {
12238: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12239: }
12240: } else {
12241: $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);
12242: }
12243: }
12244: } else {
12245: $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);
12246: }
12247: if ($error) {
12248: &Apache::lonnet::logthis($error);
12249: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12250: }
12251: }
1.48 raeburn 12252: if (ref($domconfig{'scantron'}) eq 'HASH') {
12253: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12254: if ($env{'form.scantronformat_del'}) {
12255: $confhash{'scantron'}{'scantronformat'} = '';
12256: $changes{'scantronformat'} = 1;
1.46 raeburn 12257: }
12258: }
12259: }
12260: if (keys(%confhash) > 0) {
12261: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12262: $dom);
12263: if ($putresult eq 'ok') {
12264: if (keys(%changes) > 0) {
1.48 raeburn 12265: if (ref($confhash{'scantron'}) eq 'HASH') {
12266: $resulttext = &mt('Changes made:').'<ul>';
12267: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 12268: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 12269: } else {
1.130 raeburn 12270: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 12271: }
1.48 raeburn 12272: $resulttext .= '</ul>';
12273: } else {
1.130 raeburn 12274: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 12275: }
12276: $resulttext .= '</ul>';
12277: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12278: if (ref($lastactref) eq 'HASH') {
12279: $lastactref->{'domainconfig'} = 1;
12280: }
1.46 raeburn 12281: } else {
1.130 raeburn 12282: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12283: }
12284: } else {
12285: $resulttext = '<span class="LC_error">'.
12286: &mt('An error occurred: [_1]',$putresult).'</span>';
12287: }
12288: } else {
1.130 raeburn 12289: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12290: }
12291: if ($errors) {
12292: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12293: $errors.'</ul>';
12294: }
12295: return $resulttext;
12296: }
12297:
1.48 raeburn 12298: sub modify_coursecategories {
1.160.6.43 raeburn 12299: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12300: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12301: $cathash);
1.48 raeburn 12302: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 12303: my @catitems = ('unauth','auth');
12304: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12305: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12306: $cathash = $domconfig{'coursecategories'}{'cats'};
12307: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12308: $changes{'togglecats'} = 1;
12309: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12310: }
12311: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12312: $changes{'categorize'} = 1;
12313: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12314: }
1.120 raeburn 12315: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12316: $changes{'togglecatscomm'} = 1;
12317: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12318: }
12319: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12320: $changes{'categorizecomm'} = 1;
12321: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
12322: }
1.160.6.42 raeburn 12323: foreach my $item (@catitems) {
12324: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12325: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12326: $changes{$item} = 1;
12327: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12328: }
12329: }
12330: }
1.57 raeburn 12331: } else {
12332: $changes{'togglecats'} = 1;
12333: $changes{'categorize'} = 1;
1.124 raeburn 12334: $changes{'togglecatscomm'} = 1;
12335: $changes{'categorizecomm'} = 1;
1.87 raeburn 12336: $domconfig{'coursecategories'} = {
12337: togglecats => $env{'form.togglecats'},
12338: categorize => $env{'form.categorize'},
1.124 raeburn 12339: togglecatscomm => $env{'form.togglecatscomm'},
12340: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 12341: };
1.160.6.42 raeburn 12342: foreach my $item (@catitems) {
12343: if ($env{'form.coursecat_'.$item} ne 'std') {
12344: $changes{$item} = 1;
12345: }
12346: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12347: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12348: }
12349: }
1.57 raeburn 12350: }
12351: if (ref($cathash) eq 'HASH') {
12352: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12353: push (@deletecategory,'instcode::0');
12354: }
1.120 raeburn 12355: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12356: push(@deletecategory,'communities::0');
12357: }
1.48 raeburn 12358: }
1.57 raeburn 12359: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12360: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12361: if (@deletecategory > 0) {
12362: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12363: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12364: foreach my $item (@deletecategory) {
1.57 raeburn 12365: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12366: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12367: $deletions{$item} = 1;
1.57 raeburn 12368: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12369: }
12370: }
12371: }
1.57 raeburn 12372: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12373: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12374: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12375: $reorderings{$item} = 1;
1.57 raeburn 12376: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12377: }
12378: if ($env{'form.addcategory_name_'.$item} ne '') {
12379: my $newcat = $env{'form.addcategory_name_'.$item};
12380: my $newdepth = $depth+1;
12381: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12382: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12383: $adds{$newitem} = 1;
12384: }
12385: if ($env{'form.subcat_'.$item} ne '') {
12386: my $newcat = $env{'form.subcat_'.$item};
12387: my $newdepth = $depth+1;
12388: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12389: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 12390: $adds{$newitem} = 1;
12391: }
12392: }
12393: }
12394: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 12395: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12396: my $newitem = 'instcode::0';
1.57 raeburn 12397: if ($cathash->{$newitem} eq '') {
12398: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12399: $adds{$newitem} = 1;
12400: }
12401: } else {
12402: my $newitem = 'instcode::0';
1.57 raeburn 12403: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12404: $adds{$newitem} = 1;
12405: }
12406: }
1.120 raeburn 12407: if ($env{'form.communities'} eq '1') {
12408: if (ref($cathash) eq 'HASH') {
12409: my $newitem = 'communities::0';
12410: if ($cathash->{$newitem} eq '') {
12411: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12412: $adds{$newitem} = 1;
12413: }
12414: } else {
12415: my $newitem = 'communities::0';
12416: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12417: $adds{$newitem} = 1;
12418: }
12419: }
1.48 raeburn 12420: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 12421: if (($env{'form.addcategory_name'} ne 'instcode') &&
12422: ($env{'form.addcategory_name'} ne 'communities')) {
12423: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12424: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12425: $adds{$newitem} = 1;
12426: }
1.48 raeburn 12427: }
1.57 raeburn 12428: my $putresult;
1.48 raeburn 12429: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12430: if (keys(%deletions) > 0) {
12431: foreach my $key (keys(%deletions)) {
12432: if ($predelallitems{$key} ne '') {
12433: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12434: }
12435: }
12436: }
12437: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 12438: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 12439: if (ref($chkcats[0]) eq 'ARRAY') {
12440: my $depth = 0;
12441: my $chg = 0;
12442: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12443: my $name = $chkcats[0][$i];
12444: my $item;
12445: if ($name eq '') {
12446: $chg ++;
12447: } else {
12448: $item = &escape($name).'::0';
12449: if ($chg) {
1.57 raeburn 12450: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12451: }
12452: $depth ++;
1.57 raeburn 12453: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12454: $depth --;
12455: }
12456: }
12457: }
1.57 raeburn 12458: }
12459: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12460: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12461: if ($putresult eq 'ok') {
1.57 raeburn 12462: my %title = (
1.120 raeburn 12463: togglecats => 'Show/Hide a course in catalog',
12464: categorize => 'Assign a category to a course',
12465: togglecatscomm => 'Show/Hide a community in catalog',
12466: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12467: );
12468: my %level = (
1.120 raeburn 12469: dom => 'set in Domain ("Modify Course/Community")',
12470: crs => 'set in Course ("Course Configuration")',
12471: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 12472: none => 'No catalog',
12473: std => 'Standard catalog',
12474: domonly => 'Domain-only catalog',
12475: codesrch => 'Code search form',
1.57 raeburn 12476: );
1.48 raeburn 12477: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12478: if ($changes{'togglecats'}) {
12479: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12480: }
12481: if ($changes{'categorize'}) {
12482: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12483: }
1.120 raeburn 12484: if ($changes{'togglecatscomm'}) {
12485: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12486: }
12487: if ($changes{'categorizecomm'}) {
12488: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12489: }
1.160.6.42 raeburn 12490: if ($changes{'unauth'}) {
12491: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12492: }
12493: if ($changes{'auth'}) {
12494: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12495: }
1.57 raeburn 12496: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12497: my $cathash;
12498: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12499: $cathash = $domconfig{'coursecategories'}{'cats'};
12500: } else {
12501: $cathash = {};
12502: }
12503: my (@cats,@trails,%allitems);
12504: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12505: if (keys(%deletions) > 0) {
12506: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12507: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12508: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12509: }
12510: $resulttext .= '</ul></li>';
12511: }
12512: if (keys(%reorderings) > 0) {
12513: my %sort_by_trail;
12514: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12515: foreach my $key (keys(%reorderings)) {
12516: if ($allitems{$key} ne '') {
12517: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12518: }
1.48 raeburn 12519: }
1.57 raeburn 12520: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12521: $resulttext .= '<li>'.$trails[$trail].'</li>';
12522: }
12523: $resulttext .= '</ul></li>';
1.48 raeburn 12524: }
1.57 raeburn 12525: if (keys(%adds) > 0) {
12526: my %sort_by_trail;
12527: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12528: foreach my $key (keys(%adds)) {
12529: if ($allitems{$key} ne '') {
12530: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12531: }
12532: }
12533: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12534: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 12535: }
1.57 raeburn 12536: $resulttext .= '</ul></li>';
1.48 raeburn 12537: }
12538: }
12539: $resulttext .= '</ul>';
1.160.6.43 raeburn 12540: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 12541: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12542: if ($changes{'auth'}) {
12543: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12544: }
12545: if ($changes{'unauth'}) {
12546: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12547: }
12548: my $cachetime = 24*60*60;
12549: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 12550: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 12551: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 12552: }
12553: }
1.48 raeburn 12554: } else {
12555: $resulttext = '<span class="LC_error">'.
1.57 raeburn 12556: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 12557: }
12558: } else {
1.120 raeburn 12559: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 12560: }
12561: return $resulttext;
12562: }
12563:
1.69 raeburn 12564: sub modify_serverstatuses {
12565: my ($dom,%domconfig) = @_;
12566: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12567: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12568: %currserverstatus = %{$domconfig{'serverstatuses'}};
12569: }
12570: my @pages = &serverstatus_pages();
12571: foreach my $type (@pages) {
12572: $newserverstatus{$type}{'namedusers'} = '';
12573: $newserverstatus{$type}{'machines'} = '';
12574: if (defined($env{'form.'.$type.'_namedusers'})) {
12575: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12576: my @okusers;
12577: foreach my $user (@users) {
12578: my ($uname,$udom) = split(/:/,$user);
12579: if (($udom =~ /^$match_domain$/) &&
12580: (&Apache::lonnet::domain($udom)) &&
12581: ($uname =~ /^$match_username$/)) {
12582: if (!grep(/^\Q$user\E/,@okusers)) {
12583: push(@okusers,$user);
12584: }
12585: }
12586: }
12587: if (@okusers > 0) {
12588: @okusers = sort(@okusers);
12589: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
12590: }
12591: }
12592: if (defined($env{'form.'.$type.'_machines'})) {
12593: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
12594: my @okmachines;
12595: foreach my $ip (@machines) {
12596: my @parts = split(/\./,$ip);
12597: next if (@parts < 4);
12598: my $badip = 0;
12599: for (my $i=0; $i<4; $i++) {
12600: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
12601: $badip = 1;
12602: last;
12603: }
12604: }
12605: if (!$badip) {
12606: push(@okmachines,$ip);
12607: }
12608: }
12609: @okmachines = sort(@okmachines);
12610: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
12611: }
12612: }
12613: my %serverstatushash = (
12614: serverstatuses => \%newserverstatus,
12615: );
12616: foreach my $type (@pages) {
1.83 raeburn 12617: foreach my $setting ('namedusers','machines') {
1.84 raeburn 12618: my (@current,@new);
1.83 raeburn 12619: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 12620: if ($currserverstatus{$type}{$setting} ne '') {
12621: @current = split(/,/,$currserverstatus{$type}{$setting});
12622: }
12623: }
12624: if ($newserverstatus{$type}{$setting} ne '') {
12625: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 12626: }
12627: if (@current > 0) {
12628: if (@new > 0) {
12629: foreach my $item (@current) {
12630: if (!grep(/^\Q$item\E$/,@new)) {
12631: $changes{$type}{$setting} = 1;
1.82 raeburn 12632: last;
12633: }
12634: }
1.84 raeburn 12635: foreach my $item (@new) {
12636: if (!grep(/^\Q$item\E$/,@current)) {
12637: $changes{$type}{$setting} = 1;
12638: last;
1.82 raeburn 12639: }
12640: }
12641: } else {
1.83 raeburn 12642: $changes{$type}{$setting} = 1;
1.69 raeburn 12643: }
1.83 raeburn 12644: } elsif (@new > 0) {
12645: $changes{$type}{$setting} = 1;
1.69 raeburn 12646: }
12647: }
12648: }
12649: if (keys(%changes) > 0) {
1.81 raeburn 12650: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 12651: my $putresult = &Apache::lonnet::put_dom('configuration',
12652: \%serverstatushash,$dom);
12653: if ($putresult eq 'ok') {
12654: $resulttext .= &mt('Changes made:').'<ul>';
12655: foreach my $type (@pages) {
1.84 raeburn 12656: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 12657: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 12658: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 12659: if ($newserverstatus{$type}{'namedusers'} eq '') {
12660: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
12661: } else {
12662: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
12663: }
1.84 raeburn 12664: }
12665: if ($changes{$type}{'machines'}) {
1.69 raeburn 12666: if ($newserverstatus{$type}{'machines'} eq '') {
12667: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
12668: } else {
12669: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
12670: }
12671:
12672: }
12673: $resulttext .= '</ul></li>';
12674: }
12675: }
12676: $resulttext .= '</ul>';
12677: } else {
12678: $resulttext = '<span class="LC_error">'.
12679: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
12680:
12681: }
12682: } else {
12683: $resulttext = &mt('No changes made to access to server status pages');
12684: }
12685: return $resulttext;
12686: }
12687:
1.118 jms 12688: sub modify_helpsettings {
1.160.6.77 raeburn 12689: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 12690: my ($resulttext,$errors,%changes,%helphash);
12691: my %defaultchecked = ('submitbugs' => 'on');
12692: my @offon = ('off','on');
1.118 jms 12693: my @toggles = ('submitbugs');
1.160.6.77 raeburn 12694: my %current = ('submitbugs' => '',
12695: 'adhoc' => {},
12696: );
1.118 jms 12697: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 12698: %current = %{$domconfig{'helpsettings'}};
12699: }
1.160.6.77 raeburn 12700: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 12701: foreach my $item (@toggles) {
12702: if ($defaultchecked{$item} eq 'on') {
12703: if ($current{$item} eq '') {
12704: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 12705: $changes{$item} = 1;
12706: }
1.160.6.73 raeburn 12707: } elsif ($current{$item} ne $env{'form.'.$item}) {
12708: $changes{$item} = 1;
12709: }
12710: } elsif ($defaultchecked{$item} eq 'off') {
12711: if ($current{$item} eq '') {
12712: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 12713: $changes{$item} = 1;
12714: }
1.160.6.73 raeburn 12715: } elsif ($current{$item} ne $env{'form.'.$item}) {
12716: $changes{$item} = 1;
12717: }
12718: }
12719: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
12720: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
12721: }
12722: }
1.160.6.77 raeburn 12723: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 12724: my $confname = $dom.'-domainconfig';
12725: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 12726: my (@allpos,%newsettings,%changedprivs,$newrole);
12727: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 12728: my @accesstypes = ('all','dh','da','none','status','inc','exc');
12729: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 12730: my %lt = &Apache::lonlocal::texthash(
12731: s => 'system',
12732: d => 'domain',
12733: order => 'Display order',
12734: access => 'Role usage',
1.160.6.79 raeburn 12735: all => 'All with domain helpdesk or helpdesk assistant role',
12736: dh => 'All with domain helpdesk role',
12737: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 12738: none => 'None',
12739: status => 'Determined based on institutional status',
12740: inc => 'Include all, but exclude specific personnel',
12741: exc => 'Exclude all, but include specific personnel',
12742: );
12743: for (my $num=0; $num<=$maxnum; $num++) {
12744: my ($prefix,$identifier,$rolename,%curr);
12745: if ($num == $maxnum) {
12746: next unless ($env{'form.newcusthelp'} == $maxnum);
12747: $identifier = 'custhelp'.$num;
12748: $prefix = 'helproles_'.$num;
12749: $rolename = $env{'form.custhelpname'.$num};
12750: $rolename=~s/[^A-Za-z0-9]//gs;
12751: next if ($rolename eq '');
12752: next if (exists($existing{'rolesdef_'.$rolename}));
12753: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12754: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12755: $newprivs{'c'},$confname,$dom);
12756: if ($result ne 'ok') {
12757: $errors .= '<li><span class="LC_error">'.
12758: &mt('An error occurred storing the new custom role: [_1]',
12759: $result).'</span></li>';
12760: next;
12761: } else {
12762: $changedprivs{$rolename} = \%newprivs;
12763: $newrole = $rolename;
12764: }
12765: } else {
12766: $prefix = 'helproles_'.$num;
12767: $rolename = $env{'form.'.$prefix};
12768: next if ($rolename eq '');
12769: next unless (exists($existing{'rolesdef_'.$rolename}));
12770: $identifier = 'custhelp'.$num;
12771: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12772: my %currprivs;
12773: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
12774: split(/\_/,$existing{'rolesdef_'.$rolename});
12775: foreach my $level ('c','d','s') {
12776: if ($newprivs{$level} ne $currprivs{$level}) {
12777: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12778: $newprivs{'c'},$confname,$dom);
12779: if ($result ne 'ok') {
12780: $errors .= '<li><span class="LC_error">'.
12781: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
12782: $rolename,$result).'</span></li>';
12783: } else {
12784: $changedprivs{$rolename} = \%newprivs;
12785: }
12786: last;
12787: }
12788: }
12789: if (ref($current{'adhoc'}) eq 'HASH') {
12790: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12791: %curr = %{$current{'adhoc'}{$rolename}};
12792: }
12793: }
12794: }
12795: my $newpos = $env{'form.'.$prefix.'_pos'};
12796: $newpos =~ s/\D+//g;
12797: $allpos[$newpos] = $rolename;
12798: my $newdesc = $env{'form.'.$prefix.'_desc'};
12799: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
12800: if ($curr{'desc'}) {
12801: if ($curr{'desc'} ne $newdesc) {
12802: $changes{'customrole'}{$rolename}{'desc'} = 1;
12803: $newsettings{$rolename}{'desc'} = $newdesc;
12804: }
12805: } elsif ($newdesc ne '') {
12806: $changes{'customrole'}{$rolename}{'desc'} = 1;
12807: $newsettings{$rolename}{'desc'} = $newdesc;
12808: }
12809: my $access = $env{'form.'.$prefix.'_access'};
12810: if (grep(/^\Q$access\E$/,@accesstypes)) {
12811: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
12812: if ($access eq 'status') {
12813: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
12814: if (scalar(@statuses) == 0) {
12815: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
12816: } else {
12817: my (@shownstatus,$numtypes);
12818: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12819: if (ref($types) eq 'ARRAY') {
12820: $numtypes = scalar(@{$types});
12821: foreach my $type (sort(@statuses)) {
12822: if ($type eq 'default') {
12823: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12824: } elsif (grep(/^\Q$type\E$/,@{$types})) {
12825: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12826: push(@shownstatus,$usertypes->{$type});
12827: }
1.160.6.73 raeburn 12828: }
12829: }
1.160.6.77 raeburn 12830: if (grep(/^default$/,@statuses)) {
12831: push(@shownstatus,$othertitle);
12832: }
12833: if (scalar(@shownstatus) == 1+$numtypes) {
12834: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
12835: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
12836: } else {
12837: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
12838: if (ref($curr{'status'}) eq 'ARRAY') {
12839: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12840: if (@diffs) {
12841: $changes{'customrole'}{$rolename}{$access} = 1;
12842: }
12843: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12844: $changes{'customrole'}{$rolename}{$access} = 1;
12845: }
12846: }
12847: }
12848: } elsif (($access eq 'inc') || ($access eq 'exc')) {
12849: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
12850: my @newspecstaff;
12851: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12852: foreach my $person (sort(@personnel)) {
12853: if ($domhelpdesk{$person}) {
12854: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
12855: }
12856: }
12857: if (ref($curr{$access}) eq 'ARRAY') {
12858: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12859: if (@diffs) {
12860: $changes{'customrole'}{$rolename}{$access} = 1;
12861: }
12862: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12863: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 12864: }
1.160.6.77 raeburn 12865: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12866: my ($uname,$udom) = split(/:/,$person);
12867: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
12868: }
12869: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 12870: }
1.160.6.77 raeburn 12871: } else {
12872: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
12873: }
12874: unless ($curr{'access'} eq $access) {
12875: $changes{'customrole'}{$rolename}{'access'} = 1;
12876: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 12877: }
12878: }
1.160.6.77 raeburn 12879: if (@allpos > 0) {
12880: my $idx = 0;
12881: foreach my $rolename (@allpos) {
12882: if ($rolename ne '') {
12883: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
12884: if (ref($current{'adhoc'}) eq 'HASH') {
12885: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12886: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
12887: $changes{'customrole'}{$rolename}{'order'} = 1;
12888: $newsettings{$rolename}{'order'} = $idx+1;
12889: }
12890: }
1.160.6.73 raeburn 12891: }
1.160.6.77 raeburn 12892: $idx ++;
1.122 jms 12893: }
12894: }
1.118 jms 12895: }
1.123 jms 12896: my $putresult;
12897: if (keys(%changes) > 0) {
1.160.6.5 raeburn 12898: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
12899: if ($putresult eq 'ok') {
1.160.6.77 raeburn 12900: if (ref($helphash{'helpsettings'}) eq 'HASH') {
12901: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
12902: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
12903: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
12904: }
12905: }
12906: my $cachetime = 24*60*60;
12907: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12908: if (ref($lastactref) eq 'HASH') {
12909: $lastactref->{'domdefaults'} = 1;
12910: }
12911: } else {
12912: $errors .= '<li><span class="LC_error">'.
12913: &mt('An error occurred storing the settings: [_1]',
12914: $putresult).'</span></li>';
12915: }
12916: }
12917: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
12918: $resulttext = &mt('Changes made:').'<ul>';
12919: my (%shownprivs,@levelorder);
12920: @levelorder = ('c','d','s');
12921: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 12922: foreach my $item (sort(keys(%changes))) {
12923: if ($item eq 'submitbugs') {
12924: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
12925: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
12926: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 12927: } elsif ($item eq 'customrole') {
12928: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 12929: my @keyorder = ('order','desc','access','status','exc','inc');
12930: my %keytext = &Apache::lonlocal::texthash(
12931: order => 'Order',
12932: desc => 'Role description',
12933: access => 'Role usage',
1.160.6.83 raeburn 12934: status => 'Allowed institutional types',
1.160.6.77 raeburn 12935: exc => 'Allowed personnel',
12936: inc => 'Disallowed personnel',
12937: );
1.160.6.73 raeburn 12938: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 12939: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
12940: if ($role eq $newrole) {
12941: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
12942: $role).'<ul>';
12943: } else {
12944: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12945: $role).'<ul>';
12946: }
12947: foreach my $key (@keyorder) {
12948: if ($changes{'customrole'}{$role}{$key}) {
12949: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
12950: $keytext{$key},$newsettings{$role}{$key}).
12951: '</li>';
12952: }
12953: }
12954: if (ref($changedprivs{$role}) eq 'HASH') {
12955: $shownprivs{$role} = 1;
12956: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
12957: foreach my $level (@levelorder) {
12958: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12959: next if ($item eq '');
12960: my ($priv) = split(/\&/,$item,2);
12961: if (&Apache::lonnet::plaintext($priv)) {
12962: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12963: unless ($level eq 'c') {
12964: $resulttext .= ' ('.$lt{$level}.')';
12965: }
12966: $resulttext .= '</li>';
12967: }
12968: }
12969: }
12970: $resulttext .= '</ul>';
12971: }
12972: $resulttext .= '</ul></li>';
12973: }
1.160.6.73 raeburn 12974: }
12975: }
1.160.6.5 raeburn 12976: }
12977: }
12978: }
1.160.6.77 raeburn 12979: if (keys(%changedprivs)) {
12980: foreach my $role (sort(keys(%changedprivs))) {
12981: unless ($shownprivs{$role}) {
12982: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12983: $role).'<ul>'.
12984: '<li>'.&mt('Privileges set to :').'<ul>';
12985: foreach my $level (@levelorder) {
12986: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12987: next if ($item eq '');
12988: my ($priv) = split(/\&/,$item,2);
12989: if (&Apache::lonnet::plaintext($priv)) {
12990: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12991: unless ($level eq 'c') {
12992: $resulttext .= ' ('.$lt{$level}.')';
12993: }
12994: $resulttext .= '</li>';
12995: }
12996: }
12997: }
12998: $resulttext .= '</ul></li></ul></li>';
12999: }
13000: }
13001: }
13002: $resulttext .= '</ul>';
13003: } else {
13004: $resulttext = &mt('No changes made to help settings');
1.118 jms 13005: }
13006: if ($errors) {
1.160.6.5 raeburn 13007: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 13008: $errors.'</ul>';
1.118 jms 13009: }
13010: return $resulttext;
13011: }
13012:
1.121 raeburn 13013: sub modify_coursedefaults {
1.160.6.27 raeburn 13014: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 13015: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 13016: my %defaultchecked = (
13017: 'uselcmath' => 'on',
13018: 'usejsme' => 'on'
13019: );
13020: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 13021: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 13022: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
13023: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 13024: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 13025: my %staticdefaults = (
13026: anonsurvey_threshold => 10,
13027: uploadquota => 500,
1.160.6.57 raeburn 13028: postsubmit => 60,
1.160.6.70 raeburn 13029: mysqltables => 172800,
1.160.6.21 raeburn 13030: );
1.121 raeburn 13031:
13032: $defaultshash{'coursedefaults'} = {};
13033:
13034: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
13035: if ($domconfig{'coursedefaults'} eq '') {
13036: $domconfig{'coursedefaults'} = {};
13037: }
13038: }
13039:
13040: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
13041: foreach my $item (@toggles) {
13042: if ($defaultchecked{$item} eq 'on') {
13043: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13044: ($env{'form.'.$item} eq '0')) {
13045: $changes{$item} = 1;
1.160.6.16 raeburn 13046: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 13047: $changes{$item} = 1;
13048: }
13049: } elsif ($defaultchecked{$item} eq 'off') {
13050: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13051: ($env{'form.'.$item} eq '1')) {
13052: $changes{$item} = 1;
13053: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13054: $changes{$item} = 1;
13055: }
13056: }
13057: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13058: }
1.160.6.21 raeburn 13059: foreach my $item (@numbers) {
13060: my ($currdef,$newdef);
1.160.6.26 raeburn 13061: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 13062: if ($item eq 'anonsurvey_threshold') {
13063: $currdef = $domconfig{'coursedefaults'}{$item};
13064: $newdef =~ s/\D//g;
13065: if ($newdef eq '' || $newdef < 1) {
13066: $newdef = 1;
13067: }
13068: $defaultshash{'coursedefaults'}{$item} = $newdef;
13069: } else {
1.160.6.70 raeburn 13070: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13071: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13072: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 13073: }
13074: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 13075: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 13076: }
13077: if ($currdef ne $newdef) {
13078: my $staticdef;
13079: if ($item eq 'anonsurvey_threshold') {
13080: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13081: $changes{$item} = 1;
13082: }
1.160.6.70 raeburn 13083: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
13084: my $setting = $1;
13085: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13086: $changes{$setting} = 1;
1.160.6.21 raeburn 13087: }
13088: }
1.139 raeburn 13089: }
13090: }
1.160.6.64 raeburn 13091: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13092: my @currclonecode;
13093: if (ref($currclone) eq 'HASH') {
13094: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13095: @currclonecode = @{$currclone->{'instcode'}};
13096: }
13097: }
13098: my $newclone;
13099: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
13100: $newclone = $env{'form.canclone'};
13101: }
13102: if ($newclone eq 'instcode') {
13103: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13104: my (%codedefaults,@code_order,@clonecode);
13105: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13106: \@code_order);
13107: foreach my $item (@code_order) {
13108: if (grep(/^\Q$item\E$/,@newcodes)) {
13109: push(@clonecode,$item);
13110: }
13111: }
13112: if (@clonecode) {
13113: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13114: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13115: if (@diffs) {
13116: $changes{'canclone'} = 1;
13117: }
13118: } else {
13119: $newclone eq '';
13120: }
13121: } elsif ($newclone ne '') {
13122: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13123: }
13124: if ($newclone ne $currclone) {
13125: $changes{'canclone'} = 1;
13126: }
1.160.6.57 raeburn 13127: my %credits;
13128: foreach my $type (@types) {
13129: unless ($type eq 'community') {
13130: $credits{$type} = $env{'form.'.$type.'_credits'};
13131: $credits{$type} =~ s/[^\d.]+//g;
13132: }
13133: }
13134: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13135: ($env{'form.coursecredits'} eq '1')) {
13136: $changes{'coursecredits'} = 1;
13137: foreach my $type (keys(%credits)) {
13138: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13139: }
13140: } else {
13141: if ($env{'form.coursecredits'} eq '1') {
13142: foreach my $type (@types) {
13143: unless ($type eq 'community') {
13144: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
13145: $changes{'coursecredits'} = 1;
13146: }
13147: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13148: }
13149: }
13150: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13151: foreach my $type (@types) {
13152: unless ($type eq 'community') {
13153: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13154: $changes{'coursecredits'} = 1;
13155: last;
13156: }
13157: }
13158: }
13159: }
13160: }
13161: if ($env{'form.postsubmit'} eq '1') {
13162: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13163: my %currtimeout;
13164: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13165: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13166: $changes{'postsubmit'} = 1;
13167: }
13168: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13169: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13170: }
13171: } else {
13172: $changes{'postsubmit'} = 1;
13173: }
13174: foreach my $type (@types) {
13175: my $timeout = $env{'form.'.$type.'_timeout'};
13176: $timeout =~ s/\D//g;
13177: if ($timeout == $staticdefaults{'postsubmit'}) {
13178: $timeout = '';
13179: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13180: $timeout = '0';
13181: }
13182: unless ($timeout eq '') {
13183: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13184: }
13185: if (exists($currtimeout{$type})) {
13186: if ($timeout ne $currtimeout{$type}) {
13187: $changes{'postsubmit'} = 1;
13188: }
13189: } elsif ($timeout ne '') {
13190: $changes{'postsubmit'} = 1;
13191: }
13192: }
13193: } else {
13194: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13195: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13196: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13197: $changes{'postsubmit'} = 1;
13198: }
13199: } else {
13200: $changes{'postsubmit'} = 1;
13201: }
1.160.6.16 raeburn 13202: }
1.121 raeburn 13203: }
13204: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13205: $dom);
13206: if ($putresult eq 'ok') {
13207: if (keys(%changes) > 0) {
1.160.6.27 raeburn 13208: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 13209: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 13210: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.70 raeburn 13211: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.160.6.57 raeburn 13212: foreach my $item ('uselcmath','usejsme') {
13213: if ($changes{$item}) {
13214: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
13215: }
1.160.6.16 raeburn 13216: }
13217: if ($changes{'coursecredits'}) {
13218: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 13219: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
13220: $domdefaults{$type.'credits'} =
13221: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
13222: }
13223: }
13224: }
13225: if ($changes{'postsubmit'}) {
13226: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13227: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13228: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13229: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13230: $domdefaults{$type.'postsubtimeout'} =
13231: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13232: }
13233: }
1.160.6.16 raeburn 13234: }
13235: }
1.160.6.21 raeburn 13236: if ($changes{'uploadquota'}) {
13237: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13238: foreach my $type (@types) {
13239: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13240: }
13241: }
13242: }
1.160.6.64 raeburn 13243: if ($changes{'canclone'}) {
13244: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13245: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13246: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13247: if (@clonecodes) {
13248: $domdefaults{'canclone'} = join('+',@clonecodes);
13249: }
13250: }
13251: } else {
13252: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13253: }
13254: }
1.121 raeburn 13255: my $cachetime = 24*60*60;
13256: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 13257: if (ref($lastactref) eq 'HASH') {
13258: $lastactref->{'domdefaults'} = 1;
13259: }
1.121 raeburn 13260: }
13261: $resulttext = &mt('Changes made:').'<ul>';
13262: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 13263: if ($item eq 'uselcmath') {
1.121 raeburn 13264: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 13265: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 13266: } else {
1.160.6.57 raeburn 13267: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13268: }
13269: } elsif ($item eq 'usejsme') {
13270: if ($env{'form.'.$item} eq '1') {
13271: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13272: } else {
13273: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 13274: }
1.139 raeburn 13275: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 13276: $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 13277: } elsif ($item eq 'uploadquota') {
13278: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13279: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13280: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13281: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 13282: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
13283:
1.160.6.21 raeburn 13284: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13285: '</ul>'.
13286: '</li>';
13287: } else {
13288: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13289: }
1.160.6.70 raeburn 13290: } elsif ($item eq 'mysqltables') {
13291: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13292: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13293: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13294: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13295: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13296: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13297: '</ul>'.
13298: '</li>';
13299: } else {
13300: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13301: }
1.160.6.57 raeburn 13302: } elsif ($item eq 'postsubmit') {
13303: if ($domdefaults{'postsubmit'} eq 'off') {
13304: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13305: } else {
13306: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
13307: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13308: $resulttext .= &mt('durations:').'<ul>';
13309: foreach my $type (@types) {
13310: $resulttext .= '<li>';
13311: my $timeout;
13312: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13313: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13314: }
13315: my $display;
13316: if ($timeout eq '0') {
13317: $display = &mt('unlimited');
13318: } elsif ($timeout eq '') {
13319: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13320: } else {
13321: $display = &mt('[quant,_1,second]',$timeout);
13322: }
13323: if ($type eq 'community') {
13324: $resulttext .= &mt('Communities');
13325: } elsif ($type eq 'official') {
13326: $resulttext .= &mt('Official courses');
13327: } elsif ($type eq 'unofficial') {
13328: $resulttext .= &mt('Unofficial courses');
13329: } elsif ($type eq 'textbook') {
13330: $resulttext .= &mt('Textbook courses');
13331: }
13332: $resulttext .= ' -- '.$display.'</li>';
13333: }
13334: $resulttext .= '</ul>';
13335: }
13336: $resulttext .= '</li>';
13337: }
1.160.6.16 raeburn 13338: } elsif ($item eq 'coursecredits') {
13339: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13340: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 13341: ($domdefaults{'unofficialcredits'} eq '') &&
13342: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 13343: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13344: } else {
13345: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13346: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13347: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 13348: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 13349: '</ul>'.
13350: '</li>';
13351: }
13352: } else {
13353: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13354: }
1.160.6.64 raeburn 13355: } elsif ($item eq 'canclone') {
13356: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13357: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13358: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13359: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13360: }
13361: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13362: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13363: } else {
13364: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
13365: }
1.140 raeburn 13366: }
1.121 raeburn 13367: }
13368: $resulttext .= '</ul>';
13369: } else {
13370: $resulttext = &mt('No changes made to course defaults');
13371: }
13372: } else {
13373: $resulttext = '<span class="LC_error">'.
13374: &mt('An error occurred: [_1]',$putresult).'</span>';
13375: }
13376: return $resulttext;
13377: }
13378:
1.160.6.37 raeburn 13379: sub modify_selfenrollment {
13380: my ($dom,$lastactref,%domconfig) = @_;
13381: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
13382: my @types = ('official','unofficial','community','textbook');
13383: my %titles = &tool_titles();
13384: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13385: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
13386: $ordered{'default'} = ['types','registered','approval','limit'];
13387:
13388: my (%roles,%shown,%toplevel);
13389: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13390:
13391: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13392: if ($domconfig{'selfenrollment'} eq '') {
13393: $domconfig{'selfenrollment'} = {};
13394: }
13395: }
13396: %toplevel = (
13397: admin => 'Configuration Rights',
13398: default => 'Default settings',
13399: validation => 'Validation of self-enrollment requests',
13400: );
13401: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
13402:
13403: if (ref($ordered{'admin'}) eq 'ARRAY') {
13404: foreach my $item (@{$ordered{'admin'}}) {
13405: foreach my $type (@types) {
13406: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13407: $selfenrollhash{'admin'}{$type}{$item} = 1;
13408: } else {
13409: $selfenrollhash{'admin'}{$type}{$item} = 0;
13410: }
13411: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13412: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13413: if ($selfenrollhash{'admin'}{$type}{$item} ne
13414: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13415: push(@{$changes{'admin'}{$type}},$item);
13416: }
13417: } else {
13418: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13419: push(@{$changes{'admin'}{$type}},$item);
13420: }
13421: }
13422: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13423: push(@{$changes{'admin'}{$type}},$item);
13424: }
13425: }
13426: }
13427: }
13428:
13429: foreach my $item (@{$ordered{'default'}}) {
13430: foreach my $type (@types) {
13431: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13432: if ($item eq 'types') {
13433: unless (($value eq 'all') || ($value eq 'dom')) {
13434: $value = '';
13435: }
13436: } elsif ($item eq 'registered') {
13437: unless ($value eq '1') {
13438: $value = 0;
13439: }
13440: } elsif ($item eq 'approval') {
13441: unless ($value =~ /^[012]$/) {
13442: $value = 0;
13443: }
13444: } else {
13445: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13446: $value = 'none';
13447: }
13448: }
13449: $selfenrollhash{'default'}{$type}{$item} = $value;
13450: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13451: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13452: if ($selfenrollhash{'default'}{$type}{$item} ne
13453: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13454: push(@{$changes{'default'}{$type}},$item);
13455: }
13456: } else {
13457: push(@{$changes{'default'}{$type}},$item);
13458: }
13459: } else {
13460: push(@{$changes{'default'}{$type}},$item);
13461: }
13462: if ($item eq 'limit') {
13463: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13464: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13465: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13466: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13467: }
13468: } else {
13469: $selfenrollhash{'default'}{$type}{'cap'} = '';
13470: }
13471: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13472: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13473: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13474: push(@{$changes{'default'}{$type}},'cap');
13475: }
13476: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13477: push(@{$changes{'default'}{$type}},'cap');
13478: }
13479: }
13480: }
13481: }
13482:
13483: foreach my $item (@{$itemsref}) {
13484: if ($item eq 'fields') {
13485: my @changed;
13486: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13487: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13488: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13489: }
13490: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13491: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13492: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13493: $domconfig{'selfenrollment'}{'validation'}{$item});
13494: } else {
13495: @changed = @{$selfenrollhash{'validation'}{$item}};
13496: }
13497: } else {
13498: @changed = @{$selfenrollhash{'validation'}{$item}};
13499: }
13500: if (@changed) {
13501: if ($selfenrollhash{'validation'}{$item}) {
13502: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13503: } else {
13504: $changes{'validation'}{$item} = &mt('None');
13505: }
13506: }
13507: } else {
13508: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13509: if ($item eq 'markup') {
13510: if ($env{'form.selfenroll_validation_'.$item}) {
13511: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13512: }
13513: }
13514: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13515: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13516: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13517: }
13518: }
13519: }
13520: }
13521:
13522: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13523: $dom);
13524: if ($putresult eq 'ok') {
13525: if (keys(%changes) > 0) {
13526: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13527: $resulttext = &mt('Changes made:').'<ul>';
13528: foreach my $key ('admin','default','validation') {
13529: if (ref($changes{$key}) eq 'HASH') {
13530: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13531: if ($key eq 'validation') {
13532: foreach my $item (@{$itemsref}) {
13533: if (exists($changes{$key}{$item})) {
13534: if ($item eq 'markup') {
13535: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13536: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13537: } else {
13538: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13539: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13540: }
13541: }
13542: }
13543: } else {
13544: foreach my $type (@types) {
13545: if ($type eq 'community') {
13546: $roles{'1'} = &mt('Community personnel');
13547: } else {
13548: $roles{'1'} = &mt('Course personnel');
13549: }
13550: if (ref($changes{$key}{$type}) eq 'ARRAY') {
13551: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13552: if ($key eq 'admin') {
13553: my @mgrdc = ();
13554: if (ref($ordered{$key}) eq 'ARRAY') {
13555: foreach my $item (@{$ordered{'admin'}}) {
13556: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13557: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13558: push(@mgrdc,$item);
13559: }
13560: }
13561: }
13562: if (@mgrdc) {
13563: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
13564: } else {
13565: delete($domdefaults{$type.'selfenrolladmdc'});
13566: }
13567: }
13568: } else {
13569: if (ref($ordered{$key}) eq 'ARRAY') {
13570: foreach my $item (@{$ordered{$key}}) {
13571: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13572: $domdefaults{$type.'selfenroll'.$item} =
13573: $selfenrollhash{$key}{$type}{$item};
13574: }
13575: }
13576: }
13577: }
13578: }
13579: $resulttext .= '<li>'.$titles{$type}.'<ul>';
13580: foreach my $item (@{$ordered{$key}}) {
13581: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13582: $resulttext .= '<li>';
13583: if ($key eq 'admin') {
13584: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
13585: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
13586: } else {
13587: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
13588: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
13589: }
13590: $resulttext .= '</li>';
13591: }
13592: }
13593: $resulttext .= '</ul></li>';
13594: }
13595: }
13596: $resulttext .= '</ul></li>';
13597: }
13598: }
13599: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
13600: my $cachetime = 24*60*60;
13601: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13602: if (ref($lastactref) eq 'HASH') {
13603: $lastactref->{'domdefaults'} = 1;
13604: }
13605: }
13606: }
13607: $resulttext .= '</ul>';
13608: } else {
13609: $resulttext = &mt('No changes made to self-enrollment settings');
13610: }
13611: } else {
13612: $resulttext = '<span class="LC_error">'.
13613: &mt('An error occurred: [_1]',$putresult).'</span>';
13614: }
13615: return $resulttext;
13616: }
13617:
1.137 raeburn 13618: sub modify_usersessions {
1.160.6.27 raeburn 13619: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 13620: my @hostingtypes = ('version','excludedomain','includedomain');
13621: my @offloadtypes = ('primary','default');
13622: my %types = (
13623: remote => \@hostingtypes,
13624: hosted => \@hostingtypes,
13625: spares => \@offloadtypes,
13626: );
13627: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 13628: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 13629: my (%by_ip,%by_location,@intdoms);
13630: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
13631: my @locations = sort(keys(%by_location));
1.137 raeburn 13632: my (%defaultshash,%changes);
13633: foreach my $prefix (@prefixes) {
13634: $defaultshash{'usersessions'}{$prefix} = {};
13635: }
1.160.6.27 raeburn 13636: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 13637: my $resulttext;
1.138 raeburn 13638: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 13639: foreach my $prefix (@prefixes) {
1.145 raeburn 13640: next if ($prefix eq 'spares');
13641: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 13642: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13643: if ($type eq 'version') {
13644: my $value = $env{'form.'.$prefix.'_'.$type};
13645: my $okvalue;
13646: if ($value ne '') {
13647: if (grep(/^\Q$value\E$/,@lcversions)) {
13648: $okvalue = $value;
13649: }
13650: }
13651: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13652: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13653: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
13654: if ($inuse == 0) {
13655: $changes{$prefix}{$type} = 1;
13656: } else {
13657: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
13658: $changes{$prefix}{$type} = 1;
13659: }
13660: if ($okvalue ne '') {
13661: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13662: }
13663: }
13664: } else {
13665: if (($inuse == 1) && ($okvalue ne '')) {
13666: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13667: $changes{$prefix}{$type} = 1;
13668: }
13669: }
13670: } else {
13671: if (($inuse == 1) && ($okvalue ne '')) {
13672: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13673: $changes{$prefix}{$type} = 1;
13674: }
13675: }
13676: } else {
13677: if (($inuse == 1) && ($okvalue ne '')) {
13678: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13679: $changes{$prefix}{$type} = 1;
13680: }
13681: }
13682: } else {
13683: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13684: my @okvals;
13685: foreach my $val (@vals) {
1.138 raeburn 13686: if ($val =~ /:/) {
13687: my @items = split(/:/,$val);
13688: foreach my $item (@items) {
13689: if (ref($by_location{$item}) eq 'ARRAY') {
13690: push(@okvals,$item);
13691: }
13692: }
13693: } else {
13694: if (ref($by_location{$val}) eq 'ARRAY') {
13695: push(@okvals,$val);
13696: }
1.137 raeburn 13697: }
13698: }
13699: @okvals = sort(@okvals);
13700: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13701: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13702: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13703: if ($inuse == 0) {
13704: $changes{$prefix}{$type} = 1;
13705: } else {
13706: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13707: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
13708: if (@changed > 0) {
13709: $changes{$prefix}{$type} = 1;
13710: }
13711: }
13712: } else {
13713: if ($inuse == 1) {
13714: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13715: $changes{$prefix}{$type} = 1;
13716: }
13717: }
13718: } else {
13719: if ($inuse == 1) {
13720: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13721: $changes{$prefix}{$type} = 1;
13722: }
13723: }
13724: } else {
13725: if ($inuse == 1) {
13726: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13727: $changes{$prefix}{$type} = 1;
13728: }
13729: }
13730: }
13731: }
13732: }
1.145 raeburn 13733:
13734: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 13735: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 13736: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
13737: my $savespares;
13738:
13739: foreach my $lonhost (sort(keys(%servers))) {
13740: my $serverhomeID =
13741: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 13742: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 13743: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
13744: my %spareschg;
13745: foreach my $type (@{$types{'spares'}}) {
13746: my @okspares;
13747: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
13748: foreach my $server (@checked) {
1.152 raeburn 13749: if (&Apache::lonnet::hostname($server) ne '') {
13750: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
13751: unless (grep(/^\Q$server\E$/,@okspares)) {
13752: push(@okspares,$server);
13753: }
1.145 raeburn 13754: }
13755: }
13756: }
13757: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
13758: my $newspare;
1.152 raeburn 13759: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
13760: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 13761: $newspare = $new;
13762: }
13763: }
1.152 raeburn 13764: my @spares;
13765: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
13766: @spares = sort(@okspares,$newspare);
13767: } else {
13768: @spares = sort(@okspares);
13769: }
13770: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 13771: if (ref($spareid{$lonhost}) eq 'HASH') {
13772: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 13773: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 13774: if (@diffs > 0) {
13775: $spareschg{$type} = 1;
13776: }
13777: }
13778: }
13779: }
13780: if (keys(%spareschg) > 0) {
13781: $changes{'spares'}{$lonhost} = \%spareschg;
13782: }
13783: }
1.160.6.61 raeburn 13784: $defaultshash{'usersessions'}{'offloadnow'} = {};
13785: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
13786: my @okoffload;
13787: if (@offloadnow) {
13788: foreach my $server (@offloadnow) {
13789: if (&Apache::lonnet::hostname($server) ne '') {
13790: unless (grep(/^\Q$server\E$/,@okoffload)) {
13791: push(@okoffload,$server);
13792: }
13793: }
13794: }
13795: if (@okoffload) {
13796: foreach my $lonhost (@okoffload) {
13797: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
13798: }
13799: }
13800: }
1.145 raeburn 13801: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13802: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
13803: if (ref($changes{'spares'}) eq 'HASH') {
13804: if (keys(%{$changes{'spares'}}) > 0) {
13805: $savespares = 1;
13806: }
13807: }
13808: } else {
13809: $savespares = 1;
13810: }
1.160.6.61 raeburn 13811: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
13812: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
13813: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
13814: $changes{'offloadnow'} = 1;
13815: last;
13816: }
13817: }
13818: unless ($changes{'offloadnow'}) {
13819: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
13820: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
13821: $changes{'offloadnow'} = 1;
13822: last;
13823: }
13824: }
13825: }
13826: } elsif (@okoffload) {
13827: $changes{'offloadnow'} = 1;
13828: }
13829: } elsif (@okoffload) {
13830: $changes{'offloadnow'} = 1;
1.145 raeburn 13831: }
1.147 raeburn 13832: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
13833: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 13834: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13835: $dom);
13836: if ($putresult eq 'ok') {
13837: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13838: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
13839: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
13840: }
13841: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
13842: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
13843: }
1.160.6.61 raeburn 13844: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13845: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
13846: }
1.137 raeburn 13847: }
13848: my $cachetime = 24*60*60;
13849: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 13850: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 13851: if (ref($lastactref) eq 'HASH') {
13852: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 13853: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 13854: }
1.147 raeburn 13855: if (keys(%changes) > 0) {
13856: my %lt = &usersession_titles();
13857: $resulttext = &mt('Changes made:').'<ul>';
13858: foreach my $prefix (@prefixes) {
13859: if (ref($changes{$prefix}) eq 'HASH') {
13860: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13861: if ($prefix eq 'spares') {
13862: if (ref($changes{$prefix}) eq 'HASH') {
13863: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
13864: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 13865: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 13866: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
13867: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 13868: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
13869: foreach my $type (@{$types{$prefix}}) {
13870: if ($changes{$prefix}{$lonhost}{$type}) {
13871: my $offloadto = &mt('None');
13872: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
13873: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
13874: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
13875: }
1.145 raeburn 13876: }
1.147 raeburn 13877: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 13878: }
1.137 raeburn 13879: }
13880: }
1.147 raeburn 13881: $resulttext .= '</li>';
1.137 raeburn 13882: }
13883: }
1.147 raeburn 13884: } else {
13885: foreach my $type (@{$types{$prefix}}) {
13886: if (defined($changes{$prefix}{$type})) {
13887: my $newvalue;
13888: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13889: if (ref($defaultshash{'usersessions'}{$prefix})) {
13890: if ($type eq 'version') {
13891: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
13892: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13893: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
13894: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
13895: }
1.145 raeburn 13896: }
13897: }
13898: }
1.147 raeburn 13899: if ($newvalue eq '') {
13900: if ($type eq 'version') {
13901: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
13902: } else {
13903: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13904: }
1.145 raeburn 13905: } else {
1.147 raeburn 13906: if ($type eq 'version') {
13907: $newvalue .= ' '.&mt('(or later)');
13908: }
13909: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 13910: }
1.137 raeburn 13911: }
13912: }
13913: }
1.147 raeburn 13914: $resulttext .= '</ul>';
1.137 raeburn 13915: }
13916: }
1.160.6.61 raeburn 13917: if ($changes{'offloadnow'}) {
13918: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13919: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
13920: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
13921: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
13922: $resulttext .= '<li>'.$lonhost.'</li>';
13923: }
13924: $resulttext .= '</ul>';
13925: } else {
13926: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
13927: }
13928: } else {
13929: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
13930: }
13931: }
1.147 raeburn 13932: $resulttext .= '</ul>';
13933: } else {
13934: $resulttext = $nochgmsg;
1.137 raeburn 13935: }
13936: } else {
13937: $resulttext = '<span class="LC_error">'.
13938: &mt('An error occurred: [_1]',$putresult).'</span>';
13939: }
13940: } else {
1.147 raeburn 13941: $resulttext = $nochgmsg;
1.137 raeburn 13942: }
13943: return $resulttext;
13944: }
13945:
1.150 raeburn 13946: sub modify_loadbalancing {
13947: my ($dom,%domconfig) = @_;
13948: my $primary_id = &Apache::lonnet::domain($dom,'primary');
13949: my $intdom = &Apache::lonnet::internet_dom($primary_id);
13950: my ($othertitle,$usertypes,$types) =
13951: &Apache::loncommon::sorted_inst_types($dom);
13952: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 13953: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 13954: my @sparestypes = ('primary','default');
13955: my %typetitles = &sparestype_titles();
13956: my $resulttext;
1.160.6.7 raeburn 13957: my (%currbalancer,%currtargets,%currrules,%existing);
13958: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13959: %existing = %{$domconfig{'loadbalancing'}};
13960: }
13961: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
13962: \%currtargets,\%currrules);
13963: my ($saveloadbalancing,%defaultshash,%changes);
13964: my ($alltypes,$othertypes,$titles) =
13965: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
13966: my %ruletitles = &offloadtype_text();
13967: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
13968: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
13969: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
13970: if ($balancer eq '') {
13971: next;
13972: }
13973: if (!exists($servers{$balancer})) {
13974: if (exists($currbalancer{$balancer})) {
13975: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 13976: }
1.160.6.7 raeburn 13977: next;
13978: }
13979: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
13980: push(@{$changes{'delete'}},$balancer);
13981: next;
13982: }
13983: if (!exists($currbalancer{$balancer})) {
13984: push(@{$changes{'add'}},$balancer);
13985: }
13986: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
13987: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
13988: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
13989: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13990: $saveloadbalancing = 1;
13991: }
13992: foreach my $sparetype (@sparestypes) {
13993: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
13994: my @offloadto;
13995: foreach my $target (@targets) {
13996: if (($servers{$target}) && ($target ne $balancer)) {
13997: if ($sparetype eq 'default') {
13998: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
13999: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14000: }
14001: }
1.160.6.7 raeburn 14002: unless(grep(/^\Q$target\E$/,@offloadto)) {
14003: push(@offloadto,$target);
14004: }
1.150 raeburn 14005: }
14006: }
1.160.6.76 raeburn 14007: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14008: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14009: push(@offloadto,$balancer);
14010: }
14011: }
14012: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14013: }
1.160.6.7 raeburn 14014: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14015: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 14016: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14017: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14018: if (@targetdiffs > 0) {
1.160.6.7 raeburn 14019: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14020: }
1.160.6.7 raeburn 14021: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14022: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14023: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14024: }
14025: }
14026: }
14027: } else {
1.160.6.7 raeburn 14028: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
14029: foreach my $sparetype (@sparestypes) {
14030: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14031: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14032: $changes{'curr'}{$balancer}{'targets'} = 1;
14033: }
1.150 raeburn 14034: }
14035: }
1.160.6.7 raeburn 14036: }
1.150 raeburn 14037: }
14038: my $ishomedom;
1.160.6.7 raeburn 14039: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14040: $ishomedom = 1;
1.150 raeburn 14041: }
14042: if (ref($alltypes) eq 'ARRAY') {
14043: foreach my $type (@{$alltypes}) {
14044: my $rule;
1.160.6.7 raeburn 14045: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14046: (!$ishomedom)) {
1.160.6.7 raeburn 14047: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14048: }
14049: if ($rule eq 'specific') {
1.160.6.55 raeburn 14050: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
14051: if (exists($servers{$specifiedhost})) {
14052: $rule = $specifiedhost;
14053: }
1.150 raeburn 14054: }
1.160.6.7 raeburn 14055: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14056: if (ref($currrules{$balancer}) eq 'HASH') {
14057: if ($rule ne $currrules{$balancer}{$type}) {
14058: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14059: }
14060: } elsif ($rule ne '') {
1.160.6.7 raeburn 14061: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14062: }
14063: }
14064: }
1.160.6.7 raeburn 14065: }
14066: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14067: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14068: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14069: $defaultshash{'loadbalancing'} = {};
14070: }
14071: my $putresult = &Apache::lonnet::put_dom('configuration',
14072: \%defaultshash,$dom);
14073: if ($putresult eq 'ok') {
14074: if (keys(%changes) > 0) {
1.160.6.54 raeburn 14075: my %toupdate;
1.160.6.7 raeburn 14076: if (ref($changes{'delete'}) eq 'ARRAY') {
14077: foreach my $balancer (sort(@{$changes{'delete'}})) {
14078: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 14079: $toupdate{$balancer} = 1;
1.150 raeburn 14080: }
1.160.6.7 raeburn 14081: }
14082: if (ref($changes{'add'}) eq 'ARRAY') {
14083: foreach my $balancer (sort(@{$changes{'add'}})) {
14084: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 14085: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 14086: }
14087: }
14088: if (ref($changes{'curr'}) eq 'HASH') {
14089: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 14090: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 14091: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14092: if ($changes{'curr'}{$balancer}{'targets'}) {
14093: my %offloadstr;
14094: foreach my $sparetype (@sparestypes) {
14095: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14096: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14097: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14098: }
14099: }
1.150 raeburn 14100: }
1.160.6.7 raeburn 14101: if (keys(%offloadstr) == 0) {
14102: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 14103: } else {
1.160.6.7 raeburn 14104: my $showoffload;
14105: foreach my $sparetype (@sparestypes) {
14106: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14107: if (defined($offloadstr{$sparetype})) {
14108: $showoffload .= $offloadstr{$sparetype};
14109: } else {
14110: $showoffload .= &mt('None');
14111: }
14112: $showoffload .= (' 'x3);
14113: }
14114: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 14115: }
14116: }
14117: }
1.160.6.7 raeburn 14118: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14119: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14120: foreach my $type (@{$alltypes}) {
14121: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14122: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14123: my $balancetext;
14124: if ($rule eq '') {
14125: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 14126: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 14127: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
14128: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 14129: foreach my $sparetype (@sparestypes) {
14130: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14131: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14132: }
14133: }
1.160.6.55 raeburn 14134: foreach my $item (@{$alltypes}) {
14135: next if ($item =~ /^_LC_ipchange/);
14136: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14137: if ($hasrule eq 'homeserver') {
14138: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14139: } else {
14140: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14141: if ($servers{$hasrule}) {
14142: $toupdate{$hasrule} = 1;
14143: }
14144: }
14145: }
14146: }
14147: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14148: $balancetext = $ruletitles{$rule};
14149: } else {
14150: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14151: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14152: if ($receiver) {
14153: $toupdate{$receiver};
14154: }
14155: }
14156: } else {
14157: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 14158: }
1.160.6.7 raeburn 14159: } else {
14160: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14161: }
1.160.6.26 raeburn 14162: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 14163: }
14164: }
14165: }
14166: }
1.160.6.54 raeburn 14167: if (keys(%toupdate)) {
14168: my %thismachine;
14169: my $updatedhere;
14170: my $cachetime = 60*60*24;
14171: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14172: foreach my $lonhost (keys(%toupdate)) {
14173: if ($thismachine{$lonhost}) {
14174: unless ($updatedhere) {
14175: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14176: $defaultshash{'loadbalancing'},
14177: $cachetime);
14178: $updatedhere = 1;
14179: }
14180: } else {
14181: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
14182: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14183: }
14184: }
14185: }
1.150 raeburn 14186: }
1.160.6.7 raeburn 14187: }
14188: if ($resulttext ne '') {
14189: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 14190: } else {
14191: $resulttext = $nochgmsg;
14192: }
14193: } else {
1.160.6.7 raeburn 14194: $resulttext = $nochgmsg;
1.150 raeburn 14195: }
14196: } else {
1.160.6.7 raeburn 14197: $resulttext = '<span class="LC_error">'.
14198: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 14199: }
14200: } else {
1.160.6.7 raeburn 14201: $resulttext = $nochgmsg;
1.150 raeburn 14202: }
14203: return $resulttext;
14204: }
14205:
1.48 raeburn 14206: sub recurse_check {
14207: my ($chkcats,$categories,$depth,$name) = @_;
14208: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
14209: my $chg = 0;
14210: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
14211: my $category = $chkcats->[$depth]{$name}[$j];
14212: my $item;
14213: if ($category eq '') {
14214: $chg ++;
14215: } else {
14216: my $deeper = $depth + 1;
14217: $item = &escape($category).':'.&escape($name).':'.$depth;
14218: if ($chg) {
14219: $categories->{$item} -= $chg;
14220: }
14221: &recurse_check($chkcats,$categories,$deeper,$category);
14222: $deeper --;
14223: }
14224: }
14225: }
14226: return;
14227: }
14228:
14229: sub recurse_cat_deletes {
14230: my ($item,$coursecategories,$deletions) = @_;
14231: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14232: my $subdepth = $depth + 1;
14233: if (ref($coursecategories) eq 'HASH') {
14234: foreach my $subitem (keys(%{$coursecategories})) {
14235: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14236: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14237: delete($coursecategories->{$subitem});
14238: $deletions->{$subitem} = 1;
14239: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 14240: }
1.48 raeburn 14241: }
14242: }
14243: return;
14244: }
14245:
1.125 raeburn 14246: sub active_dc_picker {
1.160.6.16 raeburn 14247: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 14248: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 14249: my @domcoord = keys(%domcoords);
14250: if (keys(%currhash)) {
14251: foreach my $dc (keys(%currhash)) {
14252: unless (exists($domcoords{$dc})) {
14253: push(@domcoord,$dc);
14254: }
14255: }
14256: }
14257: @domcoord = sort(@domcoord);
14258: my $numdcs = scalar(@domcoord);
14259: my $rows = 0;
14260: my $table;
1.125 raeburn 14261: if ($numdcs > 1) {
1.160.6.16 raeburn 14262: $table = '<table>';
14263: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 14264: my $rem = $i%($numinrow);
14265: if ($rem == 0) {
14266: if ($i > 0) {
1.160.6.16 raeburn 14267: $table .= '</tr>';
1.125 raeburn 14268: }
1.160.6.16 raeburn 14269: $table .= '<tr>';
14270: $rows ++;
1.125 raeburn 14271: }
1.160.6.16 raeburn 14272: my $check = '';
14273: if ($inputtype eq 'radio') {
14274: if (keys(%currhash) == 0) {
14275: if (!$i) {
14276: $check = ' checked="checked"';
14277: }
14278: } elsif (exists($currhash{$domcoord[$i]})) {
14279: $check = ' checked="checked"';
14280: }
14281: } else {
14282: if (exists($currhash{$domcoord[$i]})) {
14283: $check = ' checked="checked"';
1.125 raeburn 14284: }
14285: }
1.160.6.16 raeburn 14286: if ($i == @domcoord - 1) {
1.125 raeburn 14287: my $colsleft = $numinrow - $rem;
14288: if ($colsleft > 1) {
1.160.6.16 raeburn 14289: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 14290: } else {
1.160.6.16 raeburn 14291: $table .= '<td class="LC_left_item">';
1.125 raeburn 14292: }
14293: } else {
1.160.6.16 raeburn 14294: $table .= '<td class="LC_left_item">';
14295: }
14296: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14297: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14298: $table .= '<span class="LC_nobreak"><label>'.
14299: '<input type="'.$inputtype.'" name="'.$name.'"'.
14300: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14301: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 14302: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 14303: }
1.160.6.33 raeburn 14304: $table .= '</label></span></td>';
1.125 raeburn 14305: }
1.160.6.16 raeburn 14306: $table .= '</tr></table>';
14307: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 14308: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14309: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 14310: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 14311: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 14312: if ($user ne $dcname.':'.$dcdom) {
14313: $table .= ' ('.$dcname.':'.$dcdom.')';
14314: }
1.160.6.16 raeburn 14315: } else {
14316: my $check;
14317: if (exists($currhash{$domcoord[0]})) {
14318: $check = ' checked="checked"';
14319: }
1.160.6.50 raeburn 14320: $table = '<span class="LC_nobreak"><label>'.
14321: '<input type="checkbox" name="'.$name.'" '.
14322: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 14323: if ($user ne $dcname.':'.$dcdom) {
14324: $table .= ' ('.$dcname.':'.$dcdom.')';
14325: }
14326: $table .= '</label></span>';
1.160.6.16 raeburn 14327: $rows ++;
14328: }
1.125 raeburn 14329: }
1.160.6.16 raeburn 14330: return ($numdcs,$table,$rows);
1.125 raeburn 14331: }
14332:
1.137 raeburn 14333: sub usersession_titles {
14334: return &Apache::lonlocal::texthash(
14335: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14336: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 14337: spares => 'Servers offloaded to, when busy',
1.137 raeburn 14338: version => 'LON-CAPA version requirement',
1.138 raeburn 14339: excludedomain => 'Allow all, but exclude specific domains',
14340: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 14341: primary => 'Primary (checked first)',
1.154 raeburn 14342: default => 'Default',
1.137 raeburn 14343: );
14344: }
14345:
1.152 raeburn 14346: sub id_for_thisdom {
14347: my (%servers) = @_;
14348: my %altids;
14349: foreach my $server (keys(%servers)) {
14350: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14351: if ($serverhome ne $server) {
14352: $altids{$serverhome} = $server;
14353: }
14354: }
14355: return %altids;
14356: }
14357:
1.150 raeburn 14358: sub count_servers {
14359: my ($currbalancer,%servers) = @_;
14360: my (@spares,$numspares);
14361: foreach my $lonhost (sort(keys(%servers))) {
14362: next if ($currbalancer eq $lonhost);
14363: push(@spares,$lonhost);
14364: }
14365: if ($currbalancer) {
14366: $numspares = scalar(@spares);
14367: } else {
14368: $numspares = scalar(@spares) - 1;
14369: }
14370: return ($numspares,@spares);
14371: }
14372:
14373: sub lonbalance_targets_js {
1.160.6.7 raeburn 14374: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 14375: my $select = &mt('Select');
14376: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14377: if (ref($servers) eq 'HASH') {
14378: $alltargets = join("','",sort(keys(%{$servers})));
14379: my @homedoms;
14380: foreach my $server (sort(keys(%{$servers}))) {
14381: if (&Apache::lonnet::host_domain($server) eq $dom) {
14382: push(@homedoms,'1');
14383: } else {
14384: push(@homedoms,'0');
14385: }
14386: }
14387: $allishome = join("','",@homedoms);
14388: }
14389: if (ref($types) eq 'ARRAY') {
14390: if (@{$types} > 0) {
14391: @alltypes = @{$types};
14392: }
14393: }
14394: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14395: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 14396: my (%currbalancer,%currtargets,%currrules,%existing);
14397: if (ref($settings) eq 'HASH') {
14398: %existing = %{$settings};
14399: }
14400: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
14401: \%currtargets,\%currrules);
14402: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 14403: return <<"END";
14404:
14405: <script type="text/javascript">
14406: // <![CDATA[
14407:
1.160.6.7 raeburn 14408: currBalancers = new Array('$balancers');
14409:
14410: function toggleTargets(balnum) {
14411: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14412: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14413: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14414: var prevbalancer = prevhostitem.value;
14415: var baltotal = document.getElementById('loadbalancing_total').value;
14416: prevhostitem.value = balancer;
14417: if (prevbalancer != '') {
14418: var prevIdx = currBalancers.indexOf(prevbalancer);
14419: if (prevIdx != -1) {
14420: currBalancers.splice(prevIdx,1);
14421: }
14422: }
1.150 raeburn 14423: if (balancer == '') {
1.160.6.7 raeburn 14424: hideSpares(balnum);
1.150 raeburn 14425: } else {
1.160.6.7 raeburn 14426: var currIdx = currBalancers.indexOf(balancer);
14427: if (currIdx == -1) {
14428: currBalancers.push(balancer);
14429: }
1.150 raeburn 14430: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 14431: var ishomedom = homedoms[lonhostitem.selectedIndex];
14432: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 14433: }
1.160.6.7 raeburn 14434: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 14435: return;
14436: }
14437:
1.160.6.7 raeburn 14438: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 14439: var alltargets = new Array('$alltargets');
14440: var insttypes = new Array('$allinsttypes');
1.151 raeburn 14441: var offloadtypes = new Array('primary','default');
14442:
1.160.6.7 raeburn 14443: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14444: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 14445:
1.151 raeburn 14446: for (var i=0; i<offloadtypes.length; i++) {
14447: var count = 0;
14448: for (var j=0; j<alltargets.length; j++) {
14449: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 14450: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14451: item.value = alltargets[j];
14452: item.style.textAlign='left';
14453: item.style.textFace='normal';
14454: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14455: if (currBalancers.indexOf(alltargets[j]) == -1) {
14456: item.disabled = '';
14457: } else {
14458: item.disabled = 'disabled';
14459: item.checked = false;
14460: }
1.151 raeburn 14461: count ++;
14462: }
1.150 raeburn 14463: }
14464: }
1.151 raeburn 14465: for (var k=0; k<insttypes.length; k++) {
14466: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 14467: if (ishomedom == 1) {
1.160.6.7 raeburn 14468: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14469: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14470: } else {
1.160.6.7 raeburn 14471: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14472: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 14473: }
14474: } else {
1.160.6.7 raeburn 14475: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14476: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14477: }
1.151 raeburn 14478: if ((insttypes[k] != '_LC_external') &&
14479: ((insttypes[k] != '_LC_internetdom') ||
14480: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 14481: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
14482: item.options.length = 0;
14483: item.options[0] = new Option("","",true,true);
14484: var idx = 0;
1.151 raeburn 14485: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 14486: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
14487: idx ++;
14488: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 14489: }
14490: }
14491: }
14492: }
14493: return;
14494: }
14495:
1.160.6.7 raeburn 14496: function hideSpares(balnum) {
1.150 raeburn 14497: var alltargets = new Array('$alltargets');
14498: var insttypes = new Array('$allinsttypes');
14499: var offloadtypes = new Array('primary','default');
14500:
1.160.6.7 raeburn 14501: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
14502: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 14503:
14504: var total = alltargets.length - 1;
14505: for (var i=0; i<offloadtypes; i++) {
14506: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 14507: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
14508: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
14509: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 14510: }
1.150 raeburn 14511: }
14512: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 14513: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14514: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 14515: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 14516: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
14517: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 14518: }
14519: }
14520: return;
14521: }
14522:
1.160.6.7 raeburn 14523: function checkOffloads(item,balnum,type) {
1.150 raeburn 14524: var alltargets = new Array('$alltargets');
14525: var offloadtypes = new Array('primary','default');
14526: if (item.checked) {
14527: var total = alltargets.length - 1;
14528: var other;
14529: if (type == offloadtypes[0]) {
1.151 raeburn 14530: other = offloadtypes[1];
1.150 raeburn 14531: } else {
1.151 raeburn 14532: other = offloadtypes[0];
1.150 raeburn 14533: }
14534: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 14535: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 14536: if (server == item.value) {
1.160.6.7 raeburn 14537: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
14538: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 14539: }
14540: }
14541: }
14542: }
14543: return;
14544: }
14545:
1.160.6.7 raeburn 14546: function singleServerToggle(balnum,type) {
14547: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 14548: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 14549: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
14550: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14551:
14552: } else {
1.160.6.7 raeburn 14553: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
14554: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 14555: }
14556: return;
14557: }
14558:
1.160.6.7 raeburn 14559: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 14560: if (type == '_LC_external') {
1.160.6.26 raeburn 14561: return;
1.150 raeburn 14562: }
1.160.6.7 raeburn 14563: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 14564: for (var i=0; i<typesRules.length; i++) {
14565: if (formname.elements[typesRules[i]].checked) {
14566: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 14567: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
14568: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14569: } else {
1.160.6.7 raeburn 14570: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
14571: }
14572: }
14573: }
14574: return;
14575: }
14576:
14577: function balancerDeleteChange(balnum) {
14578: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14579: var baltotal = document.getElementById('loadbalancing_total').value;
14580: var addtarget;
14581: var removetarget;
14582: var action = 'delete';
14583: if (document.getElementById('loadbalancing_delete_'+balnum)) {
14584: var lonhost = hostitem.value;
14585: var currIdx = currBalancers.indexOf(lonhost);
14586: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
14587: if (currIdx != -1) {
14588: currBalancers.splice(currIdx,1);
14589: }
14590: addtarget = lonhost;
14591: } else {
14592: if (currIdx == -1) {
14593: currBalancers.push(lonhost);
14594: }
14595: removetarget = lonhost;
14596: action = 'undelete';
14597: }
14598: balancerChange(balnum,baltotal,action,addtarget,removetarget);
14599: }
14600: return;
14601: }
14602:
14603: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
14604: if (baltotal > 1) {
14605: var offloadtypes = new Array('primary','default');
14606: var alltargets = new Array('$alltargets');
14607: var insttypes = new Array('$allinsttypes');
14608: for (var i=0; i<baltotal; i++) {
14609: if (i != balnum) {
14610: for (var j=0; j<offloadtypes.length; j++) {
14611: var total = alltargets.length - 1;
14612: for (var k=0; k<total; k++) {
14613: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
14614: var server = serveritem.value;
14615: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14616: if (server == addtarget) {
14617: serveritem.disabled = '';
14618: }
14619: }
14620: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14621: if (server == removetarget) {
14622: serveritem.disabled = 'disabled';
14623: serveritem.checked = false;
14624: }
14625: }
14626: }
14627: }
14628: for (var j=0; j<insttypes.length; j++) {
14629: if (insttypes[j] != '_LC_external') {
14630: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
14631: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
14632: var currSel = singleserver.selectedIndex;
14633: var currVal = singleserver.options[currSel].value;
14634: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14635: var numoptions = singleserver.options.length;
14636: var needsnew = 1;
14637: for (var k=0; k<numoptions; k++) {
14638: if (singleserver.options[k] == addtarget) {
14639: needsnew = 0;
14640: break;
14641: }
14642: }
14643: if (needsnew == 1) {
14644: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
14645: }
14646: }
14647: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14648: singleserver.options.length = 0;
14649: if ((currVal) && (currVal != removetarget)) {
14650: singleserver.options[0] = new Option("","",false,false);
14651: } else {
14652: singleserver.options[0] = new Option("","",true,true);
14653: }
14654: var idx = 0;
14655: for (var m=0; m<alltargets.length; m++) {
14656: if (currBalancers.indexOf(alltargets[m]) == -1) {
14657: idx ++;
14658: if (currVal == alltargets[m]) {
14659: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
14660: } else {
14661: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
14662: }
14663: }
14664: }
14665: }
14666: }
14667: }
14668: }
1.150 raeburn 14669: }
14670: }
14671: }
14672: return;
14673: }
14674:
1.152 raeburn 14675: // ]]>
14676: </script>
14677:
14678: END
14679: }
14680:
14681: sub new_spares_js {
14682: my @sparestypes = ('primary','default');
14683: my $types = join("','",@sparestypes);
14684: my $select = &mt('Select');
14685: return <<"END";
14686:
14687: <script type="text/javascript">
14688: // <![CDATA[
14689:
14690: function updateNewSpares(formname,lonhost) {
14691: var types = new Array('$types');
14692: var include = new Array();
14693: var exclude = new Array();
14694: for (var i=0; i<types.length; i++) {
14695: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
14696: for (var j=0; j<spareboxes.length; j++) {
14697: if (formname.elements[spareboxes[j]].checked) {
14698: exclude.push(formname.elements[spareboxes[j]].value);
14699: } else {
14700: include.push(formname.elements[spareboxes[j]].value);
14701: }
14702: }
14703: }
14704: for (var i=0; i<types.length; i++) {
14705: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
14706: var selIdx = newSpare.selectedIndex;
14707: var currnew = newSpare.options[selIdx].value;
14708: var okSpares = new Array();
14709: for (var j=0; j<newSpare.options.length; j++) {
14710: var possible = newSpare.options[j].value;
14711: if (possible != '') {
14712: if (exclude.indexOf(possible) == -1) {
14713: okSpares.push(possible);
14714: } else {
14715: if (currnew == possible) {
14716: selIdx = 0;
14717: }
14718: }
14719: }
14720: }
14721: for (var k=0; k<include.length; k++) {
14722: if (okSpares.indexOf(include[k]) == -1) {
14723: okSpares.push(include[k]);
14724: }
14725: }
14726: okSpares.sort();
14727: newSpare.options.length = 0;
14728: if (selIdx == 0) {
14729: newSpare.options[0] = new Option("$select","",true,true);
14730: } else {
14731: newSpare.options[0] = new Option("$select","",false,false);
14732: }
14733: for (var m=0; m<okSpares.length; m++) {
14734: var idx = m+1;
14735: var selThis = 0;
14736: if (selIdx != 0) {
14737: if (okSpares[m] == currnew) {
14738: selThis = 1;
14739: }
14740: }
14741: if (selThis == 1) {
14742: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
14743: } else {
14744: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
14745: }
14746: }
14747: }
14748: return;
14749: }
14750:
14751: function checkNewSpares(lonhost,type) {
14752: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
14753: var chosen = newSpare.options[newSpare.selectedIndex].value;
14754: if (chosen != '') {
14755: var othertype;
14756: var othernewSpare;
14757: if (type == 'primary') {
14758: othernewSpare = document.getElementById('newspare_default_'+lonhost);
14759: }
14760: if (type == 'default') {
14761: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
14762: }
14763: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
14764: othernewSpare.selectedIndex = 0;
14765: }
14766: }
14767: return;
14768: }
14769:
14770: // ]]>
14771: </script>
14772:
14773: END
14774:
14775: }
14776:
14777: sub common_domprefs_js {
14778: return <<"END";
14779:
14780: <script type="text/javascript">
14781: // <![CDATA[
14782:
1.150 raeburn 14783: function getIndicesByName(formname,item) {
1.152 raeburn 14784: var group = new Array();
1.150 raeburn 14785: for (var i=0;i<formname.elements.length;i++) {
14786: if (formname.elements[i].name == item) {
1.152 raeburn 14787: group.push(formname.elements[i].id);
1.150 raeburn 14788: }
14789: }
1.152 raeburn 14790: return group;
1.150 raeburn 14791: }
14792:
14793: // ]]>
14794: </script>
14795:
14796: END
1.152 raeburn 14797:
1.150 raeburn 14798: }
14799:
1.160.6.5 raeburn 14800: sub recaptcha_js {
14801: my %lt = &captcha_phrases();
14802: return <<"END";
14803:
14804: <script type="text/javascript">
14805: // <![CDATA[
14806:
14807: function updateCaptcha(caller,context) {
14808: var privitem;
14809: var pubitem;
14810: var privtext;
14811: var pubtext;
1.160.6.69 raeburn 14812: var versionitem;
14813: var versiontext;
1.160.6.5 raeburn 14814: if (document.getElementById(context+'_recaptchapub')) {
14815: pubitem = document.getElementById(context+'_recaptchapub');
14816: } else {
14817: return;
14818: }
14819: if (document.getElementById(context+'_recaptchapriv')) {
14820: privitem = document.getElementById(context+'_recaptchapriv');
14821: } else {
14822: return;
14823: }
14824: if (document.getElementById(context+'_recaptchapubtxt')) {
14825: pubtext = document.getElementById(context+'_recaptchapubtxt');
14826: } else {
14827: return;
14828: }
14829: if (document.getElementById(context+'_recaptchaprivtxt')) {
14830: privtext = document.getElementById(context+'_recaptchaprivtxt');
14831: } else {
14832: return;
14833: }
1.160.6.69 raeburn 14834: if (document.getElementById(context+'_recaptchaversion')) {
14835: versionitem = document.getElementById(context+'_recaptchaversion');
14836: } else {
14837: return;
14838: }
14839: if (document.getElementById(context+'_recaptchavertxt')) {
14840: versiontext = document.getElementById(context+'_recaptchavertxt');
14841: } else {
14842: return;
14843: }
1.160.6.5 raeburn 14844: if (caller.checked) {
14845: if (caller.value == 'recaptcha') {
14846: pubitem.type = 'text';
14847: privitem.type = 'text';
14848: pubitem.size = '40';
14849: privitem.size = '40';
14850: pubtext.innerHTML = "$lt{'pub'}";
14851: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 14852: versionitem.type = 'text';
14853: versionitem.size = '3';
14854: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 14855: } else {
14856: pubitem.type = 'hidden';
14857: privitem.type = 'hidden';
1.160.6.69 raeburn 14858: versionitem.type = 'hidden';
1.160.6.5 raeburn 14859: pubtext.innerHTML = '';
14860: privtext.innerHTML = '';
1.160.6.69 raeburn 14861: versiontext.innerHTML = '';
1.160.6.5 raeburn 14862: }
14863: }
14864: return;
14865: }
14866:
14867: // ]]>
14868: </script>
14869:
14870: END
14871:
14872: }
14873:
1.160.6.40 raeburn 14874: sub toggle_display_js {
1.160.6.16 raeburn 14875: return <<"END";
14876:
14877: <script type="text/javascript">
14878: // <![CDATA[
14879:
1.160.6.40 raeburn 14880: function toggleDisplay(domForm,caller) {
14881: if (document.getElementById(caller)) {
14882: var divitem = document.getElementById(caller);
14883: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 14884: var checkval = 1;
14885: var dispval = 'block';
1.160.6.40 raeburn 14886: if (caller == 'emailoptions') {
14887: optionsElement = domForm.cancreate_email;
14888: }
1.160.6.57 raeburn 14889: if (caller == 'studentsubmission') {
14890: optionsElement = domForm.postsubmit;
14891: }
1.160.6.64 raeburn 14892: if (caller == 'cloneinstcode') {
14893: optionsElement = domForm.canclone;
14894: checkval = 'instcode';
14895: }
1.160.6.40 raeburn 14896: if (optionsElement.length) {
1.160.6.16 raeburn 14897: var currval;
1.160.6.40 raeburn 14898: for (var i=0; i<optionsElement.length; i++) {
14899: if (optionsElement[i].checked) {
14900: currval = optionsElement[i].value;
1.160.6.16 raeburn 14901: }
14902: }
1.160.6.64 raeburn 14903: if (currval == checkval) {
14904: divitem.style.display = dispval;
1.160.6.16 raeburn 14905: } else {
1.160.6.40 raeburn 14906: divitem.style.display = 'none';
1.160.6.16 raeburn 14907: }
14908: }
14909: }
14910: return;
14911: }
14912:
14913: // ]]>
14914: </script>
14915:
14916: END
14917:
14918: }
14919:
1.160.6.5 raeburn 14920: sub captcha_phrases {
14921: return &Apache::lonlocal::texthash (
14922: priv => 'Private key',
14923: pub => 'Public key',
14924: original => 'original (CAPTCHA)',
14925: recaptcha => 'successor (ReCAPTCHA)',
14926: notused => 'unused',
1.160.6.69 raeburn 14927: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 14928: );
14929: }
14930:
1.160.6.24 raeburn 14931: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 14932: my ($dom,$cachekeys) = @_;
14933: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 14934: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14935: my %thismachine;
14936: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.84.2. (raeburn 14937:): my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.160.6.61 raeburn 14938: if (keys(%servers)) {
1.160.6.24 raeburn 14939: foreach my $server (keys(%servers)) {
14940: next if ($thismachine{$server});
1.160.6.27 raeburn 14941: my @cached;
14942: foreach my $name (@posscached) {
14943: if ($cachekeys->{$name}) {
14944: push(@cached,&escape($name).':'.&escape($dom));
14945: }
14946: }
14947: if (@cached) {
14948: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
14949: }
1.160.6.24 raeburn 14950: }
14951: }
14952: return;
14953: }
14954:
1.3 raeburn 14955: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>